ol-debug.js 2.6 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777617786177961780617816178261783617846178561786617876178861789617906179161792617936179461795617966179761798617996180061801618026180361804618056180661807618086180961810618116181261813618146181561816618176181861819618206182161822618236182461825618266182761828618296183061831618326183361834618356183661837618386183961840618416184261843618446184561846618476184861849618506185161852618536185461855618566185761858618596186061861618626186361864618656186661867618686186961870618716187261873618746187561876618776187861879618806188161882618836188461885618866188761888618896189061891618926189361894618956189661897618986189961900619016190261903619046190561906619076190861909619106191161912619136191461915619166191761918619196192061921619226192361924619256192661927619286192961930619316193261933619346193561936619376193861939619406194161942619436194461945619466194761948619496195061951619526195361954619556195661957619586195961960619616196261963619646196561966619676196861969619706197161972619736197461975619766197761978619796198061981619826198361984619856198661987619886198961990619916199261993619946199561996619976199861999620006200162002620036200462005620066200762008620096201062011620126201362014620156201662017620186201962020620216202262023620246202562026620276202862029620306203162032620336203462035620366203762038620396204062041620426204362044620456204662047620486204962050620516205262053620546205562056620576205862059620606206162062620636206462065620666206762068620696207062071620726207362074620756207662077620786207962080620816208262083620846208562086620876208862089620906209162092620936209462095620966209762098620996210062101621026210362104621056210662107621086210962110621116211262113621146211562116621176211862119621206212162122621236212462125621266212762128621296213062131621326213362134621356213662137621386213962140621416214262143621446214562146621476214862149621506215162152621536215462155621566215762158621596216062161621626216362164621656216662167621686216962170621716217262173621746217562176621776217862179621806218162182621836218462185621866218762188621896219062191621926219362194621956219662197621986219962200622016220262203622046220562206622076220862209622106221162212622136221462215622166221762218622196222062221622226222362224622256222662227622286222962230622316223262233622346223562236622376223862239622406224162242622436224462245622466224762248622496225062251622526225362254622556225662257622586225962260622616226262263622646226562266622676226862269622706227162272622736227462275622766227762278622796228062281622826228362284622856228662287622886228962290622916229262293622946229562296622976229862299623006230162302623036230462305623066230762308623096231062311623126231362314623156231662317623186231962320623216232262323623246232562326623276232862329623306233162332623336233462335623366233762338623396234062341623426234362344623456234662347623486234962350623516235262353623546235562356623576235862359623606236162362623636236462365623666236762368623696237062371623726237362374623756237662377623786237962380623816238262383623846238562386623876238862389623906239162392623936239462395623966239762398623996240062401624026240362404624056240662407624086240962410624116241262413624146241562416624176241862419624206242162422624236242462425624266242762428624296243062431624326243362434624356243662437624386243962440624416244262443624446244562446624476244862449624506245162452624536245462455624566245762458624596246062461624626246362464624656246662467624686246962470624716247262473624746247562476624776247862479624806248162482624836248462485624866248762488624896249062491624926249362494624956249662497624986249962500625016250262503625046250562506625076250862509625106251162512625136251462515625166251762518625196252062521625226252362524625256252662527625286252962530625316253262533625346253562536625376253862539625406254162542625436254462545625466254762548625496255062551625526255362554625556255662557625586255962560625616256262563625646256562566625676256862569625706257162572625736257462575625766257762578625796258062581625826258362584625856258662587625886258962590625916259262593625946259562596625976259862599626006260162602626036260462605626066260762608626096261062611626126261362614626156261662617626186261962620626216262262623626246262562626626276262862629626306263162632626336263462635626366263762638626396264062641626426264362644626456264662647626486264962650626516265262653626546265562656626576265862659626606266162662626636266462665626666266762668626696267062671626726267362674626756267662677626786267962680626816268262683626846268562686626876268862689626906269162692626936269462695626966269762698626996270062701627026270362704627056270662707627086270962710627116271262713627146271562716627176271862719627206272162722627236272462725627266272762728627296273062731627326273362734627356273662737627386273962740627416274262743627446274562746627476274862749627506275162752627536275462755627566275762758627596276062761627626276362764627656276662767627686276962770627716277262773627746277562776627776277862779627806278162782627836278462785627866278762788627896279062791627926279362794627956279662797627986279962800628016280262803628046280562806628076280862809628106281162812628136281462815628166281762818628196282062821628226282362824628256282662827628286282962830628316283262833628346283562836628376283862839628406284162842628436284462845628466284762848628496285062851628526285362854628556285662857628586285962860628616286262863628646286562866628676286862869628706287162872628736287462875628766287762878628796288062881628826288362884628856288662887628886288962890628916289262893628946289562896628976289862899629006290162902629036290462905629066290762908629096291062911629126291362914629156291662917629186291962920629216292262923629246292562926629276292862929629306293162932629336293462935629366293762938629396294062941629426294362944629456294662947629486294962950629516295262953629546295562956629576295862959629606296162962629636296462965629666296762968629696297062971629726297362974629756297662977629786297962980629816298262983629846298562986629876298862989629906299162992629936299462995629966299762998629996300063001630026300363004630056300663007630086300963010630116301263013630146301563016630176301863019630206302163022630236302463025630266302763028630296303063031630326303363034630356303663037630386303963040630416304263043630446304563046630476304863049630506305163052630536305463055630566305763058630596306063061630626306363064630656306663067630686306963070630716307263073630746307563076630776307863079630806308163082630836308463085630866308763088630896309063091630926309363094630956309663097630986309963100631016310263103631046310563106631076310863109631106311163112631136311463115631166311763118631196312063121631226312363124631256312663127631286312963130631316313263133631346313563136631376313863139631406314163142631436314463145631466314763148631496315063151631526315363154631556315663157631586315963160631616316263163631646316563166631676316863169631706317163172631736317463175631766317763178631796318063181631826318363184631856318663187631886318963190631916319263193631946319563196631976319863199632006320163202632036320463205632066320763208632096321063211632126321363214632156321663217632186321963220632216322263223632246322563226632276322863229632306323163232632336323463235632366323763238632396324063241632426324363244632456324663247632486324963250632516325263253632546325563256632576325863259632606326163262632636326463265632666326763268632696327063271632726327363274632756327663277632786327963280632816328263283632846328563286632876328863289632906329163292632936329463295632966329763298632996330063301633026330363304633056330663307633086330963310633116331263313633146331563316633176331863319633206332163322633236332463325633266332763328633296333063331633326333363334633356333663337633386333963340633416334263343633446334563346633476334863349633506335163352633536335463355633566335763358633596336063361633626336363364633656336663367633686336963370633716337263373633746337563376633776337863379633806338163382633836338463385633866338763388633896339063391633926339363394633956339663397633986339963400634016340263403634046340563406634076340863409634106341163412634136341463415634166341763418634196342063421634226342363424634256342663427634286342963430634316343263433634346343563436634376343863439634406344163442634436344463445634466344763448634496345063451634526345363454634556345663457634586345963460634616346263463634646346563466634676346863469634706347163472634736347463475634766347763478634796348063481634826348363484634856348663487634886348963490634916349263493634946349563496634976349863499635006350163502635036350463505635066350763508635096351063511635126351363514635156351663517635186351963520635216352263523635246352563526635276352863529635306353163532635336353463535635366353763538635396354063541635426354363544635456354663547635486354963550635516355263553635546355563556635576355863559635606356163562635636356463565635666356763568635696357063571635726357363574635756357663577635786357963580635816358263583635846358563586635876358863589635906359163592635936359463595635966359763598635996360063601636026360363604636056360663607636086360963610636116361263613636146361563616636176361863619636206362163622636236362463625636266362763628636296363063631636326363363634636356363663637636386363963640636416364263643636446364563646636476364863649636506365163652636536365463655636566365763658636596366063661636626366363664636656366663667636686366963670636716367263673636746367563676636776367863679636806368163682636836368463685636866368763688636896369063691636926369363694636956369663697636986369963700637016370263703637046370563706637076370863709637106371163712637136371463715637166371763718637196372063721637226372363724637256372663727637286372963730637316373263733637346373563736637376373863739637406374163742637436374463745637466374763748637496375063751637526375363754637556375663757637586375963760637616376263763637646376563766637676376863769637706377163772637736377463775637766377763778637796378063781637826378363784637856378663787637886378963790637916379263793637946379563796637976379863799638006380163802638036380463805638066380763808638096381063811638126381363814638156381663817638186381963820638216382263823638246382563826638276382863829638306383163832638336383463835638366383763838638396384063841638426384363844638456384663847638486384963850638516385263853638546385563856638576385863859638606386163862638636386463865638666386763868638696387063871638726387363874638756387663877638786387963880638816388263883638846388563886638876388863889638906389163892638936389463895638966389763898638996390063901639026390363904639056390663907639086390963910639116391263913639146391563916639176391863919639206392163922639236392463925639266392763928639296393063931639326393363934639356393663937639386393963940639416394263943639446394563946639476394863949639506395163952639536395463955639566395763958639596396063961639626396363964639656396663967639686396963970639716397263973639746397563976639776397863979639806398163982639836398463985639866398763988639896399063991639926399363994639956399663997639986399964000640016400264003640046400564006640076400864009640106401164012640136401464015640166401764018640196402064021640226402364024640256402664027640286402964030640316403264033640346403564036640376403864039640406404164042640436404464045640466404764048640496405064051640526405364054640556405664057640586405964060640616406264063640646406564066640676406864069640706407164072640736407464075640766407764078640796408064081640826408364084640856408664087640886408964090640916409264093640946409564096640976409864099641006410164102641036410464105641066410764108641096411064111641126411364114641156411664117641186411964120641216412264123641246412564126641276412864129641306413164132641336413464135641366413764138641396414064141641426414364144641456414664147641486414964150641516415264153641546415564156641576415864159641606416164162641636416464165641666416764168641696417064171641726417364174641756417664177641786417964180641816418264183641846418564186641876418864189641906419164192641936419464195641966419764198641996420064201642026420364204642056420664207642086420964210642116421264213642146421564216642176421864219642206422164222642236422464225642266422764228642296423064231642326423364234642356423664237642386423964240642416424264243642446424564246642476424864249642506425164252642536425464255642566425764258642596426064261642626426364264642656426664267642686426964270642716427264273642746427564276642776427864279642806428164282642836428464285642866428764288642896429064291642926429364294642956429664297642986429964300643016430264303643046430564306643076430864309643106431164312643136431464315643166431764318643196432064321643226432364324643256432664327643286432964330643316433264333643346433564336643376433864339643406434164342643436434464345643466434764348643496435064351643526435364354643556435664357643586435964360643616436264363643646436564366643676436864369643706437164372643736437464375643766437764378643796438064381643826438364384643856438664387643886438964390643916439264393643946439564396643976439864399644006440164402644036440464405644066440764408644096441064411644126441364414644156441664417644186441964420644216442264423644246442564426644276442864429644306443164432644336443464435644366443764438644396444064441644426444364444644456444664447644486444964450644516445264453644546445564456644576445864459644606446164462644636446464465644666446764468644696447064471644726447364474644756447664477644786447964480644816448264483644846448564486644876448864489644906449164492644936449464495644966449764498644996450064501645026450364504645056450664507645086450964510645116451264513645146451564516645176451864519645206452164522645236452464525645266452764528645296453064531645326453364534645356453664537645386453964540645416454264543645446454564546645476454864549645506455164552645536455464555645566455764558645596456064561645626456364564645656456664567645686456964570645716457264573645746457564576645776457864579645806458164582645836458464585645866458764588645896459064591645926459364594645956459664597645986459964600646016460264603646046460564606646076460864609646106461164612646136461464615646166461764618646196462064621646226462364624646256462664627646286462964630646316463264633646346463564636646376463864639646406464164642646436464464645646466464764648646496465064651646526465364654646556465664657646586465964660646616466264663646646466564666646676466864669646706467164672646736467464675646766467764678646796468064681646826468364684646856468664687646886468964690646916469264693646946469564696646976469864699647006470164702647036470464705647066470764708647096471064711647126471364714647156471664717647186471964720647216472264723647246472564726647276472864729647306473164732647336473464735647366473764738647396474064741647426474364744647456474664747647486474964750647516475264753647546475564756647576475864759647606476164762647636476464765647666476764768647696477064771647726477364774647756477664777647786477964780647816478264783647846478564786647876478864789647906479164792647936479464795647966479764798647996480064801648026480364804648056480664807648086480964810648116481264813648146481564816648176481864819648206482164822648236482464825648266482764828648296483064831648326483364834648356483664837648386483964840648416484264843648446484564846648476484864849648506485164852648536485464855648566485764858648596486064861648626486364864648656486664867648686486964870648716487264873648746487564876648776487864879648806488164882648836488464885648866488764888648896489064891648926489364894648956489664897648986489964900649016490264903649046490564906649076490864909649106491164912649136491464915649166491764918649196492064921649226492364924649256492664927649286492964930649316493264933649346493564936649376493864939649406494164942649436494464945649466494764948649496495064951649526495364954649556495664957649586495964960649616496264963649646496564966649676496864969649706497164972649736497464975649766497764978649796498064981649826498364984649856498664987649886498964990649916499264993649946499564996649976499864999650006500165002650036500465005650066500765008650096501065011650126501365014650156501665017650186501965020650216502265023650246502565026650276502865029650306503165032650336503465035650366503765038650396504065041650426504365044650456504665047650486504965050650516505265053650546505565056650576505865059650606506165062650636506465065650666506765068650696507065071650726507365074650756507665077650786507965080650816508265083650846508565086650876508865089650906509165092650936509465095650966509765098650996510065101651026510365104651056510665107651086510965110651116511265113651146511565116651176511865119651206512165122651236512465125651266512765128651296513065131651326513365134651356513665137651386513965140651416514265143651446514565146651476514865149651506515165152651536515465155651566515765158651596516065161651626516365164651656516665167651686516965170651716517265173651746517565176651776517865179651806518165182651836518465185651866518765188651896519065191651926519365194651956519665197651986519965200652016520265203652046520565206652076520865209652106521165212652136521465215652166521765218652196522065221652226522365224652256522665227652286522965230652316523265233652346523565236652376523865239652406524165242652436524465245652466524765248652496525065251652526525365254652556525665257652586525965260652616526265263652646526565266652676526865269652706527165272652736527465275652766527765278652796528065281652826528365284652856528665287652886528965290652916529265293652946529565296652976529865299653006530165302653036530465305653066530765308653096531065311653126531365314653156531665317653186531965320653216532265323653246532565326653276532865329653306533165332653336533465335653366533765338653396534065341653426534365344653456534665347653486534965350653516535265353653546535565356653576535865359653606536165362653636536465365653666536765368653696537065371653726537365374653756537665377653786537965380653816538265383653846538565386653876538865389653906539165392653936539465395653966539765398653996540065401654026540365404654056540665407654086540965410654116541265413654146541565416654176541865419654206542165422654236542465425654266542765428654296543065431654326543365434654356543665437654386543965440654416544265443654446544565446654476544865449654506545165452654536545465455654566545765458654596546065461654626546365464654656546665467654686546965470654716547265473654746547565476654776547865479654806548165482654836548465485654866548765488654896549065491654926549365494654956549665497654986549965500655016550265503655046550565506655076550865509655106551165512655136551465515655166551765518655196552065521655226552365524655256552665527655286552965530655316553265533655346553565536655376553865539655406554165542655436554465545655466554765548655496555065551655526555365554655556555665557655586555965560655616556265563655646556565566655676556865569655706557165572655736557465575655766557765578655796558065581655826558365584655856558665587655886558965590655916559265593655946559565596655976559865599656006560165602656036560465605656066560765608656096561065611656126561365614656156561665617656186561965620656216562265623656246562565626656276562865629656306563165632656336563465635656366563765638656396564065641656426564365644656456564665647656486564965650656516565265653656546565565656656576565865659656606566165662656636566465665656666566765668656696567065671656726567365674656756567665677656786567965680656816568265683656846568565686656876568865689656906569165692656936569465695656966569765698656996570065701657026570365704657056570665707657086570965710657116571265713657146571565716657176571865719657206572165722657236572465725657266572765728657296573065731657326573365734657356573665737657386573965740657416574265743657446574565746657476574865749657506575165752657536575465755657566575765758657596576065761657626576365764657656576665767657686576965770657716577265773657746577565776657776577865779657806578165782657836578465785657866578765788657896579065791657926579365794657956579665797657986579965800658016580265803658046580565806658076580865809658106581165812658136581465815658166581765818658196582065821658226582365824658256582665827658286582965830658316583265833658346583565836658376583865839658406584165842658436584465845658466584765848658496585065851658526585365854658556585665857658586585965860658616586265863658646586565866658676586865869658706587165872658736587465875658766587765878658796588065881658826588365884658856588665887658886588965890658916589265893658946589565896658976589865899659006590165902659036590465905659066590765908659096591065911659126591365914659156591665917659186591965920659216592265923659246592565926659276592865929659306593165932659336593465935659366593765938659396594065941659426594365944659456594665947659486594965950659516595265953659546595565956659576595865959659606596165962659636596465965659666596765968659696597065971659726597365974659756597665977659786597965980659816598265983659846598565986659876598865989659906599165992659936599465995659966599765998659996600066001660026600366004660056600666007660086600966010660116601266013660146601566016660176601866019660206602166022660236602466025660266602766028660296603066031660326603366034660356603666037660386603966040660416604266043660446604566046660476604866049660506605166052660536605466055660566605766058660596606066061660626606366064660656606666067660686606966070660716607266073660746607566076660776607866079660806608166082660836608466085660866608766088660896609066091660926609366094660956609666097660986609966100661016610266103661046610566106661076610866109661106611166112661136611466115661166611766118661196612066121661226612366124661256612666127661286612966130661316613266133661346613566136661376613866139661406614166142661436614466145661466614766148661496615066151661526615366154661556615666157661586615966160661616616266163661646616566166661676616866169661706617166172661736617466175661766617766178661796618066181661826618366184661856618666187661886618966190661916619266193661946619566196661976619866199662006620166202662036620466205662066620766208662096621066211662126621366214662156621666217662186621966220662216622266223662246622566226662276622866229662306623166232662336623466235662366623766238662396624066241662426624366244662456624666247662486624966250662516625266253662546625566256662576625866259662606626166262662636626466265662666626766268662696627066271662726627366274662756627666277662786627966280662816628266283662846628566286662876628866289662906629166292662936629466295662966629766298662996630066301663026630366304663056630666307663086630966310663116631266313663146631566316663176631866319663206632166322663236632466325663266632766328663296633066331663326633366334663356633666337663386633966340663416634266343663446634566346663476634866349663506635166352663536635466355663566635766358663596636066361663626636366364663656636666367663686636966370663716637266373663746637566376663776637866379663806638166382663836638466385663866638766388663896639066391663926639366394663956639666397663986639966400664016640266403664046640566406664076640866409664106641166412664136641466415664166641766418664196642066421664226642366424664256642666427664286642966430664316643266433664346643566436664376643866439664406644166442664436644466445664466644766448664496645066451664526645366454664556645666457664586645966460664616646266463664646646566466664676646866469664706647166472664736647466475664766647766478664796648066481664826648366484664856648666487664886648966490664916649266493664946649566496664976649866499665006650166502665036650466505665066650766508665096651066511665126651366514665156651666517665186651966520665216652266523665246652566526665276652866529665306653166532665336653466535665366653766538665396654066541665426654366544665456654666547665486654966550665516655266553665546655566556665576655866559665606656166562665636656466565665666656766568665696657066571665726657366574665756657666577665786657966580665816658266583665846658566586665876658866589665906659166592665936659466595665966659766598665996660066601666026660366604666056660666607666086660966610666116661266613666146661566616666176661866619666206662166622666236662466625666266662766628666296663066631666326663366634666356663666637666386663966640666416664266643666446664566646666476664866649666506665166652666536665466655666566665766658666596666066661666626666366664666656666666667666686666966670666716667266673666746667566676666776667866679666806668166682666836668466685666866668766688666896669066691666926669366694666956669666697666986669966700667016670266703667046670566706667076670866709667106671166712667136671466715667166671766718667196672066721667226672366724667256672666727667286672966730667316673266733667346673566736667376673866739667406674166742667436674466745667466674766748667496675066751667526675366754667556675666757667586675966760667616676266763667646676566766667676676866769667706677166772667736677466775667766677766778667796678066781667826678366784667856678666787667886678966790667916679266793667946679566796667976679866799668006680166802668036680466805668066680766808668096681066811668126681366814668156681666817668186681966820668216682266823668246682566826668276682866829668306683166832668336683466835668366683766838668396684066841668426684366844668456684666847668486684966850668516685266853668546685566856668576685866859668606686166862668636686466865668666686766868668696687066871668726687366874668756687666877668786687966880668816688266883668846688566886668876688866889668906689166892668936689466895668966689766898668996690066901669026690366904669056690666907669086690966910669116691266913669146691566916669176691866919669206692166922669236692466925669266692766928669296693066931669326693366934669356693666937669386693966940669416694266943669446694566946669476694866949669506695166952669536695466955669566695766958669596696066961669626696366964669656696666967669686696966970669716697266973669746697566976669776697866979669806698166982669836698466985669866698766988669896699066991669926699366994669956699666997669986699967000670016700267003670046700567006670076700867009670106701167012670136701467015670166701767018670196702067021670226702367024670256702667027670286702967030670316703267033670346703567036670376703867039670406704167042670436704467045670466704767048670496705067051670526705367054670556705667057670586705967060670616706267063670646706567066670676706867069670706707167072670736707467075670766707767078670796708067081670826708367084670856708667087670886708967090670916709267093670946709567096670976709867099671006710167102671036710467105671066710767108671096711067111671126711367114671156711667117671186711967120671216712267123671246712567126671276712867129671306713167132671336713467135671366713767138671396714067141671426714367144671456714667147671486714967150671516715267153671546715567156671576715867159671606716167162671636716467165671666716767168671696717067171671726717367174671756717667177671786717967180671816718267183671846718567186671876718867189671906719167192671936719467195671966719767198671996720067201672026720367204672056720667207672086720967210672116721267213672146721567216672176721867219672206722167222672236722467225672266722767228672296723067231672326723367234672356723667237672386723967240672416724267243672446724567246672476724867249672506725167252672536725467255672566725767258672596726067261672626726367264672656726667267672686726967270672716727267273672746727567276672776727867279672806728167282672836728467285672866728767288672896729067291672926729367294672956729667297672986729967300673016730267303673046730567306673076730867309673106731167312673136731467315673166731767318673196732067321673226732367324673256732667327673286732967330673316733267333673346733567336673376733867339673406734167342673436734467345673466734767348673496735067351673526735367354673556735667357673586735967360673616736267363673646736567366673676736867369673706737167372673736737467375673766737767378673796738067381673826738367384673856738667387673886738967390673916739267393673946739567396673976739867399674006740167402674036740467405674066740767408674096741067411674126741367414674156741667417674186741967420674216742267423674246742567426674276742867429674306743167432674336743467435674366743767438674396744067441674426744367444674456744667447674486744967450674516745267453674546745567456674576745867459674606746167462674636746467465674666746767468674696747067471674726747367474674756747667477674786747967480674816748267483674846748567486674876748867489674906749167492674936749467495674966749767498674996750067501675026750367504675056750667507675086750967510675116751267513675146751567516675176751867519675206752167522675236752467525675266752767528675296753067531675326753367534675356753667537675386753967540675416754267543675446754567546675476754867549675506755167552675536755467555675566755767558675596756067561675626756367564675656756667567675686756967570675716757267573675746757567576675776757867579675806758167582675836758467585675866758767588675896759067591675926759367594675956759667597675986759967600676016760267603676046760567606676076760867609676106761167612676136761467615676166761767618676196762067621676226762367624676256762667627676286762967630676316763267633676346763567636676376763867639676406764167642676436764467645676466764767648676496765067651676526765367654676556765667657676586765967660676616766267663676646766567666676676766867669676706767167672676736767467675676766767767678676796768067681676826768367684676856768667687676886768967690676916769267693676946769567696676976769867699677006770167702677036770467705677066770767708677096771067711677126771367714677156771667717677186771967720677216772267723677246772567726677276772867729677306773167732677336773467735677366773767738677396774067741677426774367744677456774667747677486774967750677516775267753677546775567756677576775867759677606776167762677636776467765677666776767768677696777067771677726777367774677756777667777677786777967780677816778267783677846778567786677876778867789677906779167792677936779467795677966779767798677996780067801678026780367804678056780667807678086780967810678116781267813678146781567816678176781867819678206782167822678236782467825678266782767828678296783067831678326783367834678356783667837678386783967840678416784267843678446784567846678476784867849678506785167852678536785467855678566785767858678596786067861678626786367864678656786667867678686786967870678716787267873678746787567876678776787867879678806788167882678836788467885678866788767888678896789067891678926789367894678956789667897678986789967900679016790267903679046790567906679076790867909679106791167912679136791467915679166791767918679196792067921679226792367924679256792667927679286792967930679316793267933679346793567936679376793867939679406794167942679436794467945679466794767948679496795067951679526795367954679556795667957679586795967960679616796267963679646796567966679676796867969679706797167972679736797467975679766797767978679796798067981679826798367984679856798667987679886798967990679916799267993679946799567996679976799867999680006800168002680036800468005680066800768008680096801068011680126801368014680156801668017680186801968020680216802268023680246802568026680276802868029680306803168032680336803468035680366803768038680396804068041680426804368044680456804668047680486804968050680516805268053680546805568056680576805868059680606806168062680636806468065680666806768068680696807068071680726807368074680756807668077680786807968080680816808268083680846808568086680876808868089680906809168092680936809468095680966809768098680996810068101681026810368104681056810668107681086810968110681116811268113681146811568116681176811868119681206812168122681236812468125681266812768128681296813068131681326813368134681356813668137681386813968140681416814268143681446814568146681476814868149681506815168152681536815468155681566815768158681596816068161681626816368164681656816668167681686816968170681716817268173681746817568176681776817868179681806818168182681836818468185681866818768188681896819068191681926819368194681956819668197681986819968200682016820268203682046820568206682076820868209682106821168212682136821468215682166821768218682196822068221682226822368224682256822668227682286822968230682316823268233682346823568236682376823868239682406824168242682436824468245682466824768248682496825068251682526825368254682556825668257682586825968260682616826268263682646826568266682676826868269682706827168272682736827468275682766827768278682796828068281682826828368284682856828668287682886828968290682916829268293682946829568296682976829868299683006830168302683036830468305683066830768308683096831068311683126831368314683156831668317683186831968320683216832268323683246832568326683276832868329683306833168332683336833468335683366833768338683396834068341683426834368344683456834668347683486834968350683516835268353683546835568356683576835868359683606836168362683636836468365683666836768368683696837068371683726837368374683756837668377683786837968380683816838268383683846838568386683876838868389683906839168392683936839468395683966839768398683996840068401684026840368404684056840668407684086840968410684116841268413684146841568416684176841868419684206842168422684236842468425684266842768428684296843068431684326843368434684356843668437684386843968440684416844268443684446844568446684476844868449684506845168452684536845468455684566845768458684596846068461684626846368464684656846668467684686846968470684716847268473684746847568476684776847868479684806848168482684836848468485684866848768488684896849068491684926849368494684956849668497684986849968500685016850268503685046850568506685076850868509685106851168512685136851468515685166851768518685196852068521685226852368524685256852668527685286852968530685316853268533685346853568536685376853868539685406854168542685436854468545685466854768548685496855068551685526855368554685556855668557685586855968560685616856268563685646856568566685676856868569685706857168572685736857468575685766857768578685796858068581685826858368584685856858668587685886858968590685916859268593685946859568596685976859868599686006860168602686036860468605686066860768608686096861068611686126861368614686156861668617686186861968620686216862268623686246862568626686276862868629686306863168632686336863468635686366863768638686396864068641686426864368644686456864668647686486864968650686516865268653686546865568656686576865868659686606866168662686636866468665686666866768668686696867068671686726867368674686756867668677686786867968680686816868268683686846868568686686876868868689686906869168692686936869468695686966869768698686996870068701687026870368704687056870668707687086870968710687116871268713687146871568716687176871868719687206872168722687236872468725687266872768728687296873068731687326873368734687356873668737687386873968740687416874268743687446874568746687476874868749687506875168752687536875468755687566875768758687596876068761687626876368764687656876668767687686876968770687716877268773687746877568776687776877868779687806878168782687836878468785687866878768788687896879068791687926879368794687956879668797687986879968800688016880268803688046880568806688076880868809688106881168812688136881468815688166881768818688196882068821688226882368824688256882668827688286882968830688316883268833688346883568836688376883868839688406884168842688436884468845688466884768848688496885068851688526885368854688556885668857688586885968860688616886268863688646886568866688676886868869688706887168872688736887468875688766887768878688796888068881688826888368884688856888668887688886888968890688916889268893688946889568896688976889868899689006890168902689036890468905689066890768908689096891068911689126891368914689156891668917689186891968920689216892268923689246892568926689276892868929689306893168932689336893468935689366893768938689396894068941689426894368944689456894668947689486894968950689516895268953689546895568956689576895868959689606896168962689636896468965689666896768968689696897068971689726897368974689756897668977689786897968980689816898268983689846898568986689876898868989689906899168992689936899468995689966899768998689996900069001690026900369004690056900669007690086900969010690116901269013690146901569016690176901869019690206902169022690236902469025690266902769028690296903069031690326903369034690356903669037690386903969040690416904269043690446904569046690476904869049690506905169052690536905469055690566905769058690596906069061690626906369064690656906669067690686906969070690716907269073690746907569076690776907869079690806908169082690836908469085690866908769088690896909069091690926909369094690956909669097690986909969100691016910269103691046910569106691076910869109691106911169112691136911469115691166911769118691196912069121691226912369124691256912669127691286912969130691316913269133691346913569136691376913869139691406914169142691436914469145691466914769148691496915069151691526915369154691556915669157691586915969160691616916269163691646916569166691676916869169691706917169172691736917469175691766917769178691796918069181691826918369184691856918669187691886918969190691916919269193691946919569196691976919869199692006920169202692036920469205692066920769208692096921069211692126921369214692156921669217692186921969220692216922269223692246922569226692276922869229692306923169232692336923469235692366923769238692396924069241692426924369244692456924669247692486924969250692516925269253692546925569256692576925869259692606926169262692636926469265692666926769268692696927069271692726927369274692756927669277692786927969280692816928269283692846928569286692876928869289692906929169292692936929469295692966929769298692996930069301693026930369304693056930669307693086930969310693116931269313693146931569316693176931869319693206932169322693236932469325693266932769328693296933069331693326933369334693356933669337693386933969340693416934269343693446934569346693476934869349693506935169352693536935469355693566935769358693596936069361693626936369364693656936669367693686936969370693716937269373693746937569376693776937869379693806938169382693836938469385693866938769388693896939069391693926939369394693956939669397693986939969400694016940269403694046940569406694076940869409694106941169412694136941469415694166941769418694196942069421694226942369424694256942669427694286942969430694316943269433694346943569436694376943869439694406944169442694436944469445694466944769448694496945069451694526945369454694556945669457694586945969460694616946269463694646946569466694676946869469694706947169472694736947469475694766947769478694796948069481694826948369484694856948669487694886948969490694916949269493694946949569496694976949869499695006950169502695036950469505695066950769508695096951069511695126951369514695156951669517695186951969520695216952269523695246952569526695276952869529695306953169532695336953469535695366953769538695396954069541695426954369544695456954669547695486954969550695516955269553695546955569556695576955869559695606956169562695636956469565695666956769568695696957069571695726957369574695756957669577695786957969580695816958269583695846958569586695876958869589695906959169592695936959469595695966959769598695996960069601696026960369604696056960669607696086960969610696116961269613696146961569616696176961869619696206962169622696236962469625696266962769628696296963069631696326963369634696356963669637696386963969640696416964269643696446964569646696476964869649696506965169652696536965469655696566965769658696596966069661696626966369664696656966669667696686966969670696716967269673696746967569676696776967869679696806968169682696836968469685696866968769688696896969069691696926969369694696956969669697696986969969700697016970269703697046970569706697076970869709697106971169712697136971469715697166971769718697196972069721697226972369724697256972669727697286972969730697316973269733697346973569736697376973869739697406974169742697436974469745697466974769748697496975069751697526975369754697556975669757697586975969760697616976269763697646976569766697676976869769697706977169772697736977469775697766977769778697796978069781697826978369784697856978669787697886978969790697916979269793697946979569796697976979869799698006980169802698036980469805698066980769808698096981069811698126981369814698156981669817698186981969820698216982269823698246982569826698276982869829698306983169832698336983469835698366983769838698396984069841698426984369844698456984669847698486984969850698516985269853698546985569856698576985869859698606986169862698636986469865698666986769868698696987069871698726987369874698756987669877698786987969880698816988269883698846988569886698876988869889698906989169892698936989469895698966989769898698996990069901699026990369904699056990669907699086990969910699116991269913699146991569916699176991869919699206992169922699236992469925699266992769928699296993069931699326993369934699356993669937699386993969940699416994269943699446994569946699476994869949699506995169952699536995469955699566995769958699596996069961699626996369964699656996669967699686996969970699716997269973699746997569976699776997869979699806998169982699836998469985699866998769988699896999069991699926999369994699956999669997699986999970000700017000270003700047000570006700077000870009700107001170012700137001470015700167001770018700197002070021700227002370024700257002670027700287002970030700317003270033700347003570036700377003870039700407004170042700437004470045700467004770048700497005070051700527005370054700557005670057700587005970060700617006270063700647006570066700677006870069700707007170072700737007470075700767007770078700797008070081700827008370084700857008670087700887008970090700917009270093700947009570096700977009870099701007010170102701037010470105701067010770108701097011070111701127011370114701157011670117701187011970120701217012270123701247012570126701277012870129701307013170132701337013470135701367013770138701397014070141701427014370144701457014670147701487014970150701517015270153701547015570156701577015870159701607016170162701637016470165701667016770168701697017070171701727017370174701757017670177701787017970180701817018270183701847018570186701877018870189701907019170192701937019470195701967019770198701997020070201702027020370204702057020670207702087020970210702117021270213702147021570216702177021870219702207022170222702237022470225702267022770228702297023070231702327023370234702357023670237702387023970240702417024270243702447024570246702477024870249702507025170252702537025470255702567025770258702597026070261702627026370264702657026670267702687026970270702717027270273702747027570276702777027870279702807028170282702837028470285702867028770288702897029070291702927029370294702957029670297702987029970300703017030270303703047030570306703077030870309703107031170312703137031470315703167031770318703197032070321703227032370324703257032670327703287032970330703317033270333703347033570336703377033870339703407034170342703437034470345703467034770348703497035070351703527035370354703557035670357703587035970360703617036270363703647036570366703677036870369703707037170372703737037470375703767037770378703797038070381703827038370384703857038670387703887038970390703917039270393703947039570396703977039870399704007040170402704037040470405704067040770408704097041070411704127041370414704157041670417704187041970420704217042270423704247042570426704277042870429704307043170432704337043470435704367043770438704397044070441704427044370444704457044670447704487044970450704517045270453704547045570456704577045870459704607046170462704637046470465704667046770468704697047070471704727047370474704757047670477704787047970480704817048270483704847048570486704877048870489704907049170492704937049470495704967049770498704997050070501705027050370504705057050670507705087050970510705117051270513705147051570516705177051870519705207052170522705237052470525705267052770528705297053070531705327053370534705357053670537705387053970540705417054270543705447054570546705477054870549705507055170552705537055470555705567055770558705597056070561705627056370564705657056670567705687056970570705717057270573705747057570576705777057870579705807058170582705837058470585705867058770588705897059070591705927059370594705957059670597705987059970600706017060270603706047060570606706077060870609706107061170612706137061470615706167061770618706197062070621706227062370624706257062670627706287062970630706317063270633706347063570636706377063870639706407064170642706437064470645706467064770648706497065070651706527065370654706557065670657706587065970660706617066270663706647066570666706677066870669706707067170672706737067470675706767067770678706797068070681706827068370684706857068670687706887068970690706917069270693706947069570696706977069870699707007070170702707037070470705707067070770708707097071070711707127071370714707157071670717707187071970720707217072270723707247072570726707277072870729707307073170732707337073470735707367073770738707397074070741707427074370744707457074670747707487074970750707517075270753707547075570756707577075870759707607076170762707637076470765707667076770768707697077070771707727077370774707757077670777707787077970780707817078270783707847078570786707877078870789707907079170792707937079470795707967079770798707997080070801708027080370804708057080670807708087080970810708117081270813708147081570816708177081870819708207082170822708237082470825708267082770828708297083070831708327083370834708357083670837708387083970840708417084270843708447084570846708477084870849708507085170852708537085470855708567085770858708597086070861708627086370864708657086670867708687086970870708717087270873708747087570876708777087870879708807088170882708837088470885708867088770888708897089070891708927089370894708957089670897708987089970900709017090270903709047090570906709077090870909709107091170912709137091470915709167091770918709197092070921709227092370924709257092670927709287092970930709317093270933709347093570936709377093870939709407094170942709437094470945709467094770948709497095070951709527095370954709557095670957709587095970960709617096270963709647096570966709677096870969709707097170972709737097470975709767097770978709797098070981709827098370984709857098670987709887098970990709917099270993709947099570996709977099870999710007100171002710037100471005710067100771008710097101071011710127101371014710157101671017710187101971020710217102271023710247102571026710277102871029710307103171032710337103471035710367103771038710397104071041710427104371044710457104671047710487104971050710517105271053710547105571056710577105871059710607106171062710637106471065710667106771068710697107071071710727107371074710757107671077710787107971080710817108271083710847108571086710877108871089710907109171092710937109471095710967109771098710997110071101711027110371104711057110671107711087110971110711117111271113711147111571116711177111871119711207112171122711237112471125711267112771128711297113071131711327113371134711357113671137711387113971140711417114271143711447114571146711477114871149711507115171152711537115471155711567115771158711597116071161711627116371164711657116671167711687116971170711717117271173711747117571176711777117871179711807118171182711837118471185711867118771188711897119071191711927119371194711957119671197711987119971200712017120271203712047120571206712077120871209712107121171212712137121471215712167121771218712197122071221712227122371224712257122671227712287122971230712317123271233712347123571236712377123871239712407124171242712437124471245712467124771248712497125071251712527125371254712557125671257712587125971260712617126271263712647126571266712677126871269712707127171272712737127471275712767127771278712797128071281712827128371284712857128671287712887128971290712917129271293712947129571296712977129871299713007130171302713037130471305713067130771308713097131071311713127131371314713157131671317713187131971320713217132271323713247132571326713277132871329713307133171332713337133471335713367133771338713397134071341713427134371344713457134671347713487134971350713517135271353713547135571356713577135871359713607136171362713637136471365713667136771368713697137071371713727137371374713757137671377713787137971380713817138271383713847138571386713877138871389713907139171392713937139471395713967139771398713997140071401714027140371404714057140671407714087140971410714117141271413714147141571416714177141871419714207142171422714237142471425714267142771428714297143071431714327143371434714357143671437714387143971440714417144271443714447144571446714477144871449714507145171452714537145471455714567145771458714597146071461714627146371464714657146671467714687146971470714717147271473714747147571476714777147871479714807148171482714837148471485714867148771488714897149071491714927149371494714957149671497714987149971500715017150271503715047150571506715077150871509715107151171512715137151471515715167151771518715197152071521715227152371524715257152671527715287152971530715317153271533715347153571536715377153871539715407154171542715437154471545715467154771548715497155071551715527155371554715557155671557715587155971560715617156271563715647156571566715677156871569715707157171572715737157471575715767157771578715797158071581715827158371584715857158671587715887158971590715917159271593715947159571596715977159871599716007160171602716037160471605716067160771608716097161071611716127161371614716157161671617716187161971620716217162271623716247162571626716277162871629716307163171632716337163471635716367163771638716397164071641716427164371644716457164671647716487164971650716517165271653716547165571656716577165871659716607166171662716637166471665716667166771668716697167071671716727167371674716757167671677716787167971680716817168271683716847168571686716877168871689716907169171692716937169471695716967169771698716997170071701717027170371704717057170671707717087170971710717117171271713717147171571716717177171871719717207172171722717237172471725717267172771728717297173071731717327173371734717357173671737717387173971740717417174271743717447174571746717477174871749717507175171752717537175471755717567175771758717597176071761717627176371764717657176671767717687176971770717717177271773717747177571776717777177871779717807178171782717837178471785717867178771788717897179071791717927179371794717957179671797717987179971800718017180271803718047180571806718077180871809718107181171812718137181471815718167181771818718197182071821718227182371824718257182671827718287182971830718317183271833718347183571836718377183871839718407184171842718437184471845718467184771848718497185071851718527185371854718557185671857718587185971860718617186271863718647186571866718677186871869718707187171872718737187471875718767187771878718797188071881718827188371884718857188671887718887188971890718917189271893718947189571896718977189871899719007190171902719037190471905719067190771908719097191071911719127191371914719157191671917719187191971920719217192271923719247192571926719277192871929719307193171932719337193471935719367193771938719397194071941719427194371944719457194671947719487194971950719517195271953719547195571956719577195871959719607196171962719637196471965719667196771968719697197071971719727197371974719757197671977719787197971980719817198271983719847198571986719877198871989719907199171992719937199471995719967199771998719997200072001720027200372004720057200672007720087200972010720117201272013720147201572016720177201872019720207202172022720237202472025720267202772028720297203072031720327203372034720357203672037720387203972040720417204272043720447204572046720477204872049720507205172052720537205472055720567205772058720597206072061720627206372064720657206672067720687206972070720717207272073720747207572076720777207872079720807208172082720837208472085720867208772088720897209072091720927209372094720957209672097720987209972100721017210272103721047210572106721077210872109721107211172112721137211472115721167211772118721197212072121721227212372124721257212672127721287212972130721317213272133721347213572136721377213872139721407214172142721437214472145721467214772148721497215072151721527215372154721557215672157721587215972160721617216272163721647216572166721677216872169721707217172172721737217472175721767217772178721797218072181721827218372184721857218672187721887218972190721917219272193721947219572196721977219872199722007220172202722037220472205722067220772208722097221072211722127221372214722157221672217722187221972220722217222272223722247222572226722277222872229722307223172232722337223472235722367223772238722397224072241722427224372244722457224672247722487224972250722517225272253722547225572256722577225872259722607226172262722637226472265722667226772268722697227072271722727227372274722757227672277722787227972280722817228272283722847228572286722877228872289722907229172292722937229472295722967229772298722997230072301723027230372304723057230672307723087230972310723117231272313723147231572316723177231872319723207232172322723237232472325723267232772328723297233072331723327233372334723357233672337723387233972340723417234272343723447234572346723477234872349723507235172352723537235472355723567235772358723597236072361723627236372364723657236672367723687236972370723717237272373723747237572376723777237872379723807238172382723837238472385723867238772388723897239072391723927239372394723957239672397723987239972400724017240272403724047240572406724077240872409724107241172412724137241472415724167241772418724197242072421724227242372424724257242672427724287242972430724317243272433724347243572436724377243872439724407244172442724437244472445724467244772448724497245072451724527245372454724557245672457724587245972460724617246272463724647246572466724677246872469724707247172472724737247472475724767247772478724797248072481724827248372484724857248672487724887248972490724917249272493724947249572496724977249872499725007250172502725037250472505725067250772508725097251072511725127251372514725157251672517725187251972520725217252272523725247252572526725277252872529725307253172532725337253472535725367253772538725397254072541725427254372544725457254672547725487254972550725517255272553725547255572556725577255872559725607256172562725637256472565725667256772568725697257072571725727257372574725757257672577725787257972580725817258272583725847258572586725877258872589725907259172592725937259472595725967259772598725997260072601726027260372604726057260672607726087260972610726117261272613726147261572616726177261872619726207262172622726237262472625726267262772628726297263072631726327263372634726357263672637726387263972640726417264272643726447264572646726477264872649726507265172652726537265472655726567265772658726597266072661726627266372664726657266672667726687266972670726717267272673726747267572676726777267872679726807268172682726837268472685726867268772688726897269072691726927269372694726957269672697726987269972700727017270272703727047270572706727077270872709727107271172712727137271472715727167271772718727197272072721727227272372724727257272672727727287272972730727317273272733727347273572736727377273872739727407274172742727437274472745727467274772748727497275072751727527275372754727557275672757727587275972760727617276272763727647276572766727677276872769727707277172772727737277472775727767277772778727797278072781727827278372784727857278672787727887278972790727917279272793727947279572796727977279872799728007280172802728037280472805728067280772808728097281072811728127281372814728157281672817728187281972820728217282272823728247282572826728277282872829728307283172832728337283472835728367283772838728397284072841728427284372844728457284672847728487284972850728517285272853728547285572856728577285872859728607286172862728637286472865728667286772868728697287072871728727287372874728757287672877728787287972880728817288272883728847288572886728877288872889728907289172892728937289472895728967289772898728997290072901729027290372904729057290672907729087290972910729117291272913729147291572916729177291872919729207292172922729237292472925729267292772928729297293072931729327293372934729357293672937729387293972940729417294272943729447294572946729477294872949729507295172952729537295472955729567295772958729597296072961729627296372964729657296672967729687296972970729717297272973729747297572976729777297872979729807298172982729837298472985729867298772988729897299072991729927299372994729957299672997729987299973000730017300273003730047300573006730077300873009730107301173012730137301473015730167301773018730197302073021730227302373024730257302673027730287302973030730317303273033730347303573036730377303873039730407304173042730437304473045730467304773048730497305073051730527305373054730557305673057730587305973060730617306273063730647306573066730677306873069730707307173072730737307473075730767307773078730797308073081730827308373084730857308673087730887308973090730917309273093730947309573096730977309873099731007310173102731037310473105731067310773108731097311073111731127311373114731157311673117731187311973120731217312273123731247312573126731277312873129731307313173132731337313473135731367313773138731397314073141731427314373144731457314673147731487314973150731517315273153731547315573156731577315873159731607316173162731637316473165731667316773168731697317073171731727317373174731757317673177731787317973180731817318273183731847318573186731877318873189731907319173192731937319473195731967319773198731997320073201732027320373204732057320673207732087320973210732117321273213732147321573216732177321873219732207322173222732237322473225732267322773228732297323073231732327323373234732357323673237732387323973240732417324273243732447324573246732477324873249732507325173252732537325473255732567325773258732597326073261732627326373264732657326673267732687326973270732717327273273732747327573276732777327873279732807328173282732837328473285732867328773288732897329073291732927329373294732957329673297732987329973300733017330273303733047330573306733077330873309733107331173312733137331473315733167331773318733197332073321733227332373324733257332673327733287332973330733317333273333733347333573336733377333873339733407334173342733437334473345733467334773348733497335073351733527335373354733557335673357733587335973360733617336273363733647336573366733677336873369733707337173372733737337473375733767337773378733797338073381733827338373384733857338673387733887338973390733917339273393733947339573396733977339873399734007340173402734037340473405734067340773408734097341073411734127341373414734157341673417734187341973420734217342273423734247342573426734277342873429734307343173432734337343473435734367343773438734397344073441734427344373444734457344673447734487344973450734517345273453734547345573456734577345873459734607346173462734637346473465734667346773468734697347073471734727347373474734757347673477734787347973480734817348273483734847348573486734877348873489734907349173492734937349473495734967349773498734997350073501735027350373504735057350673507735087350973510735117351273513735147351573516735177351873519735207352173522735237352473525735267352773528735297353073531735327353373534735357353673537735387353973540735417354273543735447354573546735477354873549735507355173552735537355473555735567355773558735597356073561735627356373564735657356673567735687356973570735717357273573735747357573576735777357873579735807358173582735837358473585735867358773588735897359073591735927359373594735957359673597735987359973600736017360273603736047360573606736077360873609736107361173612736137361473615736167361773618736197362073621736227362373624736257362673627736287362973630736317363273633736347363573636736377363873639736407364173642736437364473645736467364773648736497365073651736527365373654736557365673657736587365973660736617366273663736647366573666736677366873669736707367173672736737367473675736767367773678736797368073681736827368373684736857368673687736887368973690736917369273693736947369573696736977369873699737007370173702737037370473705737067370773708737097371073711737127371373714737157371673717737187371973720737217372273723737247372573726737277372873729737307373173732737337373473735737367373773738737397374073741737427374373744737457374673747737487374973750737517375273753737547375573756737577375873759737607376173762737637376473765737667376773768737697377073771737727377373774737757377673777737787377973780737817378273783737847378573786737877378873789737907379173792737937379473795737967379773798737997380073801738027380373804738057380673807738087380973810738117381273813738147381573816738177381873819738207382173822738237382473825738267382773828738297383073831738327383373834738357383673837738387383973840738417384273843738447384573846738477384873849738507385173852738537385473855738567385773858738597386073861738627386373864738657386673867738687386973870738717387273873738747387573876738777387873879738807388173882738837388473885738867388773888738897389073891738927389373894738957389673897738987389973900739017390273903739047390573906739077390873909739107391173912739137391473915739167391773918739197392073921739227392373924739257392673927739287392973930739317393273933739347393573936739377393873939739407394173942739437394473945739467394773948739497395073951739527395373954739557395673957739587395973960739617396273963739647396573966739677396873969739707397173972739737397473975739767397773978739797398073981739827398373984739857398673987739887398973990739917399273993739947399573996739977399873999740007400174002740037400474005740067400774008740097401074011740127401374014740157401674017740187401974020740217402274023740247402574026740277402874029740307403174032740337403474035740367403774038740397404074041740427404374044740457404674047740487404974050740517405274053740547405574056740577405874059740607406174062740637406474065740667406774068740697407074071740727407374074740757407674077740787407974080740817408274083740847408574086740877408874089740907409174092740937409474095740967409774098740997410074101741027410374104741057410674107741087410974110741117411274113741147411574116741177411874119741207412174122741237412474125741267412774128741297413074131741327413374134741357413674137741387413974140741417414274143741447414574146741477414874149741507415174152741537415474155741567415774158741597416074161741627416374164741657416674167741687416974170741717417274173741747417574176741777417874179741807418174182741837418474185741867418774188741897419074191741927419374194741957419674197741987419974200742017420274203742047420574206742077420874209742107421174212742137421474215742167421774218742197422074221742227422374224742257422674227742287422974230742317423274233742347423574236742377423874239742407424174242742437424474245742467424774248742497425074251742527425374254742557425674257742587425974260742617426274263742647426574266742677426874269742707427174272742737427474275742767427774278742797428074281742827428374284742857428674287742887428974290742917429274293742947429574296742977429874299743007430174302743037430474305743067430774308743097431074311743127431374314743157431674317743187431974320743217432274323743247432574326743277432874329743307433174332743337433474335743367433774338743397434074341743427434374344743457434674347743487434974350743517435274353743547435574356743577435874359743607436174362743637436474365743667436774368743697437074371743727437374374743757437674377743787437974380743817438274383743847438574386743877438874389743907439174392743937439474395743967439774398743997440074401744027440374404744057440674407744087440974410744117441274413744147441574416744177441874419744207442174422744237442474425744267442774428744297443074431744327443374434744357443674437744387443974440744417444274443744447444574446744477444874449744507445174452744537445474455744567445774458744597446074461744627446374464744657446674467744687446974470744717447274473744747447574476744777447874479744807448174482744837448474485744867448774488744897449074491744927449374494744957449674497744987449974500745017450274503745047450574506745077450874509745107451174512745137451474515745167451774518745197452074521745227452374524745257452674527745287452974530745317453274533745347453574536745377453874539745407454174542745437454474545745467454774548745497455074551745527455374554745557455674557745587455974560745617456274563745647456574566745677456874569745707457174572745737457474575745767457774578745797458074581745827458374584745857458674587745887458974590745917459274593745947459574596745977459874599746007460174602746037460474605746067460774608746097461074611746127461374614746157461674617746187461974620746217462274623746247462574626746277462874629746307463174632746337463474635746367463774638746397464074641746427464374644746457464674647746487464974650746517465274653746547465574656746577465874659746607466174662746637466474665746667466774668746697467074671746727467374674746757467674677746787467974680746817468274683746847468574686746877468874689746907469174692746937469474695746967469774698746997470074701747027470374704747057470674707747087470974710747117471274713747147471574716747177471874719747207472174722747237472474725747267472774728747297473074731747327473374734747357473674737747387473974740747417474274743747447474574746747477474874749747507475174752747537475474755747567475774758747597476074761747627476374764747657476674767747687476974770747717477274773747747477574776747777477874779747807478174782747837478474785747867478774788747897479074791747927479374794747957479674797747987479974800748017480274803748047480574806748077480874809748107481174812748137481474815748167481774818748197482074821748227482374824748257482674827748287482974830748317483274833748347483574836748377483874839748407484174842748437484474845748467484774848748497485074851748527485374854748557485674857748587485974860748617486274863748647486574866748677486874869748707487174872748737487474875748767487774878748797488074881748827488374884748857488674887748887488974890748917489274893748947489574896748977489874899749007490174902749037490474905749067490774908749097491074911749127491374914749157491674917749187491974920749217492274923749247492574926749277492874929749307493174932749337493474935749367493774938749397494074941749427494374944749457494674947749487494974950749517495274953749547495574956749577495874959749607496174962749637496474965749667496774968749697497074971749727497374974749757497674977749787497974980749817498274983749847498574986749877498874989749907499174992749937499474995749967499774998749997500075001750027500375004750057500675007750087500975010750117501275013750147501575016750177501875019750207502175022750237502475025750267502775028750297503075031750327503375034750357503675037750387503975040750417504275043750447504575046750477504875049750507505175052750537505475055750567505775058750597506075061750627506375064750657506675067750687506975070750717507275073750747507575076750777507875079750807508175082750837508475085750867508775088750897509075091750927509375094750957509675097750987509975100751017510275103751047510575106751077510875109751107511175112751137511475115751167511775118751197512075121751227512375124751257512675127751287512975130751317513275133751347513575136751377513875139751407514175142751437514475145751467514775148751497515075151751527515375154751557515675157751587515975160751617516275163751647516575166751677516875169751707517175172751737517475175751767517775178751797518075181751827518375184751857518675187751887518975190751917519275193751947519575196751977519875199752007520175202752037520475205752067520775208752097521075211752127521375214752157521675217752187521975220752217522275223752247522575226752277522875229752307523175232752337523475235752367523775238752397524075241752427524375244752457524675247752487524975250752517525275253752547525575256752577525875259752607526175262752637526475265752667526775268752697527075271752727527375274752757527675277752787527975280752817528275283752847528575286752877528875289752907529175292752937529475295752967529775298752997530075301753027530375304753057530675307753087530975310753117531275313753147531575316753177531875319753207532175322753237532475325753267532775328753297533075331753327533375334753357533675337753387533975340753417534275343753447534575346753477534875349753507535175352753537535475355753567535775358753597536075361753627536375364753657536675367753687536975370753717537275373753747537575376753777537875379753807538175382753837538475385753867538775388753897539075391753927539375394753957539675397753987539975400754017540275403754047540575406754077540875409754107541175412754137541475415754167541775418754197542075421754227542375424754257542675427754287542975430754317543275433754347543575436754377543875439754407544175442754437544475445754467544775448754497545075451754527545375454754557545675457754587545975460754617546275463754647546575466754677546875469754707547175472754737547475475754767547775478754797548075481754827548375484754857548675487754887548975490754917549275493754947549575496754977549875499755007550175502755037550475505755067550775508755097551075511755127551375514755157551675517755187551975520755217552275523755247552575526755277552875529755307553175532755337553475535755367553775538755397554075541755427554375544755457554675547755487554975550755517555275553755547555575556755577555875559755607556175562755637556475565755667556775568755697557075571755727557375574755757557675577755787557975580755817558275583755847558575586755877558875589755907559175592755937559475595755967559775598755997560075601756027560375604756057560675607756087560975610756117561275613756147561575616756177561875619756207562175622756237562475625756267562775628756297563075631756327563375634756357563675637756387563975640756417564275643756447564575646756477564875649756507565175652756537565475655756567565775658756597566075661756627566375664756657566675667756687566975670756717567275673756747567575676756777567875679756807568175682756837568475685756867568775688756897569075691756927569375694756957569675697756987569975700757017570275703757047570575706757077570875709757107571175712757137571475715757167571775718757197572075721757227572375724757257572675727757287572975730757317573275733757347573575736757377573875739757407574175742757437574475745757467574775748757497575075751757527575375754757557575675757757587575975760757617576275763757647576575766757677576875769757707577175772757737577475775757767577775778757797578075781757827578375784757857578675787757887578975790757917579275793757947579575796757977579875799758007580175802758037580475805758067580775808758097581075811758127581375814758157581675817758187581975820758217582275823758247582575826758277582875829758307583175832758337583475835758367583775838758397584075841758427584375844758457584675847758487584975850758517585275853758547585575856758577585875859758607586175862758637586475865758667586775868758697587075871758727587375874758757587675877758787587975880758817588275883758847588575886758877588875889758907589175892758937589475895758967589775898758997590075901759027590375904759057590675907759087590975910759117591275913759147591575916759177591875919759207592175922759237592475925759267592775928759297593075931759327593375934759357593675937759387593975940759417594275943759447594575946759477594875949759507595175952759537595475955759567595775958759597596075961759627596375964759657596675967759687596975970759717597275973759747597575976759777597875979759807598175982759837598475985759867598775988759897599075991759927599375994759957599675997759987599976000760017600276003760047600576006760077600876009760107601176012760137601476015760167601776018760197602076021760227602376024760257602676027760287602976030760317603276033760347603576036760377603876039760407604176042760437604476045760467604776048760497605076051760527605376054760557605676057760587605976060760617606276063760647606576066760677606876069760707607176072760737607476075760767607776078760797608076081760827608376084760857608676087760887608976090760917609276093760947609576096760977609876099761007610176102761037610476105761067610776108761097611076111761127611376114761157611676117761187611976120761217612276123761247612576126761277612876129761307613176132761337613476135761367613776138761397614076141761427614376144761457614676147761487614976150761517615276153761547615576156761577615876159761607616176162761637616476165761667616776168761697617076171761727617376174761757617676177761787617976180761817618276183761847618576186761877618876189761907619176192761937619476195761967619776198761997620076201762027620376204762057620676207762087620976210762117621276213762147621576216762177621876219762207622176222762237622476225762267622776228762297623076231762327623376234762357623676237762387623976240762417624276243762447624576246762477624876249762507625176252762537625476255762567625776258762597626076261762627626376264762657626676267762687626976270762717627276273762747627576276762777627876279762807628176282762837628476285762867628776288762897629076291762927629376294762957629676297762987629976300763017630276303763047630576306763077630876309763107631176312763137631476315763167631776318763197632076321763227632376324763257632676327763287632976330763317633276333763347633576336763377633876339763407634176342763437634476345763467634776348763497635076351763527635376354763557635676357763587635976360763617636276363763647636576366763677636876369763707637176372763737637476375763767637776378763797638076381763827638376384763857638676387763887638976390763917639276393763947639576396763977639876399764007640176402764037640476405764067640776408764097641076411764127641376414764157641676417764187641976420764217642276423764247642576426764277642876429764307643176432764337643476435764367643776438764397644076441764427644376444764457644676447764487644976450764517645276453764547645576456764577645876459764607646176462764637646476465764667646776468764697647076471764727647376474764757647676477764787647976480764817648276483764847648576486764877648876489764907649176492764937649476495764967649776498764997650076501765027650376504765057650676507765087650976510765117651276513765147651576516765177651876519765207652176522765237652476525765267652776528765297653076531765327653376534765357653676537765387653976540765417654276543765447654576546765477654876549765507655176552765537655476555765567655776558765597656076561765627656376564765657656676567765687656976570765717657276573765747657576576765777657876579765807658176582765837658476585765867658776588765897659076591765927659376594765957659676597765987659976600766017660276603766047660576606766077660876609766107661176612766137661476615766167661776618766197662076621766227662376624766257662676627766287662976630766317663276633766347663576636766377663876639766407664176642766437664476645766467664776648766497665076651766527665376654766557665676657766587665976660766617666276663766647666576666766677666876669766707667176672766737667476675766767667776678766797668076681766827668376684766857668676687766887668976690766917669276693766947669576696766977669876699767007670176702767037670476705767067670776708767097671076711767127671376714767157671676717767187671976720767217672276723767247672576726767277672876729767307673176732767337673476735767367673776738767397674076741767427674376744767457674676747767487674976750767517675276753767547675576756767577675876759767607676176762767637676476765767667676776768767697677076771767727677376774767757677676777767787677976780767817678276783767847678576786767877678876789767907679176792767937679476795767967679776798767997680076801768027680376804768057680676807768087680976810768117681276813768147681576816768177681876819768207682176822768237682476825768267682776828768297683076831768327683376834768357683676837768387683976840768417684276843768447684576846768477684876849768507685176852768537685476855768567685776858768597686076861768627686376864768657686676867768687686976870768717687276873768747687576876768777687876879768807688176882768837688476885768867688776888768897689076891768927689376894768957689676897768987689976900769017690276903769047690576906769077690876909769107691176912769137691476915769167691776918769197692076921769227692376924769257692676927769287692976930769317693276933769347693576936769377693876939769407694176942769437694476945769467694776948769497695076951769527695376954769557695676957769587695976960769617696276963769647696576966769677696876969769707697176972769737697476975769767697776978769797698076981769827698376984769857698676987769887698976990769917699276993769947699576996769977699876999770007700177002770037700477005770067700777008770097701077011770127701377014770157701677017770187701977020770217702277023770247702577026770277702877029770307703177032770337703477035770367703777038770397704077041770427704377044770457704677047770487704977050770517705277053770547705577056770577705877059770607706177062770637706477065770667706777068770697707077071770727707377074770757707677077770787707977080770817708277083770847708577086770877708877089770907709177092770937709477095770967709777098770997710077101771027710377104771057710677107771087710977110771117711277113771147711577116771177711877119771207712177122771237712477125771267712777128771297713077131771327713377134771357713677137771387713977140771417714277143771447714577146771477714877149771507715177152771537715477155771567715777158771597716077161771627716377164771657716677167771687716977170771717717277173771747717577176771777717877179771807718177182771837718477185771867718777188771897719077191771927719377194771957719677197771987719977200772017720277203772047720577206772077720877209772107721177212772137721477215772167721777218772197722077221772227722377224772257722677227772287722977230772317723277233772347723577236772377723877239772407724177242772437724477245772467724777248772497725077251772527725377254772557725677257772587725977260772617726277263772647726577266772677726877269772707727177272772737727477275772767727777278772797728077281772827728377284772857728677287772887728977290772917729277293772947729577296772977729877299773007730177302773037730477305773067730777308773097731077311773127731377314773157731677317773187731977320773217732277323773247732577326773277732877329773307733177332773337733477335773367733777338773397734077341773427734377344773457734677347773487734977350773517735277353773547735577356773577735877359773607736177362773637736477365773667736777368773697737077371773727737377374773757737677377773787737977380773817738277383773847738577386773877738877389773907739177392773937739477395773967739777398773997740077401774027740377404774057740677407774087740977410774117741277413774147741577416774177741877419774207742177422774237742477425774267742777428774297743077431774327743377434774357743677437774387743977440774417744277443774447744577446774477744877449774507745177452774537745477455774567745777458774597746077461774627746377464774657746677467774687746977470774717747277473774747747577476774777747877479774807748177482774837748477485774867748777488774897749077491774927749377494774957749677497774987749977500775017750277503775047750577506775077750877509775107751177512775137751477515775167751777518775197752077521775227752377524775257752677527775287752977530775317753277533775347753577536775377753877539775407754177542775437754477545775467754777548775497755077551775527755377554775557755677557775587755977560775617756277563775647756577566775677756877569775707757177572775737757477575775767757777578775797758077581775827758377584775857758677587775887758977590775917759277593775947759577596775977759877599776007760177602776037760477605776067760777608776097761077611776127761377614776157761677617776187761977620776217762277623776247762577626776277762877629776307763177632776337763477635776367763777638776397764077641776427764377644776457764677647776487764977650776517765277653776547765577656776577765877659776607766177662776637766477665776667766777668776697767077671776727767377674776757767677677776787767977680776817768277683776847768577686776877768877689776907769177692776937769477695776967769777698776997770077701777027770377704777057770677707777087770977710777117771277713777147771577716777177771877719777207772177722777237772477725777267772777728777297773077731777327773377734777357773677737777387773977740777417774277743777447774577746777477774877749777507775177752777537775477755777567775777758777597776077761777627776377764777657776677767777687776977770777717777277773777747777577776777777777877779777807778177782777837778477785777867778777788777897779077791777927779377794777957779677797777987779977800778017780277803778047780577806778077780877809778107781177812778137781477815778167781777818778197782077821778227782377824778257782677827778287782977830778317783277833778347783577836778377783877839778407784177842778437784477845778467784777848778497785077851778527785377854778557785677857778587785977860778617786277863778647786577866778677786877869778707787177872778737787477875778767787777878778797788077881778827788377884778857788677887778887788977890778917789277893778947789577896778977789877899779007790177902779037790477905779067790777908779097791077911779127791377914779157791677917779187791977920779217792277923779247792577926779277792877929779307793177932779337793477935779367793777938779397794077941779427794377944779457794677947779487794977950779517795277953779547795577956779577795877959779607796177962779637796477965779667796777968779697797077971779727797377974779757797677977779787797977980779817798277983779847798577986779877798877989779907799177992779937799477995779967799777998779997800078001780027800378004780057800678007780087800978010780117801278013780147801578016780177801878019780207802178022780237802478025780267802778028780297803078031780327803378034780357803678037780387803978040780417804278043780447804578046780477804878049780507805178052780537805478055780567805778058780597806078061780627806378064780657806678067780687806978070780717807278073780747807578076780777807878079780807808178082780837808478085780867808778088780897809078091780927809378094780957809678097780987809978100781017810278103781047810578106781077810878109781107811178112781137811478115781167811778118781197812078121781227812378124781257812678127781287812978130781317813278133781347813578136781377813878139781407814178142781437814478145781467814778148781497815078151781527815378154781557815678157781587815978160781617816278163781647816578166781677816878169781707817178172781737817478175781767817778178781797818078181781827818378184781857818678187781887818978190781917819278193781947819578196781977819878199782007820178202782037820478205782067820778208782097821078211782127821378214782157821678217782187821978220782217822278223782247822578226782277822878229782307823178232782337823478235782367823778238782397824078241782427824378244782457824678247782487824978250782517825278253782547825578256782577825878259782607826178262782637826478265782667826778268782697827078271782727827378274782757827678277782787827978280782817828278283782847828578286782877828878289782907829178292782937829478295782967829778298782997830078301783027830378304783057830678307783087830978310783117831278313783147831578316783177831878319783207832178322783237832478325783267832778328783297833078331783327833378334783357833678337783387833978340783417834278343783447834578346783477834878349783507835178352783537835478355783567835778358783597836078361783627836378364783657836678367783687836978370783717837278373783747837578376783777837878379783807838178382783837838478385783867838778388783897839078391783927839378394783957839678397783987839978400784017840278403784047840578406784077840878409784107841178412784137841478415784167841778418784197842078421784227842378424784257842678427784287842978430784317843278433784347843578436784377843878439784407844178442784437844478445784467844778448784497845078451784527845378454784557845678457784587845978460784617846278463784647846578466784677846878469784707847178472784737847478475784767847778478784797848078481784827848378484784857848678487784887848978490784917849278493784947849578496784977849878499785007850178502785037850478505785067850778508785097851078511785127851378514785157851678517785187851978520785217852278523785247852578526785277852878529785307853178532785337853478535785367853778538785397854078541785427854378544785457854678547785487854978550785517855278553785547855578556785577855878559785607856178562785637856478565785667856778568785697857078571785727857378574785757857678577785787857978580785817858278583785847858578586785877858878589785907859178592785937859478595785967859778598785997860078601786027860378604786057860678607786087860978610786117861278613786147861578616786177861878619786207862178622786237862478625786267862778628786297863078631786327863378634786357863678637786387863978640786417864278643786447864578646786477864878649786507865178652786537865478655786567865778658786597866078661786627866378664786657866678667786687866978670786717867278673786747867578676786777867878679786807868178682786837868478685786867868778688786897869078691786927869378694786957869678697786987869978700787017870278703787047870578706787077870878709787107871178712787137871478715787167871778718787197872078721787227872378724787257872678727787287872978730787317873278733787347873578736787377873878739787407874178742787437874478745787467874778748787497875078751787527875378754787557875678757787587875978760787617876278763787647876578766787677876878769787707877178772787737877478775787767877778778787797878078781787827878378784787857878678787787887878978790787917879278793787947879578796787977879878799788007880178802788037880478805788067880778808788097881078811788127881378814788157881678817788187881978820788217882278823788247882578826788277882878829788307883178832788337883478835788367883778838788397884078841788427884378844788457884678847788487884978850788517885278853788547885578856788577885878859788607886178862788637886478865788667886778868788697887078871788727887378874788757887678877788787887978880788817888278883788847888578886788877888878889788907889178892788937889478895788967889778898788997890078901789027890378904789057890678907789087890978910789117891278913789147891578916789177891878919789207892178922789237892478925789267892778928789297893078931789327893378934789357893678937789387893978940789417894278943789447894578946789477894878949789507895178952789537895478955789567895778958789597896078961789627896378964789657896678967789687896978970789717897278973789747897578976789777897878979789807898178982789837898478985789867898778988789897899078991789927899378994789957899678997789987899979000790017900279003790047900579006790077900879009790107901179012790137901479015790167901779018790197902079021790227902379024790257902679027790287902979030790317903279033790347903579036790377903879039790407904179042790437904479045790467904779048790497905079051790527905379054790557905679057790587905979060790617906279063790647906579066790677906879069790707907179072790737907479075790767907779078790797908079081790827908379084790857908679087790887908979090790917909279093790947909579096790977909879099791007910179102791037910479105791067910779108791097911079111791127911379114791157911679117791187911979120791217912279123791247912579126791277912879129791307913179132791337913479135791367913779138791397914079141791427914379144791457914679147791487914979150791517915279153791547915579156791577915879159791607916179162791637916479165791667916779168791697917079171791727917379174791757917679177791787917979180791817918279183791847918579186791877918879189791907919179192791937919479195791967919779198791997920079201792027920379204792057920679207792087920979210792117921279213792147921579216792177921879219792207922179222792237922479225792267922779228792297923079231792327923379234792357923679237792387923979240792417924279243792447924579246792477924879249792507925179252792537925479255792567925779258792597926079261792627926379264792657926679267792687926979270792717927279273792747927579276792777927879279792807928179282792837928479285792867928779288792897929079291792927929379294792957929679297792987929979300793017930279303793047930579306793077930879309793107931179312793137931479315793167931779318793197932079321793227932379324793257932679327793287932979330793317933279333793347933579336793377933879339793407934179342793437934479345793467934779348793497935079351793527935379354793557935679357793587935979360793617936279363793647936579366793677936879369793707937179372793737937479375793767937779378793797938079381793827938379384793857938679387793887938979390793917939279393793947939579396793977939879399794007940179402794037940479405794067940779408794097941079411794127941379414794157941679417794187941979420794217942279423794247942579426794277942879429794307943179432794337943479435794367943779438794397944079441794427944379444794457944679447794487944979450794517945279453794547945579456794577945879459794607946179462794637946479465794667946779468794697947079471794727947379474794757947679477794787947979480794817948279483794847948579486794877948879489794907949179492794937949479495794967949779498794997950079501795027950379504795057950679507795087950979510795117951279513795147951579516795177951879519795207952179522795237952479525795267952779528795297953079531795327953379534795357953679537795387953979540795417954279543795447954579546795477954879549795507955179552795537955479555795567955779558795597956079561795627956379564795657956679567795687956979570795717957279573795747957579576795777957879579795807958179582795837958479585795867958779588795897959079591795927959379594795957959679597795987959979600796017960279603796047960579606796077960879609796107961179612796137961479615796167961779618796197962079621796227962379624796257962679627796287962979630796317963279633796347963579636796377963879639796407964179642796437964479645796467964779648796497965079651796527965379654796557965679657796587965979660796617966279663796647966579666796677966879669796707967179672796737967479675796767967779678796797968079681796827968379684796857968679687796887968979690796917969279693796947969579696796977969879699797007970179702797037970479705797067970779708797097971079711797127971379714797157971679717797187971979720797217972279723797247972579726797277972879729797307973179732797337973479735797367973779738797397974079741797427974379744797457974679747797487974979750797517975279753797547975579756797577975879759797607976179762797637976479765797667976779768797697977079771797727977379774797757977679777797787977979780797817978279783797847978579786797877978879789797907979179792797937979479795797967979779798797997980079801798027980379804798057980679807798087980979810798117981279813798147981579816798177981879819798207982179822798237982479825798267982779828798297983079831798327983379834798357983679837798387983979840798417984279843798447984579846798477984879849798507985179852798537985479855798567985779858798597986079861798627986379864798657986679867798687986979870798717987279873798747987579876798777987879879798807988179882798837988479885798867988779888798897989079891798927989379894798957989679897798987989979900799017990279903799047990579906799077990879909799107991179912799137991479915799167991779918799197992079921799227992379924799257992679927799287992979930799317993279933799347993579936799377993879939799407994179942799437994479945799467994779948799497995079951799527995379954799557995679957799587995979960799617996279963799647996579966799677996879969799707997179972799737997479975799767997779978799797998079981799827998379984799857998679987799887998979990799917999279993799947999579996799977999879999800008000180002800038000480005800068000780008800098001080011800128001380014800158001680017800188001980020800218002280023800248002580026800278002880029800308003180032800338003480035800368003780038800398004080041800428004380044800458004680047800488004980050800518005280053800548005580056800578005880059800608006180062800638006480065800668006780068800698007080071800728007380074800758007680077800788007980080800818008280083800848008580086800878008880089800908009180092800938009480095800968009780098800998010080101801028010380104801058010680107801088010980110801118011280113801148011580116801178011880119801208012180122801238012480125801268012780128801298013080131801328013380134801358013680137801388013980140801418014280143801448014580146801478014880149801508015180152801538015480155801568015780158801598016080161801628016380164801658016680167801688016980170801718017280173801748017580176801778017880179801808018180182801838018480185801868018780188801898019080191801928019380194801958019680197801988019980200802018020280203802048020580206802078020880209802108021180212802138021480215802168021780218802198022080221802228022380224802258022680227802288022980230802318023280233802348023580236802378023880239802408024180242802438024480245802468024780248802498025080251802528025380254802558025680257802588025980260802618026280263802648026580266802678026880269802708027180272802738027480275802768027780278802798028080281802828028380284802858028680287802888028980290802918029280293802948029580296802978029880299803008030180302803038030480305803068030780308803098031080311803128031380314803158031680317803188031980320803218032280323803248032580326803278032880329803308033180332803338033480335803368033780338803398034080341803428034380344803458034680347803488034980350803518035280353803548035580356803578035880359803608036180362803638036480365803668036780368803698037080371803728037380374803758037680377803788037980380803818038280383803848038580386803878038880389803908039180392803938039480395803968039780398803998040080401804028040380404804058040680407804088040980410804118041280413804148041580416804178041880419804208042180422804238042480425804268042780428804298043080431804328043380434804358043680437804388043980440804418044280443804448044580446804478044880449804508045180452804538045480455804568045780458804598046080461804628046380464804658046680467804688046980470804718047280473804748047580476804778047880479804808048180482804838048480485804868048780488804898049080491804928049380494804958049680497804988049980500805018050280503805048050580506805078050880509805108051180512805138051480515805168051780518805198052080521805228052380524805258052680527805288052980530805318053280533805348053580536805378053880539805408054180542805438054480545805468054780548805498055080551805528055380554805558055680557805588055980560805618056280563805648056580566805678056880569805708057180572805738057480575805768057780578805798058080581805828058380584805858058680587805888058980590805918059280593805948059580596805978059880599806008060180602806038060480605806068060780608806098061080611806128061380614806158061680617806188061980620806218062280623806248062580626806278062880629806308063180632806338063480635806368063780638806398064080641806428064380644806458064680647806488064980650806518065280653806548065580656806578065880659806608066180662806638066480665806668066780668806698067080671806728067380674806758067680677806788067980680806818068280683806848068580686806878068880689806908069180692806938069480695806968069780698806998070080701807028070380704807058070680707807088070980710807118071280713807148071580716807178071880719807208072180722807238072480725807268072780728807298073080731807328073380734807358073680737807388073980740807418074280743807448074580746807478074880749807508075180752807538075480755807568075780758807598076080761807628076380764807658076680767807688076980770807718077280773807748077580776807778077880779807808078180782807838078480785807868078780788807898079080791807928079380794807958079680797807988079980800808018080280803808048080580806808078080880809808108081180812808138081480815808168081780818808198082080821808228082380824808258082680827808288082980830808318083280833808348083580836808378083880839808408084180842808438084480845808468084780848808498085080851808528085380854808558085680857808588085980860808618086280863808648086580866808678086880869808708087180872808738087480875808768087780878808798088080881808828088380884808858088680887808888088980890808918089280893808948089580896808978089880899809008090180902809038090480905809068090780908809098091080911809128091380914809158091680917809188091980920809218092280923809248092580926809278092880929809308093180932809338093480935809368093780938809398094080941809428094380944809458094680947809488094980950809518095280953809548095580956809578095880959809608096180962809638096480965809668096780968809698097080971809728097380974809758097680977809788097980980809818098280983809848098580986809878098880989809908099180992809938099480995809968099780998809998100081001810028100381004810058100681007810088100981010810118101281013810148101581016810178101881019810208102181022810238102481025810268102781028810298103081031810328103381034810358103681037810388103981040810418104281043810448104581046810478104881049810508105181052810538105481055810568105781058810598106081061810628106381064810658106681067810688106981070810718107281073810748107581076810778107881079810808108181082810838108481085810868108781088810898109081091810928109381094810958109681097810988109981100811018110281103811048110581106811078110881109811108111181112811138111481115811168111781118811198112081121811228112381124811258112681127811288112981130811318113281133811348113581136811378113881139811408114181142811438114481145811468114781148811498115081151811528115381154811558115681157811588115981160811618116281163811648116581166811678116881169811708117181172811738117481175811768117781178811798118081181811828118381184811858118681187811888118981190811918119281193811948119581196811978119881199812008120181202812038120481205812068120781208812098121081211812128121381214812158121681217812188121981220812218122281223812248122581226812278122881229812308123181232812338123481235812368123781238812398124081241812428124381244812458124681247812488124981250812518125281253812548125581256812578125881259812608126181262812638126481265812668126781268812698127081271812728127381274812758127681277812788127981280812818128281283812848128581286812878128881289812908129181292812938129481295812968129781298812998130081301813028130381304813058130681307813088130981310813118131281313813148131581316813178131881319813208132181322813238132481325813268132781328813298133081331813328133381334813358133681337813388133981340813418134281343813448134581346813478134881349813508135181352813538135481355813568135781358813598136081361813628136381364813658136681367813688136981370813718137281373813748137581376813778137881379813808138181382813838138481385813868138781388813898139081391813928139381394813958139681397813988139981400814018140281403814048140581406814078140881409814108141181412814138141481415814168141781418814198142081421814228142381424814258142681427814288142981430814318143281433814348143581436814378143881439814408144181442814438144481445814468144781448814498145081451814528145381454814558145681457814588145981460814618146281463814648146581466814678146881469814708147181472814738147481475814768147781478814798148081481814828148381484814858148681487814888148981490814918149281493814948149581496814978149881499815008150181502815038150481505815068150781508815098151081511815128151381514815158151681517815188151981520815218152281523815248152581526815278152881529815308153181532815338153481535815368153781538815398154081541815428154381544815458154681547815488154981550815518155281553815548155581556815578155881559815608156181562815638156481565815668156781568815698157081571815728157381574815758157681577815788157981580815818158281583815848158581586815878158881589815908159181592815938159481595815968159781598815998160081601816028160381604816058160681607816088160981610816118161281613816148161581616816178161881619816208162181622816238162481625816268162781628816298163081631816328163381634816358163681637816388163981640816418164281643816448164581646816478164881649816508165181652816538165481655816568165781658816598166081661816628166381664816658166681667816688166981670816718167281673816748167581676816778167881679816808168181682816838168481685816868168781688816898169081691816928169381694816958169681697816988169981700817018170281703817048170581706817078170881709817108171181712817138171481715817168171781718817198172081721817228172381724817258172681727817288172981730817318173281733817348173581736817378173881739817408174181742817438174481745817468174781748817498175081751817528175381754817558175681757817588175981760817618176281763817648176581766817678176881769817708177181772817738177481775817768177781778817798178081781817828178381784817858178681787817888178981790817918179281793817948179581796817978179881799818008180181802818038180481805818068180781808818098181081811818128181381814818158181681817818188181981820818218182281823818248182581826818278182881829818308183181832818338183481835818368183781838818398184081841818428184381844818458184681847818488184981850818518185281853818548185581856818578185881859818608186181862818638186481865818668186781868818698187081871818728187381874818758187681877818788187981880818818188281883818848188581886818878188881889818908189181892818938189481895818968189781898818998190081901819028190381904819058190681907819088190981910819118191281913819148191581916819178191881919819208192181922819238192481925819268192781928819298193081931819328193381934819358193681937819388193981940819418194281943819448194581946819478194881949819508195181952819538195481955819568195781958819598196081961819628196381964819658196681967819688196981970819718197281973819748197581976819778197881979819808198181982819838198481985819868198781988819898199081991819928199381994819958199681997819988199982000820018200282003820048200582006820078200882009820108201182012820138201482015820168201782018820198202082021820228202382024820258202682027820288202982030820318203282033820348203582036820378203882039820408204182042820438204482045820468204782048820498205082051820528205382054820558205682057820588205982060820618206282063820648206582066820678206882069820708207182072820738207482075820768207782078820798208082081820828208382084820858208682087820888208982090820918209282093820948209582096820978209882099821008210182102821038210482105821068210782108821098211082111821128211382114821158211682117821188211982120821218212282123821248212582126821278212882129821308213182132821338213482135821368213782138821398214082141821428214382144821458214682147821488214982150821518215282153821548215582156821578215882159821608216182162821638216482165821668216782168821698217082171821728217382174821758217682177821788217982180821818218282183821848218582186821878218882189821908219182192821938219482195821968219782198821998220082201822028220382204822058220682207822088220982210822118221282213822148221582216822178221882219822208222182222822238222482225822268222782228822298223082231822328223382234822358223682237822388223982240822418224282243822448224582246822478224882249822508225182252822538225482255822568225782258822598226082261822628226382264822658226682267822688226982270822718227282273822748227582276822778227882279822808228182282822838228482285822868228782288822898229082291822928229382294822958229682297822988229982300823018230282303823048230582306823078230882309823108231182312823138231482315823168231782318823198232082321823228232382324823258232682327823288232982330823318233282333823348233582336823378233882339823408234182342823438234482345823468234782348823498235082351823528235382354823558235682357823588235982360823618236282363823648236582366823678236882369823708237182372823738237482375823768237782378823798238082381823828238382384823858238682387823888238982390823918239282393823948239582396823978239882399824008240182402824038240482405824068240782408824098241082411824128241382414824158241682417824188241982420824218242282423824248242582426824278242882429824308243182432824338243482435824368243782438824398244082441824428244382444824458244682447824488244982450824518245282453824548245582456824578245882459824608246182462824638246482465824668246782468824698247082471824728247382474824758247682477824788247982480824818248282483824848248582486824878248882489824908249182492824938249482495824968249782498824998250082501825028250382504825058250682507825088250982510825118251282513825148251582516825178251882519825208252182522825238252482525825268252782528825298253082531825328253382534825358253682537825388253982540825418254282543825448254582546825478254882549825508255182552825538255482555825568255782558825598256082561825628256382564825658256682567825688256982570825718257282573825748257582576825778257882579825808258182582825838258482585825868258782588825898259082591825928259382594825958259682597825988259982600826018260282603826048260582606826078260882609826108261182612826138261482615826168261782618826198262082621826228262382624826258262682627826288262982630826318263282633826348263582636826378263882639826408264182642826438264482645826468264782648826498265082651826528265382654826558265682657826588265982660826618266282663826648266582666826678266882669826708267182672826738267482675826768267782678826798268082681826828268382684826858268682687826888268982690826918269282693826948269582696826978269882699827008270182702827038270482705827068270782708827098271082711827128271382714827158271682717827188271982720827218272282723827248272582726827278272882729827308273182732827338273482735827368273782738827398274082741827428274382744827458274682747827488274982750827518275282753827548275582756827578275882759827608276182762827638276482765827668276782768827698277082771827728277382774827758277682777827788277982780827818278282783827848278582786827878278882789827908279182792827938279482795827968279782798827998280082801828028280382804828058280682807828088280982810828118281282813828148281582816828178281882819828208282182822828238282482825828268282782828828298283082831828328283382834828358283682837828388283982840828418284282843828448284582846828478284882849828508285182852828538285482855828568285782858828598286082861828628286382864828658286682867828688286982870828718287282873828748287582876828778287882879828808288182882828838288482885828868288782888828898289082891828928289382894828958289682897828988289982900829018290282903829048290582906829078290882909829108291182912829138291482915829168291782918829198292082921829228292382924829258292682927829288292982930829318293282933829348293582936829378293882939829408294182942829438294482945829468294782948829498295082951829528295382954829558295682957829588295982960829618296282963829648296582966829678296882969829708297182972829738297482975829768297782978829798298082981829828298382984829858298682987829888298982990829918299282993829948299582996829978299882999830008300183002830038300483005830068300783008830098301083011830128301383014830158301683017830188301983020830218302283023830248302583026830278302883029830308303183032830338303483035830368303783038830398304083041830428304383044830458304683047830488304983050830518305283053830548305583056830578305883059830608306183062830638306483065830668306783068830698307083071830728307383074830758307683077830788307983080830818308283083830848308583086830878308883089830908309183092830938309483095830968309783098830998310083101831028310383104831058310683107831088310983110831118311283113831148311583116831178311883119831208312183122831238312483125831268312783128831298313083131831328313383134831358313683137831388313983140831418314283143831448314583146831478314883149831508315183152831538315483155831568315783158831598316083161831628316383164831658316683167831688316983170831718317283173831748317583176831778317883179831808318183182831838318483185831868318783188831898319083191831928319383194831958319683197831988319983200832018320283203832048320583206832078320883209832108321183212832138321483215832168321783218832198322083221832228322383224832258322683227832288322983230832318323283233832348323583236832378323883239832408324183242832438324483245832468324783248832498325083251832528325383254832558325683257832588325983260832618326283263832648326583266832678326883269832708327183272832738327483275832768327783278832798328083281832828328383284832858328683287832888328983290832918329283293832948329583296832978329883299833008330183302833038330483305833068330783308833098331083311833128331383314833158331683317833188331983320833218332283323833248332583326833278332883329833308333183332833338333483335833368333783338833398334083341833428334383344833458334683347833488334983350833518335283353833548335583356833578335883359833608336183362833638336483365833668336783368833698337083371833728337383374833758337683377833788337983380833818338283383833848338583386833878338883389833908339183392833938339483395833968339783398833998340083401834028340383404834058340683407834088340983410834118341283413834148341583416834178341883419834208342183422834238342483425834268342783428834298343083431834328343383434834358343683437834388343983440834418344283443834448344583446834478344883449834508345183452834538345483455834568345783458834598346083461834628346383464834658346683467834688346983470834718347283473834748347583476834778347883479834808348183482834838348483485834868348783488834898349083491834928349383494834958349683497834988349983500835018350283503835048350583506835078350883509835108351183512835138351483515835168351783518835198352083521835228352383524835258352683527835288352983530835318353283533835348353583536835378353883539835408354183542835438354483545835468354783548835498355083551835528355383554835558355683557835588355983560835618356283563835648356583566835678356883569835708357183572835738357483575835768357783578835798358083581835828358383584835858358683587835888358983590835918359283593835948359583596835978359883599836008360183602836038360483605836068360783608836098361083611836128361383614836158361683617836188361983620836218362283623836248362583626836278362883629836308363183632836338363483635836368363783638836398364083641836428364383644836458364683647836488364983650836518365283653836548365583656836578365883659836608366183662836638366483665836668366783668836698367083671836728367383674836758367683677836788367983680836818368283683836848368583686836878368883689836908369183692836938369483695836968369783698836998370083701837028370383704837058370683707837088370983710837118371283713837148371583716837178371883719837208372183722837238372483725837268372783728837298373083731837328373383734837358373683737837388373983740837418374283743837448374583746837478374883749837508375183752837538375483755837568375783758837598376083761837628376383764837658376683767837688376983770837718377283773837748377583776837778377883779837808378183782837838378483785837868378783788837898379083791837928379383794837958379683797837988379983800838018380283803838048380583806838078380883809838108381183812838138381483815838168381783818838198382083821838228382383824838258382683827838288382983830838318383283833838348383583836838378383883839838408384183842838438384483845838468384783848838498385083851838528385383854838558385683857838588385983860838618386283863838648386583866838678386883869838708387183872838738387483875838768387783878838798388083881838828388383884838858388683887838888388983890838918389283893838948389583896838978389883899839008390183902839038390483905839068390783908839098391083911839128391383914839158391683917839188391983920839218392283923839248392583926839278392883929839308393183932839338393483935839368393783938839398394083941839428394383944839458394683947839488394983950839518395283953839548395583956839578395883959839608396183962839638396483965839668396783968839698397083971839728397383974839758397683977839788397983980839818398283983839848398583986839878398883989839908399183992839938399483995839968399783998839998400084001840028400384004840058400684007840088400984010840118401284013840148401584016840178401884019840208402184022840238402484025840268402784028840298403084031840328403384034840358403684037840388403984040840418404284043840448404584046840478404884049840508405184052840538405484055840568405784058840598406084061840628406384064840658406684067840688406984070840718407284073840748407584076840778407884079840808408184082840838408484085840868408784088840898409084091840928409384094840958409684097840988409984100841018410284103841048410584106841078410884109841108411184112841138411484115841168411784118841198412084121841228412384124841258412684127841288412984130841318413284133841348413584136841378413884139841408414184142841438414484145841468414784148841498415084151841528415384154841558415684157841588415984160841618416284163841648416584166841678416884169841708417184172841738417484175841768417784178841798418084181841828418384184841858418684187841888418984190841918419284193841948419584196841978419884199842008420184202842038420484205842068420784208842098421084211842128421384214842158421684217842188421984220842218422284223842248422584226842278422884229842308423184232842338423484235842368423784238842398424084241842428424384244842458424684247842488424984250842518425284253842548425584256842578425884259842608426184262842638426484265842668426784268842698427084271842728427384274842758427684277842788427984280842818428284283842848428584286842878428884289842908429184292842938429484295842968429784298842998430084301843028430384304843058430684307843088430984310843118431284313843148431584316843178431884319843208432184322843238432484325843268432784328843298433084331843328433384334843358433684337843388433984340843418434284343843448434584346843478434884349843508435184352843538435484355843568435784358843598436084361843628436384364843658436684367843688436984370843718437284373843748437584376843778437884379843808438184382843838438484385843868438784388843898439084391843928439384394843958439684397843988439984400844018440284403844048440584406844078440884409844108441184412844138441484415844168441784418844198442084421844228442384424844258442684427844288442984430844318443284433844348443584436844378443884439844408444184442844438444484445844468444784448844498445084451844528445384454844558445684457844588445984460844618446284463844648446584466844678446884469844708447184472844738447484475844768447784478844798448084481844828448384484844858448684487844888448984490844918449284493844948449584496844978449884499845008450184502845038450484505845068450784508845098451084511845128451384514845158451684517845188451984520845218452284523845248452584526845278452884529845308453184532845338453484535845368453784538845398454084541845428454384544845458454684547845488454984550845518455284553845548455584556845578455884559845608456184562845638456484565845668456784568845698457084571845728457384574845758457684577845788457984580845818458284583845848458584586845878458884589845908459184592845938459484595845968459784598845998460084601846028460384604846058460684607846088460984610846118461284613846148461584616846178461884619846208462184622846238462484625846268462784628846298463084631846328463384634846358463684637846388463984640846418464284643846448464584646846478464884649846508465184652846538465484655846568465784658846598466084661846628466384664846658466684667846688466984670846718467284673846748467584676846778467884679846808468184682846838468484685846868468784688846898469084691846928469384694846958469684697846988469984700847018470284703847048470584706847078470884709847108471184712847138471484715847168471784718847198472084721847228472384724847258472684727847288472984730847318473284733847348473584736847378473884739847408474184742847438474484745847468474784748847498475084751847528475384754847558475684757847588475984760847618476284763847648476584766847678476884769847708477184772847738477484775847768477784778847798478084781847828478384784847858478684787847888478984790847918479284793847948479584796847978479884799848008480184802848038480484805848068480784808848098481084811848128481384814848158481684817848188481984820848218482284823848248482584826848278482884829848308483184832848338483484835848368483784838848398484084841848428484384844848458484684847848488484984850848518485284853848548485584856848578485884859848608486184862848638486484865848668486784868848698487084871848728487384874848758487684877848788487984880848818488284883848848488584886848878488884889848908489184892848938489484895848968489784898848998490084901849028490384904849058490684907849088490984910849118491284913849148491584916849178491884919849208492184922849238492484925849268492784928849298493084931849328493384934849358493684937849388493984940849418494284943849448494584946849478494884949849508495184952849538495484955849568495784958849598496084961849628496384964849658496684967849688496984970849718497284973849748497584976849778497884979849808498184982849838498484985849868498784988849898499084991849928499384994849958499684997849988499985000850018500285003850048500585006850078500885009850108501185012850138501485015850168501785018850198502085021850228502385024850258502685027850288502985030850318503285033850348503585036850378503885039850408504185042850438504485045850468504785048850498505085051850528505385054850558505685057850588505985060850618506285063850648506585066850678506885069850708507185072850738507485075850768507785078850798508085081850828508385084850858508685087850888508985090850918509285093850948509585096850978509885099851008510185102851038510485105851068510785108851098511085111851128511385114851158511685117851188511985120851218512285123851248512585126851278512885129851308513185132851338513485135851368513785138851398514085141851428514385144851458514685147851488514985150851518515285153851548515585156851578515885159851608516185162851638516485165851668516785168851698517085171851728517385174851758517685177851788517985180851818518285183851848518585186851878518885189851908519185192851938519485195851968519785198851998520085201852028520385204852058520685207852088520985210852118521285213852148521585216852178521885219852208522185222852238522485225852268522785228852298523085231852328523385234852358523685237852388523985240852418524285243852448524585246852478524885249852508525185252852538525485255852568525785258852598526085261852628526385264852658526685267852688526985270852718527285273852748527585276852778527885279852808528185282852838528485285852868528785288852898529085291852928529385294852958529685297852988529985300853018530285303853048530585306853078530885309853108531185312853138531485315853168531785318853198532085321853228532385324853258532685327853288532985330853318533285333853348533585336853378533885339853408534185342853438534485345853468534785348853498535085351853528535385354853558535685357853588535985360853618536285363853648536585366853678536885369853708537185372853738537485375853768537785378853798538085381853828538385384853858538685387853888538985390853918539285393853948539585396853978539885399854008540185402854038540485405854068540785408854098541085411854128541385414854158541685417854188541985420854218542285423854248542585426854278542885429854308543185432854338543485435854368543785438854398544085441854428544385444854458544685447854488544985450854518545285453854548545585456854578545885459854608546185462854638546485465854668546785468854698547085471854728547385474854758547685477854788547985480854818548285483854848548585486854878548885489854908549185492854938549485495854968549785498854998550085501855028550385504855058550685507855088550985510855118551285513855148551585516855178551885519855208552185522855238552485525855268552785528855298553085531855328553385534855358553685537855388553985540855418554285543855448554585546855478554885549855508555185552855538555485555855568555785558855598556085561855628556385564855658556685567855688556985570855718557285573855748557585576855778557885579855808558185582855838558485585855868558785588855898559085591855928559385594855958559685597855988559985600856018560285603856048560585606856078560885609856108561185612856138561485615856168561785618856198562085621856228562385624856258562685627856288562985630856318563285633856348563585636856378563885639856408564185642856438564485645856468564785648856498565085651856528565385654856558565685657856588565985660856618566285663856648566585666856678566885669856708567185672856738567485675856768567785678856798568085681856828568385684856858568685687856888568985690856918569285693856948569585696856978569885699857008570185702857038570485705857068570785708857098571085711857128571385714857158571685717857188571985720857218572285723857248572585726857278572885729857308573185732857338573485735857368573785738857398574085741857428574385744857458574685747857488574985750857518575285753857548575585756857578575885759857608576185762857638576485765857668576785768857698577085771857728577385774857758577685777857788577985780857818578285783857848578585786857878578885789857908579185792857938579485795857968579785798857998580085801858028580385804858058580685807858088580985810858118581285813858148581585816858178581885819858208582185822858238582485825858268582785828858298583085831858328583385834858358583685837858388583985840858418584285843858448584585846858478584885849858508585185852858538585485855858568585785858858598586085861858628586385864858658586685867858688586985870858718587285873858748587585876858778587885879858808588185882858838588485885858868588785888858898589085891858928589385894858958589685897858988589985900859018590285903859048590585906859078590885909859108591185912859138591485915859168591785918859198592085921859228592385924859258592685927859288592985930859318593285933859348593585936859378593885939859408594185942859438594485945859468594785948859498595085951859528595385954859558595685957859588595985960859618596285963859648596585966859678596885969859708597185972859738597485975859768597785978859798598085981859828598385984859858598685987859888598985990859918599285993859948599585996859978599885999860008600186002860038600486005860068600786008860098601086011860128601386014860158601686017860188601986020860218602286023860248602586026860278602886029860308603186032860338603486035860368603786038860398604086041860428604386044860458604686047860488604986050860518605286053860548605586056860578605886059860608606186062860638606486065860668606786068860698607086071860728607386074860758607686077860788607986080860818608286083860848608586086860878608886089860908609186092860938609486095860968609786098860998610086101861028610386104861058610686107861088610986110861118611286113861148611586116861178611886119861208612186122861238612486125861268612786128861298613086131861328613386134861358613686137861388613986140861418614286143861448614586146861478614886149861508615186152861538615486155861568615786158861598616086161861628616386164861658616686167861688616986170861718617286173861748617586176861778617886179861808618186182861838618486185861868618786188861898619086191861928619386194861958619686197861988619986200862018620286203862048620586206862078620886209862108621186212862138621486215862168621786218862198622086221862228622386224862258622686227862288622986230862318623286233862348623586236862378623886239862408624186242862438624486245862468624786248862498625086251862528625386254862558625686257862588625986260862618626286263862648626586266862678626886269862708627186272862738627486275862768627786278862798628086281862828628386284862858628686287862888628986290862918629286293862948629586296862978629886299863008630186302863038630486305863068630786308863098631086311863128631386314863158631686317863188631986320863218632286323863248632586326863278632886329863308633186332863338633486335863368633786338863398634086341863428634386344863458634686347863488634986350863518635286353863548635586356863578635886359863608636186362863638636486365863668636786368863698637086371863728637386374863758637686377863788637986380863818638286383863848638586386863878638886389863908639186392863938639486395863968639786398863998640086401864028640386404864058640686407864088640986410864118641286413864148641586416864178641886419864208642186422864238642486425864268642786428864298643086431864328643386434864358643686437864388643986440864418644286443864448644586446864478644886449864508645186452864538645486455864568645786458864598646086461864628646386464864658646686467864688646986470864718647286473864748647586476864778647886479864808648186482864838648486485864868648786488864898649086491864928649386494864958649686497864988649986500865018650286503865048650586506865078650886509865108651186512865138651486515865168651786518865198652086521865228652386524865258652686527865288652986530865318653286533865348653586536865378653886539865408654186542865438654486545865468654786548865498655086551865528655386554865558655686557865588655986560865618656286563865648656586566865678656886569865708657186572865738657486575865768657786578865798658086581865828658386584865858658686587865888658986590865918659286593865948659586596865978659886599866008660186602866038660486605866068660786608866098661086611866128661386614866158661686617866188661986620866218662286623866248662586626866278662886629866308663186632866338663486635866368663786638866398664086641866428664386644866458664686647866488664986650866518665286653866548665586656866578665886659866608666186662866638666486665866668666786668866698667086671866728667386674866758667686677866788667986680866818668286683866848668586686866878668886689866908669186692866938669486695866968669786698866998670086701867028670386704867058670686707867088670986710867118671286713867148671586716867178671886719867208672186722867238672486725867268672786728867298673086731867328673386734867358673686737867388673986740867418674286743867448674586746867478674886749867508675186752867538675486755867568675786758867598676086761867628676386764867658676686767867688676986770867718677286773867748677586776867778677886779867808678186782867838678486785867868678786788867898679086791867928679386794867958679686797867988679986800868018680286803868048680586806868078680886809868108681186812868138681486815868168681786818868198682086821868228682386824868258682686827868288682986830868318683286833868348683586836868378683886839868408684186842868438684486845868468684786848868498685086851868528685386854868558685686857868588685986860868618686286863868648686586866868678686886869868708687186872868738687486875868768687786878868798688086881868828688386884868858688686887868888688986890868918689286893868948689586896868978689886899869008690186902869038690486905869068690786908869098691086911869128691386914869158691686917869188691986920869218692286923869248692586926869278692886929869308693186932869338693486935869368693786938869398694086941869428694386944869458694686947869488694986950869518695286953869548695586956869578695886959869608696186962869638696486965869668696786968869698697086971869728697386974869758697686977869788697986980869818698286983869848698586986869878698886989869908699186992869938699486995869968699786998869998700087001870028700387004870058700687007870088700987010870118701287013870148701587016870178701887019870208702187022870238702487025870268702787028870298703087031870328703387034870358703687037870388703987040870418704287043870448704587046870478704887049870508705187052870538705487055870568705787058870598706087061870628706387064870658706687067870688706987070870718707287073870748707587076870778707887079870808708187082870838708487085870868708787088870898709087091870928709387094870958709687097870988709987100871018710287103871048710587106871078710887109871108711187112871138711487115871168711787118871198712087121871228712387124871258712687127871288712987130871318713287133871348713587136871378713887139871408714187142871438714487145871468714787148871498715087151871528715387154871558715687157871588715987160871618716287163871648716587166871678716887169871708717187172871738717487175871768717787178871798718087181871828718387184871858718687187871888718987190871918719287193871948719587196871978719887199872008720187202872038720487205872068720787208872098721087211872128721387214872158721687217872188721987220872218722287223872248722587226872278722887229872308723187232872338723487235872368723787238872398724087241872428724387244872458724687247872488724987250872518725287253872548725587256872578725887259872608726187262872638726487265872668726787268872698727087271872728727387274872758727687277872788727987280872818728287283872848728587286872878728887289872908729187292872938729487295872968729787298872998730087301873028730387304873058730687307873088730987310873118731287313873148731587316873178731887319873208732187322873238732487325873268732787328873298733087331873328733387334873358733687337873388733987340873418734287343873448734587346873478734887349873508735187352873538735487355873568735787358873598736087361873628736387364873658736687367873688736987370873718737287373873748737587376873778737887379873808738187382873838738487385873868738787388873898739087391873928739387394873958739687397873988739987400874018740287403874048740587406874078740887409874108741187412874138741487415874168741787418874198742087421874228742387424874258742687427874288742987430874318743287433874348743587436874378743887439874408744187442874438744487445874468744787448874498745087451874528745387454874558745687457874588745987460874618746287463874648746587466874678746887469874708747187472874738747487475874768747787478874798748087481874828748387484874858748687487874888748987490874918749287493874948749587496874978749887499875008750187502875038750487505875068750787508875098751087511875128751387514875158751687517875188751987520875218752287523875248752587526875278752887529875308753187532875338753487535875368753787538875398754087541875428754387544875458754687547875488754987550875518755287553875548755587556875578755887559875608756187562875638756487565875668756787568875698757087571875728757387574875758757687577875788757987580875818758287583875848758587586875878758887589875908759187592875938759487595875968759787598875998760087601876028760387604876058760687607876088760987610876118761287613876148761587616876178761887619876208762187622876238762487625876268762787628876298763087631876328763387634876358763687637876388763987640876418764287643876448764587646876478764887649876508765187652876538765487655876568765787658876598766087661876628766387664876658766687667876688766987670876718767287673876748767587676876778767887679876808768187682876838768487685876868768787688876898769087691876928769387694876958769687697876988769987700877018770287703877048770587706877078770887709877108771187712877138771487715877168771787718877198772087721877228772387724877258772687727877288772987730877318773287733877348773587736877378773887739877408774187742877438774487745877468774787748877498775087751877528775387754877558775687757877588775987760877618776287763877648776587766877678776887769877708777187772877738777487775877768777787778877798778087781877828778387784877858778687787877888778987790877918779287793877948779587796877978779887799878008780187802878038780487805878068780787808878098781087811878128781387814878158781687817878188781987820878218782287823878248782587826878278782887829878308783187832878338783487835878368783787838878398784087841878428784387844878458784687847878488784987850878518785287853878548785587856878578785887859878608786187862878638786487865878668786787868878698787087871878728787387874878758787687877878788787987880878818788287883878848788587886878878788887889878908789187892878938789487895878968789787898878998790087901879028790387904879058790687907879088790987910879118791287913879148791587916879178791887919879208792187922879238792487925879268792787928879298793087931879328793387934879358793687937879388793987940879418794287943879448794587946879478794887949879508795187952879538795487955879568795787958879598796087961879628796387964879658796687967879688796987970879718797287973879748797587976879778797887979879808798187982879838798487985879868798787988879898799087991879928799387994879958799687997879988799988000880018800288003880048800588006880078800888009880108801188012880138801488015880168801788018880198802088021880228802388024880258802688027880288802988030880318803288033880348803588036880378803888039880408804188042880438804488045880468804788048880498805088051880528805388054880558805688057880588805988060880618806288063880648806588066880678806888069880708807188072880738807488075880768807788078880798808088081880828808388084880858808688087880888808988090880918809288093880948809588096880978809888099881008810188102881038810488105881068810788108881098811088111881128811388114881158811688117881188811988120881218812288123881248812588126881278812888129881308813188132881338813488135881368813788138881398814088141881428814388144881458814688147881488814988150881518815288153881548815588156881578815888159881608816188162881638816488165881668816788168881698817088171881728817388174881758817688177881788817988180881818818288183881848818588186881878818888189881908819188192881938819488195881968819788198881998820088201882028820388204882058820688207882088820988210882118821288213882148821588216882178821888219882208822188222882238822488225882268822788228882298823088231882328823388234882358823688237882388823988240882418824288243882448824588246882478824888249882508825188252882538825488255882568825788258882598826088261882628826388264882658826688267882688826988270882718827288273882748827588276882778827888279882808828188282882838828488285882868828788288882898829088291882928829388294882958829688297882988829988300883018830288303883048830588306883078830888309883108831188312883138831488315883168831788318883198832088321883228832388324883258832688327883288832988330883318833288333883348833588336883378833888339883408834188342883438834488345883468834788348883498835088351883528835388354883558835688357883588835988360883618836288363883648836588366883678836888369883708837188372883738837488375883768837788378883798838088381883828838388384883858838688387883888838988390883918839288393883948839588396883978839888399884008840188402884038840488405884068840788408884098841088411884128841388414884158841688417884188841988420884218842288423884248842588426884278842888429884308843188432884338843488435884368843788438884398844088441884428844388444884458844688447884488844988450884518845288453884548845588456884578845888459884608846188462884638846488465884668846788468884698847088471884728847388474884758847688477884788847988480884818848288483884848848588486884878848888489884908849188492884938849488495884968849788498884998850088501885028850388504885058850688507885088850988510885118851288513885148851588516885178851888519885208852188522885238852488525885268852788528885298853088531885328853388534885358853688537885388853988540885418854288543885448854588546885478854888549885508855188552885538855488555885568855788558885598856088561885628856388564885658856688567885688856988570885718857288573885748857588576885778857888579885808858188582885838858488585885868858788588885898859088591885928859388594885958859688597885988859988600886018860288603886048860588606886078860888609886108861188612886138861488615886168861788618886198862088621886228862388624886258862688627886288862988630886318863288633886348863588636886378863888639886408864188642886438864488645886468864788648886498865088651886528865388654886558865688657886588865988660886618866288663886648866588666886678866888669886708867188672886738867488675886768867788678886798868088681886828868388684886858868688687886888868988690886918869288693886948869588696886978869888699887008870188702887038870488705887068870788708887098871088711887128871388714887158871688717887188871988720887218872288723887248872588726887278872888729887308873188732887338873488735887368873788738887398874088741887428874388744887458874688747887488874988750887518875288753887548875588756887578875888759887608876188762887638876488765887668876788768887698877088771887728877388774887758877688777887788877988780887818878288783887848878588786887878878888789887908879188792887938879488795887968879788798887998880088801888028880388804888058880688807888088880988810888118881288813888148881588816888178881888819888208882188822888238882488825888268882788828888298883088831888328883388834888358883688837888388883988840888418884288843888448884588846888478884888849888508885188852888538885488855888568885788858888598886088861888628886388864888658886688867888688886988870888718887288873888748887588876888778887888879888808888188882888838888488885888868888788888888898889088891888928889388894888958889688897888988889988900889018890288903889048890588906889078890888909889108891188912889138891488915889168891788918889198892088921889228892388924889258892688927889288892988930889318893288933889348893588936889378893888939889408894188942889438894488945889468894788948889498895088951889528895388954889558895688957889588895988960889618896288963889648896588966889678896888969889708897188972889738897488975889768897788978889798898088981889828898388984889858898688987889888898988990889918899288993889948899588996889978899888999890008900189002890038900489005890068900789008890098901089011890128901389014890158901689017890188901989020890218902289023890248902589026890278902889029890308903189032890338903489035890368903789038890398904089041890428904389044890458904689047890488904989050890518905289053890548905589056890578905889059890608906189062890638906489065890668906789068890698907089071890728907389074890758907689077890788907989080890818908289083890848908589086890878908889089890908909189092890938909489095890968909789098890998910089101891028910389104891058910689107891088910989110891118911289113891148911589116891178911889119891208912189122891238912489125891268912789128891298913089131891328913389134891358913689137891388913989140891418914289143891448914589146891478914889149891508915189152891538915489155891568915789158891598916089161891628916389164891658916689167891688916989170891718917289173891748917589176891778917889179891808918189182891838918489185891868918789188891898919089191891928919389194891958919689197891988919989200892018920289203892048920589206892078920889209892108921189212892138921489215892168921789218892198922089221892228922389224892258922689227892288922989230892318923289233892348923589236892378923889239892408924189242892438924489245892468924789248892498925089251892528925389254892558925689257892588925989260892618926289263892648926589266892678926889269892708927189272892738927489275892768927789278892798928089281892828928389284892858928689287892888928989290892918929289293892948929589296892978929889299893008930189302893038930489305893068930789308893098931089311893128931389314893158931689317893188931989320893218932289323893248932589326893278932889329893308933189332893338933489335893368933789338893398934089341893428934389344893458934689347893488934989350893518935289353893548935589356893578935889359893608936189362893638936489365893668936789368893698937089371893728937389374893758937689377893788937989380893818938289383893848938589386893878938889389893908939189392893938939489395893968939789398893998940089401894028940389404894058940689407894088940989410894118941289413894148941589416894178941889419894208942189422894238942489425894268942789428894298943089431894328943389434894358943689437894388943989440894418944289443894448944589446894478944889449894508945189452894538945489455894568945789458894598946089461894628946389464894658946689467894688946989470894718947289473894748947589476894778947889479894808948189482894838948489485894868948789488894898949089491894928949389494894958949689497894988949989500895018950289503895048950589506895078950889509895108951189512895138951489515895168951789518895198952089521895228952389524895258952689527895288952989530895318953289533895348953589536895378953889539895408954189542895438954489545895468954789548895498955089551895528955389554895558955689557895588955989560895618956289563895648956589566895678956889569895708957189572895738957489575895768957789578895798958089581895828958389584895858958689587895888958989590895918959289593895948959589596895978959889599896008960189602896038960489605896068960789608896098961089611896128961389614896158961689617896188961989620896218962289623896248962589626896278962889629896308963189632896338963489635896368963789638896398964089641896428964389644896458964689647896488964989650896518965289653896548965589656896578965889659896608966189662896638966489665896668966789668896698967089671896728967389674896758967689677896788967989680896818968289683896848968589686896878968889689896908969189692896938969489695896968969789698896998970089701897028970389704897058970689707897088970989710897118971289713897148971589716897178971889719897208972189722897238972489725897268972789728897298973089731897328973389734897358973689737897388973989740897418974289743897448974589746897478974889749897508975189752897538975489755897568975789758897598976089761897628976389764897658976689767897688976989770897718977289773897748977589776897778977889779897808978189782897838978489785897868978789788897898979089791897928979389794897958979689797897988979989800898018980289803898048980589806898078980889809898108981189812898138981489815898168981789818898198982089821898228982389824898258982689827898288982989830898318983289833898348983589836898378983889839898408984189842898438984489845898468984789848898498985089851898528985389854898558985689857898588985989860898618986289863898648986589866898678986889869898708987189872898738987489875898768987789878898798988089881898828988389884898858988689887898888988989890898918989289893898948989589896898978989889899899008990189902899038990489905899068990789908899098991089911899128991389914899158991689917899188991989920899218992289923899248992589926899278992889929899308993189932899338993489935899368993789938899398994089941899428994389944899458994689947899488994989950899518995289953899548995589956899578995889959899608996189962899638996489965899668996789968899698997089971899728997389974899758997689977899788997989980899818998289983899848998589986899878998889989899908999189992899938999489995899968999789998899999000090001900029000390004900059000690007900089000990010900119001290013900149001590016900179001890019900209002190022900239002490025900269002790028900299003090031900329003390034900359003690037900389003990040900419004290043900449004590046900479004890049900509005190052900539005490055900569005790058900599006090061900629006390064900659006690067900689006990070900719007290073900749007590076900779007890079900809008190082900839008490085900869008790088900899009090091900929009390094900959009690097900989009990100901019010290103901049010590106901079010890109901109011190112901139011490115901169011790118901199012090121901229012390124901259012690127901289012990130901319013290133901349013590136901379013890139901409014190142901439014490145901469014790148901499015090151901529015390154901559015690157901589015990160901619016290163901649016590166901679016890169901709017190172901739017490175901769017790178901799018090181901829018390184901859018690187901889018990190901919019290193901949019590196901979019890199902009020190202902039020490205902069020790208902099021090211902129021390214902159021690217902189021990220902219022290223902249022590226902279022890229902309023190232902339023490235902369023790238902399024090241902429024390244902459024690247902489024990250902519025290253902549025590256902579025890259902609026190262902639026490265902669026790268902699027090271902729027390274902759027690277902789027990280902819028290283902849028590286902879028890289902909029190292902939029490295902969029790298902999030090301903029030390304903059030690307903089030990310903119031290313903149031590316903179031890319903209032190322903239032490325903269032790328903299033090331903329033390334903359033690337903389033990340903419034290343903449034590346903479034890349903509035190352903539035490355903569035790358903599036090361903629036390364903659036690367903689036990370903719037290373903749037590376903779037890379903809038190382903839038490385903869038790388903899039090391903929039390394903959039690397903989039990400904019040290403904049040590406904079040890409904109041190412904139041490415904169041790418904199042090421904229042390424904259042690427904289042990430904319043290433904349043590436904379043890439904409044190442904439044490445904469044790448904499045090451904529045390454904559045690457904589045990460904619046290463904649046590466904679046890469904709047190472904739047490475904769047790478904799048090481904829048390484904859048690487904889048990490904919049290493904949049590496904979049890499905009050190502905039050490505905069050790508905099051090511905129051390514905159051690517905189051990520905219052290523905249052590526905279052890529905309053190532905339053490535905369053790538905399054090541905429054390544905459054690547905489054990550905519055290553905549055590556905579055890559905609056190562905639056490565905669056790568905699057090571905729057390574905759057690577905789057990580905819058290583905849058590586905879058890589905909059190592905939059490595905969059790598905999060090601906029060390604906059060690607906089060990610906119061290613906149061590616906179061890619906209062190622906239062490625906269062790628906299063090631906329063390634906359063690637906389063990640906419064290643906449064590646906479064890649906509065190652906539065490655906569065790658906599066090661906629066390664906659066690667906689066990670906719067290673906749067590676906779067890679906809068190682906839068490685906869068790688906899069090691906929069390694906959069690697906989069990700907019070290703907049070590706907079070890709907109071190712907139071490715907169071790718907199072090721907229072390724907259072690727907289072990730907319073290733907349073590736907379073890739907409074190742907439074490745907469074790748907499075090751907529075390754907559075690757907589075990760907619076290763907649076590766907679076890769907709077190772907739077490775907769077790778907799078090781907829078390784907859078690787907889078990790907919079290793907949079590796907979079890799908009080190802908039080490805908069080790808908099081090811908129081390814908159081690817908189081990820908219082290823908249082590826908279082890829908309083190832908339083490835908369083790838908399084090841908429084390844908459084690847908489084990850908519085290853908549085590856908579085890859908609086190862908639086490865908669086790868908699087090871908729087390874908759087690877908789087990880908819088290883908849088590886908879088890889908909089190892908939089490895908969089790898908999090090901909029090390904909059090690907909089090990910909119091290913909149091590916909179091890919909209092190922909239092490925909269092790928909299093090931909329093390934909359093690937909389093990940909419094290943909449094590946909479094890949909509095190952909539095490955909569095790958909599096090961909629096390964909659096690967909689096990970909719097290973909749097590976909779097890979909809098190982909839098490985909869098790988909899099090991909929099390994909959099690997909989099991000910019100291003910049100591006910079100891009910109101191012910139101491015910169101791018910199102091021910229102391024910259102691027910289102991030910319103291033910349103591036910379103891039910409104191042910439104491045910469104791048910499105091051910529105391054910559105691057910589105991060910619106291063910649106591066910679106891069910709107191072910739107491075910769107791078910799108091081910829108391084910859108691087910889108991090910919109291093910949109591096910979109891099911009110191102911039110491105911069110791108911099111091111911129111391114911159111691117911189111991120911219112291123911249112591126911279112891129911309113191132911339113491135911369113791138911399114091141911429114391144911459114691147911489114991150911519115291153911549115591156911579115891159911609116191162911639116491165911669116791168911699117091171911729117391174911759117691177911789117991180911819118291183911849118591186911879118891189911909119191192911939119491195911969119791198911999120091201912029120391204912059120691207912089120991210912119121291213912149121591216912179121891219912209122191222912239122491225912269122791228912299123091231912329123391234912359123691237912389123991240912419124291243912449124591246912479124891249912509125191252912539125491255912569125791258912599126091261912629126391264912659126691267912689126991270912719127291273912749127591276912779127891279912809128191282912839128491285912869128791288912899129091291912929129391294912959129691297912989129991300913019130291303913049130591306913079130891309913109131191312913139131491315913169131791318913199132091321913229132391324913259132691327913289132991330913319133291333913349133591336913379133891339913409134191342913439134491345913469134791348913499135091351913529135391354913559135691357913589135991360913619136291363913649136591366913679136891369913709137191372913739137491375913769137791378913799138091381913829138391384913859138691387913889138991390913919139291393913949139591396913979139891399914009140191402914039140491405914069140791408914099141091411914129141391414914159141691417914189141991420914219142291423914249142591426914279142891429914309143191432914339143491435914369143791438914399144091441914429144391444914459144691447914489144991450914519145291453914549145591456914579145891459914609146191462914639146491465914669146791468914699147091471914729147391474914759147691477914789147991480914819148291483914849148591486914879148891489914909149191492914939149491495914969149791498914999150091501915029150391504915059150691507915089150991510915119151291513915149151591516915179151891519915209152191522915239152491525915269152791528915299153091531915329153391534915359153691537915389153991540915419154291543915449154591546915479154891549915509155191552915539155491555915569155791558915599156091561915629156391564915659156691567915689156991570915719157291573915749157591576915779157891579915809158191582915839158491585915869158791588915899159091591915929159391594915959159691597915989159991600916019160291603916049160591606916079160891609916109161191612916139161491615916169161791618916199162091621916229162391624916259162691627916289162991630916319163291633916349163591636916379163891639916409164191642916439164491645916469164791648916499165091651916529165391654916559165691657916589165991660916619166291663916649166591666916679166891669916709167191672916739167491675916769167791678916799168091681916829168391684916859168691687916889168991690916919169291693916949169591696916979169891699917009170191702917039170491705917069170791708917099171091711917129171391714917159171691717917189171991720917219172291723917249172591726917279172891729917309173191732917339173491735917369173791738917399174091741917429174391744917459174691747917489174991750917519175291753917549175591756917579175891759917609176191762917639176491765917669176791768917699177091771917729177391774917759177691777917789177991780917819178291783917849178591786917879178891789917909179191792917939179491795917969179791798917999180091801918029180391804918059180691807918089180991810918119181291813918149181591816918179181891819918209182191822918239182491825918269182791828918299183091831918329183391834918359183691837918389183991840918419184291843918449184591846918479184891849918509185191852918539185491855918569185791858918599186091861918629186391864918659186691867918689186991870918719187291873918749187591876918779187891879918809188191882918839188491885918869188791888918899189091891918929189391894918959189691897918989189991900919019190291903919049190591906919079190891909919109191191912919139191491915919169191791918919199192091921919229192391924919259192691927919289192991930919319193291933919349193591936919379193891939919409194191942919439194491945919469194791948919499195091951919529195391954919559195691957919589195991960919619196291963919649196591966919679196891969919709197191972919739197491975919769197791978919799198091981919829198391984919859198691987919889198991990919919199291993919949199591996919979199891999920009200192002920039200492005920069200792008920099201092011920129201392014920159201692017920189201992020920219202292023920249202592026920279202892029920309203192032920339203492035920369203792038920399204092041920429204392044920459204692047920489204992050920519205292053920549205592056920579205892059920609206192062920639206492065920669206792068920699207092071920729207392074920759207692077920789207992080920819208292083920849208592086920879208892089920909209192092920939209492095920969209792098920999210092101921029210392104921059210692107921089210992110921119211292113921149211592116921179211892119921209212192122921239212492125921269212792128921299213092131921329213392134921359213692137921389213992140921419214292143921449214592146921479214892149921509215192152921539215492155921569215792158921599216092161921629216392164921659216692167921689216992170921719217292173921749217592176921779217892179921809218192182921839218492185921869218792188921899219092191921929219392194921959219692197921989219992200922019220292203922049220592206922079220892209922109221192212922139221492215922169221792218922199222092221922229222392224922259222692227922289222992230922319223292233922349223592236922379223892239922409224192242922439224492245922469224792248922499225092251922529225392254922559225692257922589225992260922619226292263922649226592266922679226892269922709227192272922739227492275922769227792278922799228092281922829228392284922859228692287922889228992290922919229292293922949229592296922979229892299923009230192302923039230492305923069230792308923099231092311923129231392314923159231692317923189231992320923219232292323923249232592326923279232892329923309233192332923339233492335923369233792338923399234092341923429234392344923459234692347923489234992350923519235292353923549235592356923579235892359923609236192362923639236492365923669236792368923699237092371923729237392374923759237692377923789237992380923819238292383923849238592386923879238892389923909239192392923939239492395923969239792398923999240092401924029240392404924059240692407924089240992410924119241292413924149241592416924179241892419924209242192422924239242492425924269242792428924299243092431924329243392434924359243692437924389243992440924419244292443924449244592446924479244892449924509245192452924539245492455924569245792458924599246092461924629246392464924659246692467924689246992470924719247292473924749247592476924779247892479924809248192482924839248492485924869248792488924899249092491924929249392494924959249692497924989249992500925019250292503925049250592506925079250892509925109251192512925139251492515925169251792518925199252092521925229252392524925259252692527925289252992530925319253292533925349253592536925379253892539925409254192542925439254492545925469254792548925499255092551925529255392554925559255692557925589255992560925619256292563925649256592566925679256892569925709257192572925739257492575925769257792578925799258092581925829258392584925859258692587925889258992590925919259292593925949259592596925979259892599926009260192602926039260492605926069260792608926099261092611926129261392614926159261692617926189261992620926219262292623926249262592626926279262892629926309263192632926339263492635926369263792638926399264092641926429264392644926459264692647926489264992650926519265292653926549265592656926579265892659926609266192662926639266492665926669266792668926699267092671926729267392674926759267692677926789267992680926819268292683926849268592686926879268892689926909269192692926939269492695926969269792698926999270092701927029270392704927059270692707927089270992710927119271292713927149271592716927179271892719927209272192722927239272492725927269272792728927299273092731927329273392734927359273692737927389273992740927419274292743927449274592746927479274892749927509275192752927539275492755927569275792758927599276092761927629276392764927659276692767927689276992770927719277292773927749277592776927779277892779927809278192782927839278492785927869278792788927899279092791927929279392794927959279692797927989279992800928019280292803928049280592806928079280892809928109281192812928139281492815928169281792818928199282092821928229282392824928259282692827928289282992830928319283292833928349283592836928379283892839928409284192842928439284492845928469284792848928499285092851928529285392854928559285692857928589285992860928619286292863928649286592866928679286892869928709287192872928739287492875928769287792878928799288092881928829288392884928859288692887928889288992890928919289292893928949289592896928979289892899929009290192902929039290492905929069290792908929099291092911929129291392914929159291692917929189291992920929219292292923929249292592926929279292892929929309293192932929339293492935929369293792938929399294092941929429294392944929459294692947929489294992950929519295292953929549295592956929579295892959929609296192962929639296492965929669296792968929699297092971929729297392974929759297692977929789297992980929819298292983929849298592986929879298892989929909299192992929939299492995929969299792998929999300093001930029300393004930059300693007930089300993010930119301293013930149301593016930179301893019930209302193022930239302493025930269302793028930299303093031930329303393034930359303693037930389303993040930419304293043930449304593046930479304893049930509305193052930539305493055930569305793058930599306093061930629306393064930659306693067930689306993070930719307293073930749307593076930779307893079930809308193082930839308493085930869308793088930899309093091930929309393094930959309693097930989309993100931019310293103931049310593106931079310893109931109311193112931139311493115931169311793118931199312093121931229312393124931259312693127931289312993130931319313293133931349313593136931379313893139931409314193142931439314493145931469314793148931499315093151931529315393154931559315693157931589315993160931619316293163931649316593166931679316893169931709317193172931739317493175931769317793178931799318093181931829318393184931859318693187931889318993190931919319293193931949319593196931979319893199932009320193202932039320493205932069320793208932099321093211932129321393214932159321693217932189321993220932219322293223932249322593226932279322893229932309323193232932339323493235932369323793238932399324093241932429324393244932459324693247932489324993250932519325293253932549325593256932579325893259932609326193262932639326493265932669326793268932699327093271932729327393274932759327693277932789327993280932819328293283932849328593286932879328893289932909329193292932939329493295932969329793298932999330093301933029330393304933059330693307933089330993310933119331293313933149331593316933179331893319933209332193322933239332493325933269332793328933299333093331933329333393334933359333693337933389333993340933419334293343933449334593346933479334893349933509335193352933539335493355933569335793358933599336093361933629336393364933659336693367933689336993370933719337293373933749337593376933779337893379933809338193382933839338493385933869338793388933899339093391933929339393394933959339693397933989339993400934019340293403934049340593406934079340893409934109341193412934139341493415934169341793418934199342093421934229342393424934259342693427934289342993430934319343293433934349343593436934379343893439934409344193442934439344493445934469344793448934499345093451934529345393454934559345693457934589345993460934619346293463934649346593466934679346893469934709347193472934739347493475934769347793478934799348093481934829348393484934859348693487934889348993490934919349293493934949349593496934979349893499935009350193502935039350493505935069350793508935099351093511935129351393514935159351693517935189351993520935219352293523935249352593526935279352893529935309353193532935339353493535935369353793538935399354093541935429354393544935459354693547935489354993550935519355293553935549355593556935579355893559935609356193562935639356493565935669356793568935699357093571935729357393574935759357693577935789357993580935819358293583935849358593586935879358893589935909359193592935939359493595935969359793598935999360093601936029360393604936059360693607936089360993610936119361293613936149361593616936179361893619936209362193622936239362493625936269362793628936299363093631936329363393634936359363693637936389363993640936419364293643936449364593646936479364893649936509365193652936539365493655936569365793658936599366093661936629366393664936659366693667936689366993670936719367293673936749367593676936779367893679936809368193682936839368493685936869368793688936899369093691936929369393694936959369693697936989369993700937019370293703937049370593706937079370893709937109371193712937139371493715937169371793718937199372093721937229372393724937259372693727937289372993730937319373293733937349373593736937379373893739937409374193742937439374493745937469374793748937499375093751937529375393754937559375693757937589375993760937619376293763937649376593766937679376893769937709377193772937739377493775937769377793778937799378093781937829378393784937859378693787937889378993790937919379293793937949379593796937979379893799938009380193802938039380493805938069380793808938099381093811938129381393814938159381693817938189381993820938219382293823938249382593826938279382893829938309383193832938339383493835938369383793838938399384093841938429384393844938459384693847938489384993850938519385293853938549385593856938579385893859938609386193862938639386493865938669386793868938699387093871938729387393874938759387693877938789387993880938819388293883938849388593886938879388893889938909389193892938939389493895938969389793898938999390093901939029390393904939059390693907939089390993910939119391293913939149391593916939179391893919939209392193922939239392493925939269392793928939299393093931939329393393934939359393693937939389393993940939419394293943939449394593946939479394893949939509395193952939539395493955939569395793958939599396093961939629396393964939659396693967939689396993970939719397293973939749397593976939779397893979939809398193982939839398493985939869398793988939899399093991939929399393994939959399693997939989399994000940019400294003940049400594006940079400894009940109401194012940139401494015940169401794018940199402094021940229402394024940259402694027940289402994030940319403294033940349403594036940379403894039940409404194042940439404494045940469404794048940499405094051940529405394054940559405694057940589405994060940619406294063940649406594066940679406894069940709407194072940739407494075940769407794078940799408094081940829408394084940859408694087940889408994090940919409294093940949409594096940979409894099941009410194102941039410494105941069410794108941099411094111941129411394114941159411694117941189411994120941219412294123941249412594126941279412894129941309413194132941339413494135941369413794138941399414094141941429414394144941459414694147941489414994150941519415294153941549415594156941579415894159941609416194162941639416494165941669416794168941699417094171941729417394174941759417694177941789417994180941819418294183941849418594186941879418894189941909419194192941939419494195941969419794198941999420094201942029420394204942059420694207942089420994210942119421294213942149421594216942179421894219942209422194222942239422494225942269422794228942299423094231942329423394234942359423694237942389423994240942419424294243942449424594246942479424894249942509425194252942539425494255942569425794258942599426094261942629426394264942659426694267942689426994270942719427294273942749427594276942779427894279942809428194282942839428494285942869428794288942899429094291942929429394294942959429694297942989429994300943019430294303943049430594306943079430894309943109431194312943139431494315943169431794318943199432094321943229432394324943259432694327943289432994330943319433294333943349433594336943379433894339943409434194342943439434494345943469434794348943499435094351943529435394354943559435694357943589435994360943619436294363943649436594366943679436894369943709437194372943739437494375943769437794378943799438094381943829438394384943859438694387943889438994390943919439294393943949439594396943979439894399944009440194402944039440494405944069440794408944099441094411944129441394414944159441694417944189441994420944219442294423944249442594426944279442894429944309443194432944339443494435944369443794438944399444094441944429444394444944459444694447944489444994450944519445294453944549445594456944579445894459944609446194462944639446494465944669446794468944699447094471944729447394474944759447694477944789447994480944819448294483944849448594486944879448894489944909449194492944939449494495944969449794498944999450094501945029450394504945059450694507945089450994510945119451294513945149451594516945179451894519945209452194522945239452494525945269452794528945299453094531945329453394534945359453694537945389453994540945419454294543945449454594546945479454894549945509455194552945539455494555945569455794558945599456094561945629456394564945659456694567945689456994570945719457294573945749457594576945779457894579945809458194582945839458494585945869458794588945899459094591945929459394594945959459694597945989459994600946019460294603946049460594606946079460894609946109461194612946139461494615946169461794618946199462094621946229462394624946259462694627946289462994630946319463294633946349463594636946379463894639946409464194642946439464494645946469464794648946499465094651946529465394654946559465694657946589465994660946619466294663946649466594666946679466894669946709467194672946739467494675946769467794678946799468094681946829468394684946859468694687946889468994690946919469294693946949469594696946979469894699947009470194702947039470494705947069470794708947099471094711947129471394714947159471694717947189471994720947219472294723947249472594726947279472894729947309473194732947339473494735947369473794738947399474094741947429474394744947459474694747947489474994750947519475294753947549475594756947579475894759947609476194762947639476494765947669476794768947699477094771947729477394774947759477694777947789477994780947819478294783947849478594786947879478894789947909479194792947939479494795947969479794798947999480094801948029480394804948059480694807948089480994810948119481294813948149481594816948179481894819948209482194822948239482494825948269482794828948299483094831948329483394834948359483694837948389483994840948419484294843948449484594846948479484894849948509485194852948539485494855948569485794858948599486094861948629486394864948659486694867948689486994870948719487294873948749487594876948779487894879948809488194882948839488494885948869488794888948899489094891948929489394894948959489694897948989489994900949019490294903949049490594906949079490894909949109491194912949139491494915949169491794918949199492094921949229492394924949259492694927949289492994930949319493294933949349493594936949379493894939949409494194942949439494494945949469494794948949499495094951949529495394954949559495694957949589495994960949619496294963949649496594966949679496894969949709497194972949739497494975949769497794978949799498094981949829498394984949859498694987949889498994990949919499294993949949499594996949979499894999950009500195002950039500495005950069500795008950099501095011950129501395014950159501695017950189501995020950219502295023950249502595026950279502895029950309503195032950339503495035950369503795038950399504095041950429504395044950459504695047950489504995050950519505295053950549505595056950579505895059950609506195062950639506495065950669506795068950699507095071950729507395074950759507695077950789507995080950819508295083950849508595086950879508895089950909509195092950939509495095950969509795098950999510095101951029510395104951059510695107951089510995110951119511295113951149511595116951179511895119951209512195122951239512495125951269512795128951299513095131951329513395134951359513695137951389513995140951419514295143951449514595146951479514895149951509515195152951539515495155951569515795158951599516095161951629516395164951659516695167951689516995170951719517295173951749517595176951779517895179951809518195182951839518495185951869518795188951899519095191951929519395194951959519695197951989519995200952019520295203952049520595206952079520895209952109521195212952139521495215952169521795218952199522095221952229522395224952259522695227952289522995230952319523295233952349523595236952379523895239952409524195242952439524495245952469524795248952499525095251952529525395254952559525695257952589525995260952619526295263952649526595266952679526895269952709527195272952739527495275952769527795278952799528095281952829528395284952859528695287952889528995290952919529295293952949529595296952979529895299953009530195302953039530495305953069530795308953099531095311953129531395314953159531695317953189531995320953219532295323953249532595326953279532895329953309533195332953339533495335953369533795338953399534095341953429534395344953459534695347953489534995350953519535295353953549535595356953579535895359953609536195362953639536495365953669536795368953699537095371953729537395374953759537695377953789537995380953819538295383953849538595386953879538895389953909539195392953939539495395953969539795398953999540095401954029540395404954059540695407954089540995410954119541295413954149541595416954179541895419954209542195422954239542495425954269542795428954299543095431954329543395434954359543695437954389543995440954419544295443954449544595446954479544895449954509545195452954539545495455954569545795458954599546095461954629546395464954659546695467954689546995470954719547295473954749547595476954779547895479954809548195482954839548495485954869548795488954899549095491954929549395494954959549695497954989549995500955019550295503955049550595506955079550895509955109551195512955139551495515955169551795518955199552095521955229552395524955259552695527955289552995530955319553295533955349553595536955379553895539955409554195542955439554495545955469554795548955499555095551955529555395554955559555695557955589555995560955619556295563955649556595566955679556895569955709557195572955739557495575955769557795578955799558095581955829558395584955859558695587955889558995590955919559295593955949559595596955979559895599956009560195602956039560495605956069560795608956099561095611956129561395614956159561695617956189561995620956219562295623956249562595626956279562895629956309563195632956339563495635956369563795638956399564095641956429564395644956459564695647956489564995650956519565295653956549565595656956579565895659956609566195662956639566495665956669566795668956699567095671956729567395674956759567695677956789567995680956819568295683956849568595686956879568895689956909569195692956939569495695956969569795698956999570095701957029570395704957059570695707957089570995710957119571295713957149571595716957179571895719957209572195722957239572495725957269572795728957299573095731957329573395734957359573695737957389573995740957419574295743957449574595746957479574895749957509575195752957539575495755957569575795758957599576095761957629576395764957659576695767957689576995770957719577295773957749577595776957779577895779957809578195782957839578495785957869578795788957899579095791957929579395794957959579695797957989579995800958019580295803958049580595806958079580895809958109581195812958139581495815958169581795818958199582095821958229582395824958259582695827958289582995830958319583295833958349583595836958379583895839958409584195842958439584495845958469584795848958499585095851958529585395854958559585695857958589585995860958619586295863958649586595866958679586895869958709587195872958739587495875958769587795878958799588095881958829588395884958859588695887958889588995890958919589295893958949589595896958979589895899959009590195902959039590495905959069590795908959099591095911959129591395914959159591695917959189591995920959219592295923959249592595926959279592895929959309593195932959339593495935959369593795938959399594095941959429594395944959459594695947959489594995950959519595295953959549595595956959579595895959959609596195962959639596495965959669596795968959699597095971959729597395974959759597695977959789597995980959819598295983959849598595986959879598895989959909599195992959939599495995959969599795998959999600096001960029600396004960059600696007960089600996010960119601296013960149601596016960179601896019960209602196022960239602496025960269602796028960299603096031960329603396034960359603696037960389603996040960419604296043960449604596046960479604896049960509605196052
  1. // OpenLayers. See https://openlayers.org/
  2. // License: https://raw.githubusercontent.com/openlayers/openlayers/master/LICENSE.md
  3. // Version: v4.6.5
  4. ;(function (root, factory) {
  5. if (typeof exports === "object") {
  6. module.exports = factory();
  7. } else if (typeof define === "function" && define.amd) {
  8. define([], factory);
  9. } else {
  10. root.ol = factory();
  11. }
  12. }(this, function () {
  13. var OPENLAYERS = {};
  14. var goog = this.goog = {};
  15. this.CLOSURE_NO_DEPS = true;
  16. // Copyright 2006 The Closure Library Authors. All Rights Reserved.
  17. //
  18. // Licensed under the Apache License, Version 2.0 (the "License");
  19. // you may not use this file except in compliance with the License.
  20. // You may obtain a copy of the License at
  21. //
  22. // http://www.apache.org/licenses/LICENSE-2.0
  23. //
  24. // Unless required by applicable law or agreed to in writing, software
  25. // distributed under the License is distributed on an "AS-IS" BASIS,
  26. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. // See the License for the specific language governing permissions and
  28. // limitations under the License.
  29. /**
  30. * @fileoverview Bootstrap for the Google JS Library (Closure).
  31. *
  32. * In uncompiled mode base.js will attempt to load Closure's deps file, unless
  33. * the global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects
  34. * to include their own deps file(s) from different locations.
  35. *
  36. * Avoid including base.js more than once. This is strictly discouraged and not
  37. * supported. goog.require(...) won't work properly in that case.
  38. *
  39. * @provideGoog
  40. */
  41. /**
  42. * @define {boolean} Overridden to true by the compiler.
  43. */
  44. var COMPILED = false;
  45. /**
  46. * Base namespace for the Closure library. Checks to see goog is already
  47. * defined in the current scope before assigning to prevent clobbering if
  48. * base.js is loaded more than once.
  49. *
  50. * @const
  51. */
  52. var goog = goog || {};
  53. /**
  54. * Reference to the global context. In most cases this will be 'window'.
  55. */
  56. goog.global = this;
  57. /**
  58. * A hook for overriding the define values in uncompiled mode.
  59. *
  60. * In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before
  61. * loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES},
  62. * {@code goog.define} will use the value instead of the default value. This
  63. * allows flags to be overwritten without compilation (this is normally
  64. * accomplished with the compiler's "define" flag).
  65. *
  66. * Example:
  67. * <pre>
  68. * var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
  69. * </pre>
  70. *
  71. * @type {Object<string, (string|number|boolean)>|undefined}
  72. */
  73. goog.global.CLOSURE_UNCOMPILED_DEFINES;
  74. /**
  75. * A hook for overriding the define values in uncompiled or compiled mode,
  76. * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In
  77. * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence.
  78. *
  79. * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or
  80. * string literals or the compiler will emit an error.
  81. *
  82. * While any @define value may be set, only those set with goog.define will be
  83. * effective for uncompiled code.
  84. *
  85. * Example:
  86. * <pre>
  87. * var CLOSURE_DEFINES = {'goog.DEBUG': false} ;
  88. * </pre>
  89. *
  90. * @type {Object<string, (string|number|boolean)>|undefined}
  91. */
  92. goog.global.CLOSURE_DEFINES;
  93. /**
  94. * Returns true if the specified value is not undefined.
  95. *
  96. * @param {?} val Variable to test.
  97. * @return {boolean} Whether variable is defined.
  98. */
  99. goog.isDef = function(val) {
  100. // void 0 always evaluates to undefined and hence we do not need to depend on
  101. // the definition of the global variable named 'undefined'.
  102. return val !== void 0;
  103. };
  104. /**
  105. * Returns true if the specified value is a string.
  106. * @param {?} val Variable to test.
  107. * @return {boolean} Whether variable is a string.
  108. */
  109. goog.isString = function(val) {
  110. return typeof val == 'string';
  111. };
  112. /**
  113. * Returns true if the specified value is a boolean.
  114. * @param {?} val Variable to test.
  115. * @return {boolean} Whether variable is boolean.
  116. */
  117. goog.isBoolean = function(val) {
  118. return typeof val == 'boolean';
  119. };
  120. /**
  121. * Returns true if the specified value is a number.
  122. * @param {?} val Variable to test.
  123. * @return {boolean} Whether variable is a number.
  124. */
  125. goog.isNumber = function(val) {
  126. return typeof val == 'number';
  127. };
  128. /**
  129. * Builds an object structure for the provided namespace path, ensuring that
  130. * names that already exist are not overwritten. For example:
  131. * "a.b.c" -> a = {};a.b={};a.b.c={};
  132. * Used by goog.provide and goog.exportSymbol.
  133. * @param {string} name name of the object that this file defines.
  134. * @param {*=} opt_object the object to expose at the end of the path.
  135. * @param {Object=} opt_objectToExportTo The object to add the path to; default
  136. * is `goog.global`.
  137. * @private
  138. */
  139. goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {
  140. var parts = name.split('.');
  141. var cur = opt_objectToExportTo || goog.global;
  142. // Internet Explorer exhibits strange behavior when throwing errors from
  143. // methods externed in this manner. See the testExportSymbolExceptions in
  144. // base_test.html for an example.
  145. if (!(parts[0] in cur) && cur.execScript) {
  146. cur.execScript('var ' + parts[0]);
  147. }
  148. for (var part; parts.length && (part = parts.shift());) {
  149. if (!parts.length && goog.isDef(opt_object)) {
  150. // last part and we have an object; use it
  151. cur[part] = opt_object;
  152. } else if (cur[part] && cur[part] !== Object.prototype[part]) {
  153. cur = cur[part];
  154. } else {
  155. cur = cur[part] = {};
  156. }
  157. }
  158. };
  159. /**
  160. * Defines a named value. In uncompiled mode, the value is retrieved from
  161. * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and
  162. * has the property specified, and otherwise used the defined defaultValue.
  163. * When compiled the default can be overridden using the compiler
  164. * options or the value set in the CLOSURE_DEFINES object.
  165. *
  166. * @param {string} name The distinguished name to provide.
  167. * @param {string|number|boolean} defaultValue
  168. */
  169. goog.define = function(name, defaultValue) {
  170. var value = defaultValue;
  171. if (!COMPILED) {
  172. if (goog.global.CLOSURE_UNCOMPILED_DEFINES &&
  173. // Anti DOM-clobbering runtime check (b/37736576).
  174. /** @type {?} */ (goog.global.CLOSURE_UNCOMPILED_DEFINES).nodeType ===
  175. undefined &&
  176. Object.prototype.hasOwnProperty.call(
  177. goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) {
  178. value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name];
  179. } else if (
  180. goog.global.CLOSURE_DEFINES &&
  181. // Anti DOM-clobbering runtime check (b/37736576).
  182. /** @type {?} */ (goog.global.CLOSURE_DEFINES).nodeType === undefined &&
  183. Object.prototype.hasOwnProperty.call(
  184. goog.global.CLOSURE_DEFINES, name)) {
  185. value = goog.global.CLOSURE_DEFINES[name];
  186. }
  187. }
  188. goog.exportPath_(name, value);
  189. };
  190. /**
  191. * @define {boolean} DEBUG is provided as a convenience so that debugging code
  192. * that should not be included in a production. It can be easily stripped
  193. * by specifying --define goog.DEBUG=false to the Closure Compiler aka
  194. * JSCompiler. For example, most toString() methods should be declared inside an
  195. * "if (goog.DEBUG)" conditional because they are generally used for debugging
  196. * purposes and it is difficult for the JSCompiler to statically determine
  197. * whether they are used.
  198. */
  199. goog.define('goog.DEBUG', true);
  200. /**
  201. * @define {string} LOCALE defines the locale being used for compilation. It is
  202. * used to select locale specific data to be compiled in js binary. BUILD rule
  203. * can specify this value by "--define goog.LOCALE=<locale_name>" as a compiler
  204. * option.
  205. *
  206. * Take into account that the locale code format is important. You should use
  207. * the canonical Unicode format with hyphen as a delimiter. Language must be
  208. * lowercase, Language Script - Capitalized, Region - UPPERCASE.
  209. * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.
  210. *
  211. * See more info about locale codes here:
  212. * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers
  213. *
  214. * For language codes you should use values defined by ISO 693-1. See it here
  215. * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from
  216. * this rule: the Hebrew language. For legacy reasons the old code (iw) should
  217. * be used instead of the new code (he).
  218. *
  219. */
  220. goog.define('goog.LOCALE', 'en'); // default to en
  221. /**
  222. * @define {boolean} Whether this code is running on trusted sites.
  223. *
  224. * On untrusted sites, several native functions can be defined or overridden by
  225. * external libraries like Prototype, Datejs, and JQuery and setting this flag
  226. * to false forces closure to use its own implementations when possible.
  227. *
  228. * If your JavaScript can be loaded by a third party site and you are wary about
  229. * relying on non-standard implementations, specify
  230. * "--define goog.TRUSTED_SITE=false" to the compiler.
  231. */
  232. goog.define('goog.TRUSTED_SITE', true);
  233. /**
  234. * @define {boolean} Whether a project is expected to be running in strict mode.
  235. *
  236. * This define can be used to trigger alternate implementations compatible with
  237. * running in EcmaScript Strict mode or warn about unavailable functionality.
  238. * @see https://goo.gl/PudQ4y
  239. *
  240. */
  241. goog.define('goog.STRICT_MODE_COMPATIBLE', false);
  242. /**
  243. * @define {boolean} Whether code that calls {@link goog.setTestOnly} should
  244. * be disallowed in the compilation unit.
  245. */
  246. goog.define('goog.DISALLOW_TEST_ONLY_CODE', COMPILED && !goog.DEBUG);
  247. /**
  248. * @define {boolean} Whether to use a Chrome app CSP-compliant method for
  249. * loading scripts via goog.require. @see appendScriptSrcNode_.
  250. */
  251. goog.define('goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING', false);
  252. /**
  253. * Defines a namespace in Closure.
  254. *
  255. * A namespace may only be defined once in a codebase. It may be defined using
  256. * goog.provide() or goog.module().
  257. *
  258. * The presence of one or more goog.provide() calls in a file indicates
  259. * that the file defines the given objects/namespaces.
  260. * Provided symbols must not be null or undefined.
  261. *
  262. * In addition, goog.provide() creates the object stubs for a namespace
  263. * (for example, goog.provide("goog.foo.bar") will create the object
  264. * goog.foo.bar if it does not already exist).
  265. *
  266. * Build tools also scan for provide/require/module statements
  267. * to discern dependencies, build dependency files (see deps.js), etc.
  268. *
  269. * @see goog.require
  270. * @see goog.module
  271. * @param {string} name Namespace provided by this file in the form
  272. * "goog.package.part".
  273. */
  274. goog.provide = function(name) {
  275. if (goog.isInModuleLoader_()) {
  276. throw new Error('goog.provide can not be used within a goog.module.');
  277. }
  278. if (!COMPILED) {
  279. // Ensure that the same namespace isn't provided twice.
  280. // A goog.module/goog.provide maps a goog.require to a specific file
  281. if (goog.isProvided_(name)) {
  282. throw new Error('Namespace "' + name + '" already declared.');
  283. }
  284. }
  285. goog.constructNamespace_(name);
  286. };
  287. /**
  288. * @param {string} name Namespace provided by this file in the form
  289. * "goog.package.part".
  290. * @param {Object=} opt_obj The object to embed in the namespace.
  291. * @private
  292. */
  293. goog.constructNamespace_ = function(name, opt_obj) {
  294. if (!COMPILED) {
  295. delete goog.implicitNamespaces_[name];
  296. var namespace = name;
  297. while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
  298. if (goog.getObjectByName(namespace)) {
  299. break;
  300. }
  301. goog.implicitNamespaces_[namespace] = true;
  302. }
  303. }
  304. goog.exportPath_(name, opt_obj);
  305. };
  306. /**
  307. * Module identifier validation regexp.
  308. * Note: This is a conservative check, it is very possible to be more lenient,
  309. * the primary exclusion here is "/" and "\" and a leading ".", these
  310. * restrictions are intended to leave the door open for using goog.require
  311. * with relative file paths rather than module identifiers.
  312. * @private
  313. */
  314. goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/;
  315. /**
  316. * Defines a module in Closure.
  317. *
  318. * Marks that this file must be loaded as a module and claims the namespace.
  319. *
  320. * A namespace may only be defined once in a codebase. It may be defined using
  321. * goog.provide() or goog.module().
  322. *
  323. * goog.module() has three requirements:
  324. * - goog.module may not be used in the same file as goog.provide.
  325. * - goog.module must be the first statement in the file.
  326. * - only one goog.module is allowed per file.
  327. *
  328. * When a goog.module annotated file is loaded, it is enclosed in
  329. * a strict function closure. This means that:
  330. * - any variables declared in a goog.module file are private to the file
  331. * (not global), though the compiler is expected to inline the module.
  332. * - The code must obey all the rules of "strict" JavaScript.
  333. * - the file will be marked as "use strict"
  334. *
  335. * NOTE: unlike goog.provide, goog.module does not declare any symbols by
  336. * itself. If declared symbols are desired, use
  337. * goog.module.declareLegacyNamespace().
  338. *
  339. *
  340. * See the public goog.module proposal: http://goo.gl/Va1hin
  341. *
  342. * @param {string} name Namespace provided by this file in the form
  343. * "goog.package.part", is expected but not required.
  344. * @return {void}
  345. */
  346. goog.module = function(name) {
  347. if (!goog.isString(name) || !name ||
  348. name.search(goog.VALID_MODULE_RE_) == -1) {
  349. throw new Error('Invalid module identifier');
  350. }
  351. if (!goog.isInModuleLoader_()) {
  352. throw new Error(
  353. 'Module ' + name + ' has been loaded incorrectly. Note, ' +
  354. 'modules cannot be loaded as normal scripts. They require some kind of ' +
  355. 'pre-processing step. You\'re likely trying to load a module via a ' +
  356. 'script tag or as a part of a concatenated bundle without rewriting the ' +
  357. 'module. For more info see: ' +
  358. 'https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.');
  359. }
  360. if (goog.moduleLoaderState_.moduleName) {
  361. throw new Error('goog.module may only be called once per module.');
  362. }
  363. // Store the module name for the loader.
  364. goog.moduleLoaderState_.moduleName = name;
  365. if (!COMPILED) {
  366. // Ensure that the same namespace isn't provided twice.
  367. // A goog.module/goog.provide maps a goog.require to a specific file
  368. if (goog.isProvided_(name)) {
  369. throw new Error('Namespace "' + name + '" already declared.');
  370. }
  371. delete goog.implicitNamespaces_[name];
  372. }
  373. };
  374. /**
  375. * @param {string} name The module identifier.
  376. * @return {?} The module exports for an already loaded module or null.
  377. *
  378. * Note: This is not an alternative to goog.require, it does not
  379. * indicate a hard dependency, instead it is used to indicate
  380. * an optional dependency or to access the exports of a module
  381. * that has already been loaded.
  382. * @suppress {missingProvide}
  383. */
  384. goog.module.get = function(name) {
  385. return goog.module.getInternal_(name);
  386. };
  387. /**
  388. * @param {string} name The module identifier.
  389. * @return {?} The module exports for an already loaded module or null.
  390. * @private
  391. */
  392. goog.module.getInternal_ = function(name) {
  393. if (!COMPILED) {
  394. if (name in goog.loadedModules_) {
  395. return goog.loadedModules_[name];
  396. } else if (!goog.implicitNamespaces_[name]) {
  397. var ns = goog.getObjectByName(name);
  398. return ns != null ? ns : null;
  399. }
  400. }
  401. return null;
  402. };
  403. /**
  404. * @private {?{moduleName: (string|undefined), declareLegacyNamespace:boolean}}
  405. */
  406. goog.moduleLoaderState_ = null;
  407. /**
  408. * @private
  409. * @return {boolean} Whether a goog.module is currently being initialized.
  410. */
  411. goog.isInModuleLoader_ = function() {
  412. return goog.moduleLoaderState_ != null;
  413. };
  414. /**
  415. * Provide the module's exports as a globally accessible object under the
  416. * module's declared name. This is intended to ease migration to goog.module
  417. * for files that have existing usages.
  418. * @suppress {missingProvide}
  419. */
  420. goog.module.declareLegacyNamespace = function() {
  421. if (!COMPILED && !goog.isInModuleLoader_()) {
  422. throw new Error(
  423. 'goog.module.declareLegacyNamespace must be called from ' +
  424. 'within a goog.module');
  425. }
  426. if (!COMPILED && !goog.moduleLoaderState_.moduleName) {
  427. throw new Error(
  428. 'goog.module must be called prior to ' +
  429. 'goog.module.declareLegacyNamespace.');
  430. }
  431. goog.moduleLoaderState_.declareLegacyNamespace = true;
  432. };
  433. /**
  434. * Marks that the current file should only be used for testing, and never for
  435. * live code in production.
  436. *
  437. * In the case of unit tests, the message may optionally be an exact namespace
  438. * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra
  439. * provide (if not explicitly defined in the code).
  440. *
  441. * @param {string=} opt_message Optional message to add to the error that's
  442. * raised when used in production code.
  443. */
  444. goog.setTestOnly = function(opt_message) {
  445. if (goog.DISALLOW_TEST_ONLY_CODE) {
  446. opt_message = opt_message || '';
  447. throw new Error(
  448. 'Importing test-only code into non-debug environment' +
  449. (opt_message ? ': ' + opt_message : '.'));
  450. }
  451. };
  452. /**
  453. * Forward declares a symbol. This is an indication to the compiler that the
  454. * symbol may be used in the source yet is not required and may not be provided
  455. * in compilation.
  456. *
  457. * The most common usage of forward declaration is code that takes a type as a
  458. * function parameter but does not need to require it. By forward declaring
  459. * instead of requiring, no hard dependency is made, and (if not required
  460. * elsewhere) the namespace may never be required and thus, not be pulled
  461. * into the JavaScript binary. If it is required elsewhere, it will be type
  462. * checked as normal.
  463. *
  464. * Before using goog.forwardDeclare, please read the documentation at
  465. * https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation to
  466. * understand the options and tradeoffs when working with forward declarations.
  467. *
  468. * @param {string} name The namespace to forward declare in the form of
  469. * "goog.package.part".
  470. */
  471. goog.forwardDeclare = function(name) {};
  472. /**
  473. * Forward declare type information. Used to assign types to goog.global
  474. * referenced object that would otherwise result in unknown type references
  475. * and thus block property disambiguation.
  476. */
  477. goog.forwardDeclare('Document');
  478. goog.forwardDeclare('HTMLScriptElement');
  479. goog.forwardDeclare('XMLHttpRequest');
  480. if (!COMPILED) {
  481. /**
  482. * Check if the given name has been goog.provided. This will return false for
  483. * names that are available only as implicit namespaces.
  484. * @param {string} name name of the object to look for.
  485. * @return {boolean} Whether the name has been provided.
  486. * @private
  487. */
  488. goog.isProvided_ = function(name) {
  489. return (name in goog.loadedModules_) ||
  490. (!goog.implicitNamespaces_[name] &&
  491. goog.isDefAndNotNull(goog.getObjectByName(name)));
  492. };
  493. /**
  494. * Namespaces implicitly defined by goog.provide. For example,
  495. * goog.provide('goog.events.Event') implicitly declares that 'goog' and
  496. * 'goog.events' must be namespaces.
  497. *
  498. * @type {!Object<string, (boolean|undefined)>}
  499. * @private
  500. */
  501. goog.implicitNamespaces_ = {'goog.module': true};
  502. // NOTE: We add goog.module as an implicit namespace as goog.module is defined
  503. // here and because the existing module package has not been moved yet out of
  504. // the goog.module namespace. This satisifies both the debug loader and
  505. // ahead-of-time dependency management.
  506. }
  507. /**
  508. * Returns an object based on its fully qualified external name. The object
  509. * is not found if null or undefined. If you are using a compilation pass that
  510. * renames property names beware that using this function will not find renamed
  511. * properties.
  512. *
  513. * @param {string} name The fully qualified name.
  514. * @param {Object=} opt_obj The object within which to look; default is
  515. * |goog.global|.
  516. * @return {?} The value (object or primitive) or, if not found, null.
  517. */
  518. goog.getObjectByName = function(name, opt_obj) {
  519. var parts = name.split('.');
  520. var cur = opt_obj || goog.global;
  521. for (var i = 0; i < parts.length; i++) {
  522. cur = cur[parts[i]];
  523. if (!goog.isDefAndNotNull(cur)) {
  524. return null;
  525. }
  526. }
  527. return cur;
  528. };
  529. /**
  530. * Globalizes a whole namespace, such as goog or goog.lang.
  531. *
  532. * @param {!Object} obj The namespace to globalize.
  533. * @param {Object=} opt_global The object to add the properties to.
  534. * @deprecated Properties may be explicitly exported to the global scope, but
  535. * this should no longer be done in bulk.
  536. */
  537. goog.globalize = function(obj, opt_global) {
  538. var global = opt_global || goog.global;
  539. for (var x in obj) {
  540. global[x] = obj[x];
  541. }
  542. };
  543. /**
  544. * Adds a dependency from a file to the files it requires.
  545. * @param {string} relPath The path to the js file.
  546. * @param {!Array<string>} provides An array of strings with
  547. * the names of the objects this file provides.
  548. * @param {!Array<string>} requires An array of strings with
  549. * the names of the objects this file requires.
  550. * @param {boolean|!Object<string>=} opt_loadFlags Parameters indicating
  551. * how the file must be loaded. The boolean 'true' is equivalent
  552. * to {'module': 'goog'} for backwards-compatibility. Valid properties
  553. * and values include {'module': 'goog'} and {'lang': 'es6'}.
  554. */
  555. goog.addDependency = function(relPath, provides, requires, opt_loadFlags) {
  556. if (goog.DEPENDENCIES_ENABLED) {
  557. var provide, require;
  558. var path = relPath.replace(/\\/g, '/');
  559. var deps = goog.dependencies_;
  560. if (!opt_loadFlags || typeof opt_loadFlags === 'boolean') {
  561. opt_loadFlags = opt_loadFlags ? {'module': 'goog'} : {};
  562. }
  563. for (var i = 0; provide = provides[i]; i++) {
  564. deps.nameToPath[provide] = path;
  565. deps.loadFlags[path] = opt_loadFlags;
  566. }
  567. for (var j = 0; require = requires[j]; j++) {
  568. if (!(path in deps.requires)) {
  569. deps.requires[path] = {};
  570. }
  571. deps.requires[path][require] = true;
  572. }
  573. }
  574. };
  575. // NOTE(nnaze): The debug DOM loader was included in base.js as an original way
  576. // to do "debug-mode" development. The dependency system can sometimes be
  577. // confusing, as can the debug DOM loader's asynchronous nature.
  578. //
  579. // With the DOM loader, a call to goog.require() is not blocking -- the script
  580. // will not load until some point after the current script. If a namespace is
  581. // needed at runtime, it needs to be defined in a previous script, or loaded via
  582. // require() with its registered dependencies.
  583. //
  584. // User-defined namespaces may need their own deps file. For a reference on
  585. // creating a deps file, see:
  586. // Externally: https://developers.google.com/closure/library/docs/depswriter
  587. //
  588. // Because of legacy clients, the DOM loader can't be easily removed from
  589. // base.js. Work was done to make it disableable or replaceable for
  590. // different environments (DOM-less JavaScript interpreters like Rhino or V8,
  591. // for example). See bootstrap/ for more information.
  592. /**
  593. * @define {boolean} Whether to enable the debug loader.
  594. *
  595. * If enabled, a call to goog.require() will attempt to load the namespace by
  596. * appending a script tag to the DOM (if the namespace has been registered).
  597. *
  598. * If disabled, goog.require() will simply assert that the namespace has been
  599. * provided (and depend on the fact that some outside tool correctly ordered
  600. * the script).
  601. */
  602. goog.define('goog.ENABLE_DEBUG_LOADER', true);
  603. /**
  604. * @param {string} msg
  605. * @private
  606. */
  607. goog.logToConsole_ = function(msg) {
  608. if (goog.global.console) {
  609. goog.global.console['error'](msg);
  610. }
  611. };
  612. /**
  613. * Implements a system for the dynamic resolution of dependencies that works in
  614. * parallel with the BUILD system. Note that all calls to goog.require will be
  615. * stripped by the compiler.
  616. * @see goog.provide
  617. * @param {string} name Namespace to include (as was given in goog.provide()) in
  618. * the form "goog.package.part".
  619. * @return {?} If called within a goog.module file, the associated namespace or
  620. * module otherwise null.
  621. */
  622. goog.require = function(name) {
  623. // If the object already exists we do not need to do anything.
  624. if (!COMPILED) {
  625. if (goog.ENABLE_DEBUG_LOADER && goog.IS_OLD_IE_) {
  626. goog.maybeProcessDeferredDep_(name);
  627. }
  628. if (goog.isProvided_(name)) {
  629. if (goog.isInModuleLoader_()) {
  630. return goog.module.getInternal_(name);
  631. }
  632. } else if (goog.ENABLE_DEBUG_LOADER) {
  633. var path = goog.getPathFromDeps_(name);
  634. if (path) {
  635. goog.writeScripts_(path);
  636. } else {
  637. var errorMessage = 'goog.require could not find: ' + name;
  638. goog.logToConsole_(errorMessage);
  639. throw new Error(errorMessage);
  640. }
  641. }
  642. return null;
  643. }
  644. };
  645. /**
  646. * Path for included scripts.
  647. * @type {string}
  648. */
  649. goog.basePath = '';
  650. /**
  651. * A hook for overriding the base path.
  652. * @type {string|undefined}
  653. */
  654. goog.global.CLOSURE_BASE_PATH;
  655. /**
  656. * Whether to attempt to load Closure's deps file. By default, when uncompiled,
  657. * deps files will attempt to be loaded.
  658. * @type {boolean|undefined}
  659. */
  660. goog.global.CLOSURE_NO_DEPS;
  661. /**
  662. * A function to import a single script. This is meant to be overridden when
  663. * Closure is being run in non-HTML contexts, such as web workers. It's defined
  664. * in the global scope so that it can be set before base.js is loaded, which
  665. * allows deps.js to be imported properly.
  666. *
  667. * The function is passed the script source, which is a relative URI. It should
  668. * return true if the script was imported, false otherwise.
  669. * @type {(function(string): boolean)|undefined}
  670. */
  671. goog.global.CLOSURE_IMPORT_SCRIPT;
  672. /**
  673. * Null function used for default values of callbacks, etc.
  674. * @return {void} Nothing.
  675. */
  676. goog.nullFunction = function() {};
  677. /**
  678. * When defining a class Foo with an abstract method bar(), you can do:
  679. * Foo.prototype.bar = goog.abstractMethod
  680. *
  681. * Now if a subclass of Foo fails to override bar(), an error will be thrown
  682. * when bar() is invoked.
  683. *
  684. * @type {!Function}
  685. * @throws {Error} when invoked to indicate the method should be overridden.
  686. */
  687. goog.abstractMethod = function() {
  688. throw new Error('unimplemented abstract method');
  689. };
  690. /**
  691. * Adds a {@code getInstance} static method that always returns the same
  692. * instance object.
  693. * @param {!Function} ctor The constructor for the class to add the static
  694. * method to.
  695. */
  696. goog.addSingletonGetter = function(ctor) {
  697. // instance_ is immediately set to prevent issues with sealed constructors
  698. // such as are encountered when a constructor is returned as the export object
  699. // of a goog.module in unoptimized code.
  700. ctor.instance_ = undefined;
  701. ctor.getInstance = function() {
  702. if (ctor.instance_) {
  703. return ctor.instance_;
  704. }
  705. if (goog.DEBUG) {
  706. // NOTE: JSCompiler can't optimize away Array#push.
  707. goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor;
  708. }
  709. return ctor.instance_ = new ctor;
  710. };
  711. };
  712. /**
  713. * All singleton classes that have been instantiated, for testing. Don't read
  714. * it directly, use the {@code goog.testing.singleton} module. The compiler
  715. * removes this variable if unused.
  716. * @type {!Array<!Function>}
  717. * @private
  718. */
  719. goog.instantiatedSingletons_ = [];
  720. /**
  721. * @define {boolean} Whether to load goog.modules using {@code eval} when using
  722. * the debug loader. This provides a better debugging experience as the
  723. * source is unmodified and can be edited using Chrome Workspaces or similar.
  724. * However in some environments the use of {@code eval} is banned
  725. * so we provide an alternative.
  726. */
  727. goog.define('goog.LOAD_MODULE_USING_EVAL', true);
  728. /**
  729. * @define {boolean} Whether the exports of goog.modules should be sealed when
  730. * possible.
  731. */
  732. goog.define('goog.SEAL_MODULE_EXPORTS', goog.DEBUG);
  733. /**
  734. * The registry of initialized modules:
  735. * the module identifier to module exports map.
  736. * @private @const {!Object<string, ?>}
  737. */
  738. goog.loadedModules_ = {};
  739. /**
  740. * True if goog.dependencies_ is available.
  741. * @const {boolean}
  742. */
  743. goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER;
  744. /**
  745. * @define {string} How to decide whether to transpile. Valid values
  746. * are 'always', 'never', and 'detect'. The default ('detect') is to
  747. * use feature detection to determine which language levels need
  748. * transpilation.
  749. */
  750. // NOTE(user): we could expand this to accept a language level to bypass
  751. // detection: e.g. goog.TRANSPILE == 'es5' would transpile ES6 files but
  752. // would leave ES3 and ES5 files alone.
  753. goog.define('goog.TRANSPILE', 'detect');
  754. /**
  755. * @define {string} Path to the transpiler. Executing the script at this
  756. * path (relative to base.js) should define a function $jscomp.transpile.
  757. */
  758. goog.define('goog.TRANSPILER', 'transpile.js');
  759. if (goog.DEPENDENCIES_ENABLED) {
  760. /**
  761. * This object is used to keep track of dependencies and other data that is
  762. * used for loading scripts.
  763. * @private
  764. * @type {{
  765. * loadFlags: !Object<string, !Object<string, string>>,
  766. * nameToPath: !Object<string, string>,
  767. * requires: !Object<string, !Object<string, boolean>>,
  768. * visited: !Object<string, boolean>,
  769. * written: !Object<string, boolean>,
  770. * deferred: !Object<string, string>
  771. * }}
  772. */
  773. goog.dependencies_ = {
  774. loadFlags: {}, // 1 to 1
  775. nameToPath: {}, // 1 to 1
  776. requires: {}, // 1 to many
  777. // Used when resolving dependencies to prevent us from visiting file twice.
  778. visited: {},
  779. written: {}, // Used to keep track of script files we have written.
  780. deferred: {} // Used to track deferred module evaluations in old IEs
  781. };
  782. /**
  783. * Tries to detect whether is in the context of an HTML document.
  784. * @return {boolean} True if it looks like HTML document.
  785. * @private
  786. */
  787. goog.inHtmlDocument_ = function() {
  788. /** @type {Document} */
  789. var doc = goog.global.document;
  790. return doc != null && 'write' in doc; // XULDocument misses write.
  791. };
  792. /**
  793. * Tries to detect the base path of base.js script that bootstraps Closure.
  794. * @private
  795. */
  796. goog.findBasePath_ = function() {
  797. if (goog.isDef(goog.global.CLOSURE_BASE_PATH) &&
  798. // Anti DOM-clobbering runtime check (b/37736576).
  799. goog.isString(goog.global.CLOSURE_BASE_PATH)) {
  800. goog.basePath = goog.global.CLOSURE_BASE_PATH;
  801. return;
  802. } else if (!goog.inHtmlDocument_()) {
  803. return;
  804. }
  805. /** @type {Document} */
  806. var doc = goog.global.document;
  807. // If we have a currentScript available, use it exclusively.
  808. var currentScript = doc.currentScript;
  809. if (currentScript) {
  810. var scripts = [currentScript];
  811. } else {
  812. var scripts = doc.getElementsByTagName('SCRIPT');
  813. }
  814. // Search backwards since the current script is in almost all cases the one
  815. // that has base.js.
  816. for (var i = scripts.length - 1; i >= 0; --i) {
  817. var script = /** @type {!HTMLScriptElement} */ (scripts[i]);
  818. var src = script.src;
  819. var qmark = src.lastIndexOf('?');
  820. var l = qmark == -1 ? src.length : qmark;
  821. if (src.substr(l - 7, 7) == 'base.js') {
  822. goog.basePath = src.substr(0, l - 7);
  823. return;
  824. }
  825. }
  826. };
  827. /**
  828. * Imports a script if, and only if, that script hasn't already been imported.
  829. * (Must be called at execution time)
  830. * @param {string} src Script source.
  831. * @param {string=} opt_sourceText The optionally source text to evaluate
  832. * @private
  833. */
  834. goog.importScript_ = function(src, opt_sourceText) {
  835. var importScript =
  836. goog.global.CLOSURE_IMPORT_SCRIPT || goog.writeScriptTag_;
  837. if (importScript(src, opt_sourceText)) {
  838. goog.dependencies_.written[src] = true;
  839. }
  840. };
  841. /**
  842. * Whether the browser is IE9 or earlier, which needs special handling
  843. * for deferred modules.
  844. * @const @private {boolean}
  845. */
  846. goog.IS_OLD_IE_ =
  847. !!(!goog.global.atob && goog.global.document && goog.global.document.all);
  848. /**
  849. * Whether IE9 or earlier is waiting on a dependency. This ensures that
  850. * deferred modules that have no non-deferred dependencies actually get
  851. * loaded, since if we defer them and then never pull in a non-deferred
  852. * script, then `goog.loadQueuedModules_` will never be called. Instead,
  853. * if not waiting on anything we simply don't defer in the first place.
  854. * @private {boolean}
  855. */
  856. goog.oldIeWaiting_ = false;
  857. /**
  858. * Given a URL initiate retrieval and execution of a script that needs
  859. * pre-processing.
  860. * @param {string} src Script source URL.
  861. * @param {boolean} isModule Whether this is a goog.module.
  862. * @param {boolean} needsTranspile Whether this source needs transpilation.
  863. * @private
  864. */
  865. goog.importProcessedScript_ = function(src, isModule, needsTranspile) {
  866. // In an attempt to keep browsers from timing out loading scripts using
  867. // synchronous XHRs, put each load in its own script block.
  868. var bootstrap = 'goog.retrieveAndExec_("' + src + '", ' + isModule + ', ' +
  869. needsTranspile + ');';
  870. goog.importScript_('', bootstrap);
  871. };
  872. /** @private {!Array<string>} */
  873. goog.queuedModules_ = [];
  874. /**
  875. * Return an appropriate module text. Suitable to insert into
  876. * a script tag (that is unescaped).
  877. * @param {string} srcUrl
  878. * @param {string} scriptText
  879. * @return {string}
  880. * @private
  881. */
  882. goog.wrapModule_ = function(srcUrl, scriptText) {
  883. if (!goog.LOAD_MODULE_USING_EVAL || !goog.isDef(goog.global.JSON)) {
  884. return '' +
  885. 'goog.loadModule(function(exports) {' +
  886. '"use strict";' + scriptText +
  887. '\n' + // terminate any trailing single line comment.
  888. ';return exports' +
  889. '});' +
  890. '\n//# sourceURL=' + srcUrl + '\n';
  891. } else {
  892. return '' +
  893. 'goog.loadModule(' +
  894. goog.global.JSON.stringify(
  895. scriptText + '\n//# sourceURL=' + srcUrl + '\n') +
  896. ');';
  897. }
  898. };
  899. // On IE9 and earlier, it is necessary to handle
  900. // deferred module loads. In later browsers, the
  901. // code to be evaluated is simply inserted as a script
  902. // block in the correct order. To eval deferred
  903. // code at the right time, we piggy back on goog.require to call
  904. // goog.maybeProcessDeferredDep_.
  905. //
  906. // The goog.requires are used both to bootstrap
  907. // the loading process (when no deps are available) and
  908. // declare that they should be available.
  909. //
  910. // Here we eval the sources, if all the deps are available
  911. // either already eval'd or goog.require'd. This will
  912. // be the case when all the dependencies have already
  913. // been loaded, and the dependent module is loaded.
  914. //
  915. // But this alone isn't sufficient because it is also
  916. // necessary to handle the case where there is no root
  917. // that is not deferred. For that there we register for an event
  918. // and trigger goog.loadQueuedModules_ handle any remaining deferred
  919. // evaluations.
  920. /**
  921. * Handle any remaining deferred goog.module evals.
  922. * @private
  923. */
  924. goog.loadQueuedModules_ = function() {
  925. var count = goog.queuedModules_.length;
  926. if (count > 0) {
  927. var queue = goog.queuedModules_;
  928. goog.queuedModules_ = [];
  929. for (var i = 0; i < count; i++) {
  930. var path = queue[i];
  931. goog.maybeProcessDeferredPath_(path);
  932. }
  933. }
  934. goog.oldIeWaiting_ = false;
  935. };
  936. /**
  937. * Eval the named module if its dependencies are
  938. * available.
  939. * @param {string} name The module to load.
  940. * @private
  941. */
  942. goog.maybeProcessDeferredDep_ = function(name) {
  943. if (goog.isDeferredModule_(name) && goog.allDepsAreAvailable_(name)) {
  944. var path = goog.getPathFromDeps_(name);
  945. goog.maybeProcessDeferredPath_(goog.basePath + path);
  946. }
  947. };
  948. /**
  949. * @param {string} name The module to check.
  950. * @return {boolean} Whether the name represents a
  951. * module whose evaluation has been deferred.
  952. * @private
  953. */
  954. goog.isDeferredModule_ = function(name) {
  955. var path = goog.getPathFromDeps_(name);
  956. var loadFlags = path && goog.dependencies_.loadFlags[path] || {};
  957. var languageLevel = loadFlags['lang'] || 'es3';
  958. if (path && (loadFlags['module'] == 'goog' ||
  959. goog.needsTranspile_(languageLevel))) {
  960. var abspath = goog.basePath + path;
  961. return (abspath) in goog.dependencies_.deferred;
  962. }
  963. return false;
  964. };
  965. /**
  966. * @param {string} name The module to check.
  967. * @return {boolean} Whether the name represents a
  968. * module whose declared dependencies have all been loaded
  969. * (eval'd or a deferred module load)
  970. * @private
  971. */
  972. goog.allDepsAreAvailable_ = function(name) {
  973. var path = goog.getPathFromDeps_(name);
  974. if (path && (path in goog.dependencies_.requires)) {
  975. for (var requireName in goog.dependencies_.requires[path]) {
  976. if (!goog.isProvided_(requireName) &&
  977. !goog.isDeferredModule_(requireName)) {
  978. return false;
  979. }
  980. }
  981. }
  982. return true;
  983. };
  984. /**
  985. * @param {string} abspath
  986. * @private
  987. */
  988. goog.maybeProcessDeferredPath_ = function(abspath) {
  989. if (abspath in goog.dependencies_.deferred) {
  990. var src = goog.dependencies_.deferred[abspath];
  991. delete goog.dependencies_.deferred[abspath];
  992. goog.globalEval(src);
  993. }
  994. };
  995. /**
  996. * Load a goog.module from the provided URL. This is not a general purpose
  997. * code loader and does not support late loading code, that is it should only
  998. * be used during page load. This method exists to support unit tests and
  999. * "debug" loaders that would otherwise have inserted script tags. Under the
  1000. * hood this needs to use a synchronous XHR and is not recommeneded for
  1001. * production code.
  1002. *
  1003. * The module's goog.requires must have already been satisified; an exception
  1004. * will be thrown if this is not the case. This assumption is that no
  1005. * "deps.js" file exists, so there is no way to discover and locate the
  1006. * module-to-be-loaded's dependencies and no attempt is made to do so.
  1007. *
  1008. * There should only be one attempt to load a module. If
  1009. * "goog.loadModuleFromUrl" is called for an already loaded module, an
  1010. * exception will be throw.
  1011. *
  1012. * @param {string} url The URL from which to attempt to load the goog.module.
  1013. */
  1014. goog.loadModuleFromUrl = function(url) {
  1015. // Because this executes synchronously, we don't need to do any additional
  1016. // bookkeeping. When "goog.loadModule" the namespace will be marked as
  1017. // having been provided which is sufficient.
  1018. goog.retrieveAndExec_(url, true, false);
  1019. };
  1020. /**
  1021. * Writes a new script pointing to {@code src} directly into the DOM.
  1022. *
  1023. * NOTE: This method is not CSP-compliant. @see goog.appendScriptSrcNode_ for
  1024. * the fallback mechanism.
  1025. *
  1026. * @param {string} src The script URL.
  1027. * @private
  1028. */
  1029. goog.writeScriptSrcNode_ = function(src) {
  1030. goog.global.document.write(
  1031. '<script type="text/javascript" src="' + src + '"></' +
  1032. 'script>');
  1033. };
  1034. /**
  1035. * Appends a new script node to the DOM using a CSP-compliant mechanism. This
  1036. * method exists as a fallback for document.write (which is not allowed in a
  1037. * strict CSP context, e.g., Chrome apps).
  1038. *
  1039. * NOTE: This method is not analogous to using document.write to insert a
  1040. * <script> tag; specifically, the user agent will execute a script added by
  1041. * document.write immediately after the current script block finishes
  1042. * executing, whereas the DOM-appended script node will not be executed until
  1043. * the entire document is parsed and executed. That is to say, this script is
  1044. * added to the end of the script execution queue.
  1045. *
  1046. * The page must not attempt to call goog.required entities until after the
  1047. * document has loaded, e.g., in or after the window.onload callback.
  1048. *
  1049. * @param {string} src The script URL.
  1050. * @private
  1051. */
  1052. goog.appendScriptSrcNode_ = function(src) {
  1053. /** @type {Document} */
  1054. var doc = goog.global.document;
  1055. var scriptEl =
  1056. /** @type {HTMLScriptElement} */ (doc.createElement('script'));
  1057. scriptEl.type = 'text/javascript';
  1058. scriptEl.src = src;
  1059. scriptEl.defer = false;
  1060. scriptEl.async = false;
  1061. doc.head.appendChild(scriptEl);
  1062. };
  1063. /**
  1064. * The default implementation of the import function. Writes a script tag to
  1065. * import the script.
  1066. *
  1067. * @param {string} src The script url.
  1068. * @param {string=} opt_sourceText The optionally source text to evaluate
  1069. * @return {boolean} True if the script was imported, false otherwise.
  1070. * @private
  1071. */
  1072. goog.writeScriptTag_ = function(src, opt_sourceText) {
  1073. if (goog.inHtmlDocument_()) {
  1074. /** @type {!HTMLDocument} */
  1075. var doc = goog.global.document;
  1076. // If the user tries to require a new symbol after document load,
  1077. // something has gone terribly wrong. Doing a document.write would
  1078. // wipe out the page. This does not apply to the CSP-compliant method
  1079. // of writing script tags.
  1080. if (!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING &&
  1081. doc.readyState == 'complete') {
  1082. // Certain test frameworks load base.js multiple times, which tries
  1083. // to write deps.js each time. If that happens, just fail silently.
  1084. // These frameworks wipe the page between each load of base.js, so this
  1085. // is OK.
  1086. var isDeps = /\bdeps.js$/.test(src);
  1087. if (isDeps) {
  1088. return false;
  1089. } else {
  1090. throw new Error('Cannot write "' + src + '" after document load');
  1091. }
  1092. }
  1093. if (opt_sourceText === undefined) {
  1094. if (!goog.IS_OLD_IE_) {
  1095. if (goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING) {
  1096. goog.appendScriptSrcNode_(src);
  1097. } else {
  1098. goog.writeScriptSrcNode_(src);
  1099. }
  1100. } else {
  1101. goog.oldIeWaiting_ = true;
  1102. var state = ' onreadystatechange=\'goog.onScriptLoad_(this, ' +
  1103. ++goog.lastNonModuleScriptIndex_ + ')\' ';
  1104. doc.write(
  1105. '<script type="text/javascript" src="' + src + '"' + state +
  1106. '></' +
  1107. 'script>');
  1108. }
  1109. } else {
  1110. doc.write(
  1111. '<script type="text/javascript">' +
  1112. goog.protectScriptTag_(opt_sourceText) + '</' +
  1113. 'script>');
  1114. }
  1115. return true;
  1116. } else {
  1117. return false;
  1118. }
  1119. };
  1120. /**
  1121. * Rewrites closing script tags in input to avoid ending an enclosing script
  1122. * tag.
  1123. *
  1124. * @param {string} str
  1125. * @return {string}
  1126. * @private
  1127. */
  1128. goog.protectScriptTag_ = function(str) {
  1129. return str.replace(/<\/(SCRIPT)/ig, '\\x3c/$1');
  1130. };
  1131. /**
  1132. * Determines whether the given language needs to be transpiled.
  1133. * @param {string} lang
  1134. * @return {boolean}
  1135. * @private
  1136. */
  1137. goog.needsTranspile_ = function(lang) {
  1138. if (goog.TRANSPILE == 'always') {
  1139. return true;
  1140. } else if (goog.TRANSPILE == 'never') {
  1141. return false;
  1142. } else if (!goog.requiresTranspilation_) {
  1143. goog.requiresTranspilation_ = goog.createRequiresTranspilation_();
  1144. }
  1145. if (lang in goog.requiresTranspilation_) {
  1146. return goog.requiresTranspilation_[lang];
  1147. } else {
  1148. throw new Error('Unknown language mode: ' + lang);
  1149. }
  1150. };
  1151. /** @private {?Object<string, boolean>} */
  1152. goog.requiresTranspilation_ = null;
  1153. /** @private {number} */
  1154. goog.lastNonModuleScriptIndex_ = 0;
  1155. /**
  1156. * A readystatechange handler for legacy IE
  1157. * @param {?} script
  1158. * @param {number} scriptIndex
  1159. * @return {boolean}
  1160. * @private
  1161. */
  1162. goog.onScriptLoad_ = function(script, scriptIndex) {
  1163. // for now load the modules when we reach the last script,
  1164. // later allow more inter-mingling.
  1165. if (script.readyState == 'complete' &&
  1166. goog.lastNonModuleScriptIndex_ == scriptIndex) {
  1167. goog.loadQueuedModules_();
  1168. }
  1169. return true;
  1170. };
  1171. /**
  1172. * Resolves dependencies based on the dependencies added using addDependency
  1173. * and calls importScript_ in the correct order.
  1174. * @param {string} pathToLoad The path from which to start discovering
  1175. * dependencies.
  1176. * @private
  1177. */
  1178. goog.writeScripts_ = function(pathToLoad) {
  1179. /** @type {!Array<string>} The scripts we need to write this time. */
  1180. var scripts = [];
  1181. var seenScript = {};
  1182. var deps = goog.dependencies_;
  1183. /** @param {string} path */
  1184. function visitNode(path) {
  1185. if (path in deps.written) {
  1186. return;
  1187. }
  1188. // We have already visited this one. We can get here if we have cyclic
  1189. // dependencies.
  1190. if (path in deps.visited) {
  1191. return;
  1192. }
  1193. deps.visited[path] = true;
  1194. if (path in deps.requires) {
  1195. for (var requireName in deps.requires[path]) {
  1196. // If the required name is defined, we assume that it was already
  1197. // bootstrapped by other means.
  1198. if (!goog.isProvided_(requireName)) {
  1199. if (requireName in deps.nameToPath) {
  1200. visitNode(deps.nameToPath[requireName]);
  1201. } else {
  1202. throw new Error('Undefined nameToPath for ' + requireName);
  1203. }
  1204. }
  1205. }
  1206. }
  1207. if (!(path in seenScript)) {
  1208. seenScript[path] = true;
  1209. scripts.push(path);
  1210. }
  1211. }
  1212. visitNode(pathToLoad);
  1213. // record that we are going to load all these scripts.
  1214. for (var i = 0; i < scripts.length; i++) {
  1215. var path = scripts[i];
  1216. goog.dependencies_.written[path] = true;
  1217. }
  1218. // If a module is loaded synchronously then we need to
  1219. // clear the current inModuleLoader value, and restore it when we are
  1220. // done loading the current "requires".
  1221. var moduleState = goog.moduleLoaderState_;
  1222. goog.moduleLoaderState_ = null;
  1223. for (var i = 0; i < scripts.length; i++) {
  1224. var path = scripts[i];
  1225. if (path) {
  1226. var loadFlags = deps.loadFlags[path] || {};
  1227. var languageLevel = loadFlags['lang'] || 'es3';
  1228. var needsTranspile = goog.needsTranspile_(languageLevel);
  1229. if (loadFlags['module'] == 'goog' || needsTranspile) {
  1230. goog.importProcessedScript_(
  1231. goog.basePath + path, loadFlags['module'] == 'goog',
  1232. needsTranspile);
  1233. } else {
  1234. goog.importScript_(goog.basePath + path);
  1235. }
  1236. } else {
  1237. goog.moduleLoaderState_ = moduleState;
  1238. throw new Error('Undefined script input');
  1239. }
  1240. }
  1241. // restore the current "module loading state"
  1242. goog.moduleLoaderState_ = moduleState;
  1243. };
  1244. /**
  1245. * Looks at the dependency rules and tries to determine the script file that
  1246. * fulfills a particular rule.
  1247. * @param {string} rule In the form goog.namespace.Class or project.script.
  1248. * @return {?string} Url corresponding to the rule, or null.
  1249. * @private
  1250. */
  1251. goog.getPathFromDeps_ = function(rule) {
  1252. if (rule in goog.dependencies_.nameToPath) {
  1253. return goog.dependencies_.nameToPath[rule];
  1254. } else {
  1255. return null;
  1256. }
  1257. };
  1258. goog.findBasePath_();
  1259. // Allow projects to manage the deps files themselves.
  1260. if (!goog.global.CLOSURE_NO_DEPS) {
  1261. goog.importScript_(goog.basePath + 'deps.js');
  1262. }
  1263. }
  1264. /**
  1265. * @package {?boolean}
  1266. * Visible for testing.
  1267. */
  1268. goog.hasBadLetScoping = null;
  1269. /**
  1270. * @return {boolean}
  1271. * @package Visible for testing.
  1272. */
  1273. goog.useSafari10Workaround = function() {
  1274. if (goog.hasBadLetScoping == null) {
  1275. var hasBadLetScoping;
  1276. try {
  1277. hasBadLetScoping = !eval(
  1278. '"use strict";' +
  1279. 'let x = 1; function f() { return typeof x; };' +
  1280. 'f() == "number";');
  1281. } catch (e) {
  1282. // Assume that ES6 syntax isn't supported.
  1283. hasBadLetScoping = false;
  1284. }
  1285. goog.hasBadLetScoping = hasBadLetScoping;
  1286. }
  1287. return goog.hasBadLetScoping;
  1288. };
  1289. /**
  1290. * @param {string} moduleDef
  1291. * @return {string}
  1292. * @package Visible for testing.
  1293. */
  1294. goog.workaroundSafari10EvalBug = function(moduleDef) {
  1295. return '(function(){' + moduleDef +
  1296. '\n' + // Terminate any trailing single line comment.
  1297. ';' + // Terminate any trailing expression.
  1298. '})();\n';
  1299. };
  1300. /**
  1301. * @param {function(?):?|string} moduleDef The module definition.
  1302. */
  1303. goog.loadModule = function(moduleDef) {
  1304. // NOTE: we allow function definitions to be either in the from
  1305. // of a string to eval (which keeps the original source intact) or
  1306. // in a eval forbidden environment (CSP) we allow a function definition
  1307. // which in its body must call {@code goog.module}, and return the exports
  1308. // of the module.
  1309. var previousState = goog.moduleLoaderState_;
  1310. try {
  1311. goog.moduleLoaderState_ = {
  1312. moduleName: undefined,
  1313. declareLegacyNamespace: false
  1314. };
  1315. var exports;
  1316. if (goog.isFunction(moduleDef)) {
  1317. exports = moduleDef.call(undefined, {});
  1318. } else if (goog.isString(moduleDef)) {
  1319. if (goog.useSafari10Workaround()) {
  1320. moduleDef = goog.workaroundSafari10EvalBug(moduleDef);
  1321. }
  1322. exports = goog.loadModuleFromSource_.call(undefined, moduleDef);
  1323. } else {
  1324. throw new Error('Invalid module definition');
  1325. }
  1326. var moduleName = goog.moduleLoaderState_.moduleName;
  1327. if (!goog.isString(moduleName) || !moduleName) {
  1328. throw new Error('Invalid module name \"' + moduleName + '\"');
  1329. }
  1330. // Don't seal legacy namespaces as they may be uses as a parent of
  1331. // another namespace
  1332. if (goog.moduleLoaderState_.declareLegacyNamespace) {
  1333. goog.constructNamespace_(moduleName, exports);
  1334. } else if (
  1335. goog.SEAL_MODULE_EXPORTS && Object.seal && typeof exports == 'object' &&
  1336. exports != null) {
  1337. Object.seal(exports);
  1338. }
  1339. goog.loadedModules_[moduleName] = exports;
  1340. } finally {
  1341. goog.moduleLoaderState_ = previousState;
  1342. }
  1343. };
  1344. /**
  1345. * @private @const
  1346. */
  1347. goog.loadModuleFromSource_ = /** @type {function(string):?} */ (function() {
  1348. // NOTE: we avoid declaring parameters or local variables here to avoid
  1349. // masking globals or leaking values into the module definition.
  1350. 'use strict';
  1351. var exports = {};
  1352. eval(arguments[0]);
  1353. return exports;
  1354. });
  1355. /**
  1356. * Normalize a file path by removing redundant ".." and extraneous "." file
  1357. * path components.
  1358. * @param {string} path
  1359. * @return {string}
  1360. * @private
  1361. */
  1362. goog.normalizePath_ = function(path) {
  1363. var components = path.split('/');
  1364. var i = 0;
  1365. while (i < components.length) {
  1366. if (components[i] == '.') {
  1367. components.splice(i, 1);
  1368. } else if (
  1369. i && components[i] == '..' && components[i - 1] &&
  1370. components[i - 1] != '..') {
  1371. components.splice(--i, 2);
  1372. } else {
  1373. i++;
  1374. }
  1375. }
  1376. return components.join('/');
  1377. };
  1378. /**
  1379. * Provides a hook for loading a file when using Closure's goog.require() API
  1380. * with goog.modules. In particular this hook is provided to support Node.js.
  1381. *
  1382. * @type {(function(string):string)|undefined}
  1383. */
  1384. goog.global.CLOSURE_LOAD_FILE_SYNC;
  1385. /**
  1386. * Loads file by synchronous XHR. Should not be used in production environments.
  1387. * @param {string} src Source URL.
  1388. * @return {?string} File contents, or null if load failed.
  1389. * @private
  1390. */
  1391. goog.loadFileSync_ = function(src) {
  1392. if (goog.global.CLOSURE_LOAD_FILE_SYNC) {
  1393. return goog.global.CLOSURE_LOAD_FILE_SYNC(src);
  1394. } else {
  1395. try {
  1396. /** @type {XMLHttpRequest} */
  1397. var xhr = new goog.global['XMLHttpRequest']();
  1398. xhr.open('get', src, false);
  1399. xhr.send();
  1400. // NOTE: Successful http: requests have a status of 200, but successful
  1401. // file: requests may have a status of zero. Any other status, or a
  1402. // thrown exception (particularly in case of file: requests) indicates
  1403. // some sort of error, which we treat as a missing or unavailable file.
  1404. return xhr.status == 0 || xhr.status == 200 ? xhr.responseText : null;
  1405. } catch (err) {
  1406. // No need to rethrow or log, since errors should show up on their own.
  1407. return null;
  1408. }
  1409. }
  1410. };
  1411. /**
  1412. * Retrieve and execute a script that needs some sort of wrapping.
  1413. * @param {string} src Script source URL.
  1414. * @param {boolean} isModule Whether to load as a module.
  1415. * @param {boolean} needsTranspile Whether to transpile down to ES3.
  1416. * @private
  1417. */
  1418. goog.retrieveAndExec_ = function(src, isModule, needsTranspile) {
  1419. if (!COMPILED) {
  1420. // The full but non-canonicalized URL for later use.
  1421. var originalPath = src;
  1422. // Canonicalize the path, removing any /./ or /../ since Chrome's debugging
  1423. // console doesn't auto-canonicalize XHR loads as it does <script> srcs.
  1424. src = goog.normalizePath_(src);
  1425. var importScript =
  1426. goog.global.CLOSURE_IMPORT_SCRIPT || goog.writeScriptTag_;
  1427. var scriptText = goog.loadFileSync_(src);
  1428. if (scriptText == null) {
  1429. throw new Error('Load of "' + src + '" failed');
  1430. }
  1431. if (needsTranspile) {
  1432. scriptText = goog.transpile_.call(goog.global, scriptText, src);
  1433. }
  1434. if (isModule) {
  1435. scriptText = goog.wrapModule_(src, scriptText);
  1436. } else {
  1437. scriptText += '\n//# sourceURL=' + src;
  1438. }
  1439. var isOldIE = goog.IS_OLD_IE_;
  1440. if (isOldIE && goog.oldIeWaiting_) {
  1441. goog.dependencies_.deferred[originalPath] = scriptText;
  1442. goog.queuedModules_.push(originalPath);
  1443. } else {
  1444. importScript(src, scriptText);
  1445. }
  1446. }
  1447. };
  1448. /**
  1449. * Lazily retrieves the transpiler and applies it to the source.
  1450. * @param {string} code JS code.
  1451. * @param {string} path Path to the code.
  1452. * @return {string} The transpiled code.
  1453. * @private
  1454. */
  1455. goog.transpile_ = function(code, path) {
  1456. var jscomp = goog.global['$jscomp'];
  1457. if (!jscomp) {
  1458. goog.global['$jscomp'] = jscomp = {};
  1459. }
  1460. var transpile = jscomp.transpile;
  1461. if (!transpile) {
  1462. var transpilerPath = goog.basePath + goog.TRANSPILER;
  1463. var transpilerCode = goog.loadFileSync_(transpilerPath);
  1464. if (transpilerCode) {
  1465. // This must be executed synchronously, since by the time we know we
  1466. // need it, we're about to load and write the ES6 code synchronously,
  1467. // so a normal script-tag load will be too slow.
  1468. eval(transpilerCode + '\n//# sourceURL=' + transpilerPath);
  1469. // Even though the transpiler is optional, if $gwtExport is found, it's
  1470. // a sign the transpiler was loaded and the $jscomp.transpile *should*
  1471. // be there.
  1472. if (goog.global['$gwtExport'] && goog.global['$gwtExport']['$jscomp'] &&
  1473. !goog.global['$gwtExport']['$jscomp']['transpile']) {
  1474. throw new Error(
  1475. 'The transpiler did not properly export the "transpile" ' +
  1476. 'method. $gwtExport: ' + JSON.stringify(goog.global['$gwtExport']));
  1477. }
  1478. // transpile.js only exports a single $jscomp function, transpile. We
  1479. // grab just that and add it to the existing definition of $jscomp which
  1480. // contains the polyfills.
  1481. goog.global['$jscomp'].transpile =
  1482. goog.global['$gwtExport']['$jscomp']['transpile'];
  1483. jscomp = goog.global['$jscomp'];
  1484. transpile = jscomp.transpile;
  1485. }
  1486. }
  1487. if (!transpile) {
  1488. // The transpiler is an optional component. If it's not available then
  1489. // replace it with a pass-through function that simply logs.
  1490. var suffix = ' requires transpilation but no transpiler was found.';
  1491. transpile = jscomp.transpile = function(code, path) {
  1492. // TODO(user): figure out some way to get this error to show up
  1493. // in test results, noting that the failure may occur in many
  1494. // different ways, including in loadModule() before the test
  1495. // runner even comes up.
  1496. goog.logToConsole_(path + suffix);
  1497. return code;
  1498. };
  1499. }
  1500. // Note: any transpilation errors/warnings will be logged to the console.
  1501. return transpile(code, path);
  1502. };
  1503. //==============================================================================
  1504. // Language Enhancements
  1505. //==============================================================================
  1506. /**
  1507. * This is a "fixed" version of the typeof operator. It differs from the typeof
  1508. * operator in such a way that null returns 'null' and arrays return 'array'.
  1509. * @param {?} value The value to get the type of.
  1510. * @return {string} The name of the type.
  1511. */
  1512. goog.typeOf = function(value) {
  1513. var s = typeof value;
  1514. if (s == 'object') {
  1515. if (value) {
  1516. // Check these first, so we can avoid calling Object.prototype.toString if
  1517. // possible.
  1518. //
  1519. // IE improperly marshals typeof across execution contexts, but a
  1520. // cross-context object will still return false for "instanceof Object".
  1521. if (value instanceof Array) {
  1522. return 'array';
  1523. } else if (value instanceof Object) {
  1524. return s;
  1525. }
  1526. // HACK: In order to use an Object prototype method on the arbitrary
  1527. // value, the compiler requires the value be cast to type Object,
  1528. // even though the ECMA spec explicitly allows it.
  1529. var className = Object.prototype.toString.call(
  1530. /** @type {!Object} */ (value));
  1531. // In Firefox 3.6, attempting to access iframe window objects' length
  1532. // property throws an NS_ERROR_FAILURE, so we need to special-case it
  1533. // here.
  1534. if (className == '[object Window]') {
  1535. return 'object';
  1536. }
  1537. // We cannot always use constructor == Array or instanceof Array because
  1538. // different frames have different Array objects. In IE6, if the iframe
  1539. // where the array was created is destroyed, the array loses its
  1540. // prototype. Then dereferencing val.splice here throws an exception, so
  1541. // we can't use goog.isFunction. Calling typeof directly returns 'unknown'
  1542. // so that will work. In this case, this function will return false and
  1543. // most array functions will still work because the array is still
  1544. // array-like (supports length and []) even though it has lost its
  1545. // prototype.
  1546. // Mark Miller noticed that Object.prototype.toString
  1547. // allows access to the unforgeable [[Class]] property.
  1548. // 15.2.4.2 Object.prototype.toString ( )
  1549. // When the toString method is called, the following steps are taken:
  1550. // 1. Get the [[Class]] property of this object.
  1551. // 2. Compute a string value by concatenating the three strings
  1552. // "[object ", Result(1), and "]".
  1553. // 3. Return Result(2).
  1554. // and this behavior survives the destruction of the execution context.
  1555. if ((className == '[object Array]' ||
  1556. // In IE all non value types are wrapped as objects across window
  1557. // boundaries (not iframe though) so we have to do object detection
  1558. // for this edge case.
  1559. typeof value.length == 'number' &&
  1560. typeof value.splice != 'undefined' &&
  1561. typeof value.propertyIsEnumerable != 'undefined' &&
  1562. !value.propertyIsEnumerable('splice')
  1563. )) {
  1564. return 'array';
  1565. }
  1566. // HACK: There is still an array case that fails.
  1567. // function ArrayImpostor() {}
  1568. // ArrayImpostor.prototype = [];
  1569. // var impostor = new ArrayImpostor;
  1570. // this can be fixed by getting rid of the fast path
  1571. // (value instanceof Array) and solely relying on
  1572. // (value && Object.prototype.toString.vall(value) === '[object Array]')
  1573. // but that would require many more function calls and is not warranted
  1574. // unless closure code is receiving objects from untrusted sources.
  1575. // IE in cross-window calls does not correctly marshal the function type
  1576. // (it appears just as an object) so we cannot use just typeof val ==
  1577. // 'function'. However, if the object has a call property, it is a
  1578. // function.
  1579. if ((className == '[object Function]' ||
  1580. typeof value.call != 'undefined' &&
  1581. typeof value.propertyIsEnumerable != 'undefined' &&
  1582. !value.propertyIsEnumerable('call'))) {
  1583. return 'function';
  1584. }
  1585. } else {
  1586. return 'null';
  1587. }
  1588. } else if (s == 'function' && typeof value.call == 'undefined') {
  1589. // In Safari typeof nodeList returns 'function', and on Firefox typeof
  1590. // behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We
  1591. // would like to return object for those and we can detect an invalid
  1592. // function by making sure that the function object has a call method.
  1593. return 'object';
  1594. }
  1595. return s;
  1596. };
  1597. /**
  1598. * Returns true if the specified value is null.
  1599. * @param {?} val Variable to test.
  1600. * @return {boolean} Whether variable is null.
  1601. */
  1602. goog.isNull = function(val) {
  1603. return val === null;
  1604. };
  1605. /**
  1606. * Returns true if the specified value is defined and not null.
  1607. * @param {?} val Variable to test.
  1608. * @return {boolean} Whether variable is defined and not null.
  1609. */
  1610. goog.isDefAndNotNull = function(val) {
  1611. // Note that undefined == null.
  1612. return val != null;
  1613. };
  1614. /**
  1615. * Returns true if the specified value is an array.
  1616. * @param {?} val Variable to test.
  1617. * @return {boolean} Whether variable is an array.
  1618. */
  1619. goog.isArray = function(val) {
  1620. return goog.typeOf(val) == 'array';
  1621. };
  1622. /**
  1623. * Returns true if the object looks like an array. To qualify as array like
  1624. * the value needs to be either a NodeList or an object with a Number length
  1625. * property. As a special case, a function value is not array like, because its
  1626. * length property is fixed to correspond to the number of expected arguments.
  1627. * @param {?} val Variable to test.
  1628. * @return {boolean} Whether variable is an array.
  1629. */
  1630. goog.isArrayLike = function(val) {
  1631. var type = goog.typeOf(val);
  1632. // We do not use goog.isObject here in order to exclude function values.
  1633. return type == 'array' || type == 'object' && typeof val.length == 'number';
  1634. };
  1635. /**
  1636. * Returns true if the object looks like a Date. To qualify as Date-like the
  1637. * value needs to be an object and have a getFullYear() function.
  1638. * @param {?} val Variable to test.
  1639. * @return {boolean} Whether variable is a like a Date.
  1640. */
  1641. goog.isDateLike = function(val) {
  1642. return goog.isObject(val) && typeof val.getFullYear == 'function';
  1643. };
  1644. /**
  1645. * Returns true if the specified value is a function.
  1646. * @param {?} val Variable to test.
  1647. * @return {boolean} Whether variable is a function.
  1648. */
  1649. goog.isFunction = function(val) {
  1650. return goog.typeOf(val) == 'function';
  1651. };
  1652. /**
  1653. * Returns true if the specified value is an object. This includes arrays and
  1654. * functions.
  1655. * @param {?} val Variable to test.
  1656. * @return {boolean} Whether variable is an object.
  1657. */
  1658. goog.isObject = function(val) {
  1659. var type = typeof val;
  1660. return type == 'object' && val != null || type == 'function';
  1661. // return Object(val) === val also works, but is slower, especially if val is
  1662. // not an object.
  1663. };
  1664. /**
  1665. * Gets a unique ID for an object. This mutates the object so that further calls
  1666. * with the same object as a parameter returns the same value. The unique ID is
  1667. * guaranteed to be unique across the current session amongst objects that are
  1668. * passed into {@code getUid}. There is no guarantee that the ID is unique or
  1669. * consistent across sessions. It is unsafe to generate unique ID for function
  1670. * prototypes.
  1671. *
  1672. * @param {Object} obj The object to get the unique ID for.
  1673. * @return {number} The unique ID for the object.
  1674. */
  1675. goog.getUid = function(obj) {
  1676. // TODO(arv): Make the type stricter, do not accept null.
  1677. // In Opera window.hasOwnProperty exists but always returns false so we avoid
  1678. // using it. As a consequence the unique ID generated for BaseClass.prototype
  1679. // and SubClass.prototype will be the same.
  1680. return obj[goog.UID_PROPERTY_] ||
  1681. (obj[goog.UID_PROPERTY_] = ++goog.uidCounter_);
  1682. };
  1683. /**
  1684. * Whether the given object is already assigned a unique ID.
  1685. *
  1686. * This does not modify the object.
  1687. *
  1688. * @param {!Object} obj The object to check.
  1689. * @return {boolean} Whether there is an assigned unique id for the object.
  1690. */
  1691. goog.hasUid = function(obj) {
  1692. return !!obj[goog.UID_PROPERTY_];
  1693. };
  1694. /**
  1695. * Removes the unique ID from an object. This is useful if the object was
  1696. * previously mutated using {@code goog.getUid} in which case the mutation is
  1697. * undone.
  1698. * @param {Object} obj The object to remove the unique ID field from.
  1699. */
  1700. goog.removeUid = function(obj) {
  1701. // TODO(arv): Make the type stricter, do not accept null.
  1702. // In IE, DOM nodes are not instances of Object and throw an exception if we
  1703. // try to delete. Instead we try to use removeAttribute.
  1704. if (obj !== null && 'removeAttribute' in obj) {
  1705. obj.removeAttribute(goog.UID_PROPERTY_);
  1706. }
  1707. try {
  1708. delete obj[goog.UID_PROPERTY_];
  1709. } catch (ex) {
  1710. }
  1711. };
  1712. /**
  1713. * Name for unique ID property. Initialized in a way to help avoid collisions
  1714. * with other closure JavaScript on the same page.
  1715. * @type {string}
  1716. * @private
  1717. */
  1718. goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);
  1719. /**
  1720. * Counter for UID.
  1721. * @type {number}
  1722. * @private
  1723. */
  1724. goog.uidCounter_ = 0;
  1725. /**
  1726. * Adds a hash code field to an object. The hash code is unique for the
  1727. * given object.
  1728. * @param {Object} obj The object to get the hash code for.
  1729. * @return {number} The hash code for the object.
  1730. * @deprecated Use goog.getUid instead.
  1731. */
  1732. goog.getHashCode = goog.getUid;
  1733. /**
  1734. * Removes the hash code field from an object.
  1735. * @param {Object} obj The object to remove the field from.
  1736. * @deprecated Use goog.removeUid instead.
  1737. */
  1738. goog.removeHashCode = goog.removeUid;
  1739. /**
  1740. * Clones a value. The input may be an Object, Array, or basic type. Objects and
  1741. * arrays will be cloned recursively.
  1742. *
  1743. * WARNINGS:
  1744. * <code>goog.cloneObject</code> does not detect reference loops. Objects that
  1745. * refer to themselves will cause infinite recursion.
  1746. *
  1747. * <code>goog.cloneObject</code> is unaware of unique identifiers, and copies
  1748. * UIDs created by <code>getUid</code> into cloned results.
  1749. *
  1750. * @param {*} obj The value to clone.
  1751. * @return {*} A clone of the input value.
  1752. * @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods.
  1753. */
  1754. goog.cloneObject = function(obj) {
  1755. var type = goog.typeOf(obj);
  1756. if (type == 'object' || type == 'array') {
  1757. if (obj.clone) {
  1758. return obj.clone();
  1759. }
  1760. var clone = type == 'array' ? [] : {};
  1761. for (var key in obj) {
  1762. clone[key] = goog.cloneObject(obj[key]);
  1763. }
  1764. return clone;
  1765. }
  1766. return obj;
  1767. };
  1768. /**
  1769. * A native implementation of goog.bind.
  1770. * @param {?function(this:T, ...)} fn A function to partially apply.
  1771. * @param {T} selfObj Specifies the object which this should point to when the
  1772. * function is run.
  1773. * @param {...*} var_args Additional arguments that are partially applied to the
  1774. * function.
  1775. * @return {!Function} A partially-applied form of the function goog.bind() was
  1776. * invoked as a method of.
  1777. * @template T
  1778. * @private
  1779. */
  1780. goog.bindNative_ = function(fn, selfObj, var_args) {
  1781. return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments));
  1782. };
  1783. /**
  1784. * A pure-JS implementation of goog.bind.
  1785. * @param {?function(this:T, ...)} fn A function to partially apply.
  1786. * @param {T} selfObj Specifies the object which this should point to when the
  1787. * function is run.
  1788. * @param {...*} var_args Additional arguments that are partially applied to the
  1789. * function.
  1790. * @return {!Function} A partially-applied form of the function goog.bind() was
  1791. * invoked as a method of.
  1792. * @template T
  1793. * @private
  1794. */
  1795. goog.bindJs_ = function(fn, selfObj, var_args) {
  1796. if (!fn) {
  1797. throw new Error();
  1798. }
  1799. if (arguments.length > 2) {
  1800. var boundArgs = Array.prototype.slice.call(arguments, 2);
  1801. return function() {
  1802. // Prepend the bound arguments to the current arguments.
  1803. var newArgs = Array.prototype.slice.call(arguments);
  1804. Array.prototype.unshift.apply(newArgs, boundArgs);
  1805. return fn.apply(selfObj, newArgs);
  1806. };
  1807. } else {
  1808. return function() {
  1809. return fn.apply(selfObj, arguments);
  1810. };
  1811. }
  1812. };
  1813. /**
  1814. * Partially applies this function to a particular 'this object' and zero or
  1815. * more arguments. The result is a new function with some arguments of the first
  1816. * function pre-filled and the value of this 'pre-specified'.
  1817. *
  1818. * Remaining arguments specified at call-time are appended to the pre-specified
  1819. * ones.
  1820. *
  1821. * Also see: {@link #partial}.
  1822. *
  1823. * Usage:
  1824. * <pre>var barMethBound = goog.bind(myFunction, myObj, 'arg1', 'arg2');
  1825. * barMethBound('arg3', 'arg4');</pre>
  1826. *
  1827. * @param {?function(this:T, ...)} fn A function to partially apply.
  1828. * @param {T} selfObj Specifies the object which this should point to when the
  1829. * function is run.
  1830. * @param {...*} var_args Additional arguments that are partially applied to the
  1831. * function.
  1832. * @return {!Function} A partially-applied form of the function goog.bind() was
  1833. * invoked as a method of.
  1834. * @template T
  1835. * @suppress {deprecated} See above.
  1836. */
  1837. goog.bind = function(fn, selfObj, var_args) {
  1838. // TODO(nicksantos): narrow the type signature.
  1839. if (Function.prototype.bind &&
  1840. // NOTE(nicksantos): Somebody pulled base.js into the default Chrome
  1841. // extension environment. This means that for Chrome extensions, they get
  1842. // the implementation of Function.prototype.bind that calls goog.bind
  1843. // instead of the native one. Even worse, we don't want to introduce a
  1844. // circular dependency between goog.bind and Function.prototype.bind, so
  1845. // we have to hack this to make sure it works correctly.
  1846. Function.prototype.bind.toString().indexOf('native code') != -1) {
  1847. goog.bind = goog.bindNative_;
  1848. } else {
  1849. goog.bind = goog.bindJs_;
  1850. }
  1851. return goog.bind.apply(null, arguments);
  1852. };
  1853. /**
  1854. * Like goog.bind(), except that a 'this object' is not required. Useful when
  1855. * the target function is already bound.
  1856. *
  1857. * Usage:
  1858. * var g = goog.partial(f, arg1, arg2);
  1859. * g(arg3, arg4);
  1860. *
  1861. * @param {Function} fn A function to partially apply.
  1862. * @param {...*} var_args Additional arguments that are partially applied to fn.
  1863. * @return {!Function} A partially-applied form of the function goog.partial()
  1864. * was invoked as a method of.
  1865. */
  1866. goog.partial = function(fn, var_args) {
  1867. var args = Array.prototype.slice.call(arguments, 1);
  1868. return function() {
  1869. // Clone the array (with slice()) and append additional arguments
  1870. // to the existing arguments.
  1871. var newArgs = args.slice();
  1872. newArgs.push.apply(newArgs, arguments);
  1873. return fn.apply(this, newArgs);
  1874. };
  1875. };
  1876. /**
  1877. * Copies all the members of a source object to a target object. This method
  1878. * does not work on all browsers for all objects that contain keys such as
  1879. * toString or hasOwnProperty. Use goog.object.extend for this purpose.
  1880. * @param {Object} target Target.
  1881. * @param {Object} source Source.
  1882. */
  1883. goog.mixin = function(target, source) {
  1884. for (var x in source) {
  1885. target[x] = source[x];
  1886. }
  1887. // For IE7 or lower, the for-in-loop does not contain any properties that are
  1888. // not enumerable on the prototype object (for example, isPrototypeOf from
  1889. // Object.prototype) but also it will not include 'replace' on objects that
  1890. // extend String and change 'replace' (not that it is common for anyone to
  1891. // extend anything except Object).
  1892. };
  1893. /**
  1894. * @return {number} An integer value representing the number of milliseconds
  1895. * between midnight, January 1, 1970 and the current time.
  1896. */
  1897. goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
  1898. // Unary plus operator converts its operand to a number which in
  1899. // the case of
  1900. // a date is done by calling getTime().
  1901. return +new Date();
  1902. });
  1903. /**
  1904. * Evals JavaScript in the global scope. In IE this uses execScript, other
  1905. * browsers use goog.global.eval. If goog.global.eval does not evaluate in the
  1906. * global scope (for example, in Safari), appends a script tag instead.
  1907. * Throws an exception if neither execScript or eval is defined.
  1908. * @param {string} script JavaScript string.
  1909. */
  1910. goog.globalEval = function(script) {
  1911. if (goog.global.execScript) {
  1912. goog.global.execScript(script, 'JavaScript');
  1913. } else if (goog.global.eval) {
  1914. // Test to see if eval works
  1915. if (goog.evalWorksForGlobals_ == null) {
  1916. goog.global.eval('var _evalTest_ = 1;');
  1917. if (typeof goog.global['_evalTest_'] != 'undefined') {
  1918. try {
  1919. delete goog.global['_evalTest_'];
  1920. } catch (ignore) {
  1921. // Microsoft edge fails the deletion above in strict mode.
  1922. }
  1923. goog.evalWorksForGlobals_ = true;
  1924. } else {
  1925. goog.evalWorksForGlobals_ = false;
  1926. }
  1927. }
  1928. if (goog.evalWorksForGlobals_) {
  1929. goog.global.eval(script);
  1930. } else {
  1931. /** @type {Document} */
  1932. var doc = goog.global.document;
  1933. var scriptElt =
  1934. /** @type {!HTMLScriptElement} */ (doc.createElement('SCRIPT'));
  1935. scriptElt.type = 'text/javascript';
  1936. scriptElt.defer = false;
  1937. // Note(user): can't use .innerHTML since "t('<test>')" will fail and
  1938. // .text doesn't work in Safari 2. Therefore we append a text node.
  1939. scriptElt.appendChild(doc.createTextNode(script));
  1940. doc.body.appendChild(scriptElt);
  1941. doc.body.removeChild(scriptElt);
  1942. }
  1943. } else {
  1944. throw new Error('goog.globalEval not available');
  1945. }
  1946. };
  1947. /**
  1948. * Indicates whether or not we can call 'eval' directly to eval code in the
  1949. * global scope. Set to a Boolean by the first call to goog.globalEval (which
  1950. * empirically tests whether eval works for globals). @see goog.globalEval
  1951. * @type {?boolean}
  1952. * @private
  1953. */
  1954. goog.evalWorksForGlobals_ = null;
  1955. /**
  1956. * Optional map of CSS class names to obfuscated names used with
  1957. * goog.getCssName().
  1958. * @private {!Object<string, string>|undefined}
  1959. * @see goog.setCssNameMapping
  1960. */
  1961. goog.cssNameMapping_;
  1962. /**
  1963. * Optional obfuscation style for CSS class names. Should be set to either
  1964. * 'BY_WHOLE' or 'BY_PART' if defined.
  1965. * @type {string|undefined}
  1966. * @private
  1967. * @see goog.setCssNameMapping
  1968. */
  1969. goog.cssNameMappingStyle_;
  1970. /**
  1971. * A hook for modifying the default behavior goog.getCssName. The function
  1972. * if present, will recieve the standard output of the goog.getCssName as
  1973. * its input.
  1974. *
  1975. * @type {(function(string):string)|undefined}
  1976. */
  1977. goog.global.CLOSURE_CSS_NAME_MAP_FN;
  1978. /**
  1979. * Handles strings that are intended to be used as CSS class names.
  1980. *
  1981. * This function works in tandem with @see goog.setCssNameMapping.
  1982. *
  1983. * Without any mapping set, the arguments are simple joined with a hyphen and
  1984. * passed through unaltered.
  1985. *
  1986. * When there is a mapping, there are two possible styles in which these
  1987. * mappings are used. In the BY_PART style, each part (i.e. in between hyphens)
  1988. * of the passed in css name is rewritten according to the map. In the BY_WHOLE
  1989. * style, the full css name is looked up in the map directly. If a rewrite is
  1990. * not specified by the map, the compiler will output a warning.
  1991. *
  1992. * When the mapping is passed to the compiler, it will replace calls to
  1993. * goog.getCssName with the strings from the mapping, e.g.
  1994. * var x = goog.getCssName('foo');
  1995. * var y = goog.getCssName(this.baseClass, 'active');
  1996. * becomes:
  1997. * var x = 'foo';
  1998. * var y = this.baseClass + '-active';
  1999. *
  2000. * If one argument is passed it will be processed, if two are passed only the
  2001. * modifier will be processed, as it is assumed the first argument was generated
  2002. * as a result of calling goog.getCssName.
  2003. *
  2004. * @param {string} className The class name.
  2005. * @param {string=} opt_modifier A modifier to be appended to the class name.
  2006. * @return {string} The class name or the concatenation of the class name and
  2007. * the modifier.
  2008. */
  2009. goog.getCssName = function(className, opt_modifier) {
  2010. // String() is used for compatibility with compiled soy where the passed
  2011. // className can be non-string objects.
  2012. if (String(className).charAt(0) == '.') {
  2013. throw new Error(
  2014. 'className passed in goog.getCssName must not start with ".".' +
  2015. ' You passed: ' + className);
  2016. }
  2017. var getMapping = function(cssName) {
  2018. return goog.cssNameMapping_[cssName] || cssName;
  2019. };
  2020. var renameByParts = function(cssName) {
  2021. // Remap all the parts individually.
  2022. var parts = cssName.split('-');
  2023. var mapped = [];
  2024. for (var i = 0; i < parts.length; i++) {
  2025. mapped.push(getMapping(parts[i]));
  2026. }
  2027. return mapped.join('-');
  2028. };
  2029. var rename;
  2030. if (goog.cssNameMapping_) {
  2031. rename =
  2032. goog.cssNameMappingStyle_ == 'BY_WHOLE' ? getMapping : renameByParts;
  2033. } else {
  2034. rename = function(a) {
  2035. return a;
  2036. };
  2037. }
  2038. var result =
  2039. opt_modifier ? className + '-' + rename(opt_modifier) : rename(className);
  2040. // The special CLOSURE_CSS_NAME_MAP_FN allows users to specify further
  2041. // processing of the class name.
  2042. if (goog.global.CLOSURE_CSS_NAME_MAP_FN) {
  2043. return goog.global.CLOSURE_CSS_NAME_MAP_FN(result);
  2044. }
  2045. return result;
  2046. };
  2047. /**
  2048. * Sets the map to check when returning a value from goog.getCssName(). Example:
  2049. * <pre>
  2050. * goog.setCssNameMapping({
  2051. * "goog": "a",
  2052. * "disabled": "b",
  2053. * });
  2054. *
  2055. * var x = goog.getCssName('goog');
  2056. * // The following evaluates to: "a a-b".
  2057. * goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')
  2058. * </pre>
  2059. * When declared as a map of string literals to string literals, the JSCompiler
  2060. * will replace all calls to goog.getCssName() using the supplied map if the
  2061. * --process_closure_primitives flag is set.
  2062. *
  2063. * @param {!Object} mapping A map of strings to strings where keys are possible
  2064. * arguments to goog.getCssName() and values are the corresponding values
  2065. * that should be returned.
  2066. * @param {string=} opt_style The style of css name mapping. There are two valid
  2067. * options: 'BY_PART', and 'BY_WHOLE'.
  2068. * @see goog.getCssName for a description.
  2069. */
  2070. goog.setCssNameMapping = function(mapping, opt_style) {
  2071. goog.cssNameMapping_ = mapping;
  2072. goog.cssNameMappingStyle_ = opt_style;
  2073. };
  2074. /**
  2075. * To use CSS renaming in compiled mode, one of the input files should have a
  2076. * call to goog.setCssNameMapping() with an object literal that the JSCompiler
  2077. * can extract and use to replace all calls to goog.getCssName(). In uncompiled
  2078. * mode, JavaScript code should be loaded before this base.js file that declares
  2079. * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is
  2080. * to ensure that the mapping is loaded before any calls to goog.getCssName()
  2081. * are made in uncompiled mode.
  2082. *
  2083. * A hook for overriding the CSS name mapping.
  2084. * @type {!Object<string, string>|undefined}
  2085. */
  2086. goog.global.CLOSURE_CSS_NAME_MAPPING;
  2087. if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
  2088. // This does not call goog.setCssNameMapping() because the JSCompiler
  2089. // requires that goog.setCssNameMapping() be called with an object literal.
  2090. goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;
  2091. }
  2092. /**
  2093. * Gets a localized message.
  2094. *
  2095. * This function is a compiler primitive. If you give the compiler a localized
  2096. * message bundle, it will replace the string at compile-time with a localized
  2097. * version, and expand goog.getMsg call to a concatenated string.
  2098. *
  2099. * Messages must be initialized in the form:
  2100. * <code>
  2101. * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});
  2102. * </code>
  2103. *
  2104. * This function produces a string which should be treated as plain text. Use
  2105. * {@link goog.html.SafeHtmlFormatter} in conjunction with goog.getMsg to
  2106. * produce SafeHtml.
  2107. *
  2108. * @param {string} str Translatable string, places holders in the form {$foo}.
  2109. * @param {Object<string, string>=} opt_values Maps place holder name to value.
  2110. * @return {string} message with placeholders filled.
  2111. */
  2112. goog.getMsg = function(str, opt_values) {
  2113. if (opt_values) {
  2114. str = str.replace(/\{\$([^}]+)}/g, function(match, key) {
  2115. return (opt_values != null && key in opt_values) ? opt_values[key] :
  2116. match;
  2117. });
  2118. }
  2119. return str;
  2120. };
  2121. /**
  2122. * Gets a localized message. If the message does not have a translation, gives a
  2123. * fallback message.
  2124. *
  2125. * This is useful when introducing a new message that has not yet been
  2126. * translated into all languages.
  2127. *
  2128. * This function is a compiler primitive. Must be used in the form:
  2129. * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>
  2130. * where MSG_A and MSG_B were initialized with goog.getMsg.
  2131. *
  2132. * @param {string} a The preferred message.
  2133. * @param {string} b The fallback message.
  2134. * @return {string} The best translated message.
  2135. */
  2136. goog.getMsgWithFallback = function(a, b) {
  2137. return a;
  2138. };
  2139. /**
  2140. * Exposes an unobfuscated global namespace path for the given object.
  2141. * Note that fields of the exported object *will* be obfuscated, unless they are
  2142. * exported in turn via this function or goog.exportProperty.
  2143. *
  2144. * Also handy for making public items that are defined in anonymous closures.
  2145. *
  2146. * ex. goog.exportSymbol('public.path.Foo', Foo);
  2147. *
  2148. * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction);
  2149. * public.path.Foo.staticFunction();
  2150. *
  2151. * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',
  2152. * Foo.prototype.myMethod);
  2153. * new public.path.Foo().myMethod();
  2154. *
  2155. * @param {string} publicPath Unobfuscated name to export.
  2156. * @param {*} object Object the name should point to.
  2157. * @param {Object=} opt_objectToExportTo The object to add the path to; default
  2158. * is goog.global.
  2159. */
  2160. goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {
  2161. goog.exportPath_(publicPath, object, opt_objectToExportTo);
  2162. };
  2163. /**
  2164. * Exports a property unobfuscated into the object's namespace.
  2165. * ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction);
  2166. * ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);
  2167. * @param {Object} object Object whose static property is being exported.
  2168. * @param {string} publicName Unobfuscated name to export.
  2169. * @param {*} symbol Object the name should point to.
  2170. */
  2171. goog.exportProperty = function(object, publicName, symbol) {
  2172. object[publicName] = symbol;
  2173. };
  2174. /**
  2175. * Inherit the prototype methods from one constructor into another.
  2176. *
  2177. * Usage:
  2178. * <pre>
  2179. * function ParentClass(a, b) { }
  2180. * ParentClass.prototype.foo = function(a) { };
  2181. *
  2182. * function ChildClass(a, b, c) {
  2183. * ChildClass.base(this, 'constructor', a, b);
  2184. * }
  2185. * goog.inherits(ChildClass, ParentClass);
  2186. *
  2187. * var child = new ChildClass('a', 'b', 'see');
  2188. * child.foo(); // This works.
  2189. * </pre>
  2190. *
  2191. * @param {!Function} childCtor Child class.
  2192. * @param {!Function} parentCtor Parent class.
  2193. */
  2194. goog.inherits = function(childCtor, parentCtor) {
  2195. /** @constructor */
  2196. function tempCtor() {}
  2197. tempCtor.prototype = parentCtor.prototype;
  2198. childCtor.superClass_ = parentCtor.prototype;
  2199. childCtor.prototype = new tempCtor();
  2200. /** @override */
  2201. childCtor.prototype.constructor = childCtor;
  2202. /**
  2203. * Calls superclass constructor/method.
  2204. *
  2205. * This function is only available if you use goog.inherits to
  2206. * express inheritance relationships between classes.
  2207. *
  2208. * NOTE: This is a replacement for goog.base and for superClass_
  2209. * property defined in childCtor.
  2210. *
  2211. * @param {!Object} me Should always be "this".
  2212. * @param {string} methodName The method name to call. Calling
  2213. * superclass constructor can be done with the special string
  2214. * 'constructor'.
  2215. * @param {...*} var_args The arguments to pass to superclass
  2216. * method/constructor.
  2217. * @return {*} The return value of the superclass method/constructor.
  2218. */
  2219. childCtor.base = function(me, methodName, var_args) {
  2220. // Copying using loop to avoid deop due to passing arguments object to
  2221. // function. This is faster in many JS engines as of late 2014.
  2222. var args = new Array(arguments.length - 2);
  2223. for (var i = 2; i < arguments.length; i++) {
  2224. args[i - 2] = arguments[i];
  2225. }
  2226. return parentCtor.prototype[methodName].apply(me, args);
  2227. };
  2228. };
  2229. /**
  2230. * Call up to the superclass.
  2231. *
  2232. * If this is called from a constructor, then this calls the superclass
  2233. * constructor with arguments 1-N.
  2234. *
  2235. * If this is called from a prototype method, then you must pass the name of the
  2236. * method as the second argument to this function. If you do not, you will get a
  2237. * runtime error. This calls the superclass' method with arguments 2-N.
  2238. *
  2239. * This function only works if you use goog.inherits to express inheritance
  2240. * relationships between your classes.
  2241. *
  2242. * This function is a compiler primitive. At compile-time, the compiler will do
  2243. * macro expansion to remove a lot of the extra overhead that this function
  2244. * introduces. The compiler will also enforce a lot of the assumptions that this
  2245. * function makes, and treat it as a compiler error if you break them.
  2246. *
  2247. * @param {!Object} me Should always be "this".
  2248. * @param {*=} opt_methodName The method name if calling a super method.
  2249. * @param {...*} var_args The rest of the arguments.
  2250. * @return {*} The return value of the superclass method.
  2251. * @suppress {es5Strict} This method can not be used in strict mode, but
  2252. * all Closure Library consumers must depend on this file.
  2253. * @deprecated goog.base is not strict mode compatible. Prefer the static
  2254. * "base" method added to the constructor by goog.inherits
  2255. * or ES6 classes and the "super" keyword.
  2256. */
  2257. goog.base = function(me, opt_methodName, var_args) {
  2258. var caller = arguments.callee.caller;
  2259. if (goog.STRICT_MODE_COMPATIBLE || (goog.DEBUG && !caller)) {
  2260. throw new Error(
  2261. 'arguments.caller not defined. goog.base() cannot be used ' +
  2262. 'with strict mode code. See ' +
  2263. 'http://www.ecma-international.org/ecma-262/5.1/#sec-C');
  2264. }
  2265. if (caller.superClass_) {
  2266. // Copying using loop to avoid deop due to passing arguments object to
  2267. // function. This is faster in many JS engines as of late 2014.
  2268. var ctorArgs = new Array(arguments.length - 1);
  2269. for (var i = 1; i < arguments.length; i++) {
  2270. ctorArgs[i - 1] = arguments[i];
  2271. }
  2272. // This is a constructor. Call the superclass constructor.
  2273. return caller.superClass_.constructor.apply(me, ctorArgs);
  2274. }
  2275. // Copying using loop to avoid deop due to passing arguments object to
  2276. // function. This is faster in many JS engines as of late 2014.
  2277. var args = new Array(arguments.length - 2);
  2278. for (var i = 2; i < arguments.length; i++) {
  2279. args[i - 2] = arguments[i];
  2280. }
  2281. var foundCaller = false;
  2282. for (var ctor = me.constructor; ctor;
  2283. ctor = ctor.superClass_ && ctor.superClass_.constructor) {
  2284. if (ctor.prototype[opt_methodName] === caller) {
  2285. foundCaller = true;
  2286. } else if (foundCaller) {
  2287. return ctor.prototype[opt_methodName].apply(me, args);
  2288. }
  2289. }
  2290. // If we did not find the caller in the prototype chain, then one of two
  2291. // things happened:
  2292. // 1) The caller is an instance method.
  2293. // 2) This method was not called by the right caller.
  2294. if (me[opt_methodName] === caller) {
  2295. return me.constructor.prototype[opt_methodName].apply(me, args);
  2296. } else {
  2297. throw new Error(
  2298. 'goog.base called from a method of one name ' +
  2299. 'to a method of a different name');
  2300. }
  2301. };
  2302. /**
  2303. * Allow for aliasing within scope functions. This function exists for
  2304. * uncompiled code - in compiled code the calls will be inlined and the aliases
  2305. * applied. In uncompiled code the function is simply run since the aliases as
  2306. * written are valid JavaScript.
  2307. *
  2308. *
  2309. * @param {function()} fn Function to call. This function can contain aliases
  2310. * to namespaces (e.g. "var dom = goog.dom") or classes
  2311. * (e.g. "var Timer = goog.Timer").
  2312. */
  2313. goog.scope = function(fn) {
  2314. if (goog.isInModuleLoader_()) {
  2315. throw new Error('goog.scope is not supported within a goog.module.');
  2316. }
  2317. fn.call(goog.global);
  2318. };
  2319. /*
  2320. * To support uncompiled, strict mode bundles that use eval to divide source
  2321. * like so:
  2322. * eval('someSource;//# sourceUrl sourcefile.js');
  2323. * We need to export the globally defined symbols "goog" and "COMPILED".
  2324. * Exporting "goog" breaks the compiler optimizations, so we required that
  2325. * be defined externally.
  2326. * NOTE: We don't use goog.exportSymbol here because we don't want to trigger
  2327. * extern generation when that compiler option is enabled.
  2328. */
  2329. if (!COMPILED) {
  2330. goog.global['COMPILED'] = COMPILED;
  2331. }
  2332. //==============================================================================
  2333. // goog.defineClass implementation
  2334. //==============================================================================
  2335. /**
  2336. * Creates a restricted form of a Closure "class":
  2337. * - from the compiler's perspective, the instance returned from the
  2338. * constructor is sealed (no new properties may be added). This enables
  2339. * better checks.
  2340. * - the compiler will rewrite this definition to a form that is optimal
  2341. * for type checking and optimization (initially this will be a more
  2342. * traditional form).
  2343. *
  2344. * @param {Function} superClass The superclass, Object or null.
  2345. * @param {goog.defineClass.ClassDescriptor} def
  2346. * An object literal describing
  2347. * the class. It may have the following properties:
  2348. * "constructor": the constructor function
  2349. * "statics": an object literal containing methods to add to the constructor
  2350. * as "static" methods or a function that will receive the constructor
  2351. * function as its only parameter to which static properties can
  2352. * be added.
  2353. * all other properties are added to the prototype.
  2354. * @return {!Function} The class constructor.
  2355. */
  2356. goog.defineClass = function(superClass, def) {
  2357. // TODO(johnlenz): consider making the superClass an optional parameter.
  2358. var constructor = def.constructor;
  2359. var statics = def.statics;
  2360. // Wrap the constructor prior to setting up the prototype and static methods.
  2361. if (!constructor || constructor == Object.prototype.constructor) {
  2362. constructor = function() {
  2363. throw new Error(
  2364. 'cannot instantiate an interface (no constructor defined).');
  2365. };
  2366. }
  2367. var cls = goog.defineClass.createSealingConstructor_(constructor, superClass);
  2368. if (superClass) {
  2369. goog.inherits(cls, superClass);
  2370. }
  2371. // Remove all the properties that should not be copied to the prototype.
  2372. delete def.constructor;
  2373. delete def.statics;
  2374. goog.defineClass.applyProperties_(cls.prototype, def);
  2375. if (statics != null) {
  2376. if (statics instanceof Function) {
  2377. statics(cls);
  2378. } else {
  2379. goog.defineClass.applyProperties_(cls, statics);
  2380. }
  2381. }
  2382. return cls;
  2383. };
  2384. /**
  2385. * @typedef {{
  2386. * constructor: (!Function|undefined),
  2387. * statics: (Object|undefined|function(Function):void)
  2388. * }}
  2389. */
  2390. goog.defineClass.ClassDescriptor;
  2391. /**
  2392. * @define {boolean} Whether the instances returned by goog.defineClass should
  2393. * be sealed when possible.
  2394. *
  2395. * When sealing is disabled the constructor function will not be wrapped by
  2396. * goog.defineClass, making it incompatible with ES6 class methods.
  2397. */
  2398. goog.define('goog.defineClass.SEAL_CLASS_INSTANCES', goog.DEBUG);
  2399. /**
  2400. * If goog.defineClass.SEAL_CLASS_INSTANCES is enabled and Object.seal is
  2401. * defined, this function will wrap the constructor in a function that seals the
  2402. * results of the provided constructor function.
  2403. *
  2404. * @param {!Function} ctr The constructor whose results maybe be sealed.
  2405. * @param {Function} superClass The superclass constructor.
  2406. * @return {!Function} The replacement constructor.
  2407. * @private
  2408. */
  2409. goog.defineClass.createSealingConstructor_ = function(ctr, superClass) {
  2410. if (!goog.defineClass.SEAL_CLASS_INSTANCES) {
  2411. // Do now wrap the constructor when sealing is disabled. Angular code
  2412. // depends on this for injection to work properly.
  2413. return ctr;
  2414. }
  2415. // Compute whether the constructor is sealable at definition time, rather
  2416. // than when the instance is being constructed.
  2417. var superclassSealable = !goog.defineClass.isUnsealable_(superClass);
  2418. /**
  2419. * @this {Object}
  2420. * @return {?}
  2421. */
  2422. var wrappedCtr = function() {
  2423. // Don't seal an instance of a subclass when it calls the constructor of
  2424. // its super class as there is most likely still setup to do.
  2425. var instance = ctr.apply(this, arguments) || this;
  2426. instance[goog.UID_PROPERTY_] = instance[goog.UID_PROPERTY_];
  2427. if (this.constructor === wrappedCtr && superclassSealable &&
  2428. Object.seal instanceof Function) {
  2429. Object.seal(instance);
  2430. }
  2431. return instance;
  2432. };
  2433. return wrappedCtr;
  2434. };
  2435. /**
  2436. * @param {Function} ctr The constructor to test.
  2437. * @return {boolean} Whether the constructor has been tagged as unsealable
  2438. * using goog.tagUnsealableClass.
  2439. * @private
  2440. */
  2441. goog.defineClass.isUnsealable_ = function(ctr) {
  2442. return ctr && ctr.prototype &&
  2443. ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_];
  2444. };
  2445. // TODO(johnlenz): share these values with the goog.object
  2446. /**
  2447. * The names of the fields that are defined on Object.prototype.
  2448. * @type {!Array<string>}
  2449. * @private
  2450. * @const
  2451. */
  2452. goog.defineClass.OBJECT_PROTOTYPE_FIELDS_ = [
  2453. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  2454. 'toLocaleString', 'toString', 'valueOf'
  2455. ];
  2456. // TODO(johnlenz): share this function with the goog.object
  2457. /**
  2458. * @param {!Object} target The object to add properties to.
  2459. * @param {!Object} source The object to copy properties from.
  2460. * @private
  2461. */
  2462. goog.defineClass.applyProperties_ = function(target, source) {
  2463. // TODO(johnlenz): update this to support ES5 getters/setters
  2464. var key;
  2465. for (key in source) {
  2466. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2467. target[key] = source[key];
  2468. }
  2469. }
  2470. // For IE the for-in-loop does not contain any properties that are not
  2471. // enumerable on the prototype object (for example isPrototypeOf from
  2472. // Object.prototype) and it will also not include 'replace' on objects that
  2473. // extend String and change 'replace' (not that it is common for anyone to
  2474. // extend anything except Object).
  2475. for (var i = 0; i < goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length; i++) {
  2476. key = goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[i];
  2477. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2478. target[key] = source[key];
  2479. }
  2480. }
  2481. };
  2482. /**
  2483. * Sealing classes breaks the older idiom of assigning properties on the
  2484. * prototype rather than in the constructor. As such, goog.defineClass
  2485. * must not seal subclasses of these old-style classes until they are fixed.
  2486. * Until then, this marks a class as "broken", instructing defineClass
  2487. * not to seal subclasses.
  2488. * @param {!Function} ctr The legacy constructor to tag as unsealable.
  2489. */
  2490. goog.tagUnsealableClass = function(ctr) {
  2491. if (!COMPILED && goog.defineClass.SEAL_CLASS_INSTANCES) {
  2492. ctr.prototype[goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_] = true;
  2493. }
  2494. };
  2495. /**
  2496. * Name for unsealable tag property.
  2497. * @const @private {string}
  2498. */
  2499. goog.UNSEALABLE_CONSTRUCTOR_PROPERTY_ = 'goog_defineClass_legacy_unsealable';
  2500. /**
  2501. * Returns a newly created map from language mode string to a boolean
  2502. * indicating whether transpilation should be done for that mode.
  2503. *
  2504. * Guaranteed invariant:
  2505. * For any two modes, l1 and l2 where l2 is a newer mode than l1,
  2506. * `map[l1] == true` implies that `map[l2] == true`.
  2507. * @private
  2508. * @return {!Object<string, boolean>}
  2509. */
  2510. goog.createRequiresTranspilation_ = function() {
  2511. var /** !Object<string, boolean> */ requiresTranspilation = {'es3': false};
  2512. var transpilationRequiredForAllLaterModes = false;
  2513. /**
  2514. * Adds an entry to requiresTranspliation for the given language mode.
  2515. *
  2516. * IMPORTANT: Calls must be made in order from oldest to newest language
  2517. * mode.
  2518. * @param {string} modeName
  2519. * @param {function(): boolean} isSupported Returns true if the JS engine
  2520. * supports the given mode.
  2521. */
  2522. function addNewerLanguageTranspilationCheck(modeName, isSupported) {
  2523. if (transpilationRequiredForAllLaterModes) {
  2524. requiresTranspilation[modeName] = true;
  2525. } else if (isSupported()) {
  2526. requiresTranspilation[modeName] = false;
  2527. } else {
  2528. requiresTranspilation[modeName] = true;
  2529. transpilationRequiredForAllLaterModes = true;
  2530. }
  2531. }
  2532. /**
  2533. * Does the given code evaluate without syntax errors and return a truthy
  2534. * result?
  2535. */
  2536. function /** boolean */ evalCheck(/** string */ code) {
  2537. try {
  2538. return !!eval(code);
  2539. } catch (ignored) {
  2540. return false;
  2541. }
  2542. }
  2543. var userAgent = goog.global.navigator && goog.global.navigator.userAgent ?
  2544. goog.global.navigator.userAgent :
  2545. '';
  2546. // Identify ES3-only browsers by their incorrect treatment of commas.
  2547. addNewerLanguageTranspilationCheck('es5', function() {
  2548. return evalCheck('[1,].length==1');
  2549. });
  2550. addNewerLanguageTranspilationCheck('es6', function() {
  2551. // Edge has a non-deterministic (i.e., not reproducible) bug with ES6:
  2552. // https://github.com/Microsoft/ChakraCore/issues/1496.
  2553. var re = /Edge\/(\d+)(\.\d)*/i;
  2554. var edgeUserAgent = userAgent.match(re);
  2555. if (edgeUserAgent && Number(edgeUserAgent[1]) < 15) {
  2556. return false;
  2557. }
  2558. // Test es6: [FF50 (?), Edge 14 (?), Chrome 50]
  2559. // (a) default params (specifically shadowing locals),
  2560. // (b) destructuring, (c) block-scoped functions,
  2561. // (d) for-of (const), (e) new.target/Reflect.construct
  2562. var es6fullTest =
  2563. 'class X{constructor(){if(new.target!=String)throw 1;this.x=42}}' +
  2564. 'let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof ' +
  2565. 'String))throw 1;for(const a of[2,3]){if(a==2)continue;function ' +
  2566. 'f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()' +
  2567. '==3}';
  2568. return evalCheck('(()=>{"use strict";' + es6fullTest + '})()');
  2569. });
  2570. // TODO(joeltine): Remove es6-impl references for b/31340605.
  2571. // Consider es6-impl (widely-implemented es6 features) to be supported
  2572. // whenever es6 is supported. Technically es6-impl is a lower level of
  2573. // support than es6, but we don't have tests specifically for it.
  2574. addNewerLanguageTranspilationCheck('es6-impl', function() {
  2575. return true;
  2576. });
  2577. // ** and **= are the only new features in 'es7'
  2578. addNewerLanguageTranspilationCheck('es7', function() {
  2579. return evalCheck('2 ** 2 == 4');
  2580. });
  2581. // async functions are the only new features in 'es8'
  2582. addNewerLanguageTranspilationCheck('es8', function() {
  2583. return evalCheck('async () => 1, true');
  2584. });
  2585. return requiresTranspilation;
  2586. };
  2587. goog.provide('ol.array');
  2588. /**
  2589. * Performs a binary search on the provided sorted list and returns the index of the item if found. If it can't be found it'll return -1.
  2590. * https://github.com/darkskyapp/binary-search
  2591. *
  2592. * @param {Array.<*>} haystack Items to search through.
  2593. * @param {*} needle The item to look for.
  2594. * @param {Function=} opt_comparator Comparator function.
  2595. * @return {number} The index of the item if found, -1 if not.
  2596. */
  2597. ol.array.binarySearch = function(haystack, needle, opt_comparator) {
  2598. var mid, cmp;
  2599. var comparator = opt_comparator || ol.array.numberSafeCompareFunction;
  2600. var low = 0;
  2601. var high = haystack.length;
  2602. var found = false;
  2603. while (low < high) {
  2604. /* Note that "(low + high) >>> 1" may overflow, and results in a typecast
  2605. * to double (which gives the wrong results). */
  2606. mid = low + (high - low >> 1);
  2607. cmp = +comparator(haystack[mid], needle);
  2608. if (cmp < 0.0) { /* Too low. */
  2609. low = mid + 1;
  2610. } else { /* Key found or too high */
  2611. high = mid;
  2612. found = !cmp;
  2613. }
  2614. }
  2615. /* Key not found. */
  2616. return found ? low : ~low;
  2617. };
  2618. /**
  2619. * Compare function for array sort that is safe for numbers.
  2620. * @param {*} a The first object to be compared.
  2621. * @param {*} b The second object to be compared.
  2622. * @return {number} A negative number, zero, or a positive number as the first
  2623. * argument is less than, equal to, or greater than the second.
  2624. */
  2625. ol.array.numberSafeCompareFunction = function(a, b) {
  2626. return a > b ? 1 : a < b ? -1 : 0;
  2627. };
  2628. /**
  2629. * Whether the array contains the given object.
  2630. * @param {Array.<*>} arr The array to test for the presence of the element.
  2631. * @param {*} obj The object for which to test.
  2632. * @return {boolean} The object is in the array.
  2633. */
  2634. ol.array.includes = function(arr, obj) {
  2635. return arr.indexOf(obj) >= 0;
  2636. };
  2637. /**
  2638. * @param {Array.<number>} arr Array.
  2639. * @param {number} target Target.
  2640. * @param {number} direction 0 means return the nearest, > 0
  2641. * means return the largest nearest, < 0 means return the
  2642. * smallest nearest.
  2643. * @return {number} Index.
  2644. */
  2645. ol.array.linearFindNearest = function(arr, target, direction) {
  2646. var n = arr.length;
  2647. if (arr[0] <= target) {
  2648. return 0;
  2649. } else if (target <= arr[n - 1]) {
  2650. return n - 1;
  2651. } else {
  2652. var i;
  2653. if (direction > 0) {
  2654. for (i = 1; i < n; ++i) {
  2655. if (arr[i] < target) {
  2656. return i - 1;
  2657. }
  2658. }
  2659. } else if (direction < 0) {
  2660. for (i = 1; i < n; ++i) {
  2661. if (arr[i] <= target) {
  2662. return i;
  2663. }
  2664. }
  2665. } else {
  2666. for (i = 1; i < n; ++i) {
  2667. if (arr[i] == target) {
  2668. return i;
  2669. } else if (arr[i] < target) {
  2670. if (arr[i - 1] - target < target - arr[i]) {
  2671. return i - 1;
  2672. } else {
  2673. return i;
  2674. }
  2675. }
  2676. }
  2677. }
  2678. return n - 1;
  2679. }
  2680. };
  2681. /**
  2682. * @param {Array.<*>} arr Array.
  2683. * @param {number} begin Begin index.
  2684. * @param {number} end End index.
  2685. */
  2686. ol.array.reverseSubArray = function(arr, begin, end) {
  2687. while (begin < end) {
  2688. var tmp = arr[begin];
  2689. arr[begin] = arr[end];
  2690. arr[end] = tmp;
  2691. ++begin;
  2692. --end;
  2693. }
  2694. };
  2695. /**
  2696. * @param {Array.<VALUE>} arr The array to modify.
  2697. * @param {Array.<VALUE>|VALUE} data The elements or arrays of elements
  2698. * to add to arr.
  2699. * @template VALUE
  2700. */
  2701. ol.array.extend = function(arr, data) {
  2702. var i;
  2703. var extension = Array.isArray(data) ? data : [data];
  2704. var length = extension.length;
  2705. for (i = 0; i < length; i++) {
  2706. arr[arr.length] = extension[i];
  2707. }
  2708. };
  2709. /**
  2710. * @param {Array.<VALUE>} arr The array to modify.
  2711. * @param {VALUE} obj The element to remove.
  2712. * @template VALUE
  2713. * @return {boolean} If the element was removed.
  2714. */
  2715. ol.array.remove = function(arr, obj) {
  2716. var i = arr.indexOf(obj);
  2717. var found = i > -1;
  2718. if (found) {
  2719. arr.splice(i, 1);
  2720. }
  2721. return found;
  2722. };
  2723. /**
  2724. * @param {Array.<VALUE>} arr The array to search in.
  2725. * @param {function(VALUE, number, ?) : boolean} func The function to compare.
  2726. * @template VALUE
  2727. * @return {VALUE} The element found.
  2728. */
  2729. ol.array.find = function(arr, func) {
  2730. var length = arr.length >>> 0;
  2731. var value;
  2732. for (var i = 0; i < length; i++) {
  2733. value = arr[i];
  2734. if (func(value, i, arr)) {
  2735. return value;
  2736. }
  2737. }
  2738. return null;
  2739. };
  2740. /**
  2741. * @param {Array|Uint8ClampedArray} arr1 The first array to compare.
  2742. * @param {Array|Uint8ClampedArray} arr2 The second array to compare.
  2743. * @return {boolean} Whether the two arrays are equal.
  2744. */
  2745. ol.array.equals = function(arr1, arr2) {
  2746. var len1 = arr1.length;
  2747. if (len1 !== arr2.length) {
  2748. return false;
  2749. }
  2750. for (var i = 0; i < len1; i++) {
  2751. if (arr1[i] !== arr2[i]) {
  2752. return false;
  2753. }
  2754. }
  2755. return true;
  2756. };
  2757. /**
  2758. * @param {Array.<*>} arr The array to sort (modifies original).
  2759. * @param {Function} compareFnc Comparison function.
  2760. */
  2761. ol.array.stableSort = function(arr, compareFnc) {
  2762. var length = arr.length;
  2763. var tmp = Array(arr.length);
  2764. var i;
  2765. for (i = 0; i < length; i++) {
  2766. tmp[i] = {index: i, value: arr[i]};
  2767. }
  2768. tmp.sort(function(a, b) {
  2769. return compareFnc(a.value, b.value) || a.index - b.index;
  2770. });
  2771. for (i = 0; i < arr.length; i++) {
  2772. arr[i] = tmp[i].value;
  2773. }
  2774. };
  2775. /**
  2776. * @param {Array.<*>} arr The array to search in.
  2777. * @param {Function} func Comparison function.
  2778. * @return {number} Return index.
  2779. */
  2780. ol.array.findIndex = function(arr, func) {
  2781. var index;
  2782. var found = !arr.every(function(el, idx) {
  2783. index = idx;
  2784. return !func(el, idx, arr);
  2785. });
  2786. return found ? index : -1;
  2787. };
  2788. /**
  2789. * @param {Array.<*>} arr The array to test.
  2790. * @param {Function=} opt_func Comparison function.
  2791. * @param {boolean=} opt_strict Strictly sorted (default false).
  2792. * @return {boolean} Return index.
  2793. */
  2794. ol.array.isSorted = function(arr, opt_func, opt_strict) {
  2795. var compare = opt_func || ol.array.numberSafeCompareFunction;
  2796. return arr.every(function(currentVal, index) {
  2797. if (index === 0) {
  2798. return true;
  2799. }
  2800. var res = compare(arr[index - 1], currentVal);
  2801. return !(res > 0 || opt_strict && res === 0);
  2802. });
  2803. };
  2804. goog.provide('ol');
  2805. /**
  2806. * Constants defined with the define tag cannot be changed in application
  2807. * code, but can be set at compile time.
  2808. * Some reduce the size of the build in advanced compile mode.
  2809. */
  2810. /**
  2811. * @define {boolean} Assume touch. Default is `false`.
  2812. */
  2813. ol.ASSUME_TOUCH = false;
  2814. /**
  2815. * TODO: rename this to something having to do with tile grids
  2816. * see https://github.com/openlayers/openlayers/issues/2076
  2817. * @define {number} Default maximum zoom for default tile grids.
  2818. */
  2819. ol.DEFAULT_MAX_ZOOM = 42;
  2820. /**
  2821. * @define {number} Default min zoom level for the map view. Default is `0`.
  2822. */
  2823. ol.DEFAULT_MIN_ZOOM = 0;
  2824. /**
  2825. * @define {number} Default maximum allowed threshold (in pixels) for
  2826. * reprojection triangulation. Default is `0.5`.
  2827. */
  2828. ol.DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD = 0.5;
  2829. /**
  2830. * @define {number} Default tile size.
  2831. */
  2832. ol.DEFAULT_TILE_SIZE = 256;
  2833. /**
  2834. * @define {string} Default WMS version.
  2835. */
  2836. ol.DEFAULT_WMS_VERSION = '1.3.0';
  2837. /**
  2838. * @define {boolean} Enable the Canvas renderer. Default is `true`. Setting
  2839. * this to false at compile time in advanced mode removes all code
  2840. * supporting the Canvas renderer from the build.
  2841. */
  2842. ol.ENABLE_CANVAS = true;
  2843. /**
  2844. * @define {boolean} Enable integration with the Proj4js library. Default is
  2845. * `true`.
  2846. */
  2847. ol.ENABLE_PROJ4JS = true;
  2848. /**
  2849. * @define {boolean} Enable automatic reprojection of raster sources. Default is
  2850. * `true`.
  2851. */
  2852. ol.ENABLE_RASTER_REPROJECTION = true;
  2853. /**
  2854. * @define {boolean} Enable the WebGL renderer. Default is `true`. Setting
  2855. * this to false at compile time in advanced mode removes all code
  2856. * supporting the WebGL renderer from the build.
  2857. */
  2858. ol.ENABLE_WEBGL = true;
  2859. /**
  2860. * @define {boolean} Include debuggable shader sources. Default is `true`.
  2861. * This should be set to `false` for production builds (if `ol.ENABLE_WEBGL`
  2862. * is `true`).
  2863. */
  2864. ol.DEBUG_WEBGL = true;
  2865. /**
  2866. * @define {number} The size in pixels of the first atlas image. Default is
  2867. * `256`.
  2868. */
  2869. ol.INITIAL_ATLAS_SIZE = 256;
  2870. /**
  2871. * @define {number} The maximum size in pixels of atlas images. Default is
  2872. * `-1`, meaning it is not used (and `ol.WEBGL_MAX_TEXTURE_SIZE` is
  2873. * used instead).
  2874. */
  2875. ol.MAX_ATLAS_SIZE = -1;
  2876. /**
  2877. * @define {number} Maximum mouse wheel delta.
  2878. */
  2879. ol.MOUSEWHEELZOOM_MAXDELTA = 1;
  2880. /**
  2881. * @define {number} Maximum width and/or height extent ratio that determines
  2882. * when the overview map should be zoomed out.
  2883. */
  2884. ol.OVERVIEWMAP_MAX_RATIO = 0.75;
  2885. /**
  2886. * @define {number} Minimum width and/or height extent ratio that determines
  2887. * when the overview map should be zoomed in.
  2888. */
  2889. ol.OVERVIEWMAP_MIN_RATIO = 0.1;
  2890. /**
  2891. * @define {number} Maximum number of source tiles for raster reprojection of
  2892. * a single tile.
  2893. * If too many source tiles are determined to be loaded to create a single
  2894. * reprojected tile the browser can become unresponsive or even crash.
  2895. * This can happen if the developer defines projections improperly and/or
  2896. * with unlimited extents.
  2897. * If too many tiles are required, no tiles are loaded and
  2898. * `ol.TileState.ERROR` state is set. Default is `100`.
  2899. */
  2900. ol.RASTER_REPROJECTION_MAX_SOURCE_TILES = 100;
  2901. /**
  2902. * @define {number} Maximum number of subdivision steps during raster
  2903. * reprojection triangulation. Prevents high memory usage and large
  2904. * number of proj4 calls (for certain transformations and areas).
  2905. * At most `2*(2^this)` triangles are created for each triangulated
  2906. * extent (tile/image). Default is `10`.
  2907. */
  2908. ol.RASTER_REPROJECTION_MAX_SUBDIVISION = 10;
  2909. /**
  2910. * @define {number} Maximum allowed size of triangle relative to world width.
  2911. * When transforming corners of world extent between certain projections,
  2912. * the resulting triangulation seems to have zero error and no subdivision
  2913. * is performed.
  2914. * If the triangle width is more than this (relative to world width; 0-1),
  2915. * subdivison is forced (up to `ol.RASTER_REPROJECTION_MAX_SUBDIVISION`).
  2916. * Default is `0.25`.
  2917. */
  2918. ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH = 0.25;
  2919. /**
  2920. * @define {number} Tolerance for geometry simplification in device pixels.
  2921. */
  2922. ol.SIMPLIFY_TOLERANCE = 0.5;
  2923. /**
  2924. * @define {number} Texture cache high water mark.
  2925. */
  2926. ol.WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK = 1024;
  2927. /**
  2928. * @define {string} OpenLayers version.
  2929. */
  2930. ol.VERSION = '';
  2931. /**
  2932. * The maximum supported WebGL texture size in pixels. If WebGL is not
  2933. * supported, the value is set to `undefined`.
  2934. * @const
  2935. * @type {number|undefined}
  2936. */
  2937. ol.WEBGL_MAX_TEXTURE_SIZE; // value is set in `ol.has`
  2938. /**
  2939. * List of supported WebGL extensions.
  2940. * @const
  2941. * @type {Array.<string>}
  2942. */
  2943. ol.WEBGL_EXTENSIONS; // value is set in `ol.has`
  2944. /**
  2945. * Inherit the prototype methods from one constructor into another.
  2946. *
  2947. * Usage:
  2948. *
  2949. * function ParentClass(a, b) { }
  2950. * ParentClass.prototype.foo = function(a) { }
  2951. *
  2952. * function ChildClass(a, b, c) {
  2953. * // Call parent constructor
  2954. * ParentClass.call(this, a, b);
  2955. * }
  2956. * ol.inherits(ChildClass, ParentClass);
  2957. *
  2958. * var child = new ChildClass('a', 'b', 'see');
  2959. * child.foo(); // This works.
  2960. *
  2961. * @param {!Function} childCtor Child constructor.
  2962. * @param {!Function} parentCtor Parent constructor.
  2963. * @function
  2964. * @api
  2965. */
  2966. ol.inherits = function(childCtor, parentCtor) {
  2967. childCtor.prototype = Object.create(parentCtor.prototype);
  2968. childCtor.prototype.constructor = childCtor;
  2969. };
  2970. /**
  2971. * A reusable function, used e.g. as a default for callbacks.
  2972. *
  2973. * @return {undefined} Nothing.
  2974. */
  2975. ol.nullFunction = function() {};
  2976. /**
  2977. * Gets a unique ID for an object. This mutates the object so that further calls
  2978. * with the same object as a parameter returns the same value. Unique IDs are generated
  2979. * as a strictly increasing sequence. Adapted from goog.getUid.
  2980. *
  2981. * @param {Object} obj The object to get the unique ID for.
  2982. * @return {number} The unique ID for the object.
  2983. */
  2984. ol.getUid = function(obj) {
  2985. return obj.ol_uid ||
  2986. (obj.ol_uid = ++ol.uidCounter_);
  2987. };
  2988. /**
  2989. * Counter for getUid.
  2990. * @type {number}
  2991. * @private
  2992. */
  2993. ol.uidCounter_ = 0;
  2994. goog.provide('ol.AssertionError');
  2995. goog.require('ol');
  2996. /**
  2997. * Error object thrown when an assertion failed. This is an ECMA-262 Error,
  2998. * extended with a `code` property.
  2999. * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
  3000. * @constructor
  3001. * @extends {Error}
  3002. * @implements {oli.AssertionError}
  3003. * @param {number} code Error code.
  3004. */
  3005. ol.AssertionError = function(code) {
  3006. var path = ol.VERSION ? ol.VERSION.split('-')[0] : 'latest';
  3007. /**
  3008. * @type {string}
  3009. */
  3010. this.message = 'Assertion failed. See https://openlayers.org/en/' + path +
  3011. '/doc/errors/#' + code + ' for details.';
  3012. /**
  3013. * Error code. The meaning of the code can be found on
  3014. * {@link https://openlayers.org/en/latest/doc/errors/} (replace `latest` with
  3015. * the version found in the OpenLayers script's header comment if a version
  3016. * other than the latest is used).
  3017. * @type {number}
  3018. * @api
  3019. */
  3020. this.code = code;
  3021. this.name = 'AssertionError';
  3022. };
  3023. ol.inherits(ol.AssertionError, Error);
  3024. goog.provide('ol.asserts');
  3025. goog.require('ol.AssertionError');
  3026. /**
  3027. * @param {*} assertion Assertion we expected to be truthy.
  3028. * @param {number} errorCode Error code.
  3029. */
  3030. ol.asserts.assert = function(assertion, errorCode) {
  3031. if (!assertion) {
  3032. throw new ol.AssertionError(errorCode);
  3033. }
  3034. };
  3035. goog.provide('ol.TileRange');
  3036. /**
  3037. * A representation of a contiguous block of tiles. A tile range is specified
  3038. * by its min/max tile coordinates and is inclusive of coordinates.
  3039. *
  3040. * @constructor
  3041. * @param {number} minX Minimum X.
  3042. * @param {number} maxX Maximum X.
  3043. * @param {number} minY Minimum Y.
  3044. * @param {number} maxY Maximum Y.
  3045. * @struct
  3046. */
  3047. ol.TileRange = function(minX, maxX, minY, maxY) {
  3048. /**
  3049. * @type {number}
  3050. */
  3051. this.minX = minX;
  3052. /**
  3053. * @type {number}
  3054. */
  3055. this.maxX = maxX;
  3056. /**
  3057. * @type {number}
  3058. */
  3059. this.minY = minY;
  3060. /**
  3061. * @type {number}
  3062. */
  3063. this.maxY = maxY;
  3064. };
  3065. /**
  3066. * @param {number} minX Minimum X.
  3067. * @param {number} maxX Maximum X.
  3068. * @param {number} minY Minimum Y.
  3069. * @param {number} maxY Maximum Y.
  3070. * @param {ol.TileRange|undefined} tileRange TileRange.
  3071. * @return {ol.TileRange} Tile range.
  3072. */
  3073. ol.TileRange.createOrUpdate = function(minX, maxX, minY, maxY, tileRange) {
  3074. if (tileRange !== undefined) {
  3075. tileRange.minX = minX;
  3076. tileRange.maxX = maxX;
  3077. tileRange.minY = minY;
  3078. tileRange.maxY = maxY;
  3079. return tileRange;
  3080. } else {
  3081. return new ol.TileRange(minX, maxX, minY, maxY);
  3082. }
  3083. };
  3084. /**
  3085. * @param {ol.TileCoord} tileCoord Tile coordinate.
  3086. * @return {boolean} Contains tile coordinate.
  3087. */
  3088. ol.TileRange.prototype.contains = function(tileCoord) {
  3089. return this.containsXY(tileCoord[1], tileCoord[2]);
  3090. };
  3091. /**
  3092. * @param {ol.TileRange} tileRange Tile range.
  3093. * @return {boolean} Contains.
  3094. */
  3095. ol.TileRange.prototype.containsTileRange = function(tileRange) {
  3096. return this.minX <= tileRange.minX && tileRange.maxX <= this.maxX &&
  3097. this.minY <= tileRange.minY && tileRange.maxY <= this.maxY;
  3098. };
  3099. /**
  3100. * @param {number} x Tile coordinate x.
  3101. * @param {number} y Tile coordinate y.
  3102. * @return {boolean} Contains coordinate.
  3103. */
  3104. ol.TileRange.prototype.containsXY = function(x, y) {
  3105. return this.minX <= x && x <= this.maxX && this.minY <= y && y <= this.maxY;
  3106. };
  3107. /**
  3108. * @param {ol.TileRange} tileRange Tile range.
  3109. * @return {boolean} Equals.
  3110. */
  3111. ol.TileRange.prototype.equals = function(tileRange) {
  3112. return this.minX == tileRange.minX && this.minY == tileRange.minY &&
  3113. this.maxX == tileRange.maxX && this.maxY == tileRange.maxY;
  3114. };
  3115. /**
  3116. * @param {ol.TileRange} tileRange Tile range.
  3117. */
  3118. ol.TileRange.prototype.extend = function(tileRange) {
  3119. if (tileRange.minX < this.minX) {
  3120. this.minX = tileRange.minX;
  3121. }
  3122. if (tileRange.maxX > this.maxX) {
  3123. this.maxX = tileRange.maxX;
  3124. }
  3125. if (tileRange.minY < this.minY) {
  3126. this.minY = tileRange.minY;
  3127. }
  3128. if (tileRange.maxY > this.maxY) {
  3129. this.maxY = tileRange.maxY;
  3130. }
  3131. };
  3132. /**
  3133. * @return {number} Height.
  3134. */
  3135. ol.TileRange.prototype.getHeight = function() {
  3136. return this.maxY - this.minY + 1;
  3137. };
  3138. /**
  3139. * @return {ol.Size} Size.
  3140. */
  3141. ol.TileRange.prototype.getSize = function() {
  3142. return [this.getWidth(), this.getHeight()];
  3143. };
  3144. /**
  3145. * @return {number} Width.
  3146. */
  3147. ol.TileRange.prototype.getWidth = function() {
  3148. return this.maxX - this.minX + 1;
  3149. };
  3150. /**
  3151. * @param {ol.TileRange} tileRange Tile range.
  3152. * @return {boolean} Intersects.
  3153. */
  3154. ol.TileRange.prototype.intersects = function(tileRange) {
  3155. return this.minX <= tileRange.maxX &&
  3156. this.maxX >= tileRange.minX &&
  3157. this.minY <= tileRange.maxY &&
  3158. this.maxY >= tileRange.minY;
  3159. };
  3160. goog.provide('ol.math');
  3161. goog.require('ol.asserts');
  3162. /**
  3163. * Takes a number and clamps it to within the provided bounds.
  3164. * @param {number} value The input number.
  3165. * @param {number} min The minimum value to return.
  3166. * @param {number} max The maximum value to return.
  3167. * @return {number} The input number if it is within bounds, or the nearest
  3168. * number within the bounds.
  3169. */
  3170. ol.math.clamp = function(value, min, max) {
  3171. return Math.min(Math.max(value, min), max);
  3172. };
  3173. /**
  3174. * Return the hyperbolic cosine of a given number. The method will use the
  3175. * native `Math.cosh` function if it is available, otherwise the hyperbolic
  3176. * cosine will be calculated via the reference implementation of the Mozilla
  3177. * developer network.
  3178. *
  3179. * @param {number} x X.
  3180. * @return {number} Hyperbolic cosine of x.
  3181. */
  3182. ol.math.cosh = (function() {
  3183. // Wrapped in a iife, to save the overhead of checking for the native
  3184. // implementation on every invocation.
  3185. var cosh;
  3186. if ('cosh' in Math) {
  3187. // The environment supports the native Math.cosh function, use it…
  3188. cosh = Math.cosh;
  3189. } else {
  3190. // … else, use the reference implementation of MDN:
  3191. cosh = function(x) {
  3192. var y = Math.exp(x);
  3193. return (y + 1 / y) / 2;
  3194. };
  3195. }
  3196. return cosh;
  3197. }());
  3198. /**
  3199. * @param {number} x X.
  3200. * @return {number} The smallest power of two greater than or equal to x.
  3201. */
  3202. ol.math.roundUpToPowerOfTwo = function(x) {
  3203. ol.asserts.assert(0 < x, 29); // `x` must be greater than `0`
  3204. return Math.pow(2, Math.ceil(Math.log(x) / Math.LN2));
  3205. };
  3206. /**
  3207. * Returns the square of the closest distance between the point (x, y) and the
  3208. * line segment (x1, y1) to (x2, y2).
  3209. * @param {number} x X.
  3210. * @param {number} y Y.
  3211. * @param {number} x1 X1.
  3212. * @param {number} y1 Y1.
  3213. * @param {number} x2 X2.
  3214. * @param {number} y2 Y2.
  3215. * @return {number} Squared distance.
  3216. */
  3217. ol.math.squaredSegmentDistance = function(x, y, x1, y1, x2, y2) {
  3218. var dx = x2 - x1;
  3219. var dy = y2 - y1;
  3220. if (dx !== 0 || dy !== 0) {
  3221. var t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
  3222. if (t > 1) {
  3223. x1 = x2;
  3224. y1 = y2;
  3225. } else if (t > 0) {
  3226. x1 += dx * t;
  3227. y1 += dy * t;
  3228. }
  3229. }
  3230. return ol.math.squaredDistance(x, y, x1, y1);
  3231. };
  3232. /**
  3233. * Returns the square of the distance between the points (x1, y1) and (x2, y2).
  3234. * @param {number} x1 X1.
  3235. * @param {number} y1 Y1.
  3236. * @param {number} x2 X2.
  3237. * @param {number} y2 Y2.
  3238. * @return {number} Squared distance.
  3239. */
  3240. ol.math.squaredDistance = function(x1, y1, x2, y2) {
  3241. var dx = x2 - x1;
  3242. var dy = y2 - y1;
  3243. return dx * dx + dy * dy;
  3244. };
  3245. /**
  3246. * Solves system of linear equations using Gaussian elimination method.
  3247. *
  3248. * @param {Array.<Array.<number>>} mat Augmented matrix (n x n + 1 column)
  3249. * in row-major order.
  3250. * @return {Array.<number>} The resulting vector.
  3251. */
  3252. ol.math.solveLinearSystem = function(mat) {
  3253. var n = mat.length;
  3254. for (var i = 0; i < n; i++) {
  3255. // Find max in the i-th column (ignoring i - 1 first rows)
  3256. var maxRow = i;
  3257. var maxEl = Math.abs(mat[i][i]);
  3258. for (var r = i + 1; r < n; r++) {
  3259. var absValue = Math.abs(mat[r][i]);
  3260. if (absValue > maxEl) {
  3261. maxEl = absValue;
  3262. maxRow = r;
  3263. }
  3264. }
  3265. if (maxEl === 0) {
  3266. return null; // matrix is singular
  3267. }
  3268. // Swap max row with i-th (current) row
  3269. var tmp = mat[maxRow];
  3270. mat[maxRow] = mat[i];
  3271. mat[i] = tmp;
  3272. // Subtract the i-th row to make all the remaining rows 0 in the i-th column
  3273. for (var j = i + 1; j < n; j++) {
  3274. var coef = -mat[j][i] / mat[i][i];
  3275. for (var k = i; k < n + 1; k++) {
  3276. if (i == k) {
  3277. mat[j][k] = 0;
  3278. } else {
  3279. mat[j][k] += coef * mat[i][k];
  3280. }
  3281. }
  3282. }
  3283. }
  3284. // Solve Ax=b for upper triangular matrix A (mat)
  3285. var x = new Array(n);
  3286. for (var l = n - 1; l >= 0; l--) {
  3287. x[l] = mat[l][n] / mat[l][l];
  3288. for (var m = l - 1; m >= 0; m--) {
  3289. mat[m][n] -= mat[m][l] * x[l];
  3290. }
  3291. }
  3292. return x;
  3293. };
  3294. /**
  3295. * Converts radians to to degrees.
  3296. *
  3297. * @param {number} angleInRadians Angle in radians.
  3298. * @return {number} Angle in degrees.
  3299. */
  3300. ol.math.toDegrees = function(angleInRadians) {
  3301. return angleInRadians * 180 / Math.PI;
  3302. };
  3303. /**
  3304. * Converts degrees to radians.
  3305. *
  3306. * @param {number} angleInDegrees Angle in degrees.
  3307. * @return {number} Angle in radians.
  3308. */
  3309. ol.math.toRadians = function(angleInDegrees) {
  3310. return angleInDegrees * Math.PI / 180;
  3311. };
  3312. /**
  3313. * Returns the modulo of a / b, depending on the sign of b.
  3314. *
  3315. * @param {number} a Dividend.
  3316. * @param {number} b Divisor.
  3317. * @return {number} Modulo.
  3318. */
  3319. ol.math.modulo = function(a, b) {
  3320. var r = a % b;
  3321. return r * b < 0 ? r + b : r;
  3322. };
  3323. /**
  3324. * Calculates the linearly interpolated value of x between a and b.
  3325. *
  3326. * @param {number} a Number
  3327. * @param {number} b Number
  3328. * @param {number} x Value to be interpolated.
  3329. * @return {number} Interpolated value.
  3330. */
  3331. ol.math.lerp = function(a, b, x) {
  3332. return a + x * (b - a);
  3333. };
  3334. goog.provide('ol.size');
  3335. /**
  3336. * Returns a buffered size.
  3337. * @param {ol.Size} size Size.
  3338. * @param {number} buffer Buffer.
  3339. * @param {ol.Size=} opt_size Optional reusable size array.
  3340. * @return {ol.Size} The buffered size.
  3341. */
  3342. ol.size.buffer = function(size, buffer, opt_size) {
  3343. if (opt_size === undefined) {
  3344. opt_size = [0, 0];
  3345. }
  3346. opt_size[0] = size[0] + 2 * buffer;
  3347. opt_size[1] = size[1] + 2 * buffer;
  3348. return opt_size;
  3349. };
  3350. /**
  3351. * Determines if a size has a positive area.
  3352. * @param {ol.Size} size The size to test.
  3353. * @return {boolean} The size has a positive area.
  3354. */
  3355. ol.size.hasArea = function(size) {
  3356. return size[0] > 0 && size[1] > 0;
  3357. };
  3358. /**
  3359. * Returns a size scaled by a ratio. The result will be an array of integers.
  3360. * @param {ol.Size} size Size.
  3361. * @param {number} ratio Ratio.
  3362. * @param {ol.Size=} opt_size Optional reusable size array.
  3363. * @return {ol.Size} The scaled size.
  3364. */
  3365. ol.size.scale = function(size, ratio, opt_size) {
  3366. if (opt_size === undefined) {
  3367. opt_size = [0, 0];
  3368. }
  3369. opt_size[0] = (size[0] * ratio + 0.5) | 0;
  3370. opt_size[1] = (size[1] * ratio + 0.5) | 0;
  3371. return opt_size;
  3372. };
  3373. /**
  3374. * Returns an `ol.Size` array for the passed in number (meaning: square) or
  3375. * `ol.Size` array.
  3376. * (meaning: non-square),
  3377. * @param {number|ol.Size} size Width and height.
  3378. * @param {ol.Size=} opt_size Optional reusable size array.
  3379. * @return {ol.Size} Size.
  3380. * @api
  3381. */
  3382. ol.size.toSize = function(size, opt_size) {
  3383. if (Array.isArray(size)) {
  3384. return size;
  3385. } else {
  3386. if (opt_size === undefined) {
  3387. opt_size = [size, size];
  3388. } else {
  3389. opt_size[0] = opt_size[1] = /** @type {number} */ (size);
  3390. }
  3391. return opt_size;
  3392. }
  3393. };
  3394. goog.provide('ol.extent.Corner');
  3395. /**
  3396. * Extent corner.
  3397. * @enum {string}
  3398. */
  3399. ol.extent.Corner = {
  3400. BOTTOM_LEFT: 'bottom-left',
  3401. BOTTOM_RIGHT: 'bottom-right',
  3402. TOP_LEFT: 'top-left',
  3403. TOP_RIGHT: 'top-right'
  3404. };
  3405. goog.provide('ol.extent.Relationship');
  3406. /**
  3407. * Relationship to an extent.
  3408. * @enum {number}
  3409. */
  3410. ol.extent.Relationship = {
  3411. UNKNOWN: 0,
  3412. INTERSECTING: 1,
  3413. ABOVE: 2,
  3414. RIGHT: 4,
  3415. BELOW: 8,
  3416. LEFT: 16
  3417. };
  3418. goog.provide('ol.extent');
  3419. goog.require('ol.asserts');
  3420. goog.require('ol.extent.Corner');
  3421. goog.require('ol.extent.Relationship');
  3422. /**
  3423. * Build an extent that includes all given coordinates.
  3424. *
  3425. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  3426. * @return {ol.Extent} Bounding extent.
  3427. * @api
  3428. */
  3429. ol.extent.boundingExtent = function(coordinates) {
  3430. var extent = ol.extent.createEmpty();
  3431. for (var i = 0, ii = coordinates.length; i < ii; ++i) {
  3432. ol.extent.extendCoordinate(extent, coordinates[i]);
  3433. }
  3434. return extent;
  3435. };
  3436. /**
  3437. * @param {Array.<number>} xs Xs.
  3438. * @param {Array.<number>} ys Ys.
  3439. * @param {ol.Extent=} opt_extent Destination extent.
  3440. * @private
  3441. * @return {ol.Extent} Extent.
  3442. */
  3443. ol.extent.boundingExtentXYs_ = function(xs, ys, opt_extent) {
  3444. var minX = Math.min.apply(null, xs);
  3445. var minY = Math.min.apply(null, ys);
  3446. var maxX = Math.max.apply(null, xs);
  3447. var maxY = Math.max.apply(null, ys);
  3448. return ol.extent.createOrUpdate(minX, minY, maxX, maxY, opt_extent);
  3449. };
  3450. /**
  3451. * Return extent increased by the provided value.
  3452. * @param {ol.Extent} extent Extent.
  3453. * @param {number} value The amount by which the extent should be buffered.
  3454. * @param {ol.Extent=} opt_extent Extent.
  3455. * @return {ol.Extent} Extent.
  3456. * @api
  3457. */
  3458. ol.extent.buffer = function(extent, value, opt_extent) {
  3459. if (opt_extent) {
  3460. opt_extent[0] = extent[0] - value;
  3461. opt_extent[1] = extent[1] - value;
  3462. opt_extent[2] = extent[2] + value;
  3463. opt_extent[3] = extent[3] + value;
  3464. return opt_extent;
  3465. } else {
  3466. return [
  3467. extent[0] - value,
  3468. extent[1] - value,
  3469. extent[2] + value,
  3470. extent[3] + value
  3471. ];
  3472. }
  3473. };
  3474. /**
  3475. * Creates a clone of an extent.
  3476. *
  3477. * @param {ol.Extent} extent Extent to clone.
  3478. * @param {ol.Extent=} opt_extent Extent.
  3479. * @return {ol.Extent} The clone.
  3480. */
  3481. ol.extent.clone = function(extent, opt_extent) {
  3482. if (opt_extent) {
  3483. opt_extent[0] = extent[0];
  3484. opt_extent[1] = extent[1];
  3485. opt_extent[2] = extent[2];
  3486. opt_extent[3] = extent[3];
  3487. return opt_extent;
  3488. } else {
  3489. return extent.slice();
  3490. }
  3491. };
  3492. /**
  3493. * @param {ol.Extent} extent Extent.
  3494. * @param {number} x X.
  3495. * @param {number} y Y.
  3496. * @return {number} Closest squared distance.
  3497. */
  3498. ol.extent.closestSquaredDistanceXY = function(extent, x, y) {
  3499. var dx, dy;
  3500. if (x < extent[0]) {
  3501. dx = extent[0] - x;
  3502. } else if (extent[2] < x) {
  3503. dx = x - extent[2];
  3504. } else {
  3505. dx = 0;
  3506. }
  3507. if (y < extent[1]) {
  3508. dy = extent[1] - y;
  3509. } else if (extent[3] < y) {
  3510. dy = y - extent[3];
  3511. } else {
  3512. dy = 0;
  3513. }
  3514. return dx * dx + dy * dy;
  3515. };
  3516. /**
  3517. * Check if the passed coordinate is contained or on the edge of the extent.
  3518. *
  3519. * @param {ol.Extent} extent Extent.
  3520. * @param {ol.Coordinate} coordinate Coordinate.
  3521. * @return {boolean} The coordinate is contained in the extent.
  3522. * @api
  3523. */
  3524. ol.extent.containsCoordinate = function(extent, coordinate) {
  3525. return ol.extent.containsXY(extent, coordinate[0], coordinate[1]);
  3526. };
  3527. /**
  3528. * Check if one extent contains another.
  3529. *
  3530. * An extent is deemed contained if it lies completely within the other extent,
  3531. * including if they share one or more edges.
  3532. *
  3533. * @param {ol.Extent} extent1 Extent 1.
  3534. * @param {ol.Extent} extent2 Extent 2.
  3535. * @return {boolean} The second extent is contained by or on the edge of the
  3536. * first.
  3537. * @api
  3538. */
  3539. ol.extent.containsExtent = function(extent1, extent2) {
  3540. return extent1[0] <= extent2[0] && extent2[2] <= extent1[2] &&
  3541. extent1[1] <= extent2[1] && extent2[3] <= extent1[3];
  3542. };
  3543. /**
  3544. * Check if the passed coordinate is contained or on the edge of the extent.
  3545. *
  3546. * @param {ol.Extent} extent Extent.
  3547. * @param {number} x X coordinate.
  3548. * @param {number} y Y coordinate.
  3549. * @return {boolean} The x, y values are contained in the extent.
  3550. * @api
  3551. */
  3552. ol.extent.containsXY = function(extent, x, y) {
  3553. return extent[0] <= x && x <= extent[2] && extent[1] <= y && y <= extent[3];
  3554. };
  3555. /**
  3556. * Get the relationship between a coordinate and extent.
  3557. * @param {ol.Extent} extent The extent.
  3558. * @param {ol.Coordinate} coordinate The coordinate.
  3559. * @return {number} The relationship (bitwise compare with
  3560. * ol.extent.Relationship).
  3561. */
  3562. ol.extent.coordinateRelationship = function(extent, coordinate) {
  3563. var minX = extent[0];
  3564. var minY = extent[1];
  3565. var maxX = extent[2];
  3566. var maxY = extent[3];
  3567. var x = coordinate[0];
  3568. var y = coordinate[1];
  3569. var relationship = ol.extent.Relationship.UNKNOWN;
  3570. if (x < minX) {
  3571. relationship = relationship | ol.extent.Relationship.LEFT;
  3572. } else if (x > maxX) {
  3573. relationship = relationship | ol.extent.Relationship.RIGHT;
  3574. }
  3575. if (y < minY) {
  3576. relationship = relationship | ol.extent.Relationship.BELOW;
  3577. } else if (y > maxY) {
  3578. relationship = relationship | ol.extent.Relationship.ABOVE;
  3579. }
  3580. if (relationship === ol.extent.Relationship.UNKNOWN) {
  3581. relationship = ol.extent.Relationship.INTERSECTING;
  3582. }
  3583. return relationship;
  3584. };
  3585. /**
  3586. * Create an empty extent.
  3587. * @return {ol.Extent} Empty extent.
  3588. * @api
  3589. */
  3590. ol.extent.createEmpty = function() {
  3591. return [Infinity, Infinity, -Infinity, -Infinity];
  3592. };
  3593. /**
  3594. * Create a new extent or update the provided extent.
  3595. * @param {number} minX Minimum X.
  3596. * @param {number} minY Minimum Y.
  3597. * @param {number} maxX Maximum X.
  3598. * @param {number} maxY Maximum Y.
  3599. * @param {ol.Extent=} opt_extent Destination extent.
  3600. * @return {ol.Extent} Extent.
  3601. */
  3602. ol.extent.createOrUpdate = function(minX, minY, maxX, maxY, opt_extent) {
  3603. if (opt_extent) {
  3604. opt_extent[0] = minX;
  3605. opt_extent[1] = minY;
  3606. opt_extent[2] = maxX;
  3607. opt_extent[3] = maxY;
  3608. return opt_extent;
  3609. } else {
  3610. return [minX, minY, maxX, maxY];
  3611. }
  3612. };
  3613. /**
  3614. * Create a new empty extent or make the provided one empty.
  3615. * @param {ol.Extent=} opt_extent Extent.
  3616. * @return {ol.Extent} Extent.
  3617. */
  3618. ol.extent.createOrUpdateEmpty = function(opt_extent) {
  3619. return ol.extent.createOrUpdate(
  3620. Infinity, Infinity, -Infinity, -Infinity, opt_extent);
  3621. };
  3622. /**
  3623. * @param {ol.Coordinate} coordinate Coordinate.
  3624. * @param {ol.Extent=} opt_extent Extent.
  3625. * @return {ol.Extent} Extent.
  3626. */
  3627. ol.extent.createOrUpdateFromCoordinate = function(coordinate, opt_extent) {
  3628. var x = coordinate[0];
  3629. var y = coordinate[1];
  3630. return ol.extent.createOrUpdate(x, y, x, y, opt_extent);
  3631. };
  3632. /**
  3633. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  3634. * @param {ol.Extent=} opt_extent Extent.
  3635. * @return {ol.Extent} Extent.
  3636. */
  3637. ol.extent.createOrUpdateFromCoordinates = function(coordinates, opt_extent) {
  3638. var extent = ol.extent.createOrUpdateEmpty(opt_extent);
  3639. return ol.extent.extendCoordinates(extent, coordinates);
  3640. };
  3641. /**
  3642. * @param {Array.<number>} flatCoordinates Flat coordinates.
  3643. * @param {number} offset Offset.
  3644. * @param {number} end End.
  3645. * @param {number} stride Stride.
  3646. * @param {ol.Extent=} opt_extent Extent.
  3647. * @return {ol.Extent} Extent.
  3648. */
  3649. ol.extent.createOrUpdateFromFlatCoordinates = function(flatCoordinates, offset, end, stride, opt_extent) {
  3650. var extent = ol.extent.createOrUpdateEmpty(opt_extent);
  3651. return ol.extent.extendFlatCoordinates(
  3652. extent, flatCoordinates, offset, end, stride);
  3653. };
  3654. /**
  3655. * @param {Array.<Array.<ol.Coordinate>>} rings Rings.
  3656. * @param {ol.Extent=} opt_extent Extent.
  3657. * @return {ol.Extent} Extent.
  3658. */
  3659. ol.extent.createOrUpdateFromRings = function(rings, opt_extent) {
  3660. var extent = ol.extent.createOrUpdateEmpty(opt_extent);
  3661. return ol.extent.extendRings(extent, rings);
  3662. };
  3663. /**
  3664. * Determine if two extents are equivalent.
  3665. * @param {ol.Extent} extent1 Extent 1.
  3666. * @param {ol.Extent} extent2 Extent 2.
  3667. * @return {boolean} The two extents are equivalent.
  3668. * @api
  3669. */
  3670. ol.extent.equals = function(extent1, extent2) {
  3671. return extent1[0] == extent2[0] && extent1[2] == extent2[2] &&
  3672. extent1[1] == extent2[1] && extent1[3] == extent2[3];
  3673. };
  3674. /**
  3675. * Modify an extent to include another extent.
  3676. * @param {ol.Extent} extent1 The extent to be modified.
  3677. * @param {ol.Extent} extent2 The extent that will be included in the first.
  3678. * @return {ol.Extent} A reference to the first (extended) extent.
  3679. * @api
  3680. */
  3681. ol.extent.extend = function(extent1, extent2) {
  3682. if (extent2[0] < extent1[0]) {
  3683. extent1[0] = extent2[0];
  3684. }
  3685. if (extent2[2] > extent1[2]) {
  3686. extent1[2] = extent2[2];
  3687. }
  3688. if (extent2[1] < extent1[1]) {
  3689. extent1[1] = extent2[1];
  3690. }
  3691. if (extent2[3] > extent1[3]) {
  3692. extent1[3] = extent2[3];
  3693. }
  3694. return extent1;
  3695. };
  3696. /**
  3697. * @param {ol.Extent} extent Extent.
  3698. * @param {ol.Coordinate} coordinate Coordinate.
  3699. */
  3700. ol.extent.extendCoordinate = function(extent, coordinate) {
  3701. if (coordinate[0] < extent[0]) {
  3702. extent[0] = coordinate[0];
  3703. }
  3704. if (coordinate[0] > extent[2]) {
  3705. extent[2] = coordinate[0];
  3706. }
  3707. if (coordinate[1] < extent[1]) {
  3708. extent[1] = coordinate[1];
  3709. }
  3710. if (coordinate[1] > extent[3]) {
  3711. extent[3] = coordinate[1];
  3712. }
  3713. };
  3714. /**
  3715. * @param {ol.Extent} extent Extent.
  3716. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  3717. * @return {ol.Extent} Extent.
  3718. */
  3719. ol.extent.extendCoordinates = function(extent, coordinates) {
  3720. var i, ii;
  3721. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  3722. ol.extent.extendCoordinate(extent, coordinates[i]);
  3723. }
  3724. return extent;
  3725. };
  3726. /**
  3727. * @param {ol.Extent} extent Extent.
  3728. * @param {Array.<number>} flatCoordinates Flat coordinates.
  3729. * @param {number} offset Offset.
  3730. * @param {number} end End.
  3731. * @param {number} stride Stride.
  3732. * @return {ol.Extent} Extent.
  3733. */
  3734. ol.extent.extendFlatCoordinates = function(extent, flatCoordinates, offset, end, stride) {
  3735. for (; offset < end; offset += stride) {
  3736. ol.extent.extendXY(
  3737. extent, flatCoordinates[offset], flatCoordinates[offset + 1]);
  3738. }
  3739. return extent;
  3740. };
  3741. /**
  3742. * @param {ol.Extent} extent Extent.
  3743. * @param {Array.<Array.<ol.Coordinate>>} rings Rings.
  3744. * @return {ol.Extent} Extent.
  3745. */
  3746. ol.extent.extendRings = function(extent, rings) {
  3747. var i, ii;
  3748. for (i = 0, ii = rings.length; i < ii; ++i) {
  3749. ol.extent.extendCoordinates(extent, rings[i]);
  3750. }
  3751. return extent;
  3752. };
  3753. /**
  3754. * @param {ol.Extent} extent Extent.
  3755. * @param {number} x X.
  3756. * @param {number} y Y.
  3757. */
  3758. ol.extent.extendXY = function(extent, x, y) {
  3759. extent[0] = Math.min(extent[0], x);
  3760. extent[1] = Math.min(extent[1], y);
  3761. extent[2] = Math.max(extent[2], x);
  3762. extent[3] = Math.max(extent[3], y);
  3763. };
  3764. /**
  3765. * This function calls `callback` for each corner of the extent. If the
  3766. * callback returns a truthy value the function returns that value
  3767. * immediately. Otherwise the function returns `false`.
  3768. * @param {ol.Extent} extent Extent.
  3769. * @param {function(this:T, ol.Coordinate): S} callback Callback.
  3770. * @param {T=} opt_this Value to use as `this` when executing `callback`.
  3771. * @return {S|boolean} Value.
  3772. * @template S, T
  3773. */
  3774. ol.extent.forEachCorner = function(extent, callback, opt_this) {
  3775. var val;
  3776. val = callback.call(opt_this, ol.extent.getBottomLeft(extent));
  3777. if (val) {
  3778. return val;
  3779. }
  3780. val = callback.call(opt_this, ol.extent.getBottomRight(extent));
  3781. if (val) {
  3782. return val;
  3783. }
  3784. val = callback.call(opt_this, ol.extent.getTopRight(extent));
  3785. if (val) {
  3786. return val;
  3787. }
  3788. val = callback.call(opt_this, ol.extent.getTopLeft(extent));
  3789. if (val) {
  3790. return val;
  3791. }
  3792. return false;
  3793. };
  3794. /**
  3795. * Get the size of an extent.
  3796. * @param {ol.Extent} extent Extent.
  3797. * @return {number} Area.
  3798. * @api
  3799. */
  3800. ol.extent.getArea = function(extent) {
  3801. var area = 0;
  3802. if (!ol.extent.isEmpty(extent)) {
  3803. area = ol.extent.getWidth(extent) * ol.extent.getHeight(extent);
  3804. }
  3805. return area;
  3806. };
  3807. /**
  3808. * Get the bottom left coordinate of an extent.
  3809. * @param {ol.Extent} extent Extent.
  3810. * @return {ol.Coordinate} Bottom left coordinate.
  3811. * @api
  3812. */
  3813. ol.extent.getBottomLeft = function(extent) {
  3814. return [extent[0], extent[1]];
  3815. };
  3816. /**
  3817. * Get the bottom right coordinate of an extent.
  3818. * @param {ol.Extent} extent Extent.
  3819. * @return {ol.Coordinate} Bottom right coordinate.
  3820. * @api
  3821. */
  3822. ol.extent.getBottomRight = function(extent) {
  3823. return [extent[2], extent[1]];
  3824. };
  3825. /**
  3826. * Get the center coordinate of an extent.
  3827. * @param {ol.Extent} extent Extent.
  3828. * @return {ol.Coordinate} Center.
  3829. * @api
  3830. */
  3831. ol.extent.getCenter = function(extent) {
  3832. return [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
  3833. };
  3834. /**
  3835. * Get a corner coordinate of an extent.
  3836. * @param {ol.Extent} extent Extent.
  3837. * @param {ol.extent.Corner} corner Corner.
  3838. * @return {ol.Coordinate} Corner coordinate.
  3839. */
  3840. ol.extent.getCorner = function(extent, corner) {
  3841. var coordinate;
  3842. if (corner === ol.extent.Corner.BOTTOM_LEFT) {
  3843. coordinate = ol.extent.getBottomLeft(extent);
  3844. } else if (corner === ol.extent.Corner.BOTTOM_RIGHT) {
  3845. coordinate = ol.extent.getBottomRight(extent);
  3846. } else if (corner === ol.extent.Corner.TOP_LEFT) {
  3847. coordinate = ol.extent.getTopLeft(extent);
  3848. } else if (corner === ol.extent.Corner.TOP_RIGHT) {
  3849. coordinate = ol.extent.getTopRight(extent);
  3850. } else {
  3851. ol.asserts.assert(false, 13); // Invalid corner
  3852. }
  3853. return /** @type {!ol.Coordinate} */ (coordinate);
  3854. };
  3855. /**
  3856. * @param {ol.Extent} extent1 Extent 1.
  3857. * @param {ol.Extent} extent2 Extent 2.
  3858. * @return {number} Enlarged area.
  3859. */
  3860. ol.extent.getEnlargedArea = function(extent1, extent2) {
  3861. var minX = Math.min(extent1[0], extent2[0]);
  3862. var minY = Math.min(extent1[1], extent2[1]);
  3863. var maxX = Math.max(extent1[2], extent2[2]);
  3864. var maxY = Math.max(extent1[3], extent2[3]);
  3865. return (maxX - minX) * (maxY - minY);
  3866. };
  3867. /**
  3868. * @param {ol.Coordinate} center Center.
  3869. * @param {number} resolution Resolution.
  3870. * @param {number} rotation Rotation.
  3871. * @param {ol.Size} size Size.
  3872. * @param {ol.Extent=} opt_extent Destination extent.
  3873. * @return {ol.Extent} Extent.
  3874. */
  3875. ol.extent.getForViewAndSize = function(center, resolution, rotation, size, opt_extent) {
  3876. var dx = resolution * size[0] / 2;
  3877. var dy = resolution * size[1] / 2;
  3878. var cosRotation = Math.cos(rotation);
  3879. var sinRotation = Math.sin(rotation);
  3880. var xCos = dx * cosRotation;
  3881. var xSin = dx * sinRotation;
  3882. var yCos = dy * cosRotation;
  3883. var ySin = dy * sinRotation;
  3884. var x = center[0];
  3885. var y = center[1];
  3886. var x0 = x - xCos + ySin;
  3887. var x1 = x - xCos - ySin;
  3888. var x2 = x + xCos - ySin;
  3889. var x3 = x + xCos + ySin;
  3890. var y0 = y - xSin - yCos;
  3891. var y1 = y - xSin + yCos;
  3892. var y2 = y + xSin + yCos;
  3893. var y3 = y + xSin - yCos;
  3894. return ol.extent.createOrUpdate(
  3895. Math.min(x0, x1, x2, x3), Math.min(y0, y1, y2, y3),
  3896. Math.max(x0, x1, x2, x3), Math.max(y0, y1, y2, y3),
  3897. opt_extent);
  3898. };
  3899. /**
  3900. * Get the height of an extent.
  3901. * @param {ol.Extent} extent Extent.
  3902. * @return {number} Height.
  3903. * @api
  3904. */
  3905. ol.extent.getHeight = function(extent) {
  3906. return extent[3] - extent[1];
  3907. };
  3908. /**
  3909. * @param {ol.Extent} extent1 Extent 1.
  3910. * @param {ol.Extent} extent2 Extent 2.
  3911. * @return {number} Intersection area.
  3912. */
  3913. ol.extent.getIntersectionArea = function(extent1, extent2) {
  3914. var intersection = ol.extent.getIntersection(extent1, extent2);
  3915. return ol.extent.getArea(intersection);
  3916. };
  3917. /**
  3918. * Get the intersection of two extents.
  3919. * @param {ol.Extent} extent1 Extent 1.
  3920. * @param {ol.Extent} extent2 Extent 2.
  3921. * @param {ol.Extent=} opt_extent Optional extent to populate with intersection.
  3922. * @return {ol.Extent} Intersecting extent.
  3923. * @api
  3924. */
  3925. ol.extent.getIntersection = function(extent1, extent2, opt_extent) {
  3926. var intersection = opt_extent ? opt_extent : ol.extent.createEmpty();
  3927. if (ol.extent.intersects(extent1, extent2)) {
  3928. if (extent1[0] > extent2[0]) {
  3929. intersection[0] = extent1[0];
  3930. } else {
  3931. intersection[0] = extent2[0];
  3932. }
  3933. if (extent1[1] > extent2[1]) {
  3934. intersection[1] = extent1[1];
  3935. } else {
  3936. intersection[1] = extent2[1];
  3937. }
  3938. if (extent1[2] < extent2[2]) {
  3939. intersection[2] = extent1[2];
  3940. } else {
  3941. intersection[2] = extent2[2];
  3942. }
  3943. if (extent1[3] < extent2[3]) {
  3944. intersection[3] = extent1[3];
  3945. } else {
  3946. intersection[3] = extent2[3];
  3947. }
  3948. }
  3949. return intersection;
  3950. };
  3951. /**
  3952. * @param {ol.Extent} extent Extent.
  3953. * @return {number} Margin.
  3954. */
  3955. ol.extent.getMargin = function(extent) {
  3956. return ol.extent.getWidth(extent) + ol.extent.getHeight(extent);
  3957. };
  3958. /**
  3959. * Get the size (width, height) of an extent.
  3960. * @param {ol.Extent} extent The extent.
  3961. * @return {ol.Size} The extent size.
  3962. * @api
  3963. */
  3964. ol.extent.getSize = function(extent) {
  3965. return [extent[2] - extent[0], extent[3] - extent[1]];
  3966. };
  3967. /**
  3968. * Get the top left coordinate of an extent.
  3969. * @param {ol.Extent} extent Extent.
  3970. * @return {ol.Coordinate} Top left coordinate.
  3971. * @api
  3972. */
  3973. ol.extent.getTopLeft = function(extent) {
  3974. return [extent[0], extent[3]];
  3975. };
  3976. /**
  3977. * Get the top right coordinate of an extent.
  3978. * @param {ol.Extent} extent Extent.
  3979. * @return {ol.Coordinate} Top right coordinate.
  3980. * @api
  3981. */
  3982. ol.extent.getTopRight = function(extent) {
  3983. return [extent[2], extent[3]];
  3984. };
  3985. /**
  3986. * Get the width of an extent.
  3987. * @param {ol.Extent} extent Extent.
  3988. * @return {number} Width.
  3989. * @api
  3990. */
  3991. ol.extent.getWidth = function(extent) {
  3992. return extent[2] - extent[0];
  3993. };
  3994. /**
  3995. * Determine if one extent intersects another.
  3996. * @param {ol.Extent} extent1 Extent 1.
  3997. * @param {ol.Extent} extent2 Extent.
  3998. * @return {boolean} The two extents intersect.
  3999. * @api
  4000. */
  4001. ol.extent.intersects = function(extent1, extent2) {
  4002. return extent1[0] <= extent2[2] &&
  4003. extent1[2] >= extent2[0] &&
  4004. extent1[1] <= extent2[3] &&
  4005. extent1[3] >= extent2[1];
  4006. };
  4007. /**
  4008. * Determine if an extent is empty.
  4009. * @param {ol.Extent} extent Extent.
  4010. * @return {boolean} Is empty.
  4011. * @api
  4012. */
  4013. ol.extent.isEmpty = function(extent) {
  4014. return extent[2] < extent[0] || extent[3] < extent[1];
  4015. };
  4016. /**
  4017. * @param {ol.Extent} extent Extent.
  4018. * @param {ol.Extent=} opt_extent Extent.
  4019. * @return {ol.Extent} Extent.
  4020. */
  4021. ol.extent.returnOrUpdate = function(extent, opt_extent) {
  4022. if (opt_extent) {
  4023. opt_extent[0] = extent[0];
  4024. opt_extent[1] = extent[1];
  4025. opt_extent[2] = extent[2];
  4026. opt_extent[3] = extent[3];
  4027. return opt_extent;
  4028. } else {
  4029. return extent;
  4030. }
  4031. };
  4032. /**
  4033. * @param {ol.Extent} extent Extent.
  4034. * @param {number} value Value.
  4035. */
  4036. ol.extent.scaleFromCenter = function(extent, value) {
  4037. var deltaX = ((extent[2] - extent[0]) / 2) * (value - 1);
  4038. var deltaY = ((extent[3] - extent[1]) / 2) * (value - 1);
  4039. extent[0] -= deltaX;
  4040. extent[2] += deltaX;
  4041. extent[1] -= deltaY;
  4042. extent[3] += deltaY;
  4043. };
  4044. /**
  4045. * Determine if the segment between two coordinates intersects (crosses,
  4046. * touches, or is contained by) the provided extent.
  4047. * @param {ol.Extent} extent The extent.
  4048. * @param {ol.Coordinate} start Segment start coordinate.
  4049. * @param {ol.Coordinate} end Segment end coordinate.
  4050. * @return {boolean} The segment intersects the extent.
  4051. */
  4052. ol.extent.intersectsSegment = function(extent, start, end) {
  4053. var intersects = false;
  4054. var startRel = ol.extent.coordinateRelationship(extent, start);
  4055. var endRel = ol.extent.coordinateRelationship(extent, end);
  4056. if (startRel === ol.extent.Relationship.INTERSECTING ||
  4057. endRel === ol.extent.Relationship.INTERSECTING) {
  4058. intersects = true;
  4059. } else {
  4060. var minX = extent[0];
  4061. var minY = extent[1];
  4062. var maxX = extent[2];
  4063. var maxY = extent[3];
  4064. var startX = start[0];
  4065. var startY = start[1];
  4066. var endX = end[0];
  4067. var endY = end[1];
  4068. var slope = (endY - startY) / (endX - startX);
  4069. var x, y;
  4070. if (!!(endRel & ol.extent.Relationship.ABOVE) &&
  4071. !(startRel & ol.extent.Relationship.ABOVE)) {
  4072. // potentially intersects top
  4073. x = endX - ((endY - maxY) / slope);
  4074. intersects = x >= minX && x <= maxX;
  4075. }
  4076. if (!intersects && !!(endRel & ol.extent.Relationship.RIGHT) &&
  4077. !(startRel & ol.extent.Relationship.RIGHT)) {
  4078. // potentially intersects right
  4079. y = endY - ((endX - maxX) * slope);
  4080. intersects = y >= minY && y <= maxY;
  4081. }
  4082. if (!intersects && !!(endRel & ol.extent.Relationship.BELOW) &&
  4083. !(startRel & ol.extent.Relationship.BELOW)) {
  4084. // potentially intersects bottom
  4085. x = endX - ((endY - minY) / slope);
  4086. intersects = x >= minX && x <= maxX;
  4087. }
  4088. if (!intersects && !!(endRel & ol.extent.Relationship.LEFT) &&
  4089. !(startRel & ol.extent.Relationship.LEFT)) {
  4090. // potentially intersects left
  4091. y = endY - ((endX - minX) * slope);
  4092. intersects = y >= minY && y <= maxY;
  4093. }
  4094. }
  4095. return intersects;
  4096. };
  4097. /**
  4098. * Apply a transform function to the extent.
  4099. * @param {ol.Extent} extent Extent.
  4100. * @param {ol.TransformFunction} transformFn Transform function. Called with
  4101. * [minX, minY, maxX, maxY] extent coordinates.
  4102. * @param {ol.Extent=} opt_extent Destination extent.
  4103. * @return {ol.Extent} Extent.
  4104. * @api
  4105. */
  4106. ol.extent.applyTransform = function(extent, transformFn, opt_extent) {
  4107. var coordinates = [
  4108. extent[0], extent[1],
  4109. extent[0], extent[3],
  4110. extent[2], extent[1],
  4111. extent[2], extent[3]
  4112. ];
  4113. transformFn(coordinates, coordinates, 2);
  4114. var xs = [coordinates[0], coordinates[2], coordinates[4], coordinates[6]];
  4115. var ys = [coordinates[1], coordinates[3], coordinates[5], coordinates[7]];
  4116. return ol.extent.boundingExtentXYs_(xs, ys, opt_extent);
  4117. };
  4118. goog.provide('ol.obj');
  4119. /**
  4120. * Polyfill for Object.assign(). Assigns enumerable and own properties from
  4121. * one or more source objects to a target object.
  4122. *
  4123. * @see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  4124. * @param {!Object} target The target object.
  4125. * @param {...Object} var_sources The source object(s).
  4126. * @return {!Object} The modified target object.
  4127. */
  4128. ol.obj.assign = (typeof Object.assign === 'function') ? Object.assign : function(target, var_sources) {
  4129. if (target === undefined || target === null) {
  4130. throw new TypeError('Cannot convert undefined or null to object');
  4131. }
  4132. var output = Object(target);
  4133. for (var i = 1, ii = arguments.length; i < ii; ++i) {
  4134. var source = arguments[i];
  4135. if (source !== undefined && source !== null) {
  4136. for (var key in source) {
  4137. if (source.hasOwnProperty(key)) {
  4138. output[key] = source[key];
  4139. }
  4140. }
  4141. }
  4142. }
  4143. return output;
  4144. };
  4145. /**
  4146. * Removes all properties from an object.
  4147. * @param {Object} object The object to clear.
  4148. */
  4149. ol.obj.clear = function(object) {
  4150. for (var property in object) {
  4151. delete object[property];
  4152. }
  4153. };
  4154. /**
  4155. * Get an array of property values from an object.
  4156. * @param {Object<K,V>} object The object from which to get the values.
  4157. * @return {!Array<V>} The property values.
  4158. * @template K,V
  4159. */
  4160. ol.obj.getValues = function(object) {
  4161. var values = [];
  4162. for (var property in object) {
  4163. values.push(object[property]);
  4164. }
  4165. return values;
  4166. };
  4167. /**
  4168. * Determine if an object has any properties.
  4169. * @param {Object} object The object to check.
  4170. * @return {boolean} The object is empty.
  4171. */
  4172. ol.obj.isEmpty = function(object) {
  4173. var property;
  4174. for (property in object) {
  4175. return false;
  4176. }
  4177. return !property;
  4178. };
  4179. goog.provide('ol.geom.GeometryType');
  4180. /**
  4181. * The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`,
  4182. * `'Polygon'`, `'MultiPoint'`, `'MultiLineString'`, `'MultiPolygon'`,
  4183. * `'GeometryCollection'`, `'Circle'`.
  4184. * @enum {string}
  4185. */
  4186. ol.geom.GeometryType = {
  4187. POINT: 'Point',
  4188. LINE_STRING: 'LineString',
  4189. LINEAR_RING: 'LinearRing',
  4190. POLYGON: 'Polygon',
  4191. MULTI_POINT: 'MultiPoint',
  4192. MULTI_LINE_STRING: 'MultiLineString',
  4193. MULTI_POLYGON: 'MultiPolygon',
  4194. GEOMETRY_COLLECTION: 'GeometryCollection',
  4195. CIRCLE: 'Circle'
  4196. };
  4197. /**
  4198. * @license
  4199. * Latitude/longitude spherical geodesy formulae taken from
  4200. * http://www.movable-type.co.uk/scripts/latlong.html
  4201. * Licensed under CC-BY-3.0.
  4202. */
  4203. goog.provide('ol.Sphere');
  4204. goog.require('ol.math');
  4205. goog.require('ol.geom.GeometryType');
  4206. /**
  4207. * @classdesc
  4208. * Class to create objects that can be used with {@link
  4209. * ol.geom.Polygon.circular}.
  4210. *
  4211. * For example to create a sphere whose radius is equal to the semi-major
  4212. * axis of the WGS84 ellipsoid:
  4213. *
  4214. * ```js
  4215. * var wgs84Sphere= new ol.Sphere(6378137);
  4216. * ```
  4217. *
  4218. * @constructor
  4219. * @param {number} radius Radius.
  4220. * @api
  4221. */
  4222. ol.Sphere = function(radius) {
  4223. /**
  4224. * @type {number}
  4225. */
  4226. this.radius = radius;
  4227. };
  4228. /**
  4229. * Returns the geodesic area for a list of coordinates.
  4230. *
  4231. * [Reference](https://trs-new.jpl.nasa.gov/handle/2014/40409)
  4232. * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for
  4233. * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion
  4234. * Laboratory, Pasadena, CA, June 2007
  4235. *
  4236. * @param {Array.<ol.Coordinate>} coordinates List of coordinates of a linear
  4237. * ring. If the ring is oriented clockwise, the area will be positive,
  4238. * otherwise it will be negative.
  4239. * @return {number} Area.
  4240. * @api
  4241. */
  4242. ol.Sphere.prototype.geodesicArea = function(coordinates) {
  4243. return ol.Sphere.getArea_(coordinates, this.radius);
  4244. };
  4245. /**
  4246. * Returns the distance from c1 to c2 using the haversine formula.
  4247. *
  4248. * @param {ol.Coordinate} c1 Coordinate 1.
  4249. * @param {ol.Coordinate} c2 Coordinate 2.
  4250. * @return {number} Haversine distance.
  4251. * @api
  4252. */
  4253. ol.Sphere.prototype.haversineDistance = function(c1, c2) {
  4254. return ol.Sphere.getDistance_(c1, c2, this.radius);
  4255. };
  4256. /**
  4257. * Returns the coordinate at the given distance and bearing from `c1`.
  4258. *
  4259. * @param {ol.Coordinate} c1 The origin point (`[lon, lat]` in degrees).
  4260. * @param {number} distance The great-circle distance between the origin
  4261. * point and the target point.
  4262. * @param {number} bearing The bearing (in radians).
  4263. * @return {ol.Coordinate} The target point.
  4264. */
  4265. ol.Sphere.prototype.offset = function(c1, distance, bearing) {
  4266. var lat1 = ol.math.toRadians(c1[1]);
  4267. var lon1 = ol.math.toRadians(c1[0]);
  4268. var dByR = distance / this.radius;
  4269. var lat = Math.asin(
  4270. Math.sin(lat1) * Math.cos(dByR) +
  4271. Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
  4272. var lon = lon1 + Math.atan2(
  4273. Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1),
  4274. Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
  4275. return [ol.math.toDegrees(lon), ol.math.toDegrees(lat)];
  4276. };
  4277. /**
  4278. * The mean Earth radius (1/3 * (2a + b)) for the WGS84 ellipsoid.
  4279. * https://en.wikipedia.org/wiki/Earth_radius#Mean_radius
  4280. * @type {number}
  4281. */
  4282. ol.Sphere.DEFAULT_RADIUS = 6371008.8;
  4283. /**
  4284. * Get the spherical length of a geometry. This length is the sum of the
  4285. * great circle distances between coordinates. For polygons, the length is
  4286. * the sum of all rings. For points, the length is zero. For multi-part
  4287. * geometries, the length is the sum of the length of each part.
  4288. * @param {ol.geom.Geometry} geometry A geometry.
  4289. * @param {olx.SphereMetricOptions=} opt_options Options for the length
  4290. * calculation. By default, geometries are assumed to be in 'EPSG:3857'.
  4291. * You can change this by providing a `projection` option.
  4292. * @return {number} The spherical length (in meters).
  4293. * @api
  4294. */
  4295. ol.Sphere.getLength = function(geometry, opt_options) {
  4296. var options = opt_options || {};
  4297. var radius = options.radius || ol.Sphere.DEFAULT_RADIUS;
  4298. var projection = options.projection || 'EPSG:3857';
  4299. geometry = geometry.clone().transform(projection, 'EPSG:4326');
  4300. var type = geometry.getType();
  4301. var length = 0;
  4302. var coordinates, coords, i, ii, j, jj;
  4303. switch (type) {
  4304. case ol.geom.GeometryType.POINT:
  4305. case ol.geom.GeometryType.MULTI_POINT: {
  4306. break;
  4307. }
  4308. case ol.geom.GeometryType.LINE_STRING:
  4309. case ol.geom.GeometryType.LINEAR_RING: {
  4310. coordinates = /** @type {ol.geom.SimpleGeometry} */ (geometry).getCoordinates();
  4311. length = ol.Sphere.getLength_(coordinates, radius);
  4312. break;
  4313. }
  4314. case ol.geom.GeometryType.MULTI_LINE_STRING:
  4315. case ol.geom.GeometryType.POLYGON: {
  4316. coordinates = /** @type {ol.geom.SimpleGeometry} */ (geometry).getCoordinates();
  4317. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  4318. length += ol.Sphere.getLength_(coordinates[i], radius);
  4319. }
  4320. break;
  4321. }
  4322. case ol.geom.GeometryType.MULTI_POLYGON: {
  4323. coordinates = /** @type {ol.geom.SimpleGeometry} */ (geometry).getCoordinates();
  4324. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  4325. coords = coordinates[i];
  4326. for (j = 0, jj = coords.length; j < jj; ++j) {
  4327. length += ol.Sphere.getLength_(coords[j], radius);
  4328. }
  4329. }
  4330. break;
  4331. }
  4332. case ol.geom.GeometryType.GEOMETRY_COLLECTION: {
  4333. var geometries = /** @type {ol.geom.GeometryCollection} */ (geometry).getGeometries();
  4334. for (i = 0, ii = geometries.length; i < ii; ++i) {
  4335. length += ol.Sphere.getLength(geometries[i], opt_options);
  4336. }
  4337. break;
  4338. }
  4339. default: {
  4340. throw new Error('Unsupported geometry type: ' + type);
  4341. }
  4342. }
  4343. return length;
  4344. };
  4345. /**
  4346. * Get the cumulative great circle length of linestring coordinates (geographic).
  4347. * @param {Array} coordinates Linestring coordinates.
  4348. * @param {number} radius The sphere radius to use.
  4349. * @return {number} The length (in meters).
  4350. */
  4351. ol.Sphere.getLength_ = function(coordinates, radius) {
  4352. var length = 0;
  4353. for (var i = 0, ii = coordinates.length; i < ii - 1; ++i) {
  4354. length += ol.Sphere.getDistance_(coordinates[i], coordinates[i + 1], radius);
  4355. }
  4356. return length;
  4357. };
  4358. /**
  4359. * Get the great circle distance between two geographic coordinates.
  4360. * @param {Array} c1 Starting coordinate.
  4361. * @param {Array} c2 Ending coordinate.
  4362. * @param {number} radius The sphere radius to use.
  4363. * @return {number} The great circle distance between the points (in meters).
  4364. */
  4365. ol.Sphere.getDistance_ = function(c1, c2, radius) {
  4366. var lat1 = ol.math.toRadians(c1[1]);
  4367. var lat2 = ol.math.toRadians(c2[1]);
  4368. var deltaLatBy2 = (lat2 - lat1) / 2;
  4369. var deltaLonBy2 = ol.math.toRadians(c2[0] - c1[0]) / 2;
  4370. var a = Math.sin(deltaLatBy2) * Math.sin(deltaLatBy2) +
  4371. Math.sin(deltaLonBy2) * Math.sin(deltaLonBy2) *
  4372. Math.cos(lat1) * Math.cos(lat2);
  4373. return 2 * radius * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  4374. };
  4375. /**
  4376. * Get the spherical area of a geometry. This is the area (in meters) assuming
  4377. * that polygon edges are segments of great circles on a sphere.
  4378. * @param {ol.geom.Geometry} geometry A geometry.
  4379. * @param {olx.SphereMetricOptions=} opt_options Options for the area
  4380. * calculation. By default, geometries are assumed to be in 'EPSG:3857'.
  4381. * You can change this by providing a `projection` option.
  4382. * @return {number} The spherical area (in square meters).
  4383. * @api
  4384. */
  4385. ol.Sphere.getArea = function(geometry, opt_options) {
  4386. var options = opt_options || {};
  4387. var radius = options.radius || ol.Sphere.DEFAULT_RADIUS;
  4388. var projection = options.projection || 'EPSG:3857';
  4389. geometry = geometry.clone().transform(projection, 'EPSG:4326');
  4390. var type = geometry.getType();
  4391. var area = 0;
  4392. var coordinates, coords, i, ii, j, jj;
  4393. switch (type) {
  4394. case ol.geom.GeometryType.POINT:
  4395. case ol.geom.GeometryType.MULTI_POINT:
  4396. case ol.geom.GeometryType.LINE_STRING:
  4397. case ol.geom.GeometryType.MULTI_LINE_STRING:
  4398. case ol.geom.GeometryType.LINEAR_RING: {
  4399. break;
  4400. }
  4401. case ol.geom.GeometryType.POLYGON: {
  4402. coordinates = /** @type {ol.geom.Polygon} */ (geometry).getCoordinates();
  4403. area = Math.abs(ol.Sphere.getArea_(coordinates[0], radius));
  4404. for (i = 1, ii = coordinates.length; i < ii; ++i) {
  4405. area -= Math.abs(ol.Sphere.getArea_(coordinates[i], radius));
  4406. }
  4407. break;
  4408. }
  4409. case ol.geom.GeometryType.MULTI_POLYGON: {
  4410. coordinates = /** @type {ol.geom.SimpleGeometry} */ (geometry).getCoordinates();
  4411. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  4412. coords = coordinates[i];
  4413. area += Math.abs(ol.Sphere.getArea_(coords[0], radius));
  4414. for (j = 1, jj = coords.length; j < jj; ++j) {
  4415. area -= Math.abs(ol.Sphere.getArea_(coords[j], radius));
  4416. }
  4417. }
  4418. break;
  4419. }
  4420. case ol.geom.GeometryType.GEOMETRY_COLLECTION: {
  4421. var geometries = /** @type {ol.geom.GeometryCollection} */ (geometry).getGeometries();
  4422. for (i = 0, ii = geometries.length; i < ii; ++i) {
  4423. area += ol.Sphere.getArea(geometries[i], opt_options);
  4424. }
  4425. break;
  4426. }
  4427. default: {
  4428. throw new Error('Unsupported geometry type: ' + type);
  4429. }
  4430. }
  4431. return area;
  4432. };
  4433. /**
  4434. * Returns the spherical area for a list of coordinates.
  4435. *
  4436. * [Reference](https://trs-new.jpl.nasa.gov/handle/2014/40409)
  4437. * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for
  4438. * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion
  4439. * Laboratory, Pasadena, CA, June 2007
  4440. *
  4441. * @param {Array.<ol.Coordinate>} coordinates List of coordinates of a linear
  4442. * ring. If the ring is oriented clockwise, the area will be positive,
  4443. * otherwise it will be negative.
  4444. * @param {number} radius The sphere radius.
  4445. * @return {number} Area (in square meters).
  4446. */
  4447. ol.Sphere.getArea_ = function(coordinates, radius) {
  4448. var area = 0, len = coordinates.length;
  4449. var x1 = coordinates[len - 1][0];
  4450. var y1 = coordinates[len - 1][1];
  4451. for (var i = 0; i < len; i++) {
  4452. var x2 = coordinates[i][0], y2 = coordinates[i][1];
  4453. area += ol.math.toRadians(x2 - x1) *
  4454. (2 + Math.sin(ol.math.toRadians(y1)) +
  4455. Math.sin(ol.math.toRadians(y2)));
  4456. x1 = x2;
  4457. y1 = y2;
  4458. }
  4459. return area * radius * radius / 2.0;
  4460. };
  4461. goog.provide('ol.proj.Units');
  4462. /**
  4463. * Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or
  4464. * `'us-ft'`.
  4465. * @enum {string}
  4466. */
  4467. ol.proj.Units = {
  4468. DEGREES: 'degrees',
  4469. FEET: 'ft',
  4470. METERS: 'm',
  4471. PIXELS: 'pixels',
  4472. TILE_PIXELS: 'tile-pixels',
  4473. USFEET: 'us-ft'
  4474. };
  4475. /**
  4476. * Meters per unit lookup table.
  4477. * @const
  4478. * @type {Object.<ol.proj.Units, number>}
  4479. * @api
  4480. */
  4481. ol.proj.Units.METERS_PER_UNIT = {};
  4482. // use the radius of the Normal sphere
  4483. ol.proj.Units.METERS_PER_UNIT[ol.proj.Units.DEGREES] =
  4484. 2 * Math.PI * 6370997 / 360;
  4485. ol.proj.Units.METERS_PER_UNIT[ol.proj.Units.FEET] = 0.3048;
  4486. ol.proj.Units.METERS_PER_UNIT[ol.proj.Units.METERS] = 1;
  4487. ol.proj.Units.METERS_PER_UNIT[ol.proj.Units.USFEET] = 1200 / 3937;
  4488. goog.provide('ol.proj.proj4');
  4489. /**
  4490. * @private
  4491. * @type {Proj4}
  4492. */
  4493. ol.proj.proj4.cache_ = null;
  4494. /**
  4495. * Store the proj4 function.
  4496. * @param {Proj4} proj4 The proj4 function.
  4497. */
  4498. ol.proj.proj4.set = function(proj4) {
  4499. ol.proj.proj4.cache_ = proj4;
  4500. };
  4501. /**
  4502. * Get proj4.
  4503. * @return {Proj4} The proj4 function set above or available globally.
  4504. */
  4505. ol.proj.proj4.get = function() {
  4506. return ol.proj.proj4.cache_ || window['proj4'];
  4507. };
  4508. goog.provide('ol.proj.Projection');
  4509. goog.require('ol');
  4510. goog.require('ol.proj.Units');
  4511. goog.require('ol.proj.proj4');
  4512. /**
  4513. * @classdesc
  4514. * Projection definition class. One of these is created for each projection
  4515. * supported in the application and stored in the {@link ol.proj} namespace.
  4516. * You can use these in applications, but this is not required, as API params
  4517. * and options use {@link ol.ProjectionLike} which means the simple string
  4518. * code will suffice.
  4519. *
  4520. * You can use {@link ol.proj.get} to retrieve the object for a particular
  4521. * projection.
  4522. *
  4523. * The library includes definitions for `EPSG:4326` and `EPSG:3857`, together
  4524. * with the following aliases:
  4525. * * `EPSG:4326`: CRS:84, urn:ogc:def:crs:EPSG:6.6:4326,
  4526. * urn:ogc:def:crs:OGC:1.3:CRS84, urn:ogc:def:crs:OGC:2:84,
  4527. * http://www.opengis.net/gml/srs/epsg.xml#4326,
  4528. * urn:x-ogc:def:crs:EPSG:4326
  4529. * * `EPSG:3857`: EPSG:102100, EPSG:102113, EPSG:900913,
  4530. * urn:ogc:def:crs:EPSG:6.18:3:3857,
  4531. * http://www.opengis.net/gml/srs/epsg.xml#3857
  4532. *
  4533. * If you use proj4js, aliases can be added using `proj4.defs()`; see
  4534. * [documentation](https://github.com/proj4js/proj4js). To set an alternative
  4535. * namespace for proj4, use {@link ol.proj.setProj4}.
  4536. *
  4537. * @constructor
  4538. * @param {olx.ProjectionOptions} options Projection options.
  4539. * @struct
  4540. * @api
  4541. */
  4542. ol.proj.Projection = function(options) {
  4543. /**
  4544. * @private
  4545. * @type {string}
  4546. */
  4547. this.code_ = options.code;
  4548. /**
  4549. * Units of projected coordinates. When set to `ol.proj.Units.TILE_PIXELS`, a
  4550. * `this.extent_` and `this.worldExtent_` must be configured properly for each
  4551. * tile.
  4552. * @private
  4553. * @type {ol.proj.Units}
  4554. */
  4555. this.units_ = /** @type {ol.proj.Units} */ (options.units);
  4556. /**
  4557. * Validity extent of the projection in projected coordinates. For projections
  4558. * with `ol.proj.Units.TILE_PIXELS` units, this is the extent of the tile in
  4559. * tile pixel space.
  4560. * @private
  4561. * @type {ol.Extent}
  4562. */
  4563. this.extent_ = options.extent !== undefined ? options.extent : null;
  4564. /**
  4565. * Extent of the world in EPSG:4326. For projections with
  4566. * `ol.proj.Units.TILE_PIXELS` units, this is the extent of the tile in
  4567. * projected coordinate space.
  4568. * @private
  4569. * @type {ol.Extent}
  4570. */
  4571. this.worldExtent_ = options.worldExtent !== undefined ?
  4572. options.worldExtent : null;
  4573. /**
  4574. * @private
  4575. * @type {string}
  4576. */
  4577. this.axisOrientation_ = options.axisOrientation !== undefined ?
  4578. options.axisOrientation : 'enu';
  4579. /**
  4580. * @private
  4581. * @type {boolean}
  4582. */
  4583. this.global_ = options.global !== undefined ? options.global : false;
  4584. /**
  4585. * @private
  4586. * @type {boolean}
  4587. */
  4588. this.canWrapX_ = !!(this.global_ && this.extent_);
  4589. /**
  4590. * @private
  4591. * @type {function(number, ol.Coordinate):number|undefined}
  4592. */
  4593. this.getPointResolutionFunc_ = options.getPointResolution;
  4594. /**
  4595. * @private
  4596. * @type {ol.tilegrid.TileGrid}
  4597. */
  4598. this.defaultTileGrid_ = null;
  4599. /**
  4600. * @private
  4601. * @type {number|undefined}
  4602. */
  4603. this.metersPerUnit_ = options.metersPerUnit;
  4604. var code = options.code;
  4605. if (ol.ENABLE_PROJ4JS) {
  4606. var proj4js = ol.proj.proj4.get();
  4607. if (typeof proj4js == 'function') {
  4608. var def = proj4js.defs(code);
  4609. if (def !== undefined) {
  4610. if (def.axis !== undefined && options.axisOrientation === undefined) {
  4611. this.axisOrientation_ = def.axis;
  4612. }
  4613. if (options.metersPerUnit === undefined) {
  4614. this.metersPerUnit_ = def.to_meter;
  4615. }
  4616. if (options.units === undefined) {
  4617. this.units_ = def.units;
  4618. }
  4619. }
  4620. }
  4621. }
  4622. };
  4623. /**
  4624. * @return {boolean} The projection is suitable for wrapping the x-axis
  4625. */
  4626. ol.proj.Projection.prototype.canWrapX = function() {
  4627. return this.canWrapX_;
  4628. };
  4629. /**
  4630. * Get the code for this projection, e.g. 'EPSG:4326'.
  4631. * @return {string} Code.
  4632. * @api
  4633. */
  4634. ol.proj.Projection.prototype.getCode = function() {
  4635. return this.code_;
  4636. };
  4637. /**
  4638. * Get the validity extent for this projection.
  4639. * @return {ol.Extent} Extent.
  4640. * @api
  4641. */
  4642. ol.proj.Projection.prototype.getExtent = function() {
  4643. return this.extent_;
  4644. };
  4645. /**
  4646. * Get the units of this projection.
  4647. * @return {ol.proj.Units} Units.
  4648. * @api
  4649. */
  4650. ol.proj.Projection.prototype.getUnits = function() {
  4651. return this.units_;
  4652. };
  4653. /**
  4654. * Get the amount of meters per unit of this projection. If the projection is
  4655. * not configured with `metersPerUnit` or a units identifier, the return is
  4656. * `undefined`.
  4657. * @return {number|undefined} Meters.
  4658. * @api
  4659. */
  4660. ol.proj.Projection.prototype.getMetersPerUnit = function() {
  4661. return this.metersPerUnit_ || ol.proj.Units.METERS_PER_UNIT[this.units_];
  4662. };
  4663. /**
  4664. * Get the world extent for this projection.
  4665. * @return {ol.Extent} Extent.
  4666. * @api
  4667. */
  4668. ol.proj.Projection.prototype.getWorldExtent = function() {
  4669. return this.worldExtent_;
  4670. };
  4671. /**
  4672. * Get the axis orientation of this projection.
  4673. * Example values are:
  4674. * enu - the default easting, northing, elevation.
  4675. * neu - northing, easting, up - useful for "lat/long" geographic coordinates,
  4676. * or south orientated transverse mercator.
  4677. * wnu - westing, northing, up - some planetary coordinate systems have
  4678. * "west positive" coordinate systems
  4679. * @return {string} Axis orientation.
  4680. * @api
  4681. */
  4682. ol.proj.Projection.prototype.getAxisOrientation = function() {
  4683. return this.axisOrientation_;
  4684. };
  4685. /**
  4686. * Is this projection a global projection which spans the whole world?
  4687. * @return {boolean} Whether the projection is global.
  4688. * @api
  4689. */
  4690. ol.proj.Projection.prototype.isGlobal = function() {
  4691. return this.global_;
  4692. };
  4693. /**
  4694. * Set if the projection is a global projection which spans the whole world
  4695. * @param {boolean} global Whether the projection is global.
  4696. * @api
  4697. */
  4698. ol.proj.Projection.prototype.setGlobal = function(global) {
  4699. this.global_ = global;
  4700. this.canWrapX_ = !!(global && this.extent_);
  4701. };
  4702. /**
  4703. * @return {ol.tilegrid.TileGrid} The default tile grid.
  4704. */
  4705. ol.proj.Projection.prototype.getDefaultTileGrid = function() {
  4706. return this.defaultTileGrid_;
  4707. };
  4708. /**
  4709. * @param {ol.tilegrid.TileGrid} tileGrid The default tile grid.
  4710. */
  4711. ol.proj.Projection.prototype.setDefaultTileGrid = function(tileGrid) {
  4712. this.defaultTileGrid_ = tileGrid;
  4713. };
  4714. /**
  4715. * Set the validity extent for this projection.
  4716. * @param {ol.Extent} extent Extent.
  4717. * @api
  4718. */
  4719. ol.proj.Projection.prototype.setExtent = function(extent) {
  4720. this.extent_ = extent;
  4721. this.canWrapX_ = !!(this.global_ && extent);
  4722. };
  4723. /**
  4724. * Set the world extent for this projection.
  4725. * @param {ol.Extent} worldExtent World extent
  4726. * [minlon, minlat, maxlon, maxlat].
  4727. * @api
  4728. */
  4729. ol.proj.Projection.prototype.setWorldExtent = function(worldExtent) {
  4730. this.worldExtent_ = worldExtent;
  4731. };
  4732. /**
  4733. * Set the getPointResolution function (see {@link ol.proj#getPointResolution}
  4734. * for this projection.
  4735. * @param {function(number, ol.Coordinate):number} func Function
  4736. * @api
  4737. */
  4738. ol.proj.Projection.prototype.setGetPointResolution = function(func) {
  4739. this.getPointResolutionFunc_ = func;
  4740. };
  4741. /**
  4742. * Get the custom point resolution function for this projection (if set).
  4743. * @return {function(number, ol.Coordinate):number|undefined} The custom point
  4744. * resolution function (if set).
  4745. */
  4746. ol.proj.Projection.prototype.getPointResolutionFunc = function() {
  4747. return this.getPointResolutionFunc_;
  4748. };
  4749. goog.provide('ol.proj.EPSG3857');
  4750. goog.require('ol');
  4751. goog.require('ol.math');
  4752. goog.require('ol.proj.Projection');
  4753. goog.require('ol.proj.Units');
  4754. /**
  4755. * @classdesc
  4756. * Projection object for web/spherical Mercator (EPSG:3857).
  4757. *
  4758. * @constructor
  4759. * @extends {ol.proj.Projection}
  4760. * @param {string} code Code.
  4761. * @private
  4762. */
  4763. ol.proj.EPSG3857.Projection_ = function(code) {
  4764. ol.proj.Projection.call(this, {
  4765. code: code,
  4766. units: ol.proj.Units.METERS,
  4767. extent: ol.proj.EPSG3857.EXTENT,
  4768. global: true,
  4769. worldExtent: ol.proj.EPSG3857.WORLD_EXTENT,
  4770. getPointResolution: function(resolution, point) {
  4771. return resolution / ol.math.cosh(point[1] / ol.proj.EPSG3857.RADIUS);
  4772. }
  4773. });
  4774. };
  4775. ol.inherits(ol.proj.EPSG3857.Projection_, ol.proj.Projection);
  4776. /**
  4777. * Radius of WGS84 sphere
  4778. *
  4779. * @const
  4780. * @type {number}
  4781. */
  4782. ol.proj.EPSG3857.RADIUS = 6378137;
  4783. /**
  4784. * @const
  4785. * @type {number}
  4786. */
  4787. ol.proj.EPSG3857.HALF_SIZE = Math.PI * ol.proj.EPSG3857.RADIUS;
  4788. /**
  4789. * @const
  4790. * @type {ol.Extent}
  4791. */
  4792. ol.proj.EPSG3857.EXTENT = [
  4793. -ol.proj.EPSG3857.HALF_SIZE, -ol.proj.EPSG3857.HALF_SIZE,
  4794. ol.proj.EPSG3857.HALF_SIZE, ol.proj.EPSG3857.HALF_SIZE
  4795. ];
  4796. /**
  4797. * @const
  4798. * @type {ol.Extent}
  4799. */
  4800. ol.proj.EPSG3857.WORLD_EXTENT = [-180, -85, 180, 85];
  4801. /**
  4802. * Projections equal to EPSG:3857.
  4803. *
  4804. * @const
  4805. * @type {Array.<ol.proj.Projection>}
  4806. */
  4807. ol.proj.EPSG3857.PROJECTIONS = [
  4808. new ol.proj.EPSG3857.Projection_('EPSG:3857'),
  4809. new ol.proj.EPSG3857.Projection_('EPSG:102100'),
  4810. new ol.proj.EPSG3857.Projection_('EPSG:102113'),
  4811. new ol.proj.EPSG3857.Projection_('EPSG:900913'),
  4812. new ol.proj.EPSG3857.Projection_('urn:ogc:def:crs:EPSG:6.18:3:3857'),
  4813. new ol.proj.EPSG3857.Projection_('urn:ogc:def:crs:EPSG::3857'),
  4814. new ol.proj.EPSG3857.Projection_('http://www.opengis.net/gml/srs/epsg.xml#3857')
  4815. ];
  4816. /**
  4817. * Transformation from EPSG:4326 to EPSG:3857.
  4818. *
  4819. * @param {Array.<number>} input Input array of coordinate values.
  4820. * @param {Array.<number>=} opt_output Output array of coordinate values.
  4821. * @param {number=} opt_dimension Dimension (default is `2`).
  4822. * @return {Array.<number>} Output array of coordinate values.
  4823. */
  4824. ol.proj.EPSG3857.fromEPSG4326 = function(input, opt_output, opt_dimension) {
  4825. var length = input.length,
  4826. dimension = opt_dimension > 1 ? opt_dimension : 2,
  4827. output = opt_output;
  4828. if (output === undefined) {
  4829. if (dimension > 2) {
  4830. // preserve values beyond second dimension
  4831. output = input.slice();
  4832. } else {
  4833. output = new Array(length);
  4834. }
  4835. }
  4836. var halfSize = ol.proj.EPSG3857.HALF_SIZE;
  4837. for (var i = 0; i < length; i += dimension) {
  4838. output[i] = halfSize * input[i] / 180;
  4839. var y = ol.proj.EPSG3857.RADIUS *
  4840. Math.log(Math.tan(Math.PI * (input[i + 1] + 90) / 360));
  4841. if (y > halfSize) {
  4842. y = halfSize;
  4843. } else if (y < -halfSize) {
  4844. y = -halfSize;
  4845. }
  4846. output[i + 1] = y;
  4847. }
  4848. return output;
  4849. };
  4850. /**
  4851. * Transformation from EPSG:3857 to EPSG:4326.
  4852. *
  4853. * @param {Array.<number>} input Input array of coordinate values.
  4854. * @param {Array.<number>=} opt_output Output array of coordinate values.
  4855. * @param {number=} opt_dimension Dimension (default is `2`).
  4856. * @return {Array.<number>} Output array of coordinate values.
  4857. */
  4858. ol.proj.EPSG3857.toEPSG4326 = function(input, opt_output, opt_dimension) {
  4859. var length = input.length,
  4860. dimension = opt_dimension > 1 ? opt_dimension : 2,
  4861. output = opt_output;
  4862. if (output === undefined) {
  4863. if (dimension > 2) {
  4864. // preserve values beyond second dimension
  4865. output = input.slice();
  4866. } else {
  4867. output = new Array(length);
  4868. }
  4869. }
  4870. for (var i = 0; i < length; i += dimension) {
  4871. output[i] = 180 * input[i] / ol.proj.EPSG3857.HALF_SIZE;
  4872. output[i + 1] = 360 * Math.atan(
  4873. Math.exp(input[i + 1] / ol.proj.EPSG3857.RADIUS)) / Math.PI - 90;
  4874. }
  4875. return output;
  4876. };
  4877. goog.provide('ol.proj.EPSG4326');
  4878. goog.require('ol');
  4879. goog.require('ol.proj.Projection');
  4880. goog.require('ol.proj.Units');
  4881. /**
  4882. * @classdesc
  4883. * Projection object for WGS84 geographic coordinates (EPSG:4326).
  4884. *
  4885. * Note that OpenLayers does not strictly comply with the EPSG definition.
  4886. * The EPSG registry defines 4326 as a CRS for Latitude,Longitude (y,x).
  4887. * OpenLayers treats EPSG:4326 as a pseudo-projection, with x,y coordinates.
  4888. *
  4889. * @constructor
  4890. * @extends {ol.proj.Projection}
  4891. * @param {string} code Code.
  4892. * @param {string=} opt_axisOrientation Axis orientation.
  4893. * @private
  4894. */
  4895. ol.proj.EPSG4326.Projection_ = function(code, opt_axisOrientation) {
  4896. ol.proj.Projection.call(this, {
  4897. code: code,
  4898. units: ol.proj.Units.DEGREES,
  4899. extent: ol.proj.EPSG4326.EXTENT,
  4900. axisOrientation: opt_axisOrientation,
  4901. global: true,
  4902. metersPerUnit: ol.proj.EPSG4326.METERS_PER_UNIT,
  4903. worldExtent: ol.proj.EPSG4326.EXTENT
  4904. });
  4905. };
  4906. ol.inherits(ol.proj.EPSG4326.Projection_, ol.proj.Projection);
  4907. /**
  4908. * Radius of WGS84 sphere
  4909. *
  4910. * @const
  4911. * @type {number}
  4912. */
  4913. ol.proj.EPSG4326.RADIUS = 6378137;
  4914. /**
  4915. * Extent of the EPSG:4326 projection which is the whole world.
  4916. *
  4917. * @const
  4918. * @type {ol.Extent}
  4919. */
  4920. ol.proj.EPSG4326.EXTENT = [-180, -90, 180, 90];
  4921. /**
  4922. * @const
  4923. * @type {number}
  4924. */
  4925. ol.proj.EPSG4326.METERS_PER_UNIT = Math.PI * ol.proj.EPSG4326.RADIUS / 180;
  4926. /**
  4927. * Projections equal to EPSG:4326.
  4928. *
  4929. * @const
  4930. * @type {Array.<ol.proj.Projection>}
  4931. */
  4932. ol.proj.EPSG4326.PROJECTIONS = [
  4933. new ol.proj.EPSG4326.Projection_('CRS:84'),
  4934. new ol.proj.EPSG4326.Projection_('EPSG:4326', 'neu'),
  4935. new ol.proj.EPSG4326.Projection_('urn:ogc:def:crs:EPSG::4326', 'neu'),
  4936. new ol.proj.EPSG4326.Projection_('urn:ogc:def:crs:EPSG:6.6:4326', 'neu'),
  4937. new ol.proj.EPSG4326.Projection_('urn:ogc:def:crs:OGC:1.3:CRS84'),
  4938. new ol.proj.EPSG4326.Projection_('urn:ogc:def:crs:OGC:2:84'),
  4939. new ol.proj.EPSG4326.Projection_('http://www.opengis.net/gml/srs/epsg.xml#4326', 'neu'),
  4940. new ol.proj.EPSG4326.Projection_('urn:x-ogc:def:crs:EPSG:4326', 'neu')
  4941. ];
  4942. goog.provide('ol.proj.projections');
  4943. /**
  4944. * @private
  4945. * @type {Object.<string, ol.proj.Projection>}
  4946. */
  4947. ol.proj.projections.cache_ = {};
  4948. /**
  4949. * Clear the projections cache.
  4950. */
  4951. ol.proj.projections.clear = function() {
  4952. ol.proj.projections.cache_ = {};
  4953. };
  4954. /**
  4955. * Get a cached projection by code.
  4956. * @param {string} code The code for the projection.
  4957. * @return {ol.proj.Projection} The projection (if cached).
  4958. */
  4959. ol.proj.projections.get = function(code) {
  4960. var projections = ol.proj.projections.cache_;
  4961. return projections[code] || null;
  4962. };
  4963. /**
  4964. * Add a projection to the cache.
  4965. * @param {string} code The projection code.
  4966. * @param {ol.proj.Projection} projection The projection to cache.
  4967. */
  4968. ol.proj.projections.add = function(code, projection) {
  4969. var projections = ol.proj.projections.cache_;
  4970. projections[code] = projection;
  4971. };
  4972. goog.provide('ol.proj.transforms');
  4973. goog.require('ol.obj');
  4974. /**
  4975. * @private
  4976. * @type {Object.<string, Object.<string, ol.TransformFunction>>}
  4977. */
  4978. ol.proj.transforms.cache_ = {};
  4979. /**
  4980. * Clear the transform cache.
  4981. */
  4982. ol.proj.transforms.clear = function() {
  4983. ol.proj.transforms.cache_ = {};
  4984. };
  4985. /**
  4986. * Registers a conversion function to convert coordinates from the source
  4987. * projection to the destination projection.
  4988. *
  4989. * @param {ol.proj.Projection} source Source.
  4990. * @param {ol.proj.Projection} destination Destination.
  4991. * @param {ol.TransformFunction} transformFn Transform.
  4992. */
  4993. ol.proj.transforms.add = function(source, destination, transformFn) {
  4994. var sourceCode = source.getCode();
  4995. var destinationCode = destination.getCode();
  4996. var transforms = ol.proj.transforms.cache_;
  4997. if (!(sourceCode in transforms)) {
  4998. transforms[sourceCode] = {};
  4999. }
  5000. transforms[sourceCode][destinationCode] = transformFn;
  5001. };
  5002. /**
  5003. * Unregisters the conversion function to convert coordinates from the source
  5004. * projection to the destination projection. This method is used to clean up
  5005. * cached transforms during testing.
  5006. *
  5007. * @param {ol.proj.Projection} source Source projection.
  5008. * @param {ol.proj.Projection} destination Destination projection.
  5009. * @return {ol.TransformFunction} transformFn The unregistered transform.
  5010. */
  5011. ol.proj.transforms.remove = function(source, destination) {
  5012. var sourceCode = source.getCode();
  5013. var destinationCode = destination.getCode();
  5014. var transforms = ol.proj.transforms.cache_;
  5015. var transform = transforms[sourceCode][destinationCode];
  5016. delete transforms[sourceCode][destinationCode];
  5017. if (ol.obj.isEmpty(transforms[sourceCode])) {
  5018. delete transforms[sourceCode];
  5019. }
  5020. return transform;
  5021. };
  5022. /**
  5023. * Get a transform given a source code and a destination code.
  5024. * @param {string} sourceCode The code for the source projection.
  5025. * @param {string} destinationCode The code for the destination projection.
  5026. * @return {ol.TransformFunction|undefined} The transform function (if found).
  5027. */
  5028. ol.proj.transforms.get = function(sourceCode, destinationCode) {
  5029. var transform;
  5030. var transforms = ol.proj.transforms.cache_;
  5031. if (sourceCode in transforms && destinationCode in transforms[sourceCode]) {
  5032. transform = transforms[sourceCode][destinationCode];
  5033. }
  5034. return transform;
  5035. };
  5036. goog.provide('ol.proj');
  5037. goog.require('ol');
  5038. goog.require('ol.Sphere');
  5039. goog.require('ol.extent');
  5040. goog.require('ol.math');
  5041. goog.require('ol.proj.EPSG3857');
  5042. goog.require('ol.proj.EPSG4326');
  5043. goog.require('ol.proj.Projection');
  5044. goog.require('ol.proj.Units');
  5045. goog.require('ol.proj.proj4');
  5046. goog.require('ol.proj.projections');
  5047. goog.require('ol.proj.transforms');
  5048. /**
  5049. * Meters per unit lookup table.
  5050. * @const
  5051. * @type {Object.<ol.proj.Units, number>}
  5052. * @api
  5053. */
  5054. ol.proj.METERS_PER_UNIT = ol.proj.Units.METERS_PER_UNIT;
  5055. /**
  5056. * A place to store the mean radius of the Earth.
  5057. * @private
  5058. * @type {ol.Sphere}
  5059. */
  5060. ol.proj.SPHERE_ = new ol.Sphere(ol.Sphere.DEFAULT_RADIUS);
  5061. if (ol.ENABLE_PROJ4JS) {
  5062. /**
  5063. * Register proj4. If not explicitly registered, it will be assumed that
  5064. * proj4js will be loaded in the global namespace. For example in a
  5065. * browserify ES6 environment you could use:
  5066. *
  5067. * import ol from 'openlayers';
  5068. * import proj4 from 'proj4';
  5069. * ol.proj.setProj4(proj4);
  5070. *
  5071. * @param {Proj4} proj4 Proj4.
  5072. * @api
  5073. */
  5074. ol.proj.setProj4 = function(proj4) {
  5075. ol.proj.proj4.set(proj4);
  5076. };
  5077. }
  5078. /**
  5079. * Get the resolution of the point in degrees or distance units.
  5080. * For projections with degrees as the unit this will simply return the
  5081. * provided resolution. For other projections the point resolution is
  5082. * by default estimated by transforming the 'point' pixel to EPSG:4326,
  5083. * measuring its width and height on the normal sphere,
  5084. * and taking the average of the width and height.
  5085. * A custom function can be provided for a specific projection, either
  5086. * by setting the `getPointResolution` option in the
  5087. * {@link ol.proj.Projection} constructor or by using
  5088. * {@link ol.proj.Projection#setGetPointResolution} to change an existing
  5089. * projection object.
  5090. * @param {ol.ProjectionLike} projection The projection.
  5091. * @param {number} resolution Nominal resolution in projection units.
  5092. * @param {ol.Coordinate} point Point to find adjusted resolution at.
  5093. * @param {ol.proj.Units=} opt_units Units to get the point resolution in.
  5094. * Default is the projection's units.
  5095. * @return {number} Point resolution.
  5096. * @api
  5097. */
  5098. ol.proj.getPointResolution = function(projection, resolution, point, opt_units) {
  5099. projection = ol.proj.get(projection);
  5100. var pointResolution;
  5101. var getter = projection.getPointResolutionFunc();
  5102. if (getter) {
  5103. pointResolution = getter(resolution, point);
  5104. } else {
  5105. var units = projection.getUnits();
  5106. if (units == ol.proj.Units.DEGREES && !opt_units || opt_units == ol.proj.Units.DEGREES) {
  5107. pointResolution = resolution;
  5108. } else {
  5109. // Estimate point resolution by transforming the center pixel to EPSG:4326,
  5110. // measuring its width and height on the normal sphere, and taking the
  5111. // average of the width and height.
  5112. var toEPSG4326 = ol.proj.getTransformFromProjections(projection, ol.proj.get('EPSG:4326'));
  5113. var vertices = [
  5114. point[0] - resolution / 2, point[1],
  5115. point[0] + resolution / 2, point[1],
  5116. point[0], point[1] - resolution / 2,
  5117. point[0], point[1] + resolution / 2
  5118. ];
  5119. vertices = toEPSG4326(vertices, vertices, 2);
  5120. var width = ol.proj.SPHERE_.haversineDistance(
  5121. vertices.slice(0, 2), vertices.slice(2, 4));
  5122. var height = ol.proj.SPHERE_.haversineDistance(
  5123. vertices.slice(4, 6), vertices.slice(6, 8));
  5124. pointResolution = (width + height) / 2;
  5125. var metersPerUnit = opt_units ?
  5126. ol.proj.Units.METERS_PER_UNIT[opt_units] :
  5127. projection.getMetersPerUnit();
  5128. if (metersPerUnit !== undefined) {
  5129. pointResolution /= metersPerUnit;
  5130. }
  5131. }
  5132. }
  5133. return pointResolution;
  5134. };
  5135. /**
  5136. * Registers transformation functions that don't alter coordinates. Those allow
  5137. * to transform between projections with equal meaning.
  5138. *
  5139. * @param {Array.<ol.proj.Projection>} projections Projections.
  5140. * @api
  5141. */
  5142. ol.proj.addEquivalentProjections = function(projections) {
  5143. ol.proj.addProjections(projections);
  5144. projections.forEach(function(source) {
  5145. projections.forEach(function(destination) {
  5146. if (source !== destination) {
  5147. ol.proj.transforms.add(source, destination, ol.proj.cloneTransform);
  5148. }
  5149. });
  5150. });
  5151. };
  5152. /**
  5153. * Registers transformation functions to convert coordinates in any projection
  5154. * in projection1 to any projection in projection2.
  5155. *
  5156. * @param {Array.<ol.proj.Projection>} projections1 Projections with equal
  5157. * meaning.
  5158. * @param {Array.<ol.proj.Projection>} projections2 Projections with equal
  5159. * meaning.
  5160. * @param {ol.TransformFunction} forwardTransform Transformation from any
  5161. * projection in projection1 to any projection in projection2.
  5162. * @param {ol.TransformFunction} inverseTransform Transform from any projection
  5163. * in projection2 to any projection in projection1..
  5164. */
  5165. ol.proj.addEquivalentTransforms = function(projections1, projections2, forwardTransform, inverseTransform) {
  5166. projections1.forEach(function(projection1) {
  5167. projections2.forEach(function(projection2) {
  5168. ol.proj.transforms.add(projection1, projection2, forwardTransform);
  5169. ol.proj.transforms.add(projection2, projection1, inverseTransform);
  5170. });
  5171. });
  5172. };
  5173. /**
  5174. * Add a Projection object to the list of supported projections that can be
  5175. * looked up by their code.
  5176. *
  5177. * @param {ol.proj.Projection} projection Projection instance.
  5178. * @api
  5179. */
  5180. ol.proj.addProjection = function(projection) {
  5181. ol.proj.projections.add(projection.getCode(), projection);
  5182. ol.proj.transforms.add(projection, projection, ol.proj.cloneTransform);
  5183. };
  5184. /**
  5185. * @param {Array.<ol.proj.Projection>} projections Projections.
  5186. */
  5187. ol.proj.addProjections = function(projections) {
  5188. projections.forEach(ol.proj.addProjection);
  5189. };
  5190. /**
  5191. * Clear all cached projections and transforms.
  5192. */
  5193. ol.proj.clearAllProjections = function() {
  5194. ol.proj.projections.clear();
  5195. ol.proj.transforms.clear();
  5196. };
  5197. /**
  5198. * @param {ol.proj.Projection|string|undefined} projection Projection.
  5199. * @param {string} defaultCode Default code.
  5200. * @return {ol.proj.Projection} Projection.
  5201. */
  5202. ol.proj.createProjection = function(projection, defaultCode) {
  5203. if (!projection) {
  5204. return ol.proj.get(defaultCode);
  5205. } else if (typeof projection === 'string') {
  5206. return ol.proj.get(projection);
  5207. } else {
  5208. return /** @type {ol.proj.Projection} */ (projection);
  5209. }
  5210. };
  5211. /**
  5212. * Registers coordinate transform functions to convert coordinates between the
  5213. * source projection and the destination projection.
  5214. * The forward and inverse functions convert coordinate pairs; this function
  5215. * converts these into the functions used internally which also handle
  5216. * extents and coordinate arrays.
  5217. *
  5218. * @param {ol.ProjectionLike} source Source projection.
  5219. * @param {ol.ProjectionLike} destination Destination projection.
  5220. * @param {function(ol.Coordinate): ol.Coordinate} forward The forward transform
  5221. * function (that is, from the source projection to the destination
  5222. * projection) that takes a {@link ol.Coordinate} as argument and returns
  5223. * the transformed {@link ol.Coordinate}.
  5224. * @param {function(ol.Coordinate): ol.Coordinate} inverse The inverse transform
  5225. * function (that is, from the destination projection to the source
  5226. * projection) that takes a {@link ol.Coordinate} as argument and returns
  5227. * the transformed {@link ol.Coordinate}.
  5228. * @api
  5229. */
  5230. ol.proj.addCoordinateTransforms = function(source, destination, forward, inverse) {
  5231. var sourceProj = ol.proj.get(source);
  5232. var destProj = ol.proj.get(destination);
  5233. ol.proj.transforms.add(sourceProj, destProj,
  5234. ol.proj.createTransformFromCoordinateTransform(forward));
  5235. ol.proj.transforms.add(destProj, sourceProj,
  5236. ol.proj.createTransformFromCoordinateTransform(inverse));
  5237. };
  5238. /**
  5239. * Creates a {@link ol.TransformFunction} from a simple 2D coordinate transform
  5240. * function.
  5241. * @param {function(ol.Coordinate): ol.Coordinate} transform Coordinate
  5242. * transform.
  5243. * @return {ol.TransformFunction} Transform function.
  5244. */
  5245. ol.proj.createTransformFromCoordinateTransform = function(transform) {
  5246. return (
  5247. /**
  5248. * @param {Array.<number>} input Input.
  5249. * @param {Array.<number>=} opt_output Output.
  5250. * @param {number=} opt_dimension Dimension.
  5251. * @return {Array.<number>} Output.
  5252. */
  5253. function(input, opt_output, opt_dimension) {
  5254. var length = input.length;
  5255. var dimension = opt_dimension !== undefined ? opt_dimension : 2;
  5256. var output = opt_output !== undefined ? opt_output : new Array(length);
  5257. var point, i, j;
  5258. for (i = 0; i < length; i += dimension) {
  5259. point = transform([input[i], input[i + 1]]);
  5260. output[i] = point[0];
  5261. output[i + 1] = point[1];
  5262. for (j = dimension - 1; j >= 2; --j) {
  5263. output[i + j] = input[i + j];
  5264. }
  5265. }
  5266. return output;
  5267. });
  5268. };
  5269. /**
  5270. * Transforms a coordinate from longitude/latitude to a different projection.
  5271. * @param {ol.Coordinate} coordinate Coordinate as longitude and latitude, i.e.
  5272. * an array with longitude as 1st and latitude as 2nd element.
  5273. * @param {ol.ProjectionLike=} opt_projection Target projection. The
  5274. * default is Web Mercator, i.e. 'EPSG:3857'.
  5275. * @return {ol.Coordinate} Coordinate projected to the target projection.
  5276. * @api
  5277. */
  5278. ol.proj.fromLonLat = function(coordinate, opt_projection) {
  5279. return ol.proj.transform(coordinate, 'EPSG:4326',
  5280. opt_projection !== undefined ? opt_projection : 'EPSG:3857');
  5281. };
  5282. /**
  5283. * Transforms a coordinate to longitude/latitude.
  5284. * @param {ol.Coordinate} coordinate Projected coordinate.
  5285. * @param {ol.ProjectionLike=} opt_projection Projection of the coordinate.
  5286. * The default is Web Mercator, i.e. 'EPSG:3857'.
  5287. * @return {ol.Coordinate} Coordinate as longitude and latitude, i.e. an array
  5288. * with longitude as 1st and latitude as 2nd element.
  5289. * @api
  5290. */
  5291. ol.proj.toLonLat = function(coordinate, opt_projection) {
  5292. var lonLat = ol.proj.transform(coordinate,
  5293. opt_projection !== undefined ? opt_projection : 'EPSG:3857', 'EPSG:4326');
  5294. var lon = lonLat[0];
  5295. if (lon < -180 || lon > 180) {
  5296. lonLat[0] = ol.math.modulo(lon + 180, 360) - 180;
  5297. }
  5298. return lonLat;
  5299. };
  5300. /**
  5301. * Fetches a Projection object for the code specified.
  5302. *
  5303. * @param {ol.ProjectionLike} projectionLike Either a code string which is
  5304. * a combination of authority and identifier such as "EPSG:4326", or an
  5305. * existing projection object, or undefined.
  5306. * @return {ol.proj.Projection} Projection object, or null if not in list.
  5307. * @api
  5308. */
  5309. ol.proj.get = function(projectionLike) {
  5310. var projection = null;
  5311. if (projectionLike instanceof ol.proj.Projection) {
  5312. projection = projectionLike;
  5313. } else if (typeof projectionLike === 'string') {
  5314. var code = projectionLike;
  5315. projection = ol.proj.projections.get(code);
  5316. if (ol.ENABLE_PROJ4JS && !projection) {
  5317. var proj4js = ol.proj.proj4.get();
  5318. if (typeof proj4js == 'function' &&
  5319. proj4js.defs(code) !== undefined) {
  5320. projection = new ol.proj.Projection({code: code});
  5321. ol.proj.addProjection(projection);
  5322. }
  5323. }
  5324. }
  5325. return projection;
  5326. };
  5327. /**
  5328. * Checks if two projections are the same, that is every coordinate in one
  5329. * projection does represent the same geographic point as the same coordinate in
  5330. * the other projection.
  5331. *
  5332. * @param {ol.proj.Projection} projection1 Projection 1.
  5333. * @param {ol.proj.Projection} projection2 Projection 2.
  5334. * @return {boolean} Equivalent.
  5335. * @api
  5336. */
  5337. ol.proj.equivalent = function(projection1, projection2) {
  5338. if (projection1 === projection2) {
  5339. return true;
  5340. }
  5341. var equalUnits = projection1.getUnits() === projection2.getUnits();
  5342. if (projection1.getCode() === projection2.getCode()) {
  5343. return equalUnits;
  5344. } else {
  5345. var transformFn = ol.proj.getTransformFromProjections(
  5346. projection1, projection2);
  5347. return transformFn === ol.proj.cloneTransform && equalUnits;
  5348. }
  5349. };
  5350. /**
  5351. * Given the projection-like objects, searches for a transformation
  5352. * function to convert a coordinates array from the source projection to the
  5353. * destination projection.
  5354. *
  5355. * @param {ol.ProjectionLike} source Source.
  5356. * @param {ol.ProjectionLike} destination Destination.
  5357. * @return {ol.TransformFunction} Transform function.
  5358. * @api
  5359. */
  5360. ol.proj.getTransform = function(source, destination) {
  5361. var sourceProjection = ol.proj.get(source);
  5362. var destinationProjection = ol.proj.get(destination);
  5363. return ol.proj.getTransformFromProjections(
  5364. sourceProjection, destinationProjection);
  5365. };
  5366. /**
  5367. * Searches in the list of transform functions for the function for converting
  5368. * coordinates from the source projection to the destination projection.
  5369. *
  5370. * @param {ol.proj.Projection} sourceProjection Source Projection object.
  5371. * @param {ol.proj.Projection} destinationProjection Destination Projection
  5372. * object.
  5373. * @return {ol.TransformFunction} Transform function.
  5374. */
  5375. ol.proj.getTransformFromProjections = function(sourceProjection, destinationProjection) {
  5376. var sourceCode = sourceProjection.getCode();
  5377. var destinationCode = destinationProjection.getCode();
  5378. var transform = ol.proj.transforms.get(sourceCode, destinationCode);
  5379. if (ol.ENABLE_PROJ4JS && !transform) {
  5380. var proj4js = ol.proj.proj4.get();
  5381. if (typeof proj4js == 'function') {
  5382. var sourceDef = proj4js.defs(sourceCode);
  5383. var destinationDef = proj4js.defs(destinationCode);
  5384. if (sourceDef !== undefined && destinationDef !== undefined) {
  5385. if (sourceDef === destinationDef) {
  5386. ol.proj.addEquivalentProjections([destinationProjection, sourceProjection]);
  5387. } else {
  5388. var proj4Transform = proj4js(destinationCode, sourceCode);
  5389. ol.proj.addCoordinateTransforms(destinationProjection, sourceProjection,
  5390. proj4Transform.forward, proj4Transform.inverse);
  5391. }
  5392. transform = ol.proj.transforms.get(sourceCode, destinationCode);
  5393. }
  5394. }
  5395. }
  5396. if (!transform) {
  5397. transform = ol.proj.identityTransform;
  5398. }
  5399. return transform;
  5400. };
  5401. /**
  5402. * @param {Array.<number>} input Input coordinate array.
  5403. * @param {Array.<number>=} opt_output Output array of coordinate values.
  5404. * @param {number=} opt_dimension Dimension.
  5405. * @return {Array.<number>} Input coordinate array (same array as input).
  5406. */
  5407. ol.proj.identityTransform = function(input, opt_output, opt_dimension) {
  5408. if (opt_output !== undefined && input !== opt_output) {
  5409. for (var i = 0, ii = input.length; i < ii; ++i) {
  5410. opt_output[i] = input[i];
  5411. }
  5412. input = opt_output;
  5413. }
  5414. return input;
  5415. };
  5416. /**
  5417. * @param {Array.<number>} input Input coordinate array.
  5418. * @param {Array.<number>=} opt_output Output array of coordinate values.
  5419. * @param {number=} opt_dimension Dimension.
  5420. * @return {Array.<number>} Output coordinate array (new array, same coordinate
  5421. * values).
  5422. */
  5423. ol.proj.cloneTransform = function(input, opt_output, opt_dimension) {
  5424. var output;
  5425. if (opt_output !== undefined) {
  5426. for (var i = 0, ii = input.length; i < ii; ++i) {
  5427. opt_output[i] = input[i];
  5428. }
  5429. output = opt_output;
  5430. } else {
  5431. output = input.slice();
  5432. }
  5433. return output;
  5434. };
  5435. /**
  5436. * Transforms a coordinate from source projection to destination projection.
  5437. * This returns a new coordinate (and does not modify the original).
  5438. *
  5439. * See {@link ol.proj.transformExtent} for extent transformation.
  5440. * See the transform method of {@link ol.geom.Geometry} and its subclasses for
  5441. * geometry transforms.
  5442. *
  5443. * @param {ol.Coordinate} coordinate Coordinate.
  5444. * @param {ol.ProjectionLike} source Source projection-like.
  5445. * @param {ol.ProjectionLike} destination Destination projection-like.
  5446. * @return {ol.Coordinate} Coordinate.
  5447. * @api
  5448. */
  5449. ol.proj.transform = function(coordinate, source, destination) {
  5450. var transformFn = ol.proj.getTransform(source, destination);
  5451. return transformFn(coordinate, undefined, coordinate.length);
  5452. };
  5453. /**
  5454. * Transforms an extent from source projection to destination projection. This
  5455. * returns a new extent (and does not modify the original).
  5456. *
  5457. * @param {ol.Extent} extent The extent to transform.
  5458. * @param {ol.ProjectionLike} source Source projection-like.
  5459. * @param {ol.ProjectionLike} destination Destination projection-like.
  5460. * @return {ol.Extent} The transformed extent.
  5461. * @api
  5462. */
  5463. ol.proj.transformExtent = function(extent, source, destination) {
  5464. var transformFn = ol.proj.getTransform(source, destination);
  5465. return ol.extent.applyTransform(extent, transformFn);
  5466. };
  5467. /**
  5468. * Transforms the given point to the destination projection.
  5469. *
  5470. * @param {ol.Coordinate} point Point.
  5471. * @param {ol.proj.Projection} sourceProjection Source projection.
  5472. * @param {ol.proj.Projection} destinationProjection Destination projection.
  5473. * @return {ol.Coordinate} Point.
  5474. */
  5475. ol.proj.transformWithProjections = function(point, sourceProjection, destinationProjection) {
  5476. var transformFn = ol.proj.getTransformFromProjections(
  5477. sourceProjection, destinationProjection);
  5478. return transformFn(point);
  5479. };
  5480. /**
  5481. * Add transforms to and from EPSG:4326 and EPSG:3857. This function is called
  5482. * by when this module is executed and should only need to be called again after
  5483. * `ol.proj.clearAllProjections()` is called (e.g. in tests).
  5484. */
  5485. ol.proj.addCommon = function() {
  5486. // Add transformations that don't alter coordinates to convert within set of
  5487. // projections with equal meaning.
  5488. ol.proj.addEquivalentProjections(ol.proj.EPSG3857.PROJECTIONS);
  5489. ol.proj.addEquivalentProjections(ol.proj.EPSG4326.PROJECTIONS);
  5490. // Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
  5491. // coordinates and back.
  5492. ol.proj.addEquivalentTransforms(
  5493. ol.proj.EPSG4326.PROJECTIONS,
  5494. ol.proj.EPSG3857.PROJECTIONS,
  5495. ol.proj.EPSG3857.fromEPSG4326,
  5496. ol.proj.EPSG3857.toEPSG4326);
  5497. };
  5498. ol.proj.addCommon();
  5499. goog.provide('ol.tilecoord');
  5500. /**
  5501. * @param {number} z Z.
  5502. * @param {number} x X.
  5503. * @param {number} y Y.
  5504. * @param {ol.TileCoord=} opt_tileCoord Tile coordinate.
  5505. * @return {ol.TileCoord} Tile coordinate.
  5506. */
  5507. ol.tilecoord.createOrUpdate = function(z, x, y, opt_tileCoord) {
  5508. if (opt_tileCoord !== undefined) {
  5509. opt_tileCoord[0] = z;
  5510. opt_tileCoord[1] = x;
  5511. opt_tileCoord[2] = y;
  5512. return opt_tileCoord;
  5513. } else {
  5514. return [z, x, y];
  5515. }
  5516. };
  5517. /**
  5518. * @param {number} z Z.
  5519. * @param {number} x X.
  5520. * @param {number} y Y.
  5521. * @return {string} Key.
  5522. */
  5523. ol.tilecoord.getKeyZXY = function(z, x, y) {
  5524. return z + '/' + x + '/' + y;
  5525. };
  5526. /**
  5527. * Get the key for a tile coord.
  5528. * @param {ol.TileCoord} tileCoord The tile coord.
  5529. * @return {string} Key.
  5530. */
  5531. ol.tilecoord.getKey = function(tileCoord) {
  5532. return ol.tilecoord.getKeyZXY(tileCoord[0], tileCoord[1], tileCoord[2]);
  5533. };
  5534. /**
  5535. * Get a tile coord given a key.
  5536. * @param {string} key The tile coord key.
  5537. * @return {ol.TileCoord} The tile coord.
  5538. */
  5539. ol.tilecoord.fromKey = function(key) {
  5540. return key.split('/').map(Number);
  5541. };
  5542. /**
  5543. * @param {ol.TileCoord} tileCoord Tile coord.
  5544. * @return {number} Hash.
  5545. */
  5546. ol.tilecoord.hash = function(tileCoord) {
  5547. return (tileCoord[1] << tileCoord[0]) + tileCoord[2];
  5548. };
  5549. /**
  5550. * @param {ol.TileCoord} tileCoord Tile coord.
  5551. * @return {string} Quad key.
  5552. */
  5553. ol.tilecoord.quadKey = function(tileCoord) {
  5554. var z = tileCoord[0];
  5555. var digits = new Array(z);
  5556. var mask = 1 << (z - 1);
  5557. var i, charCode;
  5558. for (i = 0; i < z; ++i) {
  5559. // 48 is charCode for 0 - '0'.charCodeAt(0)
  5560. charCode = 48;
  5561. if (tileCoord[1] & mask) {
  5562. charCode += 1;
  5563. }
  5564. if (tileCoord[2] & mask) {
  5565. charCode += 2;
  5566. }
  5567. digits[i] = String.fromCharCode(charCode);
  5568. mask >>= 1;
  5569. }
  5570. return digits.join('');
  5571. };
  5572. /**
  5573. * @param {ol.TileCoord} tileCoord Tile coordinate.
  5574. * @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
  5575. * @return {boolean} Tile coordinate is within extent and zoom level range.
  5576. */
  5577. ol.tilecoord.withinExtentAndZ = function(tileCoord, tileGrid) {
  5578. var z = tileCoord[0];
  5579. var x = tileCoord[1];
  5580. var y = tileCoord[2];
  5581. if (tileGrid.getMinZoom() > z || z > tileGrid.getMaxZoom()) {
  5582. return false;
  5583. }
  5584. var extent = tileGrid.getExtent();
  5585. var tileRange;
  5586. if (!extent) {
  5587. tileRange = tileGrid.getFullTileRange(z);
  5588. } else {
  5589. tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
  5590. }
  5591. if (!tileRange) {
  5592. return true;
  5593. } else {
  5594. return tileRange.containsXY(x, y);
  5595. }
  5596. };
  5597. goog.provide('ol.tilegrid.TileGrid');
  5598. goog.require('ol');
  5599. goog.require('ol.asserts');
  5600. goog.require('ol.TileRange');
  5601. goog.require('ol.array');
  5602. goog.require('ol.extent');
  5603. goog.require('ol.math');
  5604. goog.require('ol.size');
  5605. goog.require('ol.tilecoord');
  5606. /**
  5607. * @classdesc
  5608. * Base class for setting the grid pattern for sources accessing tiled-image
  5609. * servers.
  5610. *
  5611. * @constructor
  5612. * @param {olx.tilegrid.TileGridOptions} options Tile grid options.
  5613. * @struct
  5614. * @api
  5615. */
  5616. ol.tilegrid.TileGrid = function(options) {
  5617. /**
  5618. * @protected
  5619. * @type {number}
  5620. */
  5621. this.minZoom = options.minZoom !== undefined ? options.minZoom : 0;
  5622. /**
  5623. * @private
  5624. * @type {!Array.<number>}
  5625. */
  5626. this.resolutions_ = options.resolutions;
  5627. ol.asserts.assert(ol.array.isSorted(this.resolutions_, function(a, b) {
  5628. return b - a;
  5629. }, true), 17); // `resolutions` must be sorted in descending order
  5630. // check if we've got a consistent zoom factor and origin
  5631. var zoomFactor;
  5632. if (!options.origins) {
  5633. for (var i = 0, ii = this.resolutions_.length - 1; i < ii; ++i) {
  5634. if (!zoomFactor) {
  5635. zoomFactor = this.resolutions_[i] / this.resolutions_[i + 1];
  5636. } else {
  5637. if (this.resolutions_[i] / this.resolutions_[i + 1] !== zoomFactor) {
  5638. zoomFactor = undefined;
  5639. break;
  5640. }
  5641. }
  5642. }
  5643. }
  5644. /**
  5645. * @private
  5646. * @type {number|undefined}
  5647. */
  5648. this.zoomFactor_ = zoomFactor;
  5649. /**
  5650. * @protected
  5651. * @type {number}
  5652. */
  5653. this.maxZoom = this.resolutions_.length - 1;
  5654. /**
  5655. * @private
  5656. * @type {ol.Coordinate}
  5657. */
  5658. this.origin_ = options.origin !== undefined ? options.origin : null;
  5659. /**
  5660. * @private
  5661. * @type {Array.<ol.Coordinate>}
  5662. */
  5663. this.origins_ = null;
  5664. if (options.origins !== undefined) {
  5665. this.origins_ = options.origins;
  5666. ol.asserts.assert(this.origins_.length == this.resolutions_.length,
  5667. 20); // Number of `origins` and `resolutions` must be equal
  5668. }
  5669. var extent = options.extent;
  5670. if (extent !== undefined &&
  5671. !this.origin_ && !this.origins_) {
  5672. this.origin_ = ol.extent.getTopLeft(extent);
  5673. }
  5674. ol.asserts.assert(
  5675. (!this.origin_ && this.origins_) || (this.origin_ && !this.origins_),
  5676. 18); // Either `origin` or `origins` must be configured, never both
  5677. /**
  5678. * @private
  5679. * @type {Array.<number|ol.Size>}
  5680. */
  5681. this.tileSizes_ = null;
  5682. if (options.tileSizes !== undefined) {
  5683. this.tileSizes_ = options.tileSizes;
  5684. ol.asserts.assert(this.tileSizes_.length == this.resolutions_.length,
  5685. 19); // Number of `tileSizes` and `resolutions` must be equal
  5686. }
  5687. /**
  5688. * @private
  5689. * @type {number|ol.Size}
  5690. */
  5691. this.tileSize_ = options.tileSize !== undefined ?
  5692. options.tileSize :
  5693. !this.tileSizes_ ? ol.DEFAULT_TILE_SIZE : null;
  5694. ol.asserts.assert(
  5695. (!this.tileSize_ && this.tileSizes_) ||
  5696. (this.tileSize_ && !this.tileSizes_),
  5697. 22); // Either `tileSize` or `tileSizes` must be configured, never both
  5698. /**
  5699. * @private
  5700. * @type {ol.Extent}
  5701. */
  5702. this.extent_ = extent !== undefined ? extent : null;
  5703. /**
  5704. * @private
  5705. * @type {Array.<ol.TileRange>}
  5706. */
  5707. this.fullTileRanges_ = null;
  5708. /**
  5709. * @private
  5710. * @type {ol.Size}
  5711. */
  5712. this.tmpSize_ = [0, 0];
  5713. if (options.sizes !== undefined) {
  5714. this.fullTileRanges_ = options.sizes.map(function(size, z) {
  5715. var tileRange = new ol.TileRange(
  5716. Math.min(0, size[0]), Math.max(size[0] - 1, -1),
  5717. Math.min(0, size[1]), Math.max(size[1] - 1, -1));
  5718. return tileRange;
  5719. }, this);
  5720. } else if (extent) {
  5721. this.calculateTileRanges_(extent);
  5722. }
  5723. };
  5724. /**
  5725. * @private
  5726. * @type {ol.TileCoord}
  5727. */
  5728. ol.tilegrid.TileGrid.tmpTileCoord_ = [0, 0, 0];
  5729. /**
  5730. * Call a function with each tile coordinate for a given extent and zoom level.
  5731. *
  5732. * @param {ol.Extent} extent Extent.
  5733. * @param {number} zoom Integer zoom level.
  5734. * @param {function(ol.TileCoord)} callback Function called with each tile coordinate.
  5735. * @api
  5736. */
  5737. ol.tilegrid.TileGrid.prototype.forEachTileCoord = function(extent, zoom, callback) {
  5738. var tileRange = this.getTileRangeForExtentAndZ(extent, zoom);
  5739. for (var i = tileRange.minX, ii = tileRange.maxX; i <= ii; ++i) {
  5740. for (var j = tileRange.minY, jj = tileRange.maxY; j <= jj; ++j) {
  5741. callback([zoom, i, j]);
  5742. }
  5743. }
  5744. };
  5745. /**
  5746. * @param {ol.TileCoord} tileCoord Tile coordinate.
  5747. * @param {function(this: T, number, ol.TileRange): boolean} callback Callback.
  5748. * @param {T=} opt_this The object to use as `this` in `callback`.
  5749. * @param {ol.TileRange=} opt_tileRange Temporary ol.TileRange object.
  5750. * @param {ol.Extent=} opt_extent Temporary ol.Extent object.
  5751. * @return {boolean} Callback succeeded.
  5752. * @template T
  5753. */
  5754. ol.tilegrid.TileGrid.prototype.forEachTileCoordParentTileRange = function(tileCoord, callback, opt_this, opt_tileRange, opt_extent) {
  5755. var tileRange, x, y;
  5756. var tileCoordExtent = null;
  5757. var z = tileCoord[0] - 1;
  5758. if (this.zoomFactor_ === 2) {
  5759. x = tileCoord[1];
  5760. y = tileCoord[2];
  5761. } else {
  5762. tileCoordExtent = this.getTileCoordExtent(tileCoord, opt_extent);
  5763. }
  5764. while (z >= this.minZoom) {
  5765. if (this.zoomFactor_ === 2) {
  5766. x = Math.floor(x / 2);
  5767. y = Math.floor(y / 2);
  5768. tileRange = ol.TileRange.createOrUpdate(x, x, y, y, opt_tileRange);
  5769. } else {
  5770. tileRange = this.getTileRangeForExtentAndZ(tileCoordExtent, z, opt_tileRange);
  5771. }
  5772. if (callback.call(opt_this, z, tileRange)) {
  5773. return true;
  5774. }
  5775. --z;
  5776. }
  5777. return false;
  5778. };
  5779. /**
  5780. * Get the extent for this tile grid, if it was configured.
  5781. * @return {ol.Extent} Extent.
  5782. */
  5783. ol.tilegrid.TileGrid.prototype.getExtent = function() {
  5784. return this.extent_;
  5785. };
  5786. /**
  5787. * Get the maximum zoom level for the grid.
  5788. * @return {number} Max zoom.
  5789. * @api
  5790. */
  5791. ol.tilegrid.TileGrid.prototype.getMaxZoom = function() {
  5792. return this.maxZoom;
  5793. };
  5794. /**
  5795. * Get the minimum zoom level for the grid.
  5796. * @return {number} Min zoom.
  5797. * @api
  5798. */
  5799. ol.tilegrid.TileGrid.prototype.getMinZoom = function() {
  5800. return this.minZoom;
  5801. };
  5802. /**
  5803. * Get the origin for the grid at the given zoom level.
  5804. * @param {number} z Integer zoom level.
  5805. * @return {ol.Coordinate} Origin.
  5806. * @api
  5807. */
  5808. ol.tilegrid.TileGrid.prototype.getOrigin = function(z) {
  5809. if (this.origin_) {
  5810. return this.origin_;
  5811. } else {
  5812. return this.origins_[z];
  5813. }
  5814. };
  5815. /**
  5816. * Get the resolution for the given zoom level.
  5817. * @param {number} z Integer zoom level.
  5818. * @return {number} Resolution.
  5819. * @api
  5820. */
  5821. ol.tilegrid.TileGrid.prototype.getResolution = function(z) {
  5822. return this.resolutions_[z];
  5823. };
  5824. /**
  5825. * Get the list of resolutions for the tile grid.
  5826. * @return {Array.<number>} Resolutions.
  5827. * @api
  5828. */
  5829. ol.tilegrid.TileGrid.prototype.getResolutions = function() {
  5830. return this.resolutions_;
  5831. };
  5832. /**
  5833. * @param {ol.TileCoord} tileCoord Tile coordinate.
  5834. * @param {ol.TileRange=} opt_tileRange Temporary ol.TileRange object.
  5835. * @param {ol.Extent=} opt_extent Temporary ol.Extent object.
  5836. * @return {ol.TileRange} Tile range.
  5837. */
  5838. ol.tilegrid.TileGrid.prototype.getTileCoordChildTileRange = function(tileCoord, opt_tileRange, opt_extent) {
  5839. if (tileCoord[0] < this.maxZoom) {
  5840. if (this.zoomFactor_ === 2) {
  5841. var minX = tileCoord[1] * 2;
  5842. var minY = tileCoord[2] * 2;
  5843. return ol.TileRange.createOrUpdate(minX, minX + 1, minY, minY + 1, opt_tileRange);
  5844. }
  5845. var tileCoordExtent = this.getTileCoordExtent(tileCoord, opt_extent);
  5846. return this.getTileRangeForExtentAndZ(
  5847. tileCoordExtent, tileCoord[0] + 1, opt_tileRange);
  5848. }
  5849. return null;
  5850. };
  5851. /**
  5852. * Get the extent for a tile range.
  5853. * @param {number} z Integer zoom level.
  5854. * @param {ol.TileRange} tileRange Tile range.
  5855. * @param {ol.Extent=} opt_extent Temporary ol.Extent object.
  5856. * @return {ol.Extent} Extent.
  5857. */
  5858. ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange, opt_extent) {
  5859. var origin = this.getOrigin(z);
  5860. var resolution = this.getResolution(z);
  5861. var tileSize = ol.size.toSize(this.getTileSize(z), this.tmpSize_);
  5862. var minX = origin[0] + tileRange.minX * tileSize[0] * resolution;
  5863. var maxX = origin[0] + (tileRange.maxX + 1) * tileSize[0] * resolution;
  5864. var minY = origin[1] + tileRange.minY * tileSize[1] * resolution;
  5865. var maxY = origin[1] + (tileRange.maxY + 1) * tileSize[1] * resolution;
  5866. return ol.extent.createOrUpdate(minX, minY, maxX, maxY, opt_extent);
  5867. };
  5868. /**
  5869. * Get a tile range for the given extent and integer zoom level.
  5870. * @param {ol.Extent} extent Extent.
  5871. * @param {number} z Integer zoom level.
  5872. * @param {ol.TileRange=} opt_tileRange Temporary tile range object.
  5873. * @return {ol.TileRange} Tile range.
  5874. */
  5875. ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange) {
  5876. var tileCoord = ol.tilegrid.TileGrid.tmpTileCoord_;
  5877. this.getTileCoordForXYAndZ_(extent[0], extent[1], z, false, tileCoord);
  5878. var minX = tileCoord[1];
  5879. var minY = tileCoord[2];
  5880. this.getTileCoordForXYAndZ_(extent[2], extent[3], z, true, tileCoord);
  5881. return ol.TileRange.createOrUpdate(
  5882. minX, tileCoord[1], minY, tileCoord[2], opt_tileRange);
  5883. };
  5884. /**
  5885. * @param {ol.TileCoord} tileCoord Tile coordinate.
  5886. * @return {ol.Coordinate} Tile center.
  5887. */
  5888. ol.tilegrid.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
  5889. var origin = this.getOrigin(tileCoord[0]);
  5890. var resolution = this.getResolution(tileCoord[0]);
  5891. var tileSize = ol.size.toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
  5892. return [
  5893. origin[0] + (tileCoord[1] + 0.5) * tileSize[0] * resolution,
  5894. origin[1] + (tileCoord[2] + 0.5) * tileSize[1] * resolution
  5895. ];
  5896. };
  5897. /**
  5898. * Get the extent of a tile coordinate.
  5899. *
  5900. * @param {ol.TileCoord} tileCoord Tile coordinate.
  5901. * @param {ol.Extent=} opt_extent Temporary extent object.
  5902. * @return {ol.Extent} Extent.
  5903. * @api
  5904. */
  5905. ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord, opt_extent) {
  5906. var origin = this.getOrigin(tileCoord[0]);
  5907. var resolution = this.getResolution(tileCoord[0]);
  5908. var tileSize = ol.size.toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
  5909. var minX = origin[0] + tileCoord[1] * tileSize[0] * resolution;
  5910. var minY = origin[1] + tileCoord[2] * tileSize[1] * resolution;
  5911. var maxX = minX + tileSize[0] * resolution;
  5912. var maxY = minY + tileSize[1] * resolution;
  5913. return ol.extent.createOrUpdate(minX, minY, maxX, maxY, opt_extent);
  5914. };
  5915. /**
  5916. * Get the tile coordinate for the given map coordinate and resolution. This
  5917. * method considers that coordinates that intersect tile boundaries should be
  5918. * assigned the higher tile coordinate.
  5919. *
  5920. * @param {ol.Coordinate} coordinate Coordinate.
  5921. * @param {number} resolution Resolution.
  5922. * @param {ol.TileCoord=} opt_tileCoord Destination ol.TileCoord object.
  5923. * @return {ol.TileCoord} Tile coordinate.
  5924. * @api
  5925. */
  5926. ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(coordinate, resolution, opt_tileCoord) {
  5927. return this.getTileCoordForXYAndResolution_(
  5928. coordinate[0], coordinate[1], resolution, false, opt_tileCoord);
  5929. };
  5930. /**
  5931. * Note that this method should not be called for resolutions that correspond
  5932. * to an integer zoom level. Instead call the `getTileCoordForXYAndZ_` method.
  5933. * @param {number} x X.
  5934. * @param {number} y Y.
  5935. * @param {number} resolution Resolution (for a non-integer zoom level).
  5936. * @param {boolean} reverseIntersectionPolicy Instead of letting edge
  5937. * intersections go to the higher tile coordinate, let edge intersections
  5938. * go to the lower tile coordinate.
  5939. * @param {ol.TileCoord=} opt_tileCoord Temporary ol.TileCoord object.
  5940. * @return {ol.TileCoord} Tile coordinate.
  5941. * @private
  5942. */
  5943. ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
  5944. x, y, resolution, reverseIntersectionPolicy, opt_tileCoord) {
  5945. var z = this.getZForResolution(resolution);
  5946. var scale = resolution / this.getResolution(z);
  5947. var origin = this.getOrigin(z);
  5948. var tileSize = ol.size.toSize(this.getTileSize(z), this.tmpSize_);
  5949. var adjustX = reverseIntersectionPolicy ? 0.5 : 0;
  5950. var adjustY = reverseIntersectionPolicy ? 0 : 0.5;
  5951. var xFromOrigin = Math.floor((x - origin[0]) / resolution + adjustX);
  5952. var yFromOrigin = Math.floor((y - origin[1]) / resolution + adjustY);
  5953. var tileCoordX = scale * xFromOrigin / tileSize[0];
  5954. var tileCoordY = scale * yFromOrigin / tileSize[1];
  5955. if (reverseIntersectionPolicy) {
  5956. tileCoordX = Math.ceil(tileCoordX) - 1;
  5957. tileCoordY = Math.ceil(tileCoordY) - 1;
  5958. } else {
  5959. tileCoordX = Math.floor(tileCoordX);
  5960. tileCoordY = Math.floor(tileCoordY);
  5961. }
  5962. return ol.tilecoord.createOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord);
  5963. };
  5964. /**
  5965. * Although there is repetition between this method and `getTileCoordForXYAndResolution_`,
  5966. * they should have separate implementations. This method is for integer zoom
  5967. * levels. The other method should only be called for resolutions corresponding
  5968. * to non-integer zoom levels.
  5969. * @param {number} x Map x coordinate.
  5970. * @param {number} y Map y coordinate.
  5971. * @param {number} z Integer zoom level.
  5972. * @param {boolean} reverseIntersectionPolicy Instead of letting edge
  5973. * intersections go to the higher tile coordinate, let edge intersections
  5974. * go to the lower tile coordinate.
  5975. * @param {ol.TileCoord=} opt_tileCoord Temporary ol.TileCoord object.
  5976. * @return {ol.TileCoord} Tile coordinate.
  5977. * @private
  5978. */
  5979. ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectionPolicy, opt_tileCoord) {
  5980. var origin = this.getOrigin(z);
  5981. var resolution = this.getResolution(z);
  5982. var tileSize = ol.size.toSize(this.getTileSize(z), this.tmpSize_);
  5983. var adjustX = reverseIntersectionPolicy ? 0.5 : 0;
  5984. var adjustY = reverseIntersectionPolicy ? 0 : 0.5;
  5985. var xFromOrigin = Math.floor((x - origin[0]) / resolution + adjustX);
  5986. var yFromOrigin = Math.floor((y - origin[1]) / resolution + adjustY);
  5987. var tileCoordX = xFromOrigin / tileSize[0];
  5988. var tileCoordY = yFromOrigin / tileSize[1];
  5989. if (reverseIntersectionPolicy) {
  5990. tileCoordX = Math.ceil(tileCoordX) - 1;
  5991. tileCoordY = Math.ceil(tileCoordY) - 1;
  5992. } else {
  5993. tileCoordX = Math.floor(tileCoordX);
  5994. tileCoordY = Math.floor(tileCoordY);
  5995. }
  5996. return ol.tilecoord.createOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord);
  5997. };
  5998. /**
  5999. * Get a tile coordinate given a map coordinate and zoom level.
  6000. * @param {ol.Coordinate} coordinate Coordinate.
  6001. * @param {number} z Zoom level.
  6002. * @param {ol.TileCoord=} opt_tileCoord Destination ol.TileCoord object.
  6003. * @return {ol.TileCoord} Tile coordinate.
  6004. * @api
  6005. */
  6006. ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ = function(coordinate, z, opt_tileCoord) {
  6007. return this.getTileCoordForXYAndZ_(
  6008. coordinate[0], coordinate[1], z, false, opt_tileCoord);
  6009. };
  6010. /**
  6011. * @param {ol.TileCoord} tileCoord Tile coordinate.
  6012. * @return {number} Tile resolution.
  6013. */
  6014. ol.tilegrid.TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
  6015. return this.resolutions_[tileCoord[0]];
  6016. };
  6017. /**
  6018. * Get the tile size for a zoom level. The type of the return value matches the
  6019. * `tileSize` or `tileSizes` that the tile grid was configured with. To always
  6020. * get an `ol.Size`, run the result through `ol.size.toSize()`.
  6021. * @param {number} z Z.
  6022. * @return {number|ol.Size} Tile size.
  6023. * @api
  6024. */
  6025. ol.tilegrid.TileGrid.prototype.getTileSize = function(z) {
  6026. if (this.tileSize_) {
  6027. return this.tileSize_;
  6028. } else {
  6029. return this.tileSizes_[z];
  6030. }
  6031. };
  6032. /**
  6033. * @param {number} z Zoom level.
  6034. * @return {ol.TileRange} Extent tile range for the specified zoom level.
  6035. */
  6036. ol.tilegrid.TileGrid.prototype.getFullTileRange = function(z) {
  6037. if (!this.fullTileRanges_) {
  6038. return null;
  6039. } else {
  6040. return this.fullTileRanges_[z];
  6041. }
  6042. };
  6043. /**
  6044. * @param {number} resolution Resolution.
  6045. * @param {number=} opt_direction If 0, the nearest resolution will be used.
  6046. * If 1, the nearest lower resolution will be used. If -1, the nearest
  6047. * higher resolution will be used. Default is 0.
  6048. * @return {number} Z.
  6049. * @api
  6050. */
  6051. ol.tilegrid.TileGrid.prototype.getZForResolution = function(
  6052. resolution, opt_direction) {
  6053. var z = ol.array.linearFindNearest(this.resolutions_, resolution,
  6054. opt_direction || 0);
  6055. return ol.math.clamp(z, this.minZoom, this.maxZoom);
  6056. };
  6057. /**
  6058. * @param {!ol.Extent} extent Extent for this tile grid.
  6059. * @private
  6060. */
  6061. ol.tilegrid.TileGrid.prototype.calculateTileRanges_ = function(extent) {
  6062. var length = this.resolutions_.length;
  6063. var fullTileRanges = new Array(length);
  6064. for (var z = this.minZoom; z < length; ++z) {
  6065. fullTileRanges[z] = this.getTileRangeForExtentAndZ(extent, z);
  6066. }
  6067. this.fullTileRanges_ = fullTileRanges;
  6068. };
  6069. goog.provide('ol.tilegrid');
  6070. goog.require('ol');
  6071. goog.require('ol.size');
  6072. goog.require('ol.extent');
  6073. goog.require('ol.extent.Corner');
  6074. goog.require('ol.obj');
  6075. goog.require('ol.proj');
  6076. goog.require('ol.proj.Units');
  6077. goog.require('ol.tilegrid.TileGrid');
  6078. /**
  6079. * @param {ol.proj.Projection} projection Projection.
  6080. * @return {!ol.tilegrid.TileGrid} Default tile grid for the passed projection.
  6081. */
  6082. ol.tilegrid.getForProjection = function(projection) {
  6083. var tileGrid = projection.getDefaultTileGrid();
  6084. if (!tileGrid) {
  6085. tileGrid = ol.tilegrid.createForProjection(projection);
  6086. projection.setDefaultTileGrid(tileGrid);
  6087. }
  6088. return tileGrid;
  6089. };
  6090. /**
  6091. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
  6092. * @param {ol.TileCoord} tileCoord Tile coordinate.
  6093. * @param {ol.proj.Projection} projection Projection.
  6094. * @return {ol.TileCoord} Tile coordinate.
  6095. */
  6096. ol.tilegrid.wrapX = function(tileGrid, tileCoord, projection) {
  6097. var z = tileCoord[0];
  6098. var center = tileGrid.getTileCoordCenter(tileCoord);
  6099. var projectionExtent = ol.tilegrid.extentFromProjection(projection);
  6100. if (!ol.extent.containsCoordinate(projectionExtent, center)) {
  6101. var worldWidth = ol.extent.getWidth(projectionExtent);
  6102. var worldsAway = Math.ceil((projectionExtent[0] - center[0]) / worldWidth);
  6103. center[0] += worldWidth * worldsAway;
  6104. return tileGrid.getTileCoordForCoordAndZ(center, z);
  6105. } else {
  6106. return tileCoord;
  6107. }
  6108. };
  6109. /**
  6110. * @param {ol.Extent} extent Extent.
  6111. * @param {number=} opt_maxZoom Maximum zoom level (default is
  6112. * ol.DEFAULT_MAX_ZOOM).
  6113. * @param {number|ol.Size=} opt_tileSize Tile size (default uses
  6114. * ol.DEFAULT_TILE_SIZE).
  6115. * @param {ol.extent.Corner=} opt_corner Extent corner (default is
  6116. * ol.extent.Corner.TOP_LEFT).
  6117. * @return {!ol.tilegrid.TileGrid} TileGrid instance.
  6118. */
  6119. ol.tilegrid.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_corner) {
  6120. var corner = opt_corner !== undefined ?
  6121. opt_corner : ol.extent.Corner.TOP_LEFT;
  6122. var resolutions = ol.tilegrid.resolutionsFromExtent(
  6123. extent, opt_maxZoom, opt_tileSize);
  6124. return new ol.tilegrid.TileGrid({
  6125. extent: extent,
  6126. origin: ol.extent.getCorner(extent, corner),
  6127. resolutions: resolutions,
  6128. tileSize: opt_tileSize
  6129. });
  6130. };
  6131. /**
  6132. * Creates a tile grid with a standard XYZ tiling scheme.
  6133. * @param {olx.tilegrid.XYZOptions=} opt_options Tile grid options.
  6134. * @return {!ol.tilegrid.TileGrid} Tile grid instance.
  6135. * @api
  6136. */
  6137. ol.tilegrid.createXYZ = function(opt_options) {
  6138. var options = /** @type {olx.tilegrid.TileGridOptions} */ ({});
  6139. ol.obj.assign(options, opt_options !== undefined ?
  6140. opt_options : /** @type {olx.tilegrid.XYZOptions} */ ({}));
  6141. if (options.extent === undefined) {
  6142. options.extent = ol.proj.get('EPSG:3857').getExtent();
  6143. }
  6144. options.resolutions = ol.tilegrid.resolutionsFromExtent(
  6145. options.extent, options.maxZoom, options.tileSize);
  6146. delete options.maxZoom;
  6147. return new ol.tilegrid.TileGrid(options);
  6148. };
  6149. /**
  6150. * Create a resolutions array from an extent. A zoom factor of 2 is assumed.
  6151. * @param {ol.Extent} extent Extent.
  6152. * @param {number=} opt_maxZoom Maximum zoom level (default is
  6153. * ol.DEFAULT_MAX_ZOOM).
  6154. * @param {number|ol.Size=} opt_tileSize Tile size (default uses
  6155. * ol.DEFAULT_TILE_SIZE).
  6156. * @return {!Array.<number>} Resolutions array.
  6157. */
  6158. ol.tilegrid.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize) {
  6159. var maxZoom = opt_maxZoom !== undefined ?
  6160. opt_maxZoom : ol.DEFAULT_MAX_ZOOM;
  6161. var height = ol.extent.getHeight(extent);
  6162. var width = ol.extent.getWidth(extent);
  6163. var tileSize = ol.size.toSize(opt_tileSize !== undefined ?
  6164. opt_tileSize : ol.DEFAULT_TILE_SIZE);
  6165. var maxResolution = Math.max(
  6166. width / tileSize[0], height / tileSize[1]);
  6167. var length = maxZoom + 1;
  6168. var resolutions = new Array(length);
  6169. for (var z = 0; z < length; ++z) {
  6170. resolutions[z] = maxResolution / Math.pow(2, z);
  6171. }
  6172. return resolutions;
  6173. };
  6174. /**
  6175. * @param {ol.ProjectionLike} projection Projection.
  6176. * @param {number=} opt_maxZoom Maximum zoom level (default is
  6177. * ol.DEFAULT_MAX_ZOOM).
  6178. * @param {number|ol.Size=} opt_tileSize Tile size (default uses
  6179. * ol.DEFAULT_TILE_SIZE).
  6180. * @param {ol.extent.Corner=} opt_corner Extent corner (default is
  6181. * ol.extent.Corner.BOTTOM_LEFT).
  6182. * @return {!ol.tilegrid.TileGrid} TileGrid instance.
  6183. */
  6184. ol.tilegrid.createForProjection = function(projection, opt_maxZoom, opt_tileSize, opt_corner) {
  6185. var extent = ol.tilegrid.extentFromProjection(projection);
  6186. return ol.tilegrid.createForExtent(
  6187. extent, opt_maxZoom, opt_tileSize, opt_corner);
  6188. };
  6189. /**
  6190. * Generate a tile grid extent from a projection. If the projection has an
  6191. * extent, it is used. If not, a global extent is assumed.
  6192. * @param {ol.ProjectionLike} projection Projection.
  6193. * @return {ol.Extent} Extent.
  6194. */
  6195. ol.tilegrid.extentFromProjection = function(projection) {
  6196. projection = ol.proj.get(projection);
  6197. var extent = projection.getExtent();
  6198. if (!extent) {
  6199. var half = 180 * ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES] /
  6200. projection.getMetersPerUnit();
  6201. extent = ol.extent.createOrUpdate(-half, -half, half, half);
  6202. }
  6203. return extent;
  6204. };
  6205. goog.provide('ol.Attribution');
  6206. goog.require('ol.TileRange');
  6207. goog.require('ol.math');
  6208. goog.require('ol.tilegrid');
  6209. /**
  6210. * @classdesc
  6211. * An attribution for a layer source.
  6212. *
  6213. * Example:
  6214. *
  6215. * source: new ol.source.OSM({
  6216. * attributions: [
  6217. * new ol.Attribution({
  6218. * html: 'All maps &copy; ' +
  6219. * '<a href="https://www.opencyclemap.org/">OpenCycleMap</a>'
  6220. * }),
  6221. * ol.source.OSM.ATTRIBUTION
  6222. * ],
  6223. * ..
  6224. *
  6225. * @constructor
  6226. * @deprecated This class is deprecated and will removed in the next major release.
  6227. * @param {olx.AttributionOptions} options Attribution options.
  6228. * @struct
  6229. * @api
  6230. */
  6231. ol.Attribution = function(options) {
  6232. /**
  6233. * @private
  6234. * @type {string}
  6235. */
  6236. this.html_ = options.html;
  6237. /**
  6238. * @private
  6239. * @type {Object.<string, Array.<ol.TileRange>>}
  6240. */
  6241. this.tileRanges_ = options.tileRanges ? options.tileRanges : null;
  6242. };
  6243. /**
  6244. * Get the attribution markup.
  6245. * @return {string} The attribution HTML.
  6246. * @api
  6247. */
  6248. ol.Attribution.prototype.getHTML = function() {
  6249. return this.html_;
  6250. };
  6251. /**
  6252. * @param {Object.<string, ol.TileRange>} tileRanges Tile ranges.
  6253. * @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
  6254. * @param {!ol.proj.Projection} projection Projection.
  6255. * @return {boolean} Intersects any tile range.
  6256. */
  6257. ol.Attribution.prototype.intersectsAnyTileRange = function(tileRanges, tileGrid, projection) {
  6258. if (!this.tileRanges_) {
  6259. return true;
  6260. }
  6261. var i, ii, tileRange, zKey;
  6262. for (zKey in tileRanges) {
  6263. if (!(zKey in this.tileRanges_)) {
  6264. continue;
  6265. }
  6266. tileRange = tileRanges[zKey];
  6267. var testTileRange;
  6268. for (i = 0, ii = this.tileRanges_[zKey].length; i < ii; ++i) {
  6269. testTileRange = this.tileRanges_[zKey][i];
  6270. if (testTileRange.intersects(tileRange)) {
  6271. return true;
  6272. }
  6273. var extentTileRange = tileGrid.getTileRangeForExtentAndZ(
  6274. ol.tilegrid.extentFromProjection(projection), parseInt(zKey, 10));
  6275. var width = extentTileRange.getWidth();
  6276. if (tileRange.minX < extentTileRange.minX ||
  6277. tileRange.maxX > extentTileRange.maxX) {
  6278. if (testTileRange.intersects(new ol.TileRange(
  6279. ol.math.modulo(tileRange.minX, width),
  6280. ol.math.modulo(tileRange.maxX, width),
  6281. tileRange.minY, tileRange.maxY))) {
  6282. return true;
  6283. }
  6284. if (tileRange.getWidth() > width &&
  6285. testTileRange.intersects(extentTileRange)) {
  6286. return true;
  6287. }
  6288. }
  6289. }
  6290. }
  6291. return false;
  6292. };
  6293. goog.provide('ol.CollectionEventType');
  6294. /**
  6295. * @enum {string}
  6296. */
  6297. ol.CollectionEventType = {
  6298. /**
  6299. * Triggered when an item is added to the collection.
  6300. * @event ol.Collection.Event#add
  6301. * @api
  6302. */
  6303. ADD: 'add',
  6304. /**
  6305. * Triggered when an item is removed from the collection.
  6306. * @event ol.Collection.Event#remove
  6307. * @api
  6308. */
  6309. REMOVE: 'remove'
  6310. };
  6311. goog.provide('ol.ObjectEventType');
  6312. /**
  6313. * @enum {string}
  6314. */
  6315. ol.ObjectEventType = {
  6316. /**
  6317. * Triggered when a property is changed.
  6318. * @event ol.Object.Event#propertychange
  6319. * @api
  6320. */
  6321. PROPERTYCHANGE: 'propertychange'
  6322. };
  6323. goog.provide('ol.events');
  6324. goog.require('ol.obj');
  6325. /**
  6326. * @param {ol.EventsKey} listenerObj Listener object.
  6327. * @return {ol.EventsListenerFunctionType} Bound listener.
  6328. */
  6329. ol.events.bindListener_ = function(listenerObj) {
  6330. var boundListener = function(evt) {
  6331. var listener = listenerObj.listener;
  6332. var bindTo = listenerObj.bindTo || listenerObj.target;
  6333. if (listenerObj.callOnce) {
  6334. ol.events.unlistenByKey(listenerObj);
  6335. }
  6336. return listener.call(bindTo, evt);
  6337. };
  6338. listenerObj.boundListener = boundListener;
  6339. return boundListener;
  6340. };
  6341. /**
  6342. * Finds the matching {@link ol.EventsKey} in the given listener
  6343. * array.
  6344. *
  6345. * @param {!Array<!ol.EventsKey>} listeners Array of listeners.
  6346. * @param {!Function} listener The listener function.
  6347. * @param {Object=} opt_this The `this` value inside the listener.
  6348. * @param {boolean=} opt_setDeleteIndex Set the deleteIndex on the matching
  6349. * listener, for {@link ol.events.unlistenByKey}.
  6350. * @return {ol.EventsKey|undefined} The matching listener object.
  6351. * @private
  6352. */
  6353. ol.events.findListener_ = function(listeners, listener, opt_this,
  6354. opt_setDeleteIndex) {
  6355. var listenerObj;
  6356. for (var i = 0, ii = listeners.length; i < ii; ++i) {
  6357. listenerObj = listeners[i];
  6358. if (listenerObj.listener === listener &&
  6359. listenerObj.bindTo === opt_this) {
  6360. if (opt_setDeleteIndex) {
  6361. listenerObj.deleteIndex = i;
  6362. }
  6363. return listenerObj;
  6364. }
  6365. }
  6366. return undefined;
  6367. };
  6368. /**
  6369. * @param {ol.EventTargetLike} target Target.
  6370. * @param {string} type Type.
  6371. * @return {Array.<ol.EventsKey>|undefined} Listeners.
  6372. */
  6373. ol.events.getListeners = function(target, type) {
  6374. var listenerMap = target.ol_lm;
  6375. return listenerMap ? listenerMap[type] : undefined;
  6376. };
  6377. /**
  6378. * Get the lookup of listeners. If one does not exist on the target, it is
  6379. * created.
  6380. * @param {ol.EventTargetLike} target Target.
  6381. * @return {!Object.<string, Array.<ol.EventsKey>>} Map of
  6382. * listeners by event type.
  6383. * @private
  6384. */
  6385. ol.events.getListenerMap_ = function(target) {
  6386. var listenerMap = target.ol_lm;
  6387. if (!listenerMap) {
  6388. listenerMap = target.ol_lm = {};
  6389. }
  6390. return listenerMap;
  6391. };
  6392. /**
  6393. * Clean up all listener objects of the given type. All properties on the
  6394. * listener objects will be removed, and if no listeners remain in the listener
  6395. * map, it will be removed from the target.
  6396. * @param {ol.EventTargetLike} target Target.
  6397. * @param {string} type Type.
  6398. * @private
  6399. */
  6400. ol.events.removeListeners_ = function(target, type) {
  6401. var listeners = ol.events.getListeners(target, type);
  6402. if (listeners) {
  6403. for (var i = 0, ii = listeners.length; i < ii; ++i) {
  6404. target.removeEventListener(type, listeners[i].boundListener);
  6405. ol.obj.clear(listeners[i]);
  6406. }
  6407. listeners.length = 0;
  6408. var listenerMap = target.ol_lm;
  6409. if (listenerMap) {
  6410. delete listenerMap[type];
  6411. if (Object.keys(listenerMap).length === 0) {
  6412. delete target.ol_lm;
  6413. }
  6414. }
  6415. }
  6416. };
  6417. /**
  6418. * Registers an event listener on an event target. Inspired by
  6419. * {@link https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html}
  6420. *
  6421. * This function efficiently binds a `listener` to a `this` object, and returns
  6422. * a key for use with {@link ol.events.unlistenByKey}.
  6423. *
  6424. * @param {ol.EventTargetLike} target Event target.
  6425. * @param {string} type Event type.
  6426. * @param {ol.EventsListenerFunctionType} listener Listener.
  6427. * @param {Object=} opt_this Object referenced by the `this` keyword in the
  6428. * listener. Default is the `target`.
  6429. * @param {boolean=} opt_once If true, add the listener as one-off listener.
  6430. * @return {ol.EventsKey} Unique key for the listener.
  6431. */
  6432. ol.events.listen = function(target, type, listener, opt_this, opt_once) {
  6433. var listenerMap = ol.events.getListenerMap_(target);
  6434. var listeners = listenerMap[type];
  6435. if (!listeners) {
  6436. listeners = listenerMap[type] = [];
  6437. }
  6438. var listenerObj = ol.events.findListener_(listeners, listener, opt_this,
  6439. false);
  6440. if (listenerObj) {
  6441. if (!opt_once) {
  6442. // Turn one-off listener into a permanent one.
  6443. listenerObj.callOnce = false;
  6444. }
  6445. } else {
  6446. listenerObj = /** @type {ol.EventsKey} */ ({
  6447. bindTo: opt_this,
  6448. callOnce: !!opt_once,
  6449. listener: listener,
  6450. target: target,
  6451. type: type
  6452. });
  6453. target.addEventListener(type, ol.events.bindListener_(listenerObj));
  6454. listeners.push(listenerObj);
  6455. }
  6456. return listenerObj;
  6457. };
  6458. /**
  6459. * Registers a one-off event listener on an event target. Inspired by
  6460. * {@link https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html}
  6461. *
  6462. * This function efficiently binds a `listener` as self-unregistering listener
  6463. * to a `this` object, and returns a key for use with
  6464. * {@link ol.events.unlistenByKey} in case the listener needs to be unregistered
  6465. * before it is called.
  6466. *
  6467. * When {@link ol.events.listen} is called with the same arguments after this
  6468. * function, the self-unregistering listener will be turned into a permanent
  6469. * listener.
  6470. *
  6471. * @param {ol.EventTargetLike} target Event target.
  6472. * @param {string} type Event type.
  6473. * @param {ol.EventsListenerFunctionType} listener Listener.
  6474. * @param {Object=} opt_this Object referenced by the `this` keyword in the
  6475. * listener. Default is the `target`.
  6476. * @return {ol.EventsKey} Key for unlistenByKey.
  6477. */
  6478. ol.events.listenOnce = function(target, type, listener, opt_this) {
  6479. return ol.events.listen(target, type, listener, opt_this, true);
  6480. };
  6481. /**
  6482. * Unregisters an event listener on an event target. Inspired by
  6483. * {@link https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html}
  6484. *
  6485. * To return a listener, this function needs to be called with the exact same
  6486. * arguments that were used for a previous {@link ol.events.listen} call.
  6487. *
  6488. * @param {ol.EventTargetLike} target Event target.
  6489. * @param {string} type Event type.
  6490. * @param {ol.EventsListenerFunctionType} listener Listener.
  6491. * @param {Object=} opt_this Object referenced by the `this` keyword in the
  6492. * listener. Default is the `target`.
  6493. */
  6494. ol.events.unlisten = function(target, type, listener, opt_this) {
  6495. var listeners = ol.events.getListeners(target, type);
  6496. if (listeners) {
  6497. var listenerObj = ol.events.findListener_(listeners, listener, opt_this,
  6498. true);
  6499. if (listenerObj) {
  6500. ol.events.unlistenByKey(listenerObj);
  6501. }
  6502. }
  6503. };
  6504. /**
  6505. * Unregisters event listeners on an event target. Inspired by
  6506. * {@link https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html}
  6507. *
  6508. * The argument passed to this function is the key returned from
  6509. * {@link ol.events.listen} or {@link ol.events.listenOnce}.
  6510. *
  6511. * @param {ol.EventsKey} key The key.
  6512. */
  6513. ol.events.unlistenByKey = function(key) {
  6514. if (key && key.target) {
  6515. key.target.removeEventListener(key.type, key.boundListener);
  6516. var listeners = ol.events.getListeners(key.target, key.type);
  6517. if (listeners) {
  6518. var i = 'deleteIndex' in key ? key.deleteIndex : listeners.indexOf(key);
  6519. if (i !== -1) {
  6520. listeners.splice(i, 1);
  6521. }
  6522. if (listeners.length === 0) {
  6523. ol.events.removeListeners_(key.target, key.type);
  6524. }
  6525. }
  6526. ol.obj.clear(key);
  6527. }
  6528. };
  6529. /**
  6530. * Unregisters all event listeners on an event target. Inspired by
  6531. * {@link https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html}
  6532. *
  6533. * @param {ol.EventTargetLike} target Target.
  6534. */
  6535. ol.events.unlistenAll = function(target) {
  6536. var listenerMap = ol.events.getListenerMap_(target);
  6537. for (var type in listenerMap) {
  6538. ol.events.removeListeners_(target, type);
  6539. }
  6540. };
  6541. goog.provide('ol.Disposable');
  6542. goog.require('ol');
  6543. /**
  6544. * Objects that need to clean up after themselves.
  6545. * @constructor
  6546. */
  6547. ol.Disposable = function() {};
  6548. /**
  6549. * The object has already been disposed.
  6550. * @type {boolean}
  6551. * @private
  6552. */
  6553. ol.Disposable.prototype.disposed_ = false;
  6554. /**
  6555. * Clean up.
  6556. */
  6557. ol.Disposable.prototype.dispose = function() {
  6558. if (!this.disposed_) {
  6559. this.disposed_ = true;
  6560. this.disposeInternal();
  6561. }
  6562. };
  6563. /**
  6564. * Extension point for disposable objects.
  6565. * @protected
  6566. */
  6567. ol.Disposable.prototype.disposeInternal = ol.nullFunction;
  6568. goog.provide('ol.events.Event');
  6569. /**
  6570. * @classdesc
  6571. * Stripped down implementation of the W3C DOM Level 2 Event interface.
  6572. * @see {@link https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface}
  6573. *
  6574. * This implementation only provides `type` and `target` properties, and
  6575. * `stopPropagation` and `preventDefault` methods. It is meant as base class
  6576. * for higher level events defined in the library, and works with
  6577. * {@link ol.events.EventTarget}.
  6578. *
  6579. * @constructor
  6580. * @implements {oli.events.Event}
  6581. * @param {string} type Type.
  6582. */
  6583. ol.events.Event = function(type) {
  6584. /**
  6585. * @type {boolean}
  6586. */
  6587. this.propagationStopped;
  6588. /**
  6589. * The event type.
  6590. * @type {string}
  6591. * @api
  6592. */
  6593. this.type = type;
  6594. /**
  6595. * The event target.
  6596. * @type {Object}
  6597. * @api
  6598. */
  6599. this.target = null;
  6600. };
  6601. /**
  6602. * Stop event propagation.
  6603. * @function
  6604. * @override
  6605. * @api
  6606. */
  6607. ol.events.Event.prototype.preventDefault =
  6608. /**
  6609. * Stop event propagation.
  6610. * @function
  6611. * @override
  6612. * @api
  6613. */
  6614. ol.events.Event.prototype.stopPropagation = function() {
  6615. this.propagationStopped = true;
  6616. };
  6617. /**
  6618. * @param {Event|ol.events.Event} evt Event
  6619. */
  6620. ol.events.Event.stopPropagation = function(evt) {
  6621. evt.stopPropagation();
  6622. };
  6623. /**
  6624. * @param {Event|ol.events.Event} evt Event
  6625. */
  6626. ol.events.Event.preventDefault = function(evt) {
  6627. evt.preventDefault();
  6628. };
  6629. goog.provide('ol.events.EventTarget');
  6630. goog.require('ol');
  6631. goog.require('ol.Disposable');
  6632. goog.require('ol.events');
  6633. goog.require('ol.events.Event');
  6634. /**
  6635. * @classdesc
  6636. * A simplified implementation of the W3C DOM Level 2 EventTarget interface.
  6637. * @see {@link https://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-EventTarget}
  6638. *
  6639. * There are two important simplifications compared to the specification:
  6640. *
  6641. * 1. The handling of `useCapture` in `addEventListener` and
  6642. * `removeEventListener`. There is no real capture model.
  6643. * 2. The handling of `stopPropagation` and `preventDefault` on `dispatchEvent`.
  6644. * There is no event target hierarchy. When a listener calls
  6645. * `stopPropagation` or `preventDefault` on an event object, it means that no
  6646. * more listeners after this one will be called. Same as when the listener
  6647. * returns false.
  6648. *
  6649. * @constructor
  6650. * @extends {ol.Disposable}
  6651. */
  6652. ol.events.EventTarget = function() {
  6653. ol.Disposable.call(this);
  6654. /**
  6655. * @private
  6656. * @type {!Object.<string, number>}
  6657. */
  6658. this.pendingRemovals_ = {};
  6659. /**
  6660. * @private
  6661. * @type {!Object.<string, number>}
  6662. */
  6663. this.dispatching_ = {};
  6664. /**
  6665. * @private
  6666. * @type {!Object.<string, Array.<ol.EventsListenerFunctionType>>}
  6667. */
  6668. this.listeners_ = {};
  6669. };
  6670. ol.inherits(ol.events.EventTarget, ol.Disposable);
  6671. /**
  6672. * @param {string} type Type.
  6673. * @param {ol.EventsListenerFunctionType} listener Listener.
  6674. */
  6675. ol.events.EventTarget.prototype.addEventListener = function(type, listener) {
  6676. var listeners = this.listeners_[type];
  6677. if (!listeners) {
  6678. listeners = this.listeners_[type] = [];
  6679. }
  6680. if (listeners.indexOf(listener) === -1) {
  6681. listeners.push(listener);
  6682. }
  6683. };
  6684. /**
  6685. * @param {{type: string,
  6686. * target: (EventTarget|ol.events.EventTarget|undefined)}|ol.events.Event|
  6687. * string} event Event or event type.
  6688. * @return {boolean|undefined} `false` if anyone called preventDefault on the
  6689. * event object or if any of the listeners returned false.
  6690. */
  6691. ol.events.EventTarget.prototype.dispatchEvent = function(event) {
  6692. var evt = typeof event === 'string' ? new ol.events.Event(event) : event;
  6693. var type = evt.type;
  6694. evt.target = this;
  6695. var listeners = this.listeners_[type];
  6696. var propagate;
  6697. if (listeners) {
  6698. if (!(type in this.dispatching_)) {
  6699. this.dispatching_[type] = 0;
  6700. this.pendingRemovals_[type] = 0;
  6701. }
  6702. ++this.dispatching_[type];
  6703. for (var i = 0, ii = listeners.length; i < ii; ++i) {
  6704. if (listeners[i].call(this, evt) === false || evt.propagationStopped) {
  6705. propagate = false;
  6706. break;
  6707. }
  6708. }
  6709. --this.dispatching_[type];
  6710. if (this.dispatching_[type] === 0) {
  6711. var pendingRemovals = this.pendingRemovals_[type];
  6712. delete this.pendingRemovals_[type];
  6713. while (pendingRemovals--) {
  6714. this.removeEventListener(type, ol.nullFunction);
  6715. }
  6716. delete this.dispatching_[type];
  6717. }
  6718. return propagate;
  6719. }
  6720. };
  6721. /**
  6722. * @inheritDoc
  6723. */
  6724. ol.events.EventTarget.prototype.disposeInternal = function() {
  6725. ol.events.unlistenAll(this);
  6726. };
  6727. /**
  6728. * Get the listeners for a specified event type. Listeners are returned in the
  6729. * order that they will be called in.
  6730. *
  6731. * @param {string} type Type.
  6732. * @return {Array.<ol.EventsListenerFunctionType>} Listeners.
  6733. */
  6734. ol.events.EventTarget.prototype.getListeners = function(type) {
  6735. return this.listeners_[type];
  6736. };
  6737. /**
  6738. * @param {string=} opt_type Type. If not provided,
  6739. * `true` will be returned if this EventTarget has any listeners.
  6740. * @return {boolean} Has listeners.
  6741. */
  6742. ol.events.EventTarget.prototype.hasListener = function(opt_type) {
  6743. return opt_type ?
  6744. opt_type in this.listeners_ :
  6745. Object.keys(this.listeners_).length > 0;
  6746. };
  6747. /**
  6748. * @param {string} type Type.
  6749. * @param {ol.EventsListenerFunctionType} listener Listener.
  6750. */
  6751. ol.events.EventTarget.prototype.removeEventListener = function(type, listener) {
  6752. var listeners = this.listeners_[type];
  6753. if (listeners) {
  6754. var index = listeners.indexOf(listener);
  6755. if (type in this.pendingRemovals_) {
  6756. // make listener a no-op, and remove later in #dispatchEvent()
  6757. listeners[index] = ol.nullFunction;
  6758. ++this.pendingRemovals_[type];
  6759. } else {
  6760. listeners.splice(index, 1);
  6761. if (listeners.length === 0) {
  6762. delete this.listeners_[type];
  6763. }
  6764. }
  6765. }
  6766. };
  6767. goog.provide('ol.events.EventType');
  6768. /**
  6769. * @enum {string}
  6770. * @const
  6771. */
  6772. ol.events.EventType = {
  6773. /**
  6774. * Generic change event. Triggered when the revision counter is increased.
  6775. * @event ol.events.Event#change
  6776. * @api
  6777. */
  6778. CHANGE: 'change',
  6779. CLEAR: 'clear',
  6780. CLICK: 'click',
  6781. DBLCLICK: 'dblclick',
  6782. DRAGENTER: 'dragenter',
  6783. DRAGOVER: 'dragover',
  6784. DROP: 'drop',
  6785. ERROR: 'error',
  6786. KEYDOWN: 'keydown',
  6787. KEYPRESS: 'keypress',
  6788. LOAD: 'load',
  6789. MOUSEDOWN: 'mousedown',
  6790. MOUSEMOVE: 'mousemove',
  6791. MOUSEOUT: 'mouseout',
  6792. MOUSEUP: 'mouseup',
  6793. MOUSEWHEEL: 'mousewheel',
  6794. MSPOINTERDOWN: 'MSPointerDown',
  6795. RESIZE: 'resize',
  6796. TOUCHSTART: 'touchstart',
  6797. TOUCHMOVE: 'touchmove',
  6798. TOUCHEND: 'touchend',
  6799. WHEEL: 'wheel'
  6800. };
  6801. goog.provide('ol.Observable');
  6802. goog.require('ol');
  6803. goog.require('ol.events');
  6804. goog.require('ol.events.EventTarget');
  6805. goog.require('ol.events.EventType');
  6806. /**
  6807. * @classdesc
  6808. * Abstract base class; normally only used for creating subclasses and not
  6809. * instantiated in apps.
  6810. * An event target providing convenient methods for listener registration
  6811. * and unregistration. A generic `change` event is always available through
  6812. * {@link ol.Observable#changed}.
  6813. *
  6814. * @constructor
  6815. * @extends {ol.events.EventTarget}
  6816. * @fires ol.events.Event
  6817. * @struct
  6818. * @api
  6819. */
  6820. ol.Observable = function() {
  6821. ol.events.EventTarget.call(this);
  6822. /**
  6823. * @private
  6824. * @type {number}
  6825. */
  6826. this.revision_ = 0;
  6827. };
  6828. ol.inherits(ol.Observable, ol.events.EventTarget);
  6829. /**
  6830. * Removes an event listener using the key returned by `on()` or `once()`.
  6831. * @param {ol.EventsKey|Array.<ol.EventsKey>} key The key returned by `on()`
  6832. * or `once()` (or an array of keys).
  6833. * @api
  6834. */
  6835. ol.Observable.unByKey = function(key) {
  6836. if (Array.isArray(key)) {
  6837. for (var i = 0, ii = key.length; i < ii; ++i) {
  6838. ol.events.unlistenByKey(key[i]);
  6839. }
  6840. } else {
  6841. ol.events.unlistenByKey(/** @type {ol.EventsKey} */ (key));
  6842. }
  6843. };
  6844. /**
  6845. * Increases the revision counter and dispatches a 'change' event.
  6846. * @api
  6847. */
  6848. ol.Observable.prototype.changed = function() {
  6849. ++this.revision_;
  6850. this.dispatchEvent(ol.events.EventType.CHANGE);
  6851. };
  6852. /**
  6853. * Dispatches an event and calls all listeners listening for events
  6854. * of this type. The event parameter can either be a string or an
  6855. * Object with a `type` property.
  6856. *
  6857. * @param {{type: string,
  6858. * target: (EventTarget|ol.events.EventTarget|undefined)}|ol.events.Event|
  6859. * string} event Event object.
  6860. * @function
  6861. * @api
  6862. */
  6863. ol.Observable.prototype.dispatchEvent;
  6864. /**
  6865. * Get the version number for this object. Each time the object is modified,
  6866. * its version number will be incremented.
  6867. * @return {number} Revision.
  6868. * @api
  6869. */
  6870. ol.Observable.prototype.getRevision = function() {
  6871. return this.revision_;
  6872. };
  6873. /**
  6874. * Listen for a certain type of event.
  6875. * @param {string|Array.<string>} type The event type or array of event types.
  6876. * @param {function(?): ?} listener The listener function.
  6877. * @param {Object=} opt_this The object to use as `this` in `listener`.
  6878. * @return {ol.EventsKey|Array.<ol.EventsKey>} Unique key for the listener. If
  6879. * called with an array of event types as the first argument, the return
  6880. * will be an array of keys.
  6881. * @api
  6882. */
  6883. ol.Observable.prototype.on = function(type, listener, opt_this) {
  6884. if (Array.isArray(type)) {
  6885. var len = type.length;
  6886. var keys = new Array(len);
  6887. for (var i = 0; i < len; ++i) {
  6888. keys[i] = ol.events.listen(this, type[i], listener, opt_this);
  6889. }
  6890. return keys;
  6891. } else {
  6892. return ol.events.listen(
  6893. this, /** @type {string} */ (type), listener, opt_this);
  6894. }
  6895. };
  6896. /**
  6897. * Listen once for a certain type of event.
  6898. * @param {string|Array.<string>} type The event type or array of event types.
  6899. * @param {function(?): ?} listener The listener function.
  6900. * @param {Object=} opt_this The object to use as `this` in `listener`.
  6901. * @return {ol.EventsKey|Array.<ol.EventsKey>} Unique key for the listener. If
  6902. * called with an array of event types as the first argument, the return
  6903. * will be an array of keys.
  6904. * @api
  6905. */
  6906. ol.Observable.prototype.once = function(type, listener, opt_this) {
  6907. if (Array.isArray(type)) {
  6908. var len = type.length;
  6909. var keys = new Array(len);
  6910. for (var i = 0; i < len; ++i) {
  6911. keys[i] = ol.events.listenOnce(this, type[i], listener, opt_this);
  6912. }
  6913. return keys;
  6914. } else {
  6915. return ol.events.listenOnce(
  6916. this, /** @type {string} */ (type), listener, opt_this);
  6917. }
  6918. };
  6919. /**
  6920. * Unlisten for a certain type of event.
  6921. * @param {string|Array.<string>} type The event type or array of event types.
  6922. * @param {function(?): ?} listener The listener function.
  6923. * @param {Object=} opt_this The object which was used as `this` by the
  6924. * `listener`.
  6925. * @api
  6926. */
  6927. ol.Observable.prototype.un = function(type, listener, opt_this) {
  6928. if (Array.isArray(type)) {
  6929. for (var i = 0, ii = type.length; i < ii; ++i) {
  6930. ol.events.unlisten(this, type[i], listener, opt_this);
  6931. }
  6932. return;
  6933. } else {
  6934. ol.events.unlisten(this, /** @type {string} */ (type), listener, opt_this);
  6935. }
  6936. };
  6937. goog.provide('ol.Object');
  6938. goog.require('ol');
  6939. goog.require('ol.ObjectEventType');
  6940. goog.require('ol.Observable');
  6941. goog.require('ol.events.Event');
  6942. goog.require('ol.obj');
  6943. /**
  6944. * @classdesc
  6945. * Abstract base class; normally only used for creating subclasses and not
  6946. * instantiated in apps.
  6947. * Most non-trivial classes inherit from this.
  6948. *
  6949. * This extends {@link ol.Observable} with observable properties, where each
  6950. * property is observable as well as the object as a whole.
  6951. *
  6952. * Classes that inherit from this have pre-defined properties, to which you can
  6953. * add your owns. The pre-defined properties are listed in this documentation as
  6954. * 'Observable Properties', and have their own accessors; for example,
  6955. * {@link ol.Map} has a `target` property, accessed with `getTarget()` and
  6956. * changed with `setTarget()`. Not all properties are however settable. There
  6957. * are also general-purpose accessors `get()` and `set()`. For example,
  6958. * `get('target')` is equivalent to `getTarget()`.
  6959. *
  6960. * The `set` accessors trigger a change event, and you can monitor this by
  6961. * registering a listener. For example, {@link ol.View} has a `center`
  6962. * property, so `view.on('change:center', function(evt) {...});` would call the
  6963. * function whenever the value of the center property changes. Within the
  6964. * function, `evt.target` would be the view, so `evt.target.getCenter()` would
  6965. * return the new center.
  6966. *
  6967. * You can add your own observable properties with
  6968. * `object.set('prop', 'value')`, and retrieve that with `object.get('prop')`.
  6969. * You can listen for changes on that property value with
  6970. * `object.on('change:prop', listener)`. You can get a list of all
  6971. * properties with {@link ol.Object#getProperties object.getProperties()}.
  6972. *
  6973. * Note that the observable properties are separate from standard JS properties.
  6974. * You can, for example, give your map object a title with
  6975. * `map.title='New title'` and with `map.set('title', 'Another title')`. The
  6976. * first will be a `hasOwnProperty`; the second will appear in
  6977. * `getProperties()`. Only the second is observable.
  6978. *
  6979. * Properties can be deleted by using the unset method. E.g.
  6980. * object.unset('foo').
  6981. *
  6982. * @constructor
  6983. * @extends {ol.Observable}
  6984. * @param {Object.<string, *>=} opt_values An object with key-value pairs.
  6985. * @fires ol.Object.Event
  6986. * @api
  6987. */
  6988. ol.Object = function(opt_values) {
  6989. ol.Observable.call(this);
  6990. // Call ol.getUid to ensure that the order of objects' ids is the same as
  6991. // the order in which they were created. This also helps to ensure that
  6992. // object properties are always added in the same order, which helps many
  6993. // JavaScript engines generate faster code.
  6994. ol.getUid(this);
  6995. /**
  6996. * @private
  6997. * @type {!Object.<string, *>}
  6998. */
  6999. this.values_ = {};
  7000. if (opt_values !== undefined) {
  7001. this.setProperties(opt_values);
  7002. }
  7003. };
  7004. ol.inherits(ol.Object, ol.Observable);
  7005. /**
  7006. * @private
  7007. * @type {Object.<string, string>}
  7008. */
  7009. ol.Object.changeEventTypeCache_ = {};
  7010. /**
  7011. * @param {string} key Key name.
  7012. * @return {string} Change name.
  7013. */
  7014. ol.Object.getChangeEventType = function(key) {
  7015. return ol.Object.changeEventTypeCache_.hasOwnProperty(key) ?
  7016. ol.Object.changeEventTypeCache_[key] :
  7017. (ol.Object.changeEventTypeCache_[key] = 'change:' + key);
  7018. };
  7019. /**
  7020. * Gets a value.
  7021. * @param {string} key Key name.
  7022. * @return {*} Value.
  7023. * @api
  7024. */
  7025. ol.Object.prototype.get = function(key) {
  7026. var value;
  7027. if (this.values_.hasOwnProperty(key)) {
  7028. value = this.values_[key];
  7029. }
  7030. return value;
  7031. };
  7032. /**
  7033. * Get a list of object property names.
  7034. * @return {Array.<string>} List of property names.
  7035. * @api
  7036. */
  7037. ol.Object.prototype.getKeys = function() {
  7038. return Object.keys(this.values_);
  7039. };
  7040. /**
  7041. * Get an object of all property names and values.
  7042. * @return {Object.<string, *>} Object.
  7043. * @api
  7044. */
  7045. ol.Object.prototype.getProperties = function() {
  7046. return ol.obj.assign({}, this.values_);
  7047. };
  7048. /**
  7049. * @param {string} key Key name.
  7050. * @param {*} oldValue Old value.
  7051. */
  7052. ol.Object.prototype.notify = function(key, oldValue) {
  7053. var eventType;
  7054. eventType = ol.Object.getChangeEventType(key);
  7055. this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue));
  7056. eventType = ol.ObjectEventType.PROPERTYCHANGE;
  7057. this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue));
  7058. };
  7059. /**
  7060. * Sets a value.
  7061. * @param {string} key Key name.
  7062. * @param {*} value Value.
  7063. * @param {boolean=} opt_silent Update without triggering an event.
  7064. * @api
  7065. */
  7066. ol.Object.prototype.set = function(key, value, opt_silent) {
  7067. if (opt_silent) {
  7068. this.values_[key] = value;
  7069. } else {
  7070. var oldValue = this.values_[key];
  7071. this.values_[key] = value;
  7072. if (oldValue !== value) {
  7073. this.notify(key, oldValue);
  7074. }
  7075. }
  7076. };
  7077. /**
  7078. * Sets a collection of key-value pairs. Note that this changes any existing
  7079. * properties and adds new ones (it does not remove any existing properties).
  7080. * @param {Object.<string, *>} values Values.
  7081. * @param {boolean=} opt_silent Update without triggering an event.
  7082. * @api
  7083. */
  7084. ol.Object.prototype.setProperties = function(values, opt_silent) {
  7085. var key;
  7086. for (key in values) {
  7087. this.set(key, values[key], opt_silent);
  7088. }
  7089. };
  7090. /**
  7091. * Unsets a property.
  7092. * @param {string} key Key name.
  7093. * @param {boolean=} opt_silent Unset without triggering an event.
  7094. * @api
  7095. */
  7096. ol.Object.prototype.unset = function(key, opt_silent) {
  7097. if (key in this.values_) {
  7098. var oldValue = this.values_[key];
  7099. delete this.values_[key];
  7100. if (!opt_silent) {
  7101. this.notify(key, oldValue);
  7102. }
  7103. }
  7104. };
  7105. /**
  7106. * @classdesc
  7107. * Events emitted by {@link ol.Object} instances are instances of this type.
  7108. *
  7109. * @param {string} type The event type.
  7110. * @param {string} key The property name.
  7111. * @param {*} oldValue The old value for `key`.
  7112. * @extends {ol.events.Event}
  7113. * @implements {oli.Object.Event}
  7114. * @constructor
  7115. */
  7116. ol.Object.Event = function(type, key, oldValue) {
  7117. ol.events.Event.call(this, type);
  7118. /**
  7119. * The name of the property whose value is changing.
  7120. * @type {string}
  7121. * @api
  7122. */
  7123. this.key = key;
  7124. /**
  7125. * The old value. To get the new value use `e.target.get(e.key)` where
  7126. * `e` is the event object.
  7127. * @type {*}
  7128. * @api
  7129. */
  7130. this.oldValue = oldValue;
  7131. };
  7132. ol.inherits(ol.Object.Event, ol.events.Event);
  7133. /**
  7134. * An implementation of Google Maps' MVCArray.
  7135. * @see https://developers.google.com/maps/documentation/javascript/reference
  7136. */
  7137. goog.provide('ol.Collection');
  7138. goog.require('ol');
  7139. goog.require('ol.AssertionError');
  7140. goog.require('ol.CollectionEventType');
  7141. goog.require('ol.Object');
  7142. goog.require('ol.events.Event');
  7143. /**
  7144. * @classdesc
  7145. * An expanded version of standard JS Array, adding convenience methods for
  7146. * manipulation. Add and remove changes to the Collection trigger a Collection
  7147. * event. Note that this does not cover changes to the objects _within_ the
  7148. * Collection; they trigger events on the appropriate object, not on the
  7149. * Collection as a whole.
  7150. *
  7151. * @constructor
  7152. * @extends {ol.Object}
  7153. * @fires ol.Collection.Event
  7154. * @param {Array.<T>=} opt_array Array.
  7155. * @param {olx.CollectionOptions=} opt_options Collection options.
  7156. * @template T
  7157. * @api
  7158. */
  7159. ol.Collection = function(opt_array, opt_options) {
  7160. ol.Object.call(this);
  7161. var options = opt_options || {};
  7162. /**
  7163. * @private
  7164. * @type {boolean}
  7165. */
  7166. this.unique_ = !!options.unique;
  7167. /**
  7168. * @private
  7169. * @type {!Array.<T>}
  7170. */
  7171. this.array_ = opt_array ? opt_array : [];
  7172. if (this.unique_) {
  7173. for (var i = 0, ii = this.array_.length; i < ii; ++i) {
  7174. this.assertUnique_(this.array_[i], i);
  7175. }
  7176. }
  7177. this.updateLength_();
  7178. };
  7179. ol.inherits(ol.Collection, ol.Object);
  7180. /**
  7181. * Remove all elements from the collection.
  7182. * @api
  7183. */
  7184. ol.Collection.prototype.clear = function() {
  7185. while (this.getLength() > 0) {
  7186. this.pop();
  7187. }
  7188. };
  7189. /**
  7190. * Add elements to the collection. This pushes each item in the provided array
  7191. * to the end of the collection.
  7192. * @param {!Array.<T>} arr Array.
  7193. * @return {ol.Collection.<T>} This collection.
  7194. * @api
  7195. */
  7196. ol.Collection.prototype.extend = function(arr) {
  7197. var i, ii;
  7198. for (i = 0, ii = arr.length; i < ii; ++i) {
  7199. this.push(arr[i]);
  7200. }
  7201. return this;
  7202. };
  7203. /**
  7204. * Iterate over each element, calling the provided callback.
  7205. * @param {function(this: S, T, number, Array.<T>): *} f The function to call
  7206. * for every element. This function takes 3 arguments (the element, the
  7207. * index and the array). The return value is ignored.
  7208. * @param {S=} opt_this The object to use as `this` in `f`.
  7209. * @template S
  7210. * @api
  7211. */
  7212. ol.Collection.prototype.forEach = function(f, opt_this) {
  7213. var fn = (opt_this) ? f.bind(opt_this) : f;
  7214. var array = this.array_;
  7215. for (var i = 0, ii = array.length; i < ii; ++i) {
  7216. fn(array[i], i, array);
  7217. }
  7218. };
  7219. /**
  7220. * Get a reference to the underlying Array object. Warning: if the array
  7221. * is mutated, no events will be dispatched by the collection, and the
  7222. * collection's "length" property won't be in sync with the actual length
  7223. * of the array.
  7224. * @return {!Array.<T>} Array.
  7225. * @api
  7226. */
  7227. ol.Collection.prototype.getArray = function() {
  7228. return this.array_;
  7229. };
  7230. /**
  7231. * Get the element at the provided index.
  7232. * @param {number} index Index.
  7233. * @return {T} Element.
  7234. * @api
  7235. */
  7236. ol.Collection.prototype.item = function(index) {
  7237. return this.array_[index];
  7238. };
  7239. /**
  7240. * Get the length of this collection.
  7241. * @return {number} The length of the array.
  7242. * @observable
  7243. * @api
  7244. */
  7245. ol.Collection.prototype.getLength = function() {
  7246. return /** @type {number} */ (this.get(ol.Collection.Property_.LENGTH));
  7247. };
  7248. /**
  7249. * Insert an element at the provided index.
  7250. * @param {number} index Index.
  7251. * @param {T} elem Element.
  7252. * @api
  7253. */
  7254. ol.Collection.prototype.insertAt = function(index, elem) {
  7255. if (this.unique_) {
  7256. this.assertUnique_(elem);
  7257. }
  7258. this.array_.splice(index, 0, elem);
  7259. this.updateLength_();
  7260. this.dispatchEvent(
  7261. new ol.Collection.Event(ol.CollectionEventType.ADD, elem));
  7262. };
  7263. /**
  7264. * Remove the last element of the collection and return it.
  7265. * Return `undefined` if the collection is empty.
  7266. * @return {T|undefined} Element.
  7267. * @api
  7268. */
  7269. ol.Collection.prototype.pop = function() {
  7270. return this.removeAt(this.getLength() - 1);
  7271. };
  7272. /**
  7273. * Insert the provided element at the end of the collection.
  7274. * @param {T} elem Element.
  7275. * @return {number} New length of the collection.
  7276. * @api
  7277. */
  7278. ol.Collection.prototype.push = function(elem) {
  7279. if (this.unique_) {
  7280. this.assertUnique_(elem);
  7281. }
  7282. var n = this.getLength();
  7283. this.insertAt(n, elem);
  7284. return this.getLength();
  7285. };
  7286. /**
  7287. * Remove the first occurrence of an element from the collection.
  7288. * @param {T} elem Element.
  7289. * @return {T|undefined} The removed element or undefined if none found.
  7290. * @api
  7291. */
  7292. ol.Collection.prototype.remove = function(elem) {
  7293. var arr = this.array_;
  7294. var i, ii;
  7295. for (i = 0, ii = arr.length; i < ii; ++i) {
  7296. if (arr[i] === elem) {
  7297. return this.removeAt(i);
  7298. }
  7299. }
  7300. return undefined;
  7301. };
  7302. /**
  7303. * Remove the element at the provided index and return it.
  7304. * Return `undefined` if the collection does not contain this index.
  7305. * @param {number} index Index.
  7306. * @return {T|undefined} Value.
  7307. * @api
  7308. */
  7309. ol.Collection.prototype.removeAt = function(index) {
  7310. var prev = this.array_[index];
  7311. this.array_.splice(index, 1);
  7312. this.updateLength_();
  7313. this.dispatchEvent(
  7314. new ol.Collection.Event(ol.CollectionEventType.REMOVE, prev));
  7315. return prev;
  7316. };
  7317. /**
  7318. * Set the element at the provided index.
  7319. * @param {number} index Index.
  7320. * @param {T} elem Element.
  7321. * @api
  7322. */
  7323. ol.Collection.prototype.setAt = function(index, elem) {
  7324. var n = this.getLength();
  7325. if (index < n) {
  7326. if (this.unique_) {
  7327. this.assertUnique_(elem, index);
  7328. }
  7329. var prev = this.array_[index];
  7330. this.array_[index] = elem;
  7331. this.dispatchEvent(
  7332. new ol.Collection.Event(ol.CollectionEventType.REMOVE, prev));
  7333. this.dispatchEvent(
  7334. new ol.Collection.Event(ol.CollectionEventType.ADD, elem));
  7335. } else {
  7336. var j;
  7337. for (j = n; j < index; ++j) {
  7338. this.insertAt(j, undefined);
  7339. }
  7340. this.insertAt(index, elem);
  7341. }
  7342. };
  7343. /**
  7344. * @private
  7345. */
  7346. ol.Collection.prototype.updateLength_ = function() {
  7347. this.set(ol.Collection.Property_.LENGTH, this.array_.length);
  7348. };
  7349. /**
  7350. * @private
  7351. * @param {T} elem Element.
  7352. * @param {number=} opt_except Optional index to ignore.
  7353. */
  7354. ol.Collection.prototype.assertUnique_ = function(elem, opt_except) {
  7355. for (var i = 0, ii = this.array_.length; i < ii; ++i) {
  7356. if (this.array_[i] === elem && i !== opt_except) {
  7357. throw new ol.AssertionError(58);
  7358. }
  7359. }
  7360. };
  7361. /**
  7362. * @enum {string}
  7363. * @private
  7364. */
  7365. ol.Collection.Property_ = {
  7366. LENGTH: 'length'
  7367. };
  7368. /**
  7369. * @classdesc
  7370. * Events emitted by {@link ol.Collection} instances are instances of this
  7371. * type.
  7372. *
  7373. * @constructor
  7374. * @extends {ol.events.Event}
  7375. * @implements {oli.Collection.Event}
  7376. * @param {ol.CollectionEventType} type Type.
  7377. * @param {*=} opt_element Element.
  7378. */
  7379. ol.Collection.Event = function(type, opt_element) {
  7380. ol.events.Event.call(this, type);
  7381. /**
  7382. * The element that is added to or removed from the collection.
  7383. * @type {*}
  7384. * @api
  7385. */
  7386. this.element = opt_element;
  7387. };
  7388. ol.inherits(ol.Collection.Event, ol.events.Event);
  7389. goog.provide('ol.MapEvent');
  7390. goog.require('ol');
  7391. goog.require('ol.events.Event');
  7392. /**
  7393. * @classdesc
  7394. * Events emitted as map events are instances of this type.
  7395. * See {@link ol.Map} for which events trigger a map event.
  7396. *
  7397. * @constructor
  7398. * @extends {ol.events.Event}
  7399. * @implements {oli.MapEvent}
  7400. * @param {string} type Event type.
  7401. * @param {ol.PluggableMap} map Map.
  7402. * @param {?olx.FrameState=} opt_frameState Frame state.
  7403. */
  7404. ol.MapEvent = function(type, map, opt_frameState) {
  7405. ol.events.Event.call(this, type);
  7406. /**
  7407. * The map where the event occurred.
  7408. * @type {ol.PluggableMap}
  7409. * @api
  7410. */
  7411. this.map = map;
  7412. /**
  7413. * The frame state at the time of the event.
  7414. * @type {?olx.FrameState}
  7415. * @api
  7416. */
  7417. this.frameState = opt_frameState !== undefined ? opt_frameState : null;
  7418. };
  7419. ol.inherits(ol.MapEvent, ol.events.Event);
  7420. goog.provide('ol.MapBrowserEvent');
  7421. goog.require('ol');
  7422. goog.require('ol.MapEvent');
  7423. /**
  7424. * @classdesc
  7425. * Events emitted as map browser events are instances of this type.
  7426. * See {@link ol.Map} for which events trigger a map browser event.
  7427. *
  7428. * @constructor
  7429. * @extends {ol.MapEvent}
  7430. * @implements {oli.MapBrowserEvent}
  7431. * @param {string} type Event type.
  7432. * @param {ol.PluggableMap} map Map.
  7433. * @param {Event} browserEvent Browser event.
  7434. * @param {boolean=} opt_dragging Is the map currently being dragged?
  7435. * @param {?olx.FrameState=} opt_frameState Frame state.
  7436. */
  7437. ol.MapBrowserEvent = function(type, map, browserEvent, opt_dragging,
  7438. opt_frameState) {
  7439. ol.MapEvent.call(this, type, map, opt_frameState);
  7440. /**
  7441. * The original browser event.
  7442. * @const
  7443. * @type {Event}
  7444. * @api
  7445. */
  7446. this.originalEvent = browserEvent;
  7447. /**
  7448. * The map pixel relative to the viewport corresponding to the original browser event.
  7449. * @type {ol.Pixel}
  7450. * @api
  7451. */
  7452. this.pixel = map.getEventPixel(browserEvent);
  7453. /**
  7454. * The coordinate in view projection corresponding to the original browser event.
  7455. * @type {ol.Coordinate}
  7456. * @api
  7457. */
  7458. this.coordinate = map.getCoordinateFromPixel(this.pixel);
  7459. /**
  7460. * Indicates if the map is currently being dragged. Only set for
  7461. * `POINTERDRAG` and `POINTERMOVE` events. Default is `false`.
  7462. *
  7463. * @type {boolean}
  7464. * @api
  7465. */
  7466. this.dragging = opt_dragging !== undefined ? opt_dragging : false;
  7467. };
  7468. ol.inherits(ol.MapBrowserEvent, ol.MapEvent);
  7469. /**
  7470. * Prevents the default browser action.
  7471. * @see https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault
  7472. * @override
  7473. * @api
  7474. */
  7475. ol.MapBrowserEvent.prototype.preventDefault = function() {
  7476. ol.MapEvent.prototype.preventDefault.call(this);
  7477. this.originalEvent.preventDefault();
  7478. };
  7479. /**
  7480. * Prevents further propagation of the current event.
  7481. * @see https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation
  7482. * @override
  7483. * @api
  7484. */
  7485. ol.MapBrowserEvent.prototype.stopPropagation = function() {
  7486. ol.MapEvent.prototype.stopPropagation.call(this);
  7487. this.originalEvent.stopPropagation();
  7488. };
  7489. goog.provide('ol.webgl');
  7490. /**
  7491. * Constants taken from goog.webgl
  7492. */
  7493. /**
  7494. * @const
  7495. * @type {number}
  7496. */
  7497. ol.webgl.ONE = 1;
  7498. /**
  7499. * @const
  7500. * @type {number}
  7501. */
  7502. ol.webgl.SRC_ALPHA = 0x0302;
  7503. /**
  7504. * @const
  7505. * @type {number}
  7506. */
  7507. ol.webgl.COLOR_ATTACHMENT0 = 0x8CE0;
  7508. /**
  7509. * @const
  7510. * @type {number}
  7511. */
  7512. ol.webgl.COLOR_BUFFER_BIT = 0x00004000;
  7513. /**
  7514. * @const
  7515. * @type {number}
  7516. */
  7517. ol.webgl.TRIANGLES = 0x0004;
  7518. /**
  7519. * @const
  7520. * @type {number}
  7521. */
  7522. ol.webgl.TRIANGLE_STRIP = 0x0005;
  7523. /**
  7524. * @const
  7525. * @type {number}
  7526. */
  7527. ol.webgl.ONE_MINUS_SRC_ALPHA = 0x0303;
  7528. /**
  7529. * @const
  7530. * @type {number}
  7531. */
  7532. ol.webgl.ARRAY_BUFFER = 0x8892;
  7533. /**
  7534. * @const
  7535. * @type {number}
  7536. */
  7537. ol.webgl.ELEMENT_ARRAY_BUFFER = 0x8893;
  7538. /**
  7539. * @const
  7540. * @type {number}
  7541. */
  7542. ol.webgl.STREAM_DRAW = 0x88E0;
  7543. /**
  7544. * @const
  7545. * @type {number}
  7546. */
  7547. ol.webgl.STATIC_DRAW = 0x88E4;
  7548. /**
  7549. * @const
  7550. * @type {number}
  7551. */
  7552. ol.webgl.DYNAMIC_DRAW = 0x88E8;
  7553. /**
  7554. * @const
  7555. * @type {number}
  7556. */
  7557. ol.webgl.CULL_FACE = 0x0B44;
  7558. /**
  7559. * @const
  7560. * @type {number}
  7561. */
  7562. ol.webgl.BLEND = 0x0BE2;
  7563. /**
  7564. * @const
  7565. * @type {number}
  7566. */
  7567. ol.webgl.STENCIL_TEST = 0x0B90;
  7568. /**
  7569. * @const
  7570. * @type {number}
  7571. */
  7572. ol.webgl.DEPTH_TEST = 0x0B71;
  7573. /**
  7574. * @const
  7575. * @type {number}
  7576. */
  7577. ol.webgl.SCISSOR_TEST = 0x0C11;
  7578. /**
  7579. * @const
  7580. * @type {number}
  7581. */
  7582. ol.webgl.UNSIGNED_BYTE = 0x1401;
  7583. /**
  7584. * @const
  7585. * @type {number}
  7586. */
  7587. ol.webgl.UNSIGNED_SHORT = 0x1403;
  7588. /**
  7589. * @const
  7590. * @type {number}
  7591. */
  7592. ol.webgl.UNSIGNED_INT = 0x1405;
  7593. /**
  7594. * @const
  7595. * @type {number}
  7596. */
  7597. ol.webgl.FLOAT = 0x1406;
  7598. /**
  7599. * @const
  7600. * @type {number}
  7601. */
  7602. ol.webgl.RGBA = 0x1908;
  7603. /**
  7604. * @const
  7605. * @type {number}
  7606. */
  7607. ol.webgl.FRAGMENT_SHADER = 0x8B30;
  7608. /**
  7609. * @const
  7610. * @type {number}
  7611. */
  7612. ol.webgl.VERTEX_SHADER = 0x8B31;
  7613. /**
  7614. * @const
  7615. * @type {number}
  7616. */
  7617. ol.webgl.LINK_STATUS = 0x8B82;
  7618. /**
  7619. * @const
  7620. * @type {number}
  7621. */
  7622. ol.webgl.LINEAR = 0x2601;
  7623. /**
  7624. * @const
  7625. * @type {number}
  7626. */
  7627. ol.webgl.TEXTURE_MAG_FILTER = 0x2800;
  7628. /**
  7629. * @const
  7630. * @type {number}
  7631. */
  7632. ol.webgl.TEXTURE_MIN_FILTER = 0x2801;
  7633. /**
  7634. * @const
  7635. * @type {number}
  7636. */
  7637. ol.webgl.TEXTURE_WRAP_S = 0x2802;
  7638. /**
  7639. * @const
  7640. * @type {number}
  7641. */
  7642. ol.webgl.TEXTURE_WRAP_T = 0x2803;
  7643. /**
  7644. * @const
  7645. * @type {number}
  7646. */
  7647. ol.webgl.TEXTURE_2D = 0x0DE1;
  7648. /**
  7649. * @const
  7650. * @type {number}
  7651. */
  7652. ol.webgl.TEXTURE0 = 0x84C0;
  7653. /**
  7654. * @const
  7655. * @type {number}
  7656. */
  7657. ol.webgl.CLAMP_TO_EDGE = 0x812F;
  7658. /**
  7659. * @const
  7660. * @type {number}
  7661. */
  7662. ol.webgl.COMPILE_STATUS = 0x8B81;
  7663. /**
  7664. * @const
  7665. * @type {number}
  7666. */
  7667. ol.webgl.FRAMEBUFFER = 0x8D40;
  7668. /** end of goog.webgl constants
  7669. */
  7670. /**
  7671. * @const
  7672. * @private
  7673. * @type {Array.<string>}
  7674. */
  7675. ol.webgl.CONTEXT_IDS_ = [
  7676. 'experimental-webgl',
  7677. 'webgl',
  7678. 'webkit-3d',
  7679. 'moz-webgl'
  7680. ];
  7681. /**
  7682. * @param {HTMLCanvasElement} canvas Canvas.
  7683. * @param {Object=} opt_attributes Attributes.
  7684. * @return {WebGLRenderingContext} WebGL rendering context.
  7685. */
  7686. ol.webgl.getContext = function(canvas, opt_attributes) {
  7687. var context, i, ii = ol.webgl.CONTEXT_IDS_.length;
  7688. for (i = 0; i < ii; ++i) {
  7689. try {
  7690. context = canvas.getContext(ol.webgl.CONTEXT_IDS_[i], opt_attributes);
  7691. if (context) {
  7692. return /** @type {!WebGLRenderingContext} */ (context);
  7693. }
  7694. } catch (e) {
  7695. // pass
  7696. }
  7697. }
  7698. return null;
  7699. };
  7700. goog.provide('ol.has');
  7701. goog.require('ol');
  7702. goog.require('ol.webgl');
  7703. var ua = typeof navigator !== 'undefined' ?
  7704. navigator.userAgent.toLowerCase() : '';
  7705. /**
  7706. * User agent string says we are dealing with Firefox as browser.
  7707. * @type {boolean}
  7708. */
  7709. ol.has.FIREFOX = ua.indexOf('firefox') !== -1;
  7710. /**
  7711. * User agent string says we are dealing with Safari as browser.
  7712. * @type {boolean}
  7713. */
  7714. ol.has.SAFARI = ua.indexOf('safari') !== -1 && ua.indexOf('chrom') == -1;
  7715. /**
  7716. * User agent string says we are dealing with a WebKit engine.
  7717. * @type {boolean}
  7718. */
  7719. ol.has.WEBKIT = ua.indexOf('webkit') !== -1 && ua.indexOf('edge') == -1;
  7720. /**
  7721. * User agent string says we are dealing with a Mac as platform.
  7722. * @type {boolean}
  7723. */
  7724. ol.has.MAC = ua.indexOf('macintosh') !== -1;
  7725. /**
  7726. * The ratio between physical pixels and device-independent pixels
  7727. * (dips) on the device (`window.devicePixelRatio`).
  7728. * @const
  7729. * @type {number}
  7730. * @api
  7731. */
  7732. ol.has.DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1;
  7733. /**
  7734. * True if the browser's Canvas implementation implements {get,set}LineDash.
  7735. * @type {boolean}
  7736. */
  7737. ol.has.CANVAS_LINE_DASH = false;
  7738. /**
  7739. * True if both the library and browser support Canvas. Always `false`
  7740. * if `ol.ENABLE_CANVAS` is set to `false` at compile time.
  7741. * @const
  7742. * @type {boolean}
  7743. * @api
  7744. */
  7745. ol.has.CANVAS = ol.ENABLE_CANVAS && (
  7746. /**
  7747. * @return {boolean} Canvas supported.
  7748. */
  7749. function() {
  7750. if (!('HTMLCanvasElement' in window)) {
  7751. return false;
  7752. }
  7753. try {
  7754. var context = document.createElement('CANVAS').getContext('2d');
  7755. if (!context) {
  7756. return false;
  7757. } else {
  7758. if (context.setLineDash !== undefined) {
  7759. ol.has.CANVAS_LINE_DASH = true;
  7760. }
  7761. return true;
  7762. }
  7763. } catch (e) {
  7764. return false;
  7765. }
  7766. })();
  7767. /**
  7768. * Indicates if DeviceOrientation is supported in the user's browser.
  7769. * @const
  7770. * @type {boolean}
  7771. * @api
  7772. */
  7773. ol.has.DEVICE_ORIENTATION = 'DeviceOrientationEvent' in window;
  7774. /**
  7775. * Is HTML5 geolocation supported in the current browser?
  7776. * @const
  7777. * @type {boolean}
  7778. * @api
  7779. */
  7780. ol.has.GEOLOCATION = 'geolocation' in navigator;
  7781. /**
  7782. * True if browser supports touch events.
  7783. * @const
  7784. * @type {boolean}
  7785. * @api
  7786. */
  7787. ol.has.TOUCH = ol.ASSUME_TOUCH || 'ontouchstart' in window;
  7788. /**
  7789. * True if browser supports pointer events.
  7790. * @const
  7791. * @type {boolean}
  7792. */
  7793. ol.has.POINTER = 'PointerEvent' in window;
  7794. /**
  7795. * True if browser supports ms pointer events (IE 10).
  7796. * @const
  7797. * @type {boolean}
  7798. */
  7799. ol.has.MSPOINTER = !!(navigator.msPointerEnabled);
  7800. /**
  7801. * True if both OpenLayers and browser support WebGL. Always `false`
  7802. * if `ol.ENABLE_WEBGL` is set to `false` at compile time.
  7803. * @const
  7804. * @type {boolean}
  7805. * @api
  7806. */
  7807. ol.has.WEBGL;
  7808. (function() {
  7809. if (ol.ENABLE_WEBGL) {
  7810. var hasWebGL = false;
  7811. var textureSize;
  7812. var /** @type {Array.<string>} */ extensions = [];
  7813. if ('WebGLRenderingContext' in window) {
  7814. try {
  7815. var canvas = /** @type {HTMLCanvasElement} */
  7816. (document.createElement('CANVAS'));
  7817. var gl = ol.webgl.getContext(canvas, {
  7818. failIfMajorPerformanceCaveat: true
  7819. });
  7820. if (gl) {
  7821. hasWebGL = true;
  7822. textureSize = /** @type {number} */
  7823. (gl.getParameter(gl.MAX_TEXTURE_SIZE));
  7824. extensions = gl.getSupportedExtensions();
  7825. }
  7826. } catch (e) {
  7827. // pass
  7828. }
  7829. }
  7830. ol.has.WEBGL = hasWebGL;
  7831. ol.WEBGL_EXTENSIONS = extensions;
  7832. ol.WEBGL_MAX_TEXTURE_SIZE = textureSize;
  7833. }
  7834. })();
  7835. goog.provide('ol.MapBrowserEventType');
  7836. goog.require('ol.events.EventType');
  7837. /**
  7838. * Constants for event names.
  7839. * @enum {string}
  7840. */
  7841. ol.MapBrowserEventType = {
  7842. /**
  7843. * A true single click with no dragging and no double click. Note that this
  7844. * event is delayed by 250 ms to ensure that it is not a double click.
  7845. * @event ol.MapBrowserEvent#singleclick
  7846. * @api
  7847. */
  7848. SINGLECLICK: 'singleclick',
  7849. /**
  7850. * A click with no dragging. A double click will fire two of this.
  7851. * @event ol.MapBrowserEvent#click
  7852. * @api
  7853. */
  7854. CLICK: ol.events.EventType.CLICK,
  7855. /**
  7856. * A true double click, with no dragging.
  7857. * @event ol.MapBrowserEvent#dblclick
  7858. * @api
  7859. */
  7860. DBLCLICK: ol.events.EventType.DBLCLICK,
  7861. /**
  7862. * Triggered when a pointer is dragged.
  7863. * @event ol.MapBrowserEvent#pointerdrag
  7864. * @api
  7865. */
  7866. POINTERDRAG: 'pointerdrag',
  7867. /**
  7868. * Triggered when a pointer is moved. Note that on touch devices this is
  7869. * triggered when the map is panned, so is not the same as mousemove.
  7870. * @event ol.MapBrowserEvent#pointermove
  7871. * @api
  7872. */
  7873. POINTERMOVE: 'pointermove',
  7874. POINTERDOWN: 'pointerdown',
  7875. POINTERUP: 'pointerup',
  7876. POINTEROVER: 'pointerover',
  7877. POINTEROUT: 'pointerout',
  7878. POINTERENTER: 'pointerenter',
  7879. POINTERLEAVE: 'pointerleave',
  7880. POINTERCANCEL: 'pointercancel'
  7881. };
  7882. goog.provide('ol.MapBrowserPointerEvent');
  7883. goog.require('ol');
  7884. goog.require('ol.MapBrowserEvent');
  7885. /**
  7886. * @constructor
  7887. * @extends {ol.MapBrowserEvent}
  7888. * @param {string} type Event type.
  7889. * @param {ol.PluggableMap} map Map.
  7890. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  7891. * @param {boolean=} opt_dragging Is the map currently being dragged?
  7892. * @param {?olx.FrameState=} opt_frameState Frame state.
  7893. */
  7894. ol.MapBrowserPointerEvent = function(type, map, pointerEvent, opt_dragging,
  7895. opt_frameState) {
  7896. ol.MapBrowserEvent.call(this, type, map, pointerEvent.originalEvent, opt_dragging,
  7897. opt_frameState);
  7898. /**
  7899. * @const
  7900. * @type {ol.pointer.PointerEvent}
  7901. */
  7902. this.pointerEvent = pointerEvent;
  7903. };
  7904. ol.inherits(ol.MapBrowserPointerEvent, ol.MapBrowserEvent);
  7905. goog.provide('ol.pointer.EventType');
  7906. /**
  7907. * Constants for event names.
  7908. * @enum {string}
  7909. */
  7910. ol.pointer.EventType = {
  7911. POINTERMOVE: 'pointermove',
  7912. POINTERDOWN: 'pointerdown',
  7913. POINTERUP: 'pointerup',
  7914. POINTEROVER: 'pointerover',
  7915. POINTEROUT: 'pointerout',
  7916. POINTERENTER: 'pointerenter',
  7917. POINTERLEAVE: 'pointerleave',
  7918. POINTERCANCEL: 'pointercancel'
  7919. };
  7920. goog.provide('ol.pointer.EventSource');
  7921. /**
  7922. * @param {ol.pointer.PointerEventHandler} dispatcher Event handler.
  7923. * @param {!Object.<string, function(Event)>} mapping Event
  7924. * mapping.
  7925. * @constructor
  7926. */
  7927. ol.pointer.EventSource = function(dispatcher, mapping) {
  7928. /**
  7929. * @type {ol.pointer.PointerEventHandler}
  7930. */
  7931. this.dispatcher = dispatcher;
  7932. /**
  7933. * @private
  7934. * @const
  7935. * @type {!Object.<string, function(Event)>}
  7936. */
  7937. this.mapping_ = mapping;
  7938. };
  7939. /**
  7940. * List of events supported by this source.
  7941. * @return {Array.<string>} Event names
  7942. */
  7943. ol.pointer.EventSource.prototype.getEvents = function() {
  7944. return Object.keys(this.mapping_);
  7945. };
  7946. /**
  7947. * Returns the handler that should handle a given event type.
  7948. * @param {string} eventType The event type.
  7949. * @return {function(Event)} Handler
  7950. */
  7951. ol.pointer.EventSource.prototype.getHandlerForEvent = function(eventType) {
  7952. return this.mapping_[eventType];
  7953. };
  7954. // Based on https://github.com/Polymer/PointerEvents
  7955. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
  7956. //
  7957. // Redistribution and use in source and binary forms, with or without
  7958. // modification, are permitted provided that the following conditions are
  7959. // met:
  7960. //
  7961. // * Redistributions of source code must retain the above copyright
  7962. // notice, this list of conditions and the following disclaimer.
  7963. // * Redistributions in binary form must reproduce the above
  7964. // copyright notice, this list of conditions and the following disclaimer
  7965. // in the documentation and/or other materials provided with the
  7966. // distribution.
  7967. // * Neither the name of Google Inc. nor the names of its
  7968. // contributors may be used to endorse or promote products derived from
  7969. // this software without specific prior written permission.
  7970. //
  7971. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7972. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7973. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  7974. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7975. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  7976. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7977. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  7978. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  7979. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7980. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  7981. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7982. goog.provide('ol.pointer.MouseSource');
  7983. goog.require('ol');
  7984. goog.require('ol.pointer.EventSource');
  7985. /**
  7986. * @param {ol.pointer.PointerEventHandler} dispatcher Event handler.
  7987. * @constructor
  7988. * @extends {ol.pointer.EventSource}
  7989. */
  7990. ol.pointer.MouseSource = function(dispatcher) {
  7991. var mapping = {
  7992. 'mousedown': this.mousedown,
  7993. 'mousemove': this.mousemove,
  7994. 'mouseup': this.mouseup,
  7995. 'mouseover': this.mouseover,
  7996. 'mouseout': this.mouseout
  7997. };
  7998. ol.pointer.EventSource.call(this, dispatcher, mapping);
  7999. /**
  8000. * @const
  8001. * @type {!Object.<string, Event|Object>}
  8002. */
  8003. this.pointerMap = dispatcher.pointerMap;
  8004. /**
  8005. * @const
  8006. * @type {Array.<ol.Pixel>}
  8007. */
  8008. this.lastTouches = [];
  8009. };
  8010. ol.inherits(ol.pointer.MouseSource, ol.pointer.EventSource);
  8011. /**
  8012. * @const
  8013. * @type {number}
  8014. */
  8015. ol.pointer.MouseSource.POINTER_ID = 1;
  8016. /**
  8017. * @const
  8018. * @type {string}
  8019. */
  8020. ol.pointer.MouseSource.POINTER_TYPE = 'mouse';
  8021. /**
  8022. * Radius around touchend that swallows mouse events.
  8023. *
  8024. * @const
  8025. * @type {number}
  8026. */
  8027. ol.pointer.MouseSource.DEDUP_DIST = 25;
  8028. /**
  8029. * Detect if a mouse event was simulated from a touch by
  8030. * checking if previously there was a touch event at the
  8031. * same position.
  8032. *
  8033. * FIXME - Known problem with the native Android browser on
  8034. * Samsung GT-I9100 (Android 4.1.2):
  8035. * In case the page is scrolled, this function does not work
  8036. * correctly when a canvas is used (WebGL or canvas renderer).
  8037. * Mouse listeners on canvas elements (for this browser), create
  8038. * two mouse events: One 'good' and one 'bad' one (on other browsers or
  8039. * when a div is used, there is only one event). For the 'bad' one,
  8040. * clientX/clientY and also pageX/pageY are wrong when the page
  8041. * is scrolled. Because of that, this function can not detect if
  8042. * the events were simulated from a touch event. As result, a
  8043. * pointer event at a wrong position is dispatched, which confuses
  8044. * the map interactions.
  8045. * It is unclear, how one can get the correct position for the event
  8046. * or detect that the positions are invalid.
  8047. *
  8048. * @private
  8049. * @param {Event} inEvent The in event.
  8050. * @return {boolean} True, if the event was generated by a touch.
  8051. */
  8052. ol.pointer.MouseSource.prototype.isEventSimulatedFromTouch_ = function(inEvent) {
  8053. var lts = this.lastTouches;
  8054. var x = inEvent.clientX, y = inEvent.clientY;
  8055. for (var i = 0, l = lts.length, t; i < l && (t = lts[i]); i++) {
  8056. // simulated mouse events will be swallowed near a primary touchend
  8057. var dx = Math.abs(x - t[0]), dy = Math.abs(y - t[1]);
  8058. if (dx <= ol.pointer.MouseSource.DEDUP_DIST &&
  8059. dy <= ol.pointer.MouseSource.DEDUP_DIST) {
  8060. return true;
  8061. }
  8062. }
  8063. return false;
  8064. };
  8065. /**
  8066. * Creates a copy of the original event that will be used
  8067. * for the fake pointer event.
  8068. *
  8069. * @param {Event} inEvent The in event.
  8070. * @param {ol.pointer.PointerEventHandler} dispatcher Event handler.
  8071. * @return {Object} The copied event.
  8072. */
  8073. ol.pointer.MouseSource.prepareEvent = function(inEvent, dispatcher) {
  8074. var e = dispatcher.cloneEvent(inEvent, inEvent);
  8075. // forward mouse preventDefault
  8076. var pd = e.preventDefault;
  8077. e.preventDefault = function() {
  8078. inEvent.preventDefault();
  8079. pd();
  8080. };
  8081. e.pointerId = ol.pointer.MouseSource.POINTER_ID;
  8082. e.isPrimary = true;
  8083. e.pointerType = ol.pointer.MouseSource.POINTER_TYPE;
  8084. return e;
  8085. };
  8086. /**
  8087. * Handler for `mousedown`.
  8088. *
  8089. * @param {Event} inEvent The in event.
  8090. */
  8091. ol.pointer.MouseSource.prototype.mousedown = function(inEvent) {
  8092. if (!this.isEventSimulatedFromTouch_(inEvent)) {
  8093. // TODO(dfreedman) workaround for some elements not sending mouseup
  8094. // http://crbug/149091
  8095. if (ol.pointer.MouseSource.POINTER_ID.toString() in this.pointerMap) {
  8096. this.cancel(inEvent);
  8097. }
  8098. var e = ol.pointer.MouseSource.prepareEvent(inEvent, this.dispatcher);
  8099. this.pointerMap[ol.pointer.MouseSource.POINTER_ID.toString()] = inEvent;
  8100. this.dispatcher.down(e, inEvent);
  8101. }
  8102. };
  8103. /**
  8104. * Handler for `mousemove`.
  8105. *
  8106. * @param {Event} inEvent The in event.
  8107. */
  8108. ol.pointer.MouseSource.prototype.mousemove = function(inEvent) {
  8109. if (!this.isEventSimulatedFromTouch_(inEvent)) {
  8110. var e = ol.pointer.MouseSource.prepareEvent(inEvent, this.dispatcher);
  8111. this.dispatcher.move(e, inEvent);
  8112. }
  8113. };
  8114. /**
  8115. * Handler for `mouseup`.
  8116. *
  8117. * @param {Event} inEvent The in event.
  8118. */
  8119. ol.pointer.MouseSource.prototype.mouseup = function(inEvent) {
  8120. if (!this.isEventSimulatedFromTouch_(inEvent)) {
  8121. var p = this.pointerMap[ol.pointer.MouseSource.POINTER_ID.toString()];
  8122. if (p && p.button === inEvent.button) {
  8123. var e = ol.pointer.MouseSource.prepareEvent(inEvent, this.dispatcher);
  8124. this.dispatcher.up(e, inEvent);
  8125. this.cleanupMouse();
  8126. }
  8127. }
  8128. };
  8129. /**
  8130. * Handler for `mouseover`.
  8131. *
  8132. * @param {Event} inEvent The in event.
  8133. */
  8134. ol.pointer.MouseSource.prototype.mouseover = function(inEvent) {
  8135. if (!this.isEventSimulatedFromTouch_(inEvent)) {
  8136. var e = ol.pointer.MouseSource.prepareEvent(inEvent, this.dispatcher);
  8137. this.dispatcher.enterOver(e, inEvent);
  8138. }
  8139. };
  8140. /**
  8141. * Handler for `mouseout`.
  8142. *
  8143. * @param {Event} inEvent The in event.
  8144. */
  8145. ol.pointer.MouseSource.prototype.mouseout = function(inEvent) {
  8146. if (!this.isEventSimulatedFromTouch_(inEvent)) {
  8147. var e = ol.pointer.MouseSource.prepareEvent(inEvent, this.dispatcher);
  8148. this.dispatcher.leaveOut(e, inEvent);
  8149. }
  8150. };
  8151. /**
  8152. * Dispatches a `pointercancel` event.
  8153. *
  8154. * @param {Event} inEvent The in event.
  8155. */
  8156. ol.pointer.MouseSource.prototype.cancel = function(inEvent) {
  8157. var e = ol.pointer.MouseSource.prepareEvent(inEvent, this.dispatcher);
  8158. this.dispatcher.cancel(e, inEvent);
  8159. this.cleanupMouse();
  8160. };
  8161. /**
  8162. * Remove the mouse from the list of active pointers.
  8163. */
  8164. ol.pointer.MouseSource.prototype.cleanupMouse = function() {
  8165. delete this.pointerMap[ol.pointer.MouseSource.POINTER_ID.toString()];
  8166. };
  8167. // Based on https://github.com/Polymer/PointerEvents
  8168. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
  8169. //
  8170. // Redistribution and use in source and binary forms, with or without
  8171. // modification, are permitted provided that the following conditions are
  8172. // met:
  8173. //
  8174. // * Redistributions of source code must retain the above copyright
  8175. // notice, this list of conditions and the following disclaimer.
  8176. // * Redistributions in binary form must reproduce the above
  8177. // copyright notice, this list of conditions and the following disclaimer
  8178. // in the documentation and/or other materials provided with the
  8179. // distribution.
  8180. // * Neither the name of Google Inc. nor the names of its
  8181. // contributors may be used to endorse or promote products derived from
  8182. // this software without specific prior written permission.
  8183. //
  8184. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8185. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8186. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8187. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8188. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8189. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8190. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  8191. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  8192. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  8193. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  8194. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8195. goog.provide('ol.pointer.MsSource');
  8196. goog.require('ol');
  8197. goog.require('ol.pointer.EventSource');
  8198. /**
  8199. * @param {ol.pointer.PointerEventHandler} dispatcher Event handler.
  8200. * @constructor
  8201. * @extends {ol.pointer.EventSource}
  8202. */
  8203. ol.pointer.MsSource = function(dispatcher) {
  8204. var mapping = {
  8205. 'MSPointerDown': this.msPointerDown,
  8206. 'MSPointerMove': this.msPointerMove,
  8207. 'MSPointerUp': this.msPointerUp,
  8208. 'MSPointerOut': this.msPointerOut,
  8209. 'MSPointerOver': this.msPointerOver,
  8210. 'MSPointerCancel': this.msPointerCancel,
  8211. 'MSGotPointerCapture': this.msGotPointerCapture,
  8212. 'MSLostPointerCapture': this.msLostPointerCapture
  8213. };
  8214. ol.pointer.EventSource.call(this, dispatcher, mapping);
  8215. /**
  8216. * @const
  8217. * @type {!Object.<string, Event|Object>}
  8218. */
  8219. this.pointerMap = dispatcher.pointerMap;
  8220. /**
  8221. * @const
  8222. * @type {Array.<string>}
  8223. */
  8224. this.POINTER_TYPES = [
  8225. '',
  8226. 'unavailable',
  8227. 'touch',
  8228. 'pen',
  8229. 'mouse'
  8230. ];
  8231. };
  8232. ol.inherits(ol.pointer.MsSource, ol.pointer.EventSource);
  8233. /**
  8234. * Creates a copy of the original event that will be used
  8235. * for the fake pointer event.
  8236. *
  8237. * @private
  8238. * @param {Event} inEvent The in event.
  8239. * @return {Object} The copied event.
  8240. */
  8241. ol.pointer.MsSource.prototype.prepareEvent_ = function(inEvent) {
  8242. var e = inEvent;
  8243. if (typeof inEvent.pointerType === 'number') {
  8244. e = this.dispatcher.cloneEvent(inEvent, inEvent);
  8245. e.pointerType = this.POINTER_TYPES[inEvent.pointerType];
  8246. }
  8247. return e;
  8248. };
  8249. /**
  8250. * Remove this pointer from the list of active pointers.
  8251. * @param {number} pointerId Pointer identifier.
  8252. */
  8253. ol.pointer.MsSource.prototype.cleanup = function(pointerId) {
  8254. delete this.pointerMap[pointerId.toString()];
  8255. };
  8256. /**
  8257. * Handler for `msPointerDown`.
  8258. *
  8259. * @param {Event} inEvent The in event.
  8260. */
  8261. ol.pointer.MsSource.prototype.msPointerDown = function(inEvent) {
  8262. this.pointerMap[inEvent.pointerId.toString()] = inEvent;
  8263. var e = this.prepareEvent_(inEvent);
  8264. this.dispatcher.down(e, inEvent);
  8265. };
  8266. /**
  8267. * Handler for `msPointerMove`.
  8268. *
  8269. * @param {Event} inEvent The in event.
  8270. */
  8271. ol.pointer.MsSource.prototype.msPointerMove = function(inEvent) {
  8272. var e = this.prepareEvent_(inEvent);
  8273. this.dispatcher.move(e, inEvent);
  8274. };
  8275. /**
  8276. * Handler for `msPointerUp`.
  8277. *
  8278. * @param {Event} inEvent The in event.
  8279. */
  8280. ol.pointer.MsSource.prototype.msPointerUp = function(inEvent) {
  8281. var e = this.prepareEvent_(inEvent);
  8282. this.dispatcher.up(e, inEvent);
  8283. this.cleanup(inEvent.pointerId);
  8284. };
  8285. /**
  8286. * Handler for `msPointerOut`.
  8287. *
  8288. * @param {Event} inEvent The in event.
  8289. */
  8290. ol.pointer.MsSource.prototype.msPointerOut = function(inEvent) {
  8291. var e = this.prepareEvent_(inEvent);
  8292. this.dispatcher.leaveOut(e, inEvent);
  8293. };
  8294. /**
  8295. * Handler for `msPointerOver`.
  8296. *
  8297. * @param {Event} inEvent The in event.
  8298. */
  8299. ol.pointer.MsSource.prototype.msPointerOver = function(inEvent) {
  8300. var e = this.prepareEvent_(inEvent);
  8301. this.dispatcher.enterOver(e, inEvent);
  8302. };
  8303. /**
  8304. * Handler for `msPointerCancel`.
  8305. *
  8306. * @param {Event} inEvent The in event.
  8307. */
  8308. ol.pointer.MsSource.prototype.msPointerCancel = function(inEvent) {
  8309. var e = this.prepareEvent_(inEvent);
  8310. this.dispatcher.cancel(e, inEvent);
  8311. this.cleanup(inEvent.pointerId);
  8312. };
  8313. /**
  8314. * Handler for `msLostPointerCapture`.
  8315. *
  8316. * @param {Event} inEvent The in event.
  8317. */
  8318. ol.pointer.MsSource.prototype.msLostPointerCapture = function(inEvent) {
  8319. var e = this.dispatcher.makeEvent('lostpointercapture',
  8320. inEvent, inEvent);
  8321. this.dispatcher.dispatchEvent(e);
  8322. };
  8323. /**
  8324. * Handler for `msGotPointerCapture`.
  8325. *
  8326. * @param {Event} inEvent The in event.
  8327. */
  8328. ol.pointer.MsSource.prototype.msGotPointerCapture = function(inEvent) {
  8329. var e = this.dispatcher.makeEvent('gotpointercapture',
  8330. inEvent, inEvent);
  8331. this.dispatcher.dispatchEvent(e);
  8332. };
  8333. // Based on https://github.com/Polymer/PointerEvents
  8334. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
  8335. //
  8336. // Redistribution and use in source and binary forms, with or without
  8337. // modification, are permitted provided that the following conditions are
  8338. // met:
  8339. //
  8340. // * Redistributions of source code must retain the above copyright
  8341. // notice, this list of conditions and the following disclaimer.
  8342. // * Redistributions in binary form must reproduce the above
  8343. // copyright notice, this list of conditions and the following disclaimer
  8344. // in the documentation and/or other materials provided with the
  8345. // distribution.
  8346. // * Neither the name of Google Inc. nor the names of its
  8347. // contributors may be used to endorse or promote products derived from
  8348. // this software without specific prior written permission.
  8349. //
  8350. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8351. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8352. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8353. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8354. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8355. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8356. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  8357. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  8358. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  8359. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  8360. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8361. goog.provide('ol.pointer.NativeSource');
  8362. goog.require('ol');
  8363. goog.require('ol.pointer.EventSource');
  8364. /**
  8365. * @param {ol.pointer.PointerEventHandler} dispatcher Event handler.
  8366. * @constructor
  8367. * @extends {ol.pointer.EventSource}
  8368. */
  8369. ol.pointer.NativeSource = function(dispatcher) {
  8370. var mapping = {
  8371. 'pointerdown': this.pointerDown,
  8372. 'pointermove': this.pointerMove,
  8373. 'pointerup': this.pointerUp,
  8374. 'pointerout': this.pointerOut,
  8375. 'pointerover': this.pointerOver,
  8376. 'pointercancel': this.pointerCancel,
  8377. 'gotpointercapture': this.gotPointerCapture,
  8378. 'lostpointercapture': this.lostPointerCapture
  8379. };
  8380. ol.pointer.EventSource.call(this, dispatcher, mapping);
  8381. };
  8382. ol.inherits(ol.pointer.NativeSource, ol.pointer.EventSource);
  8383. /**
  8384. * Handler for `pointerdown`.
  8385. *
  8386. * @param {Event} inEvent The in event.
  8387. */
  8388. ol.pointer.NativeSource.prototype.pointerDown = function(inEvent) {
  8389. this.dispatcher.fireNativeEvent(inEvent);
  8390. };
  8391. /**
  8392. * Handler for `pointermove`.
  8393. *
  8394. * @param {Event} inEvent The in event.
  8395. */
  8396. ol.pointer.NativeSource.prototype.pointerMove = function(inEvent) {
  8397. this.dispatcher.fireNativeEvent(inEvent);
  8398. };
  8399. /**
  8400. * Handler for `pointerup`.
  8401. *
  8402. * @param {Event} inEvent The in event.
  8403. */
  8404. ol.pointer.NativeSource.prototype.pointerUp = function(inEvent) {
  8405. this.dispatcher.fireNativeEvent(inEvent);
  8406. };
  8407. /**
  8408. * Handler for `pointerout`.
  8409. *
  8410. * @param {Event} inEvent The in event.
  8411. */
  8412. ol.pointer.NativeSource.prototype.pointerOut = function(inEvent) {
  8413. this.dispatcher.fireNativeEvent(inEvent);
  8414. };
  8415. /**
  8416. * Handler for `pointerover`.
  8417. *
  8418. * @param {Event} inEvent The in event.
  8419. */
  8420. ol.pointer.NativeSource.prototype.pointerOver = function(inEvent) {
  8421. this.dispatcher.fireNativeEvent(inEvent);
  8422. };
  8423. /**
  8424. * Handler for `pointercancel`.
  8425. *
  8426. * @param {Event} inEvent The in event.
  8427. */
  8428. ol.pointer.NativeSource.prototype.pointerCancel = function(inEvent) {
  8429. this.dispatcher.fireNativeEvent(inEvent);
  8430. };
  8431. /**
  8432. * Handler for `lostpointercapture`.
  8433. *
  8434. * @param {Event} inEvent The in event.
  8435. */
  8436. ol.pointer.NativeSource.prototype.lostPointerCapture = function(inEvent) {
  8437. this.dispatcher.fireNativeEvent(inEvent);
  8438. };
  8439. /**
  8440. * Handler for `gotpointercapture`.
  8441. *
  8442. * @param {Event} inEvent The in event.
  8443. */
  8444. ol.pointer.NativeSource.prototype.gotPointerCapture = function(inEvent) {
  8445. this.dispatcher.fireNativeEvent(inEvent);
  8446. };
  8447. // Based on https://github.com/Polymer/PointerEvents
  8448. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
  8449. //
  8450. // Redistribution and use in source and binary forms, with or without
  8451. // modification, are permitted provided that the following conditions are
  8452. // met:
  8453. //
  8454. // * Redistributions of source code must retain the above copyright
  8455. // notice, this list of conditions and the following disclaimer.
  8456. // * Redistributions in binary form must reproduce the above
  8457. // copyright notice, this list of conditions and the following disclaimer
  8458. // in the documentation and/or other materials provided with the
  8459. // distribution.
  8460. // * Neither the name of Google Inc. nor the names of its
  8461. // contributors may be used to endorse or promote products derived from
  8462. // this software without specific prior written permission.
  8463. //
  8464. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8465. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8466. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8467. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8468. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8469. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8470. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  8471. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  8472. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  8473. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  8474. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8475. goog.provide('ol.pointer.PointerEvent');
  8476. goog.require('ol');
  8477. goog.require('ol.events.Event');
  8478. /**
  8479. * A class for pointer events.
  8480. *
  8481. * This class is used as an abstraction for mouse events,
  8482. * touch events and even native pointer events.
  8483. *
  8484. * @constructor
  8485. * @extends {ol.events.Event}
  8486. * @param {string} type The type of the event to create.
  8487. * @param {Event} originalEvent The event.
  8488. * @param {Object.<string, ?>=} opt_eventDict An optional dictionary of
  8489. * initial event properties.
  8490. */
  8491. ol.pointer.PointerEvent = function(type, originalEvent, opt_eventDict) {
  8492. ol.events.Event.call(this, type);
  8493. /**
  8494. * @const
  8495. * @type {Event}
  8496. */
  8497. this.originalEvent = originalEvent;
  8498. var eventDict = opt_eventDict ? opt_eventDict : {};
  8499. /**
  8500. * @type {number}
  8501. */
  8502. this.buttons = this.getButtons_(eventDict);
  8503. /**
  8504. * @type {number}
  8505. */
  8506. this.pressure = this.getPressure_(eventDict, this.buttons);
  8507. // MouseEvent related properties
  8508. /**
  8509. * @type {boolean}
  8510. */
  8511. this.bubbles = 'bubbles' in eventDict ? eventDict['bubbles'] : false;
  8512. /**
  8513. * @type {boolean}
  8514. */
  8515. this.cancelable = 'cancelable' in eventDict ? eventDict['cancelable'] : false;
  8516. /**
  8517. * @type {Object}
  8518. */
  8519. this.view = 'view' in eventDict ? eventDict['view'] : null;
  8520. /**
  8521. * @type {number}
  8522. */
  8523. this.detail = 'detail' in eventDict ? eventDict['detail'] : null;
  8524. /**
  8525. * @type {number}
  8526. */
  8527. this.screenX = 'screenX' in eventDict ? eventDict['screenX'] : 0;
  8528. /**
  8529. * @type {number}
  8530. */
  8531. this.screenY = 'screenY' in eventDict ? eventDict['screenY'] : 0;
  8532. /**
  8533. * @type {number}
  8534. */
  8535. this.clientX = 'clientX' in eventDict ? eventDict['clientX'] : 0;
  8536. /**
  8537. * @type {number}
  8538. */
  8539. this.clientY = 'clientY' in eventDict ? eventDict['clientY'] : 0;
  8540. /**
  8541. * @type {boolean}
  8542. */
  8543. this.ctrlKey = 'ctrlKey' in eventDict ? eventDict['ctrlKey'] : false;
  8544. /**
  8545. * @type {boolean}
  8546. */
  8547. this.altKey = 'altKey' in eventDict ? eventDict['altKey'] : false;
  8548. /**
  8549. * @type {boolean}
  8550. */
  8551. this.shiftKey = 'shiftKey' in eventDict ? eventDict['shiftKey'] : false;
  8552. /**
  8553. * @type {boolean}
  8554. */
  8555. this.metaKey = 'metaKey' in eventDict ? eventDict['metaKey'] : false;
  8556. /**
  8557. * @type {number}
  8558. */
  8559. this.button = 'button' in eventDict ? eventDict['button'] : 0;
  8560. /**
  8561. * @type {Node}
  8562. */
  8563. this.relatedTarget = 'relatedTarget' in eventDict ?
  8564. eventDict['relatedTarget'] : null;
  8565. // PointerEvent related properties
  8566. /**
  8567. * @const
  8568. * @type {number}
  8569. */
  8570. this.pointerId = 'pointerId' in eventDict ? eventDict['pointerId'] : 0;
  8571. /**
  8572. * @type {number}
  8573. */
  8574. this.width = 'width' in eventDict ? eventDict['width'] : 0;
  8575. /**
  8576. * @type {number}
  8577. */
  8578. this.height = 'height' in eventDict ? eventDict['height'] : 0;
  8579. /**
  8580. * @type {number}
  8581. */
  8582. this.tiltX = 'tiltX' in eventDict ? eventDict['tiltX'] : 0;
  8583. /**
  8584. * @type {number}
  8585. */
  8586. this.tiltY = 'tiltY' in eventDict ? eventDict['tiltY'] : 0;
  8587. /**
  8588. * @type {string}
  8589. */
  8590. this.pointerType = 'pointerType' in eventDict ? eventDict['pointerType'] : '';
  8591. /**
  8592. * @type {number}
  8593. */
  8594. this.hwTimestamp = 'hwTimestamp' in eventDict ? eventDict['hwTimestamp'] : 0;
  8595. /**
  8596. * @type {boolean}
  8597. */
  8598. this.isPrimary = 'isPrimary' in eventDict ? eventDict['isPrimary'] : false;
  8599. // keep the semantics of preventDefault
  8600. if (originalEvent.preventDefault) {
  8601. this.preventDefault = function() {
  8602. originalEvent.preventDefault();
  8603. };
  8604. }
  8605. };
  8606. ol.inherits(ol.pointer.PointerEvent, ol.events.Event);
  8607. /**
  8608. * @private
  8609. * @param {Object.<string, ?>} eventDict The event dictionary.
  8610. * @return {number} Button indicator.
  8611. */
  8612. ol.pointer.PointerEvent.prototype.getButtons_ = function(eventDict) {
  8613. // According to the w3c spec,
  8614. // http://www.w3.org/TR/DOM-Level-3-Events/#events-MouseEvent-button
  8615. // MouseEvent.button == 0 can mean either no mouse button depressed, or the
  8616. // left mouse button depressed.
  8617. //
  8618. // As of now, the only way to distinguish between the two states of
  8619. // MouseEvent.button is by using the deprecated MouseEvent.which property, as
  8620. // this maps mouse buttons to positive integers > 0, and uses 0 to mean that
  8621. // no mouse button is held.
  8622. //
  8623. // MouseEvent.which is derived from MouseEvent.button at MouseEvent creation,
  8624. // but initMouseEvent does not expose an argument with which to set
  8625. // MouseEvent.which. Calling initMouseEvent with a buttonArg of 0 will set
  8626. // MouseEvent.button == 0 and MouseEvent.which == 1, breaking the expectations
  8627. // of app developers.
  8628. //
  8629. // The only way to propagate the correct state of MouseEvent.which and
  8630. // MouseEvent.button to a new MouseEvent.button == 0 and MouseEvent.which == 0
  8631. // is to call initMouseEvent with a buttonArg value of -1.
  8632. //
  8633. // This is fixed with DOM Level 4's use of buttons
  8634. var buttons;
  8635. if (eventDict.buttons || ol.pointer.PointerEvent.HAS_BUTTONS) {
  8636. buttons = eventDict.buttons;
  8637. } else {
  8638. switch (eventDict.which) {
  8639. case 1: buttons = 1; break;
  8640. case 2: buttons = 4; break;
  8641. case 3: buttons = 2; break;
  8642. default: buttons = 0;
  8643. }
  8644. }
  8645. return buttons;
  8646. };
  8647. /**
  8648. * @private
  8649. * @param {Object.<string, ?>} eventDict The event dictionary.
  8650. * @param {number} buttons Button indicator.
  8651. * @return {number} The pressure.
  8652. */
  8653. ol.pointer.PointerEvent.prototype.getPressure_ = function(eventDict, buttons) {
  8654. // Spec requires that pointers without pressure specified use 0.5 for down
  8655. // state and 0 for up state.
  8656. var pressure = 0;
  8657. if (eventDict.pressure) {
  8658. pressure = eventDict.pressure;
  8659. } else {
  8660. pressure = buttons ? 0.5 : 0;
  8661. }
  8662. return pressure;
  8663. };
  8664. /**
  8665. * Is the `buttons` property supported?
  8666. * @type {boolean}
  8667. */
  8668. ol.pointer.PointerEvent.HAS_BUTTONS = false;
  8669. /**
  8670. * Checks if the `buttons` property is supported.
  8671. */
  8672. (function() {
  8673. try {
  8674. var ev = new MouseEvent('click', {buttons: 1});
  8675. ol.pointer.PointerEvent.HAS_BUTTONS = ev.buttons === 1;
  8676. } catch (e) {
  8677. // pass
  8678. }
  8679. })();
  8680. // Based on https://github.com/Polymer/PointerEvents
  8681. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
  8682. //
  8683. // Redistribution and use in source and binary forms, with or without
  8684. // modification, are permitted provided that the following conditions are
  8685. // met:
  8686. //
  8687. // * Redistributions of source code must retain the above copyright
  8688. // notice, this list of conditions and the following disclaimer.
  8689. // * Redistributions in binary form must reproduce the above
  8690. // copyright notice, this list of conditions and the following disclaimer
  8691. // in the documentation and/or other materials provided with the
  8692. // distribution.
  8693. // * Neither the name of Google Inc. nor the names of its
  8694. // contributors may be used to endorse or promote products derived from
  8695. // this software without specific prior written permission.
  8696. //
  8697. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8698. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8699. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8700. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8701. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8702. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8703. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  8704. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  8705. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  8706. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  8707. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8708. goog.provide('ol.pointer.TouchSource');
  8709. goog.require('ol');
  8710. goog.require('ol.array');
  8711. goog.require('ol.pointer.EventSource');
  8712. goog.require('ol.pointer.MouseSource');
  8713. /**
  8714. * @constructor
  8715. * @param {ol.pointer.PointerEventHandler} dispatcher The event handler.
  8716. * @param {ol.pointer.MouseSource} mouseSource Mouse source.
  8717. * @extends {ol.pointer.EventSource}
  8718. */
  8719. ol.pointer.TouchSource = function(dispatcher, mouseSource) {
  8720. var mapping = {
  8721. 'touchstart': this.touchstart,
  8722. 'touchmove': this.touchmove,
  8723. 'touchend': this.touchend,
  8724. 'touchcancel': this.touchcancel
  8725. };
  8726. ol.pointer.EventSource.call(this, dispatcher, mapping);
  8727. /**
  8728. * @const
  8729. * @type {!Object.<string, Event|Object>}
  8730. */
  8731. this.pointerMap = dispatcher.pointerMap;
  8732. /**
  8733. * @const
  8734. * @type {ol.pointer.MouseSource}
  8735. */
  8736. this.mouseSource = mouseSource;
  8737. /**
  8738. * @private
  8739. * @type {number|undefined}
  8740. */
  8741. this.firstTouchId_ = undefined;
  8742. /**
  8743. * @private
  8744. * @type {number}
  8745. */
  8746. this.clickCount_ = 0;
  8747. /**
  8748. * @private
  8749. * @type {number|undefined}
  8750. */
  8751. this.resetId_ = undefined;
  8752. };
  8753. ol.inherits(ol.pointer.TouchSource, ol.pointer.EventSource);
  8754. /**
  8755. * Mouse event timeout: This should be long enough to
  8756. * ignore compat mouse events made by touch.
  8757. * @const
  8758. * @type {number}
  8759. */
  8760. ol.pointer.TouchSource.DEDUP_TIMEOUT = 2500;
  8761. /**
  8762. * @const
  8763. * @type {number}
  8764. */
  8765. ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT = 200;
  8766. /**
  8767. * @const
  8768. * @type {string}
  8769. */
  8770. ol.pointer.TouchSource.POINTER_TYPE = 'touch';
  8771. /**
  8772. * @private
  8773. * @param {Touch} inTouch The in touch.
  8774. * @return {boolean} True, if this is the primary touch.
  8775. */
  8776. ol.pointer.TouchSource.prototype.isPrimaryTouch_ = function(inTouch) {
  8777. return this.firstTouchId_ === inTouch.identifier;
  8778. };
  8779. /**
  8780. * Set primary touch if there are no pointers, or the only pointer is the mouse.
  8781. * @param {Touch} inTouch The in touch.
  8782. * @private
  8783. */
  8784. ol.pointer.TouchSource.prototype.setPrimaryTouch_ = function(inTouch) {
  8785. var count = Object.keys(this.pointerMap).length;
  8786. if (count === 0 || (count === 1 &&
  8787. ol.pointer.MouseSource.POINTER_ID.toString() in this.pointerMap)) {
  8788. this.firstTouchId_ = inTouch.identifier;
  8789. this.cancelResetClickCount_();
  8790. }
  8791. };
  8792. /**
  8793. * @private
  8794. * @param {Object} inPointer The in pointer object.
  8795. */
  8796. ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) {
  8797. if (inPointer.isPrimary) {
  8798. this.firstTouchId_ = undefined;
  8799. this.resetClickCount_();
  8800. }
  8801. };
  8802. /**
  8803. * @private
  8804. */
  8805. ol.pointer.TouchSource.prototype.resetClickCount_ = function() {
  8806. this.resetId_ = setTimeout(
  8807. this.resetClickCountHandler_.bind(this),
  8808. ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT);
  8809. };
  8810. /**
  8811. * @private
  8812. */
  8813. ol.pointer.TouchSource.prototype.resetClickCountHandler_ = function() {
  8814. this.clickCount_ = 0;
  8815. this.resetId_ = undefined;
  8816. };
  8817. /**
  8818. * @private
  8819. */
  8820. ol.pointer.TouchSource.prototype.cancelResetClickCount_ = function() {
  8821. if (this.resetId_ !== undefined) {
  8822. clearTimeout(this.resetId_);
  8823. }
  8824. };
  8825. /**
  8826. * @private
  8827. * @param {Event} browserEvent Browser event
  8828. * @param {Touch} inTouch Touch event
  8829. * @return {Object} A pointer object.
  8830. */
  8831. ol.pointer.TouchSource.prototype.touchToPointer_ = function(browserEvent, inTouch) {
  8832. var e = this.dispatcher.cloneEvent(browserEvent, inTouch);
  8833. // Spec specifies that pointerId 1 is reserved for Mouse.
  8834. // Touch identifiers can start at 0.
  8835. // Add 2 to the touch identifier for compatibility.
  8836. e.pointerId = inTouch.identifier + 2;
  8837. // TODO: check if this is necessary?
  8838. //e.target = findTarget(e);
  8839. e.bubbles = true;
  8840. e.cancelable = true;
  8841. e.detail = this.clickCount_;
  8842. e.button = 0;
  8843. e.buttons = 1;
  8844. e.width = inTouch.webkitRadiusX || inTouch.radiusX || 0;
  8845. e.height = inTouch.webkitRadiusY || inTouch.radiusY || 0;
  8846. e.pressure = inTouch.webkitForce || inTouch.force || 0.5;
  8847. e.isPrimary = this.isPrimaryTouch_(inTouch);
  8848. e.pointerType = ol.pointer.TouchSource.POINTER_TYPE;
  8849. // make sure that the properties that are different for
  8850. // each `Touch` object are not copied from the BrowserEvent object
  8851. e.clientX = inTouch.clientX;
  8852. e.clientY = inTouch.clientY;
  8853. e.screenX = inTouch.screenX;
  8854. e.screenY = inTouch.screenY;
  8855. return e;
  8856. };
  8857. /**
  8858. * @private
  8859. * @param {Event} inEvent Touch event
  8860. * @param {function(Event, Object)} inFunction In function.
  8861. */
  8862. ol.pointer.TouchSource.prototype.processTouches_ = function(inEvent, inFunction) {
  8863. var touches = Array.prototype.slice.call(
  8864. inEvent.changedTouches);
  8865. var count = touches.length;
  8866. function preventDefault() {
  8867. inEvent.preventDefault();
  8868. }
  8869. var i, pointer;
  8870. for (i = 0; i < count; ++i) {
  8871. pointer = this.touchToPointer_(inEvent, touches[i]);
  8872. // forward touch preventDefaults
  8873. pointer.preventDefault = preventDefault;
  8874. inFunction.call(this, inEvent, pointer);
  8875. }
  8876. };
  8877. /**
  8878. * @private
  8879. * @param {TouchList} touchList The touch list.
  8880. * @param {number} searchId Search identifier.
  8881. * @return {boolean} True, if the `Touch` with the given id is in the list.
  8882. */
  8883. ol.pointer.TouchSource.prototype.findTouch_ = function(touchList, searchId) {
  8884. var l = touchList.length;
  8885. var touch;
  8886. for (var i = 0; i < l; i++) {
  8887. touch = touchList[i];
  8888. if (touch.identifier === searchId) {
  8889. return true;
  8890. }
  8891. }
  8892. return false;
  8893. };
  8894. /**
  8895. * In some instances, a touchstart can happen without a touchend. This
  8896. * leaves the pointermap in a broken state.
  8897. * Therefore, on every touchstart, we remove the touches that did not fire a
  8898. * touchend event.
  8899. * To keep state globally consistent, we fire a pointercancel for
  8900. * this "abandoned" touch
  8901. *
  8902. * @private
  8903. * @param {Event} inEvent The in event.
  8904. */
  8905. ol.pointer.TouchSource.prototype.vacuumTouches_ = function(inEvent) {
  8906. var touchList = inEvent.touches;
  8907. // pointerMap.getCount() should be < touchList.length here,
  8908. // as the touchstart has not been processed yet.
  8909. var keys = Object.keys(this.pointerMap);
  8910. var count = keys.length;
  8911. if (count >= touchList.length) {
  8912. var d = [];
  8913. var i, key, value;
  8914. for (i = 0; i < count; ++i) {
  8915. key = keys[i];
  8916. value = this.pointerMap[key];
  8917. // Never remove pointerId == 1, which is mouse.
  8918. // Touch identifiers are 2 smaller than their pointerId, which is the
  8919. // index in pointermap.
  8920. if (key != ol.pointer.MouseSource.POINTER_ID &&
  8921. !this.findTouch_(touchList, key - 2)) {
  8922. d.push(value.out);
  8923. }
  8924. }
  8925. for (i = 0; i < d.length; ++i) {
  8926. this.cancelOut_(inEvent, d[i]);
  8927. }
  8928. }
  8929. };
  8930. /**
  8931. * Handler for `touchstart`, triggers `pointerover`,
  8932. * `pointerenter` and `pointerdown` events.
  8933. *
  8934. * @param {Event} inEvent The in event.
  8935. */
  8936. ol.pointer.TouchSource.prototype.touchstart = function(inEvent) {
  8937. this.vacuumTouches_(inEvent);
  8938. this.setPrimaryTouch_(inEvent.changedTouches[0]);
  8939. this.dedupSynthMouse_(inEvent);
  8940. this.clickCount_++;
  8941. this.processTouches_(inEvent, this.overDown_);
  8942. };
  8943. /**
  8944. * @private
  8945. * @param {Event} browserEvent The event.
  8946. * @param {Object} inPointer The in pointer object.
  8947. */
  8948. ol.pointer.TouchSource.prototype.overDown_ = function(browserEvent, inPointer) {
  8949. this.pointerMap[inPointer.pointerId] = {
  8950. target: inPointer.target,
  8951. out: inPointer,
  8952. outTarget: inPointer.target
  8953. };
  8954. this.dispatcher.over(inPointer, browserEvent);
  8955. this.dispatcher.enter(inPointer, browserEvent);
  8956. this.dispatcher.down(inPointer, browserEvent);
  8957. };
  8958. /**
  8959. * Handler for `touchmove`.
  8960. *
  8961. * @param {Event} inEvent The in event.
  8962. */
  8963. ol.pointer.TouchSource.prototype.touchmove = function(inEvent) {
  8964. inEvent.preventDefault();
  8965. this.processTouches_(inEvent, this.moveOverOut_);
  8966. };
  8967. /**
  8968. * @private
  8969. * @param {Event} browserEvent The event.
  8970. * @param {Object} inPointer The in pointer.
  8971. */
  8972. ol.pointer.TouchSource.prototype.moveOverOut_ = function(browserEvent, inPointer) {
  8973. var event = inPointer;
  8974. var pointer = this.pointerMap[event.pointerId];
  8975. // a finger drifted off the screen, ignore it
  8976. if (!pointer) {
  8977. return;
  8978. }
  8979. var outEvent = pointer.out;
  8980. var outTarget = pointer.outTarget;
  8981. this.dispatcher.move(event, browserEvent);
  8982. if (outEvent && outTarget !== event.target) {
  8983. outEvent.relatedTarget = event.target;
  8984. event.relatedTarget = outTarget;
  8985. // recover from retargeting by shadow
  8986. outEvent.target = outTarget;
  8987. if (event.target) {
  8988. this.dispatcher.leaveOut(outEvent, browserEvent);
  8989. this.dispatcher.enterOver(event, browserEvent);
  8990. } else {
  8991. // clean up case when finger leaves the screen
  8992. event.target = outTarget;
  8993. event.relatedTarget = null;
  8994. this.cancelOut_(browserEvent, event);
  8995. }
  8996. }
  8997. pointer.out = event;
  8998. pointer.outTarget = event.target;
  8999. };
  9000. /**
  9001. * Handler for `touchend`, triggers `pointerup`,
  9002. * `pointerout` and `pointerleave` events.
  9003. *
  9004. * @param {Event} inEvent The event.
  9005. */
  9006. ol.pointer.TouchSource.prototype.touchend = function(inEvent) {
  9007. this.dedupSynthMouse_(inEvent);
  9008. this.processTouches_(inEvent, this.upOut_);
  9009. };
  9010. /**
  9011. * @private
  9012. * @param {Event} browserEvent An event.
  9013. * @param {Object} inPointer The inPointer object.
  9014. */
  9015. ol.pointer.TouchSource.prototype.upOut_ = function(browserEvent, inPointer) {
  9016. this.dispatcher.up(inPointer, browserEvent);
  9017. this.dispatcher.out(inPointer, browserEvent);
  9018. this.dispatcher.leave(inPointer, browserEvent);
  9019. this.cleanUpPointer_(inPointer);
  9020. };
  9021. /**
  9022. * Handler for `touchcancel`, triggers `pointercancel`,
  9023. * `pointerout` and `pointerleave` events.
  9024. *
  9025. * @param {Event} inEvent The in event.
  9026. */
  9027. ol.pointer.TouchSource.prototype.touchcancel = function(inEvent) {
  9028. this.processTouches_(inEvent, this.cancelOut_);
  9029. };
  9030. /**
  9031. * @private
  9032. * @param {Event} browserEvent The event.
  9033. * @param {Object} inPointer The in pointer.
  9034. */
  9035. ol.pointer.TouchSource.prototype.cancelOut_ = function(browserEvent, inPointer) {
  9036. this.dispatcher.cancel(inPointer, browserEvent);
  9037. this.dispatcher.out(inPointer, browserEvent);
  9038. this.dispatcher.leave(inPointer, browserEvent);
  9039. this.cleanUpPointer_(inPointer);
  9040. };
  9041. /**
  9042. * @private
  9043. * @param {Object} inPointer The inPointer object.
  9044. */
  9045. ol.pointer.TouchSource.prototype.cleanUpPointer_ = function(inPointer) {
  9046. delete this.pointerMap[inPointer.pointerId];
  9047. this.removePrimaryPointer_(inPointer);
  9048. };
  9049. /**
  9050. * Prevent synth mouse events from creating pointer events.
  9051. *
  9052. * @private
  9053. * @param {Event} inEvent The in event.
  9054. */
  9055. ol.pointer.TouchSource.prototype.dedupSynthMouse_ = function(inEvent) {
  9056. var lts = this.mouseSource.lastTouches;
  9057. var t = inEvent.changedTouches[0];
  9058. // only the primary finger will synth mouse events
  9059. if (this.isPrimaryTouch_(t)) {
  9060. // remember x/y of last touch
  9061. var lt = [t.clientX, t.clientY];
  9062. lts.push(lt);
  9063. setTimeout(function() {
  9064. // remove touch after timeout
  9065. ol.array.remove(lts, lt);
  9066. }, ol.pointer.TouchSource.DEDUP_TIMEOUT);
  9067. }
  9068. };
  9069. // Based on https://github.com/Polymer/PointerEvents
  9070. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
  9071. //
  9072. // Redistribution and use in source and binary forms, with or without
  9073. // modification, are permitted provided that the following conditions are
  9074. // met:
  9075. //
  9076. // * Redistributions of source code must retain the above copyright
  9077. // notice, this list of conditions and the following disclaimer.
  9078. // * Redistributions in binary form must reproduce the above
  9079. // copyright notice, this list of conditions and the following disclaimer
  9080. // in the documentation and/or other materials provided with the
  9081. // distribution.
  9082. // * Neither the name of Google Inc. nor the names of its
  9083. // contributors may be used to endorse or promote products derived from
  9084. // this software without specific prior written permission.
  9085. //
  9086. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  9087. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  9088. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9089. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9090. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  9091. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9092. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  9093. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  9094. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9095. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  9096. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9097. goog.provide('ol.pointer.PointerEventHandler');
  9098. goog.require('ol');
  9099. goog.require('ol.events');
  9100. goog.require('ol.events.EventTarget');
  9101. goog.require('ol.has');
  9102. goog.require('ol.pointer.EventType');
  9103. goog.require('ol.pointer.MouseSource');
  9104. goog.require('ol.pointer.MsSource');
  9105. goog.require('ol.pointer.NativeSource');
  9106. goog.require('ol.pointer.PointerEvent');
  9107. goog.require('ol.pointer.TouchSource');
  9108. /**
  9109. * @constructor
  9110. * @extends {ol.events.EventTarget}
  9111. * @param {Element|HTMLDocument} element Viewport element.
  9112. */
  9113. ol.pointer.PointerEventHandler = function(element) {
  9114. ol.events.EventTarget.call(this);
  9115. /**
  9116. * @const
  9117. * @private
  9118. * @type {Element|HTMLDocument}
  9119. */
  9120. this.element_ = element;
  9121. /**
  9122. * @const
  9123. * @type {!Object.<string, Event|Object>}
  9124. */
  9125. this.pointerMap = {};
  9126. /**
  9127. * @type {Object.<string, function(Event)>}
  9128. * @private
  9129. */
  9130. this.eventMap_ = {};
  9131. /**
  9132. * @type {Array.<ol.pointer.EventSource>}
  9133. * @private
  9134. */
  9135. this.eventSourceList_ = [];
  9136. this.registerSources();
  9137. };
  9138. ol.inherits(ol.pointer.PointerEventHandler, ol.events.EventTarget);
  9139. /**
  9140. * Set up the event sources (mouse, touch and native pointers)
  9141. * that generate pointer events.
  9142. */
  9143. ol.pointer.PointerEventHandler.prototype.registerSources = function() {
  9144. if (ol.has.POINTER) {
  9145. this.registerSource('native', new ol.pointer.NativeSource(this));
  9146. } else if (ol.has.MSPOINTER) {
  9147. this.registerSource('ms', new ol.pointer.MsSource(this));
  9148. } else {
  9149. var mouseSource = new ol.pointer.MouseSource(this);
  9150. this.registerSource('mouse', mouseSource);
  9151. if (ol.has.TOUCH) {
  9152. this.registerSource('touch',
  9153. new ol.pointer.TouchSource(this, mouseSource));
  9154. }
  9155. }
  9156. // register events on the viewport element
  9157. this.register_();
  9158. };
  9159. /**
  9160. * Add a new event source that will generate pointer events.
  9161. *
  9162. * @param {string} name A name for the event source
  9163. * @param {ol.pointer.EventSource} source The source event.
  9164. */
  9165. ol.pointer.PointerEventHandler.prototype.registerSource = function(name, source) {
  9166. var s = source;
  9167. var newEvents = s.getEvents();
  9168. if (newEvents) {
  9169. newEvents.forEach(function(e) {
  9170. var handler = s.getHandlerForEvent(e);
  9171. if (handler) {
  9172. this.eventMap_[e] = handler.bind(s);
  9173. }
  9174. }, this);
  9175. this.eventSourceList_.push(s);
  9176. }
  9177. };
  9178. /**
  9179. * Set up the events for all registered event sources.
  9180. * @private
  9181. */
  9182. ol.pointer.PointerEventHandler.prototype.register_ = function() {
  9183. var l = this.eventSourceList_.length;
  9184. var eventSource;
  9185. for (var i = 0; i < l; i++) {
  9186. eventSource = this.eventSourceList_[i];
  9187. this.addEvents_(eventSource.getEvents());
  9188. }
  9189. };
  9190. /**
  9191. * Remove all registered events.
  9192. * @private
  9193. */
  9194. ol.pointer.PointerEventHandler.prototype.unregister_ = function() {
  9195. var l = this.eventSourceList_.length;
  9196. var eventSource;
  9197. for (var i = 0; i < l; i++) {
  9198. eventSource = this.eventSourceList_[i];
  9199. this.removeEvents_(eventSource.getEvents());
  9200. }
  9201. };
  9202. /**
  9203. * Calls the right handler for a new event.
  9204. * @private
  9205. * @param {Event} inEvent Browser event.
  9206. */
  9207. ol.pointer.PointerEventHandler.prototype.eventHandler_ = function(inEvent) {
  9208. var type = inEvent.type;
  9209. var handler = this.eventMap_[type];
  9210. if (handler) {
  9211. handler(inEvent);
  9212. }
  9213. };
  9214. /**
  9215. * Setup listeners for the given events.
  9216. * @private
  9217. * @param {Array.<string>} events List of events.
  9218. */
  9219. ol.pointer.PointerEventHandler.prototype.addEvents_ = function(events) {
  9220. events.forEach(function(eventName) {
  9221. ol.events.listen(this.element_, eventName, this.eventHandler_, this);
  9222. }, this);
  9223. };
  9224. /**
  9225. * Unregister listeners for the given events.
  9226. * @private
  9227. * @param {Array.<string>} events List of events.
  9228. */
  9229. ol.pointer.PointerEventHandler.prototype.removeEvents_ = function(events) {
  9230. events.forEach(function(e) {
  9231. ol.events.unlisten(this.element_, e, this.eventHandler_, this);
  9232. }, this);
  9233. };
  9234. /**
  9235. * Returns a snapshot of inEvent, with writable properties.
  9236. *
  9237. * @param {Event} event Browser event.
  9238. * @param {Event|Touch} inEvent An event that contains
  9239. * properties to copy.
  9240. * @return {Object} An object containing shallow copies of
  9241. * `inEvent`'s properties.
  9242. */
  9243. ol.pointer.PointerEventHandler.prototype.cloneEvent = function(event, inEvent) {
  9244. var eventCopy = {}, p;
  9245. for (var i = 0, ii = ol.pointer.PointerEventHandler.CLONE_PROPS.length; i < ii; i++) {
  9246. p = ol.pointer.PointerEventHandler.CLONE_PROPS[i][0];
  9247. eventCopy[p] = event[p] || inEvent[p] || ol.pointer.PointerEventHandler.CLONE_PROPS[i][1];
  9248. }
  9249. return eventCopy;
  9250. };
  9251. // EVENTS
  9252. /**
  9253. * Triggers a 'pointerdown' event.
  9254. * @param {Object} data Pointer event data.
  9255. * @param {Event} event The event.
  9256. */
  9257. ol.pointer.PointerEventHandler.prototype.down = function(data, event) {
  9258. this.fireEvent(ol.pointer.EventType.POINTERDOWN, data, event);
  9259. };
  9260. /**
  9261. * Triggers a 'pointermove' event.
  9262. * @param {Object} data Pointer event data.
  9263. * @param {Event} event The event.
  9264. */
  9265. ol.pointer.PointerEventHandler.prototype.move = function(data, event) {
  9266. this.fireEvent(ol.pointer.EventType.POINTERMOVE, data, event);
  9267. };
  9268. /**
  9269. * Triggers a 'pointerup' event.
  9270. * @param {Object} data Pointer event data.
  9271. * @param {Event} event The event.
  9272. */
  9273. ol.pointer.PointerEventHandler.prototype.up = function(data, event) {
  9274. this.fireEvent(ol.pointer.EventType.POINTERUP, data, event);
  9275. };
  9276. /**
  9277. * Triggers a 'pointerenter' event.
  9278. * @param {Object} data Pointer event data.
  9279. * @param {Event} event The event.
  9280. */
  9281. ol.pointer.PointerEventHandler.prototype.enter = function(data, event) {
  9282. data.bubbles = false;
  9283. this.fireEvent(ol.pointer.EventType.POINTERENTER, data, event);
  9284. };
  9285. /**
  9286. * Triggers a 'pointerleave' event.
  9287. * @param {Object} data Pointer event data.
  9288. * @param {Event} event The event.
  9289. */
  9290. ol.pointer.PointerEventHandler.prototype.leave = function(data, event) {
  9291. data.bubbles = false;
  9292. this.fireEvent(ol.pointer.EventType.POINTERLEAVE, data, event);
  9293. };
  9294. /**
  9295. * Triggers a 'pointerover' event.
  9296. * @param {Object} data Pointer event data.
  9297. * @param {Event} event The event.
  9298. */
  9299. ol.pointer.PointerEventHandler.prototype.over = function(data, event) {
  9300. data.bubbles = true;
  9301. this.fireEvent(ol.pointer.EventType.POINTEROVER, data, event);
  9302. };
  9303. /**
  9304. * Triggers a 'pointerout' event.
  9305. * @param {Object} data Pointer event data.
  9306. * @param {Event} event The event.
  9307. */
  9308. ol.pointer.PointerEventHandler.prototype.out = function(data, event) {
  9309. data.bubbles = true;
  9310. this.fireEvent(ol.pointer.EventType.POINTEROUT, data, event);
  9311. };
  9312. /**
  9313. * Triggers a 'pointercancel' event.
  9314. * @param {Object} data Pointer event data.
  9315. * @param {Event} event The event.
  9316. */
  9317. ol.pointer.PointerEventHandler.prototype.cancel = function(data, event) {
  9318. this.fireEvent(ol.pointer.EventType.POINTERCANCEL, data, event);
  9319. };
  9320. /**
  9321. * Triggers a combination of 'pointerout' and 'pointerleave' events.
  9322. * @param {Object} data Pointer event data.
  9323. * @param {Event} event The event.
  9324. */
  9325. ol.pointer.PointerEventHandler.prototype.leaveOut = function(data, event) {
  9326. this.out(data, event);
  9327. if (!this.contains_(data.target, data.relatedTarget)) {
  9328. this.leave(data, event);
  9329. }
  9330. };
  9331. /**
  9332. * Triggers a combination of 'pointerover' and 'pointerevents' events.
  9333. * @param {Object} data Pointer event data.
  9334. * @param {Event} event The event.
  9335. */
  9336. ol.pointer.PointerEventHandler.prototype.enterOver = function(data, event) {
  9337. this.over(data, event);
  9338. if (!this.contains_(data.target, data.relatedTarget)) {
  9339. this.enter(data, event);
  9340. }
  9341. };
  9342. /**
  9343. * @private
  9344. * @param {Element} container The container element.
  9345. * @param {Element} contained The contained element.
  9346. * @return {boolean} Returns true if the container element
  9347. * contains the other element.
  9348. */
  9349. ol.pointer.PointerEventHandler.prototype.contains_ = function(container, contained) {
  9350. if (!container || !contained) {
  9351. return false;
  9352. }
  9353. return container.contains(contained);
  9354. };
  9355. // EVENT CREATION AND TRACKING
  9356. /**
  9357. * Creates a new Event of type `inType`, based on the information in
  9358. * `data`.
  9359. *
  9360. * @param {string} inType A string representing the type of event to create.
  9361. * @param {Object} data Pointer event data.
  9362. * @param {Event} event The event.
  9363. * @return {ol.pointer.PointerEvent} A PointerEvent of type `inType`.
  9364. */
  9365. ol.pointer.PointerEventHandler.prototype.makeEvent = function(inType, data, event) {
  9366. return new ol.pointer.PointerEvent(inType, event, data);
  9367. };
  9368. /**
  9369. * Make and dispatch an event in one call.
  9370. * @param {string} inType A string representing the type of event.
  9371. * @param {Object} data Pointer event data.
  9372. * @param {Event} event The event.
  9373. */
  9374. ol.pointer.PointerEventHandler.prototype.fireEvent = function(inType, data, event) {
  9375. var e = this.makeEvent(inType, data, event);
  9376. this.dispatchEvent(e);
  9377. };
  9378. /**
  9379. * Creates a pointer event from a native pointer event
  9380. * and dispatches this event.
  9381. * @param {Event} event A platform event with a target.
  9382. */
  9383. ol.pointer.PointerEventHandler.prototype.fireNativeEvent = function(event) {
  9384. var e = this.makeEvent(event.type, event, event);
  9385. this.dispatchEvent(e);
  9386. };
  9387. /**
  9388. * Wrap a native mouse event into a pointer event.
  9389. * This proxy method is required for the legacy IE support.
  9390. * @param {string} eventType The pointer event type.
  9391. * @param {Event} event The event.
  9392. * @return {ol.pointer.PointerEvent} The wrapped event.
  9393. */
  9394. ol.pointer.PointerEventHandler.prototype.wrapMouseEvent = function(eventType, event) {
  9395. var pointerEvent = this.makeEvent(
  9396. eventType, ol.pointer.MouseSource.prepareEvent(event, this), event);
  9397. return pointerEvent;
  9398. };
  9399. /**
  9400. * @inheritDoc
  9401. */
  9402. ol.pointer.PointerEventHandler.prototype.disposeInternal = function() {
  9403. this.unregister_();
  9404. ol.events.EventTarget.prototype.disposeInternal.call(this);
  9405. };
  9406. /**
  9407. * Properties to copy when cloning an event, with default values.
  9408. * @type {Array.<Array>}
  9409. */
  9410. ol.pointer.PointerEventHandler.CLONE_PROPS = [
  9411. // MouseEvent
  9412. ['bubbles', false],
  9413. ['cancelable', false],
  9414. ['view', null],
  9415. ['detail', null],
  9416. ['screenX', 0],
  9417. ['screenY', 0],
  9418. ['clientX', 0],
  9419. ['clientY', 0],
  9420. ['ctrlKey', false],
  9421. ['altKey', false],
  9422. ['shiftKey', false],
  9423. ['metaKey', false],
  9424. ['button', 0],
  9425. ['relatedTarget', null],
  9426. // DOM Level 3
  9427. ['buttons', 0],
  9428. // PointerEvent
  9429. ['pointerId', 0],
  9430. ['width', 0],
  9431. ['height', 0],
  9432. ['pressure', 0],
  9433. ['tiltX', 0],
  9434. ['tiltY', 0],
  9435. ['pointerType', ''],
  9436. ['hwTimestamp', 0],
  9437. ['isPrimary', false],
  9438. // event instance
  9439. ['type', ''],
  9440. ['target', null],
  9441. ['currentTarget', null],
  9442. ['which', 0]
  9443. ];
  9444. goog.provide('ol.MapBrowserEventHandler');
  9445. goog.require('ol');
  9446. goog.require('ol.has');
  9447. goog.require('ol.MapBrowserEventType');
  9448. goog.require('ol.MapBrowserPointerEvent');
  9449. goog.require('ol.events');
  9450. goog.require('ol.events.EventTarget');
  9451. goog.require('ol.pointer.EventType');
  9452. goog.require('ol.pointer.PointerEventHandler');
  9453. /**
  9454. * @param {ol.PluggableMap} map The map with the viewport to listen to events on.
  9455. * @param {number|undefined} moveTolerance The minimal distance the pointer must travel to trigger a move.
  9456. * @constructor
  9457. * @extends {ol.events.EventTarget}
  9458. */
  9459. ol.MapBrowserEventHandler = function(map, moveTolerance) {
  9460. ol.events.EventTarget.call(this);
  9461. /**
  9462. * This is the element that we will listen to the real events on.
  9463. * @type {ol.PluggableMap}
  9464. * @private
  9465. */
  9466. this.map_ = map;
  9467. /**
  9468. * @type {number}
  9469. * @private
  9470. */
  9471. this.clickTimeoutId_ = 0;
  9472. /**
  9473. * @type {boolean}
  9474. * @private
  9475. */
  9476. this.dragging_ = false;
  9477. /**
  9478. * @type {!Array.<ol.EventsKey>}
  9479. * @private
  9480. */
  9481. this.dragListenerKeys_ = [];
  9482. /**
  9483. * @type {number}
  9484. * @private
  9485. */
  9486. this.moveTolerance_ = moveTolerance ?
  9487. moveTolerance * ol.has.DEVICE_PIXEL_RATIO : ol.has.DEVICE_PIXEL_RATIO;
  9488. /**
  9489. * The most recent "down" type event (or null if none have occurred).
  9490. * Set on pointerdown.
  9491. * @type {ol.pointer.PointerEvent}
  9492. * @private
  9493. */
  9494. this.down_ = null;
  9495. var element = this.map_.getViewport();
  9496. /**
  9497. * @type {number}
  9498. * @private
  9499. */
  9500. this.activePointers_ = 0;
  9501. /**
  9502. * @type {!Object.<number, boolean>}
  9503. * @private
  9504. */
  9505. this.trackedTouches_ = {};
  9506. /**
  9507. * Event handler which generates pointer events for
  9508. * the viewport element.
  9509. *
  9510. * @type {ol.pointer.PointerEventHandler}
  9511. * @private
  9512. */
  9513. this.pointerEventHandler_ = new ol.pointer.PointerEventHandler(element);
  9514. /**
  9515. * Event handler which generates pointer events for
  9516. * the document (used when dragging).
  9517. *
  9518. * @type {ol.pointer.PointerEventHandler}
  9519. * @private
  9520. */
  9521. this.documentPointerEventHandler_ = null;
  9522. /**
  9523. * @type {?ol.EventsKey}
  9524. * @private
  9525. */
  9526. this.pointerdownListenerKey_ = ol.events.listen(this.pointerEventHandler_,
  9527. ol.pointer.EventType.POINTERDOWN,
  9528. this.handlePointerDown_, this);
  9529. /**
  9530. * @type {?ol.EventsKey}
  9531. * @private
  9532. */
  9533. this.relayedListenerKey_ = ol.events.listen(this.pointerEventHandler_,
  9534. ol.pointer.EventType.POINTERMOVE,
  9535. this.relayEvent_, this);
  9536. };
  9537. ol.inherits(ol.MapBrowserEventHandler, ol.events.EventTarget);
  9538. /**
  9539. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9540. * @private
  9541. */
  9542. ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) {
  9543. var newEvent = new ol.MapBrowserPointerEvent(
  9544. ol.MapBrowserEventType.CLICK, this.map_, pointerEvent);
  9545. this.dispatchEvent(newEvent);
  9546. if (this.clickTimeoutId_ !== 0) {
  9547. // double-click
  9548. clearTimeout(this.clickTimeoutId_);
  9549. this.clickTimeoutId_ = 0;
  9550. newEvent = new ol.MapBrowserPointerEvent(
  9551. ol.MapBrowserEventType.DBLCLICK, this.map_, pointerEvent);
  9552. this.dispatchEvent(newEvent);
  9553. } else {
  9554. // click
  9555. this.clickTimeoutId_ = setTimeout(function() {
  9556. this.clickTimeoutId_ = 0;
  9557. var newEvent = new ol.MapBrowserPointerEvent(
  9558. ol.MapBrowserEventType.SINGLECLICK, this.map_, pointerEvent);
  9559. this.dispatchEvent(newEvent);
  9560. }.bind(this), 250);
  9561. }
  9562. };
  9563. /**
  9564. * Keeps track on how many pointers are currently active.
  9565. *
  9566. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9567. * @private
  9568. */
  9569. ol.MapBrowserEventHandler.prototype.updateActivePointers_ = function(pointerEvent) {
  9570. var event = pointerEvent;
  9571. if (event.type == ol.MapBrowserEventType.POINTERUP ||
  9572. event.type == ol.MapBrowserEventType.POINTERCANCEL) {
  9573. delete this.trackedTouches_[event.pointerId];
  9574. } else if (event.type == ol.MapBrowserEventType.POINTERDOWN) {
  9575. this.trackedTouches_[event.pointerId] = true;
  9576. }
  9577. this.activePointers_ = Object.keys(this.trackedTouches_).length;
  9578. };
  9579. /**
  9580. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9581. * @private
  9582. */
  9583. ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) {
  9584. this.updateActivePointers_(pointerEvent);
  9585. var newEvent = new ol.MapBrowserPointerEvent(
  9586. ol.MapBrowserEventType.POINTERUP, this.map_, pointerEvent);
  9587. this.dispatchEvent(newEvent);
  9588. // We emulate click events on left mouse button click, touch contact, and pen
  9589. // contact. isMouseActionButton returns true in these cases (evt.button is set
  9590. // to 0).
  9591. // See http://www.w3.org/TR/pointerevents/#button-states
  9592. // We only fire click, singleclick, and doubleclick if nobody has called
  9593. // event.stopPropagation() or event.preventDefault().
  9594. if (!newEvent.propagationStopped && !this.dragging_ && this.isMouseActionButton_(pointerEvent)) {
  9595. this.emulateClick_(this.down_);
  9596. }
  9597. if (this.activePointers_ === 0) {
  9598. this.dragListenerKeys_.forEach(ol.events.unlistenByKey);
  9599. this.dragListenerKeys_.length = 0;
  9600. this.dragging_ = false;
  9601. this.down_ = null;
  9602. this.documentPointerEventHandler_.dispose();
  9603. this.documentPointerEventHandler_ = null;
  9604. }
  9605. };
  9606. /**
  9607. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9608. * @return {boolean} If the left mouse button was pressed.
  9609. * @private
  9610. */
  9611. ol.MapBrowserEventHandler.prototype.isMouseActionButton_ = function(pointerEvent) {
  9612. return pointerEvent.button === 0;
  9613. };
  9614. /**
  9615. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9616. * @private
  9617. */
  9618. ol.MapBrowserEventHandler.prototype.handlePointerDown_ = function(pointerEvent) {
  9619. this.updateActivePointers_(pointerEvent);
  9620. var newEvent = new ol.MapBrowserPointerEvent(
  9621. ol.MapBrowserEventType.POINTERDOWN, this.map_, pointerEvent);
  9622. this.dispatchEvent(newEvent);
  9623. this.down_ = pointerEvent;
  9624. if (this.dragListenerKeys_.length === 0) {
  9625. /* Set up a pointer event handler on the `document`,
  9626. * which is required when the pointer is moved outside
  9627. * the viewport when dragging.
  9628. */
  9629. this.documentPointerEventHandler_ =
  9630. new ol.pointer.PointerEventHandler(document);
  9631. this.dragListenerKeys_.push(
  9632. ol.events.listen(this.documentPointerEventHandler_,
  9633. ol.MapBrowserEventType.POINTERMOVE,
  9634. this.handlePointerMove_, this),
  9635. ol.events.listen(this.documentPointerEventHandler_,
  9636. ol.MapBrowserEventType.POINTERUP,
  9637. this.handlePointerUp_, this),
  9638. /* Note that the listener for `pointercancel is set up on
  9639. * `pointerEventHandler_` and not `documentPointerEventHandler_` like
  9640. * the `pointerup` and `pointermove` listeners.
  9641. *
  9642. * The reason for this is the following: `TouchSource.vacuumTouches_()`
  9643. * issues `pointercancel` events, when there was no `touchend` for a
  9644. * `touchstart`. Now, let's say a first `touchstart` is registered on
  9645. * `pointerEventHandler_`. The `documentPointerEventHandler_` is set up.
  9646. * But `documentPointerEventHandler_` doesn't know about the first
  9647. * `touchstart`. If there is no `touchend` for the `touchstart`, we can
  9648. * only receive a `touchcancel` from `pointerEventHandler_`, because it is
  9649. * only registered there.
  9650. */
  9651. ol.events.listen(this.pointerEventHandler_,
  9652. ol.MapBrowserEventType.POINTERCANCEL,
  9653. this.handlePointerUp_, this)
  9654. );
  9655. }
  9656. };
  9657. /**
  9658. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9659. * @private
  9660. */
  9661. ol.MapBrowserEventHandler.prototype.handlePointerMove_ = function(pointerEvent) {
  9662. // Between pointerdown and pointerup, pointermove events are triggered.
  9663. // To avoid a 'false' touchmove event to be dispatched, we test if the pointer
  9664. // moved a significant distance.
  9665. if (this.isMoving_(pointerEvent)) {
  9666. this.dragging_ = true;
  9667. var newEvent = new ol.MapBrowserPointerEvent(
  9668. ol.MapBrowserEventType.POINTERDRAG, this.map_, pointerEvent,
  9669. this.dragging_);
  9670. this.dispatchEvent(newEvent);
  9671. }
  9672. // Some native android browser triggers mousemove events during small period
  9673. // of time. See: https://code.google.com/p/android/issues/detail?id=5491 or
  9674. // https://code.google.com/p/android/issues/detail?id=19827
  9675. // ex: Galaxy Tab P3110 + Android 4.1.1
  9676. pointerEvent.preventDefault();
  9677. };
  9678. /**
  9679. * Wrap and relay a pointer event. Note that this requires that the type
  9680. * string for the MapBrowserPointerEvent matches the PointerEvent type.
  9681. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9682. * @private
  9683. */
  9684. ol.MapBrowserEventHandler.prototype.relayEvent_ = function(pointerEvent) {
  9685. var dragging = !!(this.down_ && this.isMoving_(pointerEvent));
  9686. this.dispatchEvent(new ol.MapBrowserPointerEvent(
  9687. pointerEvent.type, this.map_, pointerEvent, dragging));
  9688. };
  9689. /**
  9690. * @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
  9691. * @return {boolean} Is moving.
  9692. * @private
  9693. */
  9694. ol.MapBrowserEventHandler.prototype.isMoving_ = function(pointerEvent) {
  9695. return Math.abs(pointerEvent.clientX - this.down_.clientX) > this.moveTolerance_ ||
  9696. Math.abs(pointerEvent.clientY - this.down_.clientY) > this.moveTolerance_;
  9697. };
  9698. /**
  9699. * @inheritDoc
  9700. */
  9701. ol.MapBrowserEventHandler.prototype.disposeInternal = function() {
  9702. if (this.relayedListenerKey_) {
  9703. ol.events.unlistenByKey(this.relayedListenerKey_);
  9704. this.relayedListenerKey_ = null;
  9705. }
  9706. if (this.pointerdownListenerKey_) {
  9707. ol.events.unlistenByKey(this.pointerdownListenerKey_);
  9708. this.pointerdownListenerKey_ = null;
  9709. }
  9710. this.dragListenerKeys_.forEach(ol.events.unlistenByKey);
  9711. this.dragListenerKeys_.length = 0;
  9712. if (this.documentPointerEventHandler_) {
  9713. this.documentPointerEventHandler_.dispose();
  9714. this.documentPointerEventHandler_ = null;
  9715. }
  9716. if (this.pointerEventHandler_) {
  9717. this.pointerEventHandler_.dispose();
  9718. this.pointerEventHandler_ = null;
  9719. }
  9720. ol.events.EventTarget.prototype.disposeInternal.call(this);
  9721. };
  9722. goog.provide('ol.MapEventType');
  9723. /**
  9724. * @enum {string}
  9725. */
  9726. ol.MapEventType = {
  9727. /**
  9728. * Triggered after a map frame is rendered.
  9729. * @event ol.MapEvent#postrender
  9730. * @api
  9731. */
  9732. POSTRENDER: 'postrender',
  9733. /**
  9734. * Triggered when the map starts moving.
  9735. * @event ol.MapEvent#movestart
  9736. * @api
  9737. */
  9738. MOVESTART: 'movestart',
  9739. /**
  9740. * Triggered after the map is moved.
  9741. * @event ol.MapEvent#moveend
  9742. * @api
  9743. */
  9744. MOVEEND: 'moveend'
  9745. };
  9746. goog.provide('ol.MapProperty');
  9747. /**
  9748. * @enum {string}
  9749. */
  9750. ol.MapProperty = {
  9751. LAYERGROUP: 'layergroup',
  9752. SIZE: 'size',
  9753. TARGET: 'target',
  9754. VIEW: 'view'
  9755. };
  9756. goog.provide('ol.TileState');
  9757. /**
  9758. * @enum {number}
  9759. */
  9760. ol.TileState = {
  9761. IDLE: 0,
  9762. LOADING: 1,
  9763. LOADED: 2,
  9764. ERROR: 3,
  9765. EMPTY: 4,
  9766. ABORT: 5
  9767. };
  9768. goog.provide('ol.structs.PriorityQueue');
  9769. goog.require('ol.asserts');
  9770. goog.require('ol.obj');
  9771. /**
  9772. * Priority queue.
  9773. *
  9774. * The implementation is inspired from the Closure Library's Heap class and
  9775. * Python's heapq module.
  9776. *
  9777. * @see http://closure-library.googlecode.com/svn/docs/closure_goog_structs_heap.js.source.html
  9778. * @see http://hg.python.org/cpython/file/2.7/Lib/heapq.py
  9779. *
  9780. * @constructor
  9781. * @param {function(T): number} priorityFunction Priority function.
  9782. * @param {function(T): string} keyFunction Key function.
  9783. * @struct
  9784. * @template T
  9785. */
  9786. ol.structs.PriorityQueue = function(priorityFunction, keyFunction) {
  9787. /**
  9788. * @type {function(T): number}
  9789. * @private
  9790. */
  9791. this.priorityFunction_ = priorityFunction;
  9792. /**
  9793. * @type {function(T): string}
  9794. * @private
  9795. */
  9796. this.keyFunction_ = keyFunction;
  9797. /**
  9798. * @type {Array.<T>}
  9799. * @private
  9800. */
  9801. this.elements_ = [];
  9802. /**
  9803. * @type {Array.<number>}
  9804. * @private
  9805. */
  9806. this.priorities_ = [];
  9807. /**
  9808. * @type {Object.<string, boolean>}
  9809. * @private
  9810. */
  9811. this.queuedElements_ = {};
  9812. };
  9813. /**
  9814. * @const
  9815. * @type {number}
  9816. */
  9817. ol.structs.PriorityQueue.DROP = Infinity;
  9818. /**
  9819. * FIXME empty description for jsdoc
  9820. */
  9821. ol.structs.PriorityQueue.prototype.clear = function() {
  9822. this.elements_.length = 0;
  9823. this.priorities_.length = 0;
  9824. ol.obj.clear(this.queuedElements_);
  9825. };
  9826. /**
  9827. * Remove and return the highest-priority element. O(log N).
  9828. * @return {T} Element.
  9829. */
  9830. ol.structs.PriorityQueue.prototype.dequeue = function() {
  9831. var elements = this.elements_;
  9832. var priorities = this.priorities_;
  9833. var element = elements[0];
  9834. if (elements.length == 1) {
  9835. elements.length = 0;
  9836. priorities.length = 0;
  9837. } else {
  9838. elements[0] = elements.pop();
  9839. priorities[0] = priorities.pop();
  9840. this.siftUp_(0);
  9841. }
  9842. var elementKey = this.keyFunction_(element);
  9843. delete this.queuedElements_[elementKey];
  9844. return element;
  9845. };
  9846. /**
  9847. * Enqueue an element. O(log N).
  9848. * @param {T} element Element.
  9849. * @return {boolean} The element was added to the queue.
  9850. */
  9851. ol.structs.PriorityQueue.prototype.enqueue = function(element) {
  9852. ol.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_),
  9853. 31); // Tried to enqueue an `element` that was already added to the queue
  9854. var priority = this.priorityFunction_(element);
  9855. if (priority != ol.structs.PriorityQueue.DROP) {
  9856. this.elements_.push(element);
  9857. this.priorities_.push(priority);
  9858. this.queuedElements_[this.keyFunction_(element)] = true;
  9859. this.siftDown_(0, this.elements_.length - 1);
  9860. return true;
  9861. }
  9862. return false;
  9863. };
  9864. /**
  9865. * @return {number} Count.
  9866. */
  9867. ol.structs.PriorityQueue.prototype.getCount = function() {
  9868. return this.elements_.length;
  9869. };
  9870. /**
  9871. * Gets the index of the left child of the node at the given index.
  9872. * @param {number} index The index of the node to get the left child for.
  9873. * @return {number} The index of the left child.
  9874. * @private
  9875. */
  9876. ol.structs.PriorityQueue.prototype.getLeftChildIndex_ = function(index) {
  9877. return index * 2 + 1;
  9878. };
  9879. /**
  9880. * Gets the index of the right child of the node at the given index.
  9881. * @param {number} index The index of the node to get the right child for.
  9882. * @return {number} The index of the right child.
  9883. * @private
  9884. */
  9885. ol.structs.PriorityQueue.prototype.getRightChildIndex_ = function(index) {
  9886. return index * 2 + 2;
  9887. };
  9888. /**
  9889. * Gets the index of the parent of the node at the given index.
  9890. * @param {number} index The index of the node to get the parent for.
  9891. * @return {number} The index of the parent.
  9892. * @private
  9893. */
  9894. ol.structs.PriorityQueue.prototype.getParentIndex_ = function(index) {
  9895. return (index - 1) >> 1;
  9896. };
  9897. /**
  9898. * Make this a heap. O(N).
  9899. * @private
  9900. */
  9901. ol.structs.PriorityQueue.prototype.heapify_ = function() {
  9902. var i;
  9903. for (i = (this.elements_.length >> 1) - 1; i >= 0; i--) {
  9904. this.siftUp_(i);
  9905. }
  9906. };
  9907. /**
  9908. * @return {boolean} Is empty.
  9909. */
  9910. ol.structs.PriorityQueue.prototype.isEmpty = function() {
  9911. return this.elements_.length === 0;
  9912. };
  9913. /**
  9914. * @param {string} key Key.
  9915. * @return {boolean} Is key queued.
  9916. */
  9917. ol.structs.PriorityQueue.prototype.isKeyQueued = function(key) {
  9918. return key in this.queuedElements_;
  9919. };
  9920. /**
  9921. * @param {T} element Element.
  9922. * @return {boolean} Is queued.
  9923. */
  9924. ol.structs.PriorityQueue.prototype.isQueued = function(element) {
  9925. return this.isKeyQueued(this.keyFunction_(element));
  9926. };
  9927. /**
  9928. * @param {number} index The index of the node to move down.
  9929. * @private
  9930. */
  9931. ol.structs.PriorityQueue.prototype.siftUp_ = function(index) {
  9932. var elements = this.elements_;
  9933. var priorities = this.priorities_;
  9934. var count = elements.length;
  9935. var element = elements[index];
  9936. var priority = priorities[index];
  9937. var startIndex = index;
  9938. while (index < (count >> 1)) {
  9939. var lIndex = this.getLeftChildIndex_(index);
  9940. var rIndex = this.getRightChildIndex_(index);
  9941. var smallerChildIndex = rIndex < count &&
  9942. priorities[rIndex] < priorities[lIndex] ?
  9943. rIndex : lIndex;
  9944. elements[index] = elements[smallerChildIndex];
  9945. priorities[index] = priorities[smallerChildIndex];
  9946. index = smallerChildIndex;
  9947. }
  9948. elements[index] = element;
  9949. priorities[index] = priority;
  9950. this.siftDown_(startIndex, index);
  9951. };
  9952. /**
  9953. * @param {number} startIndex The index of the root.
  9954. * @param {number} index The index of the node to move up.
  9955. * @private
  9956. */
  9957. ol.structs.PriorityQueue.prototype.siftDown_ = function(startIndex, index) {
  9958. var elements = this.elements_;
  9959. var priorities = this.priorities_;
  9960. var element = elements[index];
  9961. var priority = priorities[index];
  9962. while (index > startIndex) {
  9963. var parentIndex = this.getParentIndex_(index);
  9964. if (priorities[parentIndex] > priority) {
  9965. elements[index] = elements[parentIndex];
  9966. priorities[index] = priorities[parentIndex];
  9967. index = parentIndex;
  9968. } else {
  9969. break;
  9970. }
  9971. }
  9972. elements[index] = element;
  9973. priorities[index] = priority;
  9974. };
  9975. /**
  9976. * FIXME empty description for jsdoc
  9977. */
  9978. ol.structs.PriorityQueue.prototype.reprioritize = function() {
  9979. var priorityFunction = this.priorityFunction_;
  9980. var elements = this.elements_;
  9981. var priorities = this.priorities_;
  9982. var index = 0;
  9983. var n = elements.length;
  9984. var element, i, priority;
  9985. for (i = 0; i < n; ++i) {
  9986. element = elements[i];
  9987. priority = priorityFunction(element);
  9988. if (priority == ol.structs.PriorityQueue.DROP) {
  9989. delete this.queuedElements_[this.keyFunction_(element)];
  9990. } else {
  9991. priorities[index] = priority;
  9992. elements[index++] = element;
  9993. }
  9994. }
  9995. elements.length = index;
  9996. priorities.length = index;
  9997. this.heapify_();
  9998. };
  9999. goog.provide('ol.TileQueue');
  10000. goog.require('ol');
  10001. goog.require('ol.TileState');
  10002. goog.require('ol.events');
  10003. goog.require('ol.events.EventType');
  10004. goog.require('ol.structs.PriorityQueue');
  10005. /**
  10006. * @constructor
  10007. * @extends {ol.structs.PriorityQueue.<Array>}
  10008. * @param {ol.TilePriorityFunction} tilePriorityFunction
  10009. * Tile priority function.
  10010. * @param {function(): ?} tileChangeCallback
  10011. * Function called on each tile change event.
  10012. * @struct
  10013. */
  10014. ol.TileQueue = function(tilePriorityFunction, tileChangeCallback) {
  10015. ol.structs.PriorityQueue.call(
  10016. this,
  10017. /**
  10018. * @param {Array} element Element.
  10019. * @return {number} Priority.
  10020. */
  10021. function(element) {
  10022. return tilePriorityFunction.apply(null, element);
  10023. },
  10024. /**
  10025. * @param {Array} element Element.
  10026. * @return {string} Key.
  10027. */
  10028. function(element) {
  10029. return /** @type {ol.Tile} */ (element[0]).getKey();
  10030. });
  10031. /**
  10032. * @private
  10033. * @type {function(): ?}
  10034. */
  10035. this.tileChangeCallback_ = tileChangeCallback;
  10036. /**
  10037. * @private
  10038. * @type {number}
  10039. */
  10040. this.tilesLoading_ = 0;
  10041. /**
  10042. * @private
  10043. * @type {!Object.<string,boolean>}
  10044. */
  10045. this.tilesLoadingKeys_ = {};
  10046. };
  10047. ol.inherits(ol.TileQueue, ol.structs.PriorityQueue);
  10048. /**
  10049. * @inheritDoc
  10050. */
  10051. ol.TileQueue.prototype.enqueue = function(element) {
  10052. var added = ol.structs.PriorityQueue.prototype.enqueue.call(this, element);
  10053. if (added) {
  10054. var tile = element[0];
  10055. ol.events.listen(tile, ol.events.EventType.CHANGE,
  10056. this.handleTileChange, this);
  10057. }
  10058. return added;
  10059. };
  10060. /**
  10061. * @return {number} Number of tiles loading.
  10062. */
  10063. ol.TileQueue.prototype.getTilesLoading = function() {
  10064. return this.tilesLoading_;
  10065. };
  10066. /**
  10067. * @param {ol.events.Event} event Event.
  10068. * @protected
  10069. */
  10070. ol.TileQueue.prototype.handleTileChange = function(event) {
  10071. var tile = /** @type {ol.Tile} */ (event.target);
  10072. var state = tile.getState();
  10073. if (state === ol.TileState.LOADED || state === ol.TileState.ERROR ||
  10074. state === ol.TileState.EMPTY || state === ol.TileState.ABORT) {
  10075. ol.events.unlisten(tile, ol.events.EventType.CHANGE,
  10076. this.handleTileChange, this);
  10077. var tileKey = tile.getKey();
  10078. if (tileKey in this.tilesLoadingKeys_) {
  10079. delete this.tilesLoadingKeys_[tileKey];
  10080. --this.tilesLoading_;
  10081. }
  10082. this.tileChangeCallback_();
  10083. }
  10084. };
  10085. /**
  10086. * @param {number} maxTotalLoading Maximum number tiles to load simultaneously.
  10087. * @param {number} maxNewLoads Maximum number of new tiles to load.
  10088. */
  10089. ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) {
  10090. var newLoads = 0;
  10091. var abortedTiles = false;
  10092. var state, tile, tileKey;
  10093. while (this.tilesLoading_ < maxTotalLoading && newLoads < maxNewLoads &&
  10094. this.getCount() > 0) {
  10095. tile = /** @type {ol.Tile} */ (this.dequeue()[0]);
  10096. tileKey = tile.getKey();
  10097. state = tile.getState();
  10098. if (state === ol.TileState.ABORT) {
  10099. abortedTiles = true;
  10100. } else if (state === ol.TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) {
  10101. this.tilesLoadingKeys_[tileKey] = true;
  10102. ++this.tilesLoading_;
  10103. ++newLoads;
  10104. tile.load();
  10105. }
  10106. }
  10107. if (newLoads === 0 && abortedTiles) {
  10108. // Do not stop the render loop when all wanted tiles were aborted due to
  10109. // a small, saturated tile cache.
  10110. this.tileChangeCallback_();
  10111. }
  10112. };
  10113. goog.provide('ol.CenterConstraint');
  10114. goog.require('ol.math');
  10115. /**
  10116. * @param {ol.Extent} extent Extent.
  10117. * @return {ol.CenterConstraintType} The constraint.
  10118. */
  10119. ol.CenterConstraint.createExtent = function(extent) {
  10120. return (
  10121. /**
  10122. * @param {ol.Coordinate|undefined} center Center.
  10123. * @return {ol.Coordinate|undefined} Center.
  10124. */
  10125. function(center) {
  10126. if (center) {
  10127. return [
  10128. ol.math.clamp(center[0], extent[0], extent[2]),
  10129. ol.math.clamp(center[1], extent[1], extent[3])
  10130. ];
  10131. } else {
  10132. return undefined;
  10133. }
  10134. });
  10135. };
  10136. /**
  10137. * @param {ol.Coordinate|undefined} center Center.
  10138. * @return {ol.Coordinate|undefined} Center.
  10139. */
  10140. ol.CenterConstraint.none = function(center) {
  10141. return center;
  10142. };
  10143. goog.provide('ol.ResolutionConstraint');
  10144. goog.require('ol.array');
  10145. goog.require('ol.math');
  10146. /**
  10147. * @param {Array.<number>} resolutions Resolutions.
  10148. * @return {ol.ResolutionConstraintType} Zoom function.
  10149. */
  10150. ol.ResolutionConstraint.createSnapToResolutions = function(resolutions) {
  10151. return (
  10152. /**
  10153. * @param {number|undefined} resolution Resolution.
  10154. * @param {number} delta Delta.
  10155. * @param {number} direction Direction.
  10156. * @return {number|undefined} Resolution.
  10157. */
  10158. function(resolution, delta, direction) {
  10159. if (resolution !== undefined) {
  10160. var z =
  10161. ol.array.linearFindNearest(resolutions, resolution, direction);
  10162. z = ol.math.clamp(z + delta, 0, resolutions.length - 1);
  10163. var index = Math.floor(z);
  10164. if (z != index && index < resolutions.length - 1) {
  10165. var power = resolutions[index] / resolutions[index + 1];
  10166. return resolutions[index] / Math.pow(power, z - index);
  10167. } else {
  10168. return resolutions[index];
  10169. }
  10170. } else {
  10171. return undefined;
  10172. }
  10173. });
  10174. };
  10175. /**
  10176. * @param {number} power Power.
  10177. * @param {number} maxResolution Maximum resolution.
  10178. * @param {number=} opt_maxLevel Maximum level.
  10179. * @return {ol.ResolutionConstraintType} Zoom function.
  10180. */
  10181. ol.ResolutionConstraint.createSnapToPower = function(power, maxResolution, opt_maxLevel) {
  10182. return (
  10183. /**
  10184. * @param {number|undefined} resolution Resolution.
  10185. * @param {number} delta Delta.
  10186. * @param {number} direction Direction.
  10187. * @return {number|undefined} Resolution.
  10188. */
  10189. function(resolution, delta, direction) {
  10190. if (resolution !== undefined) {
  10191. var offset = -direction / 2 + 0.5;
  10192. var oldLevel = Math.floor(
  10193. Math.log(maxResolution / resolution) / Math.log(power) + offset);
  10194. var newLevel = Math.max(oldLevel + delta, 0);
  10195. if (opt_maxLevel !== undefined) {
  10196. newLevel = Math.min(newLevel, opt_maxLevel);
  10197. }
  10198. return maxResolution / Math.pow(power, newLevel);
  10199. } else {
  10200. return undefined;
  10201. }
  10202. });
  10203. };
  10204. goog.provide('ol.RotationConstraint');
  10205. goog.require('ol.math');
  10206. /**
  10207. * @param {number|undefined} rotation Rotation.
  10208. * @param {number} delta Delta.
  10209. * @return {number|undefined} Rotation.
  10210. */
  10211. ol.RotationConstraint.disable = function(rotation, delta) {
  10212. if (rotation !== undefined) {
  10213. return 0;
  10214. } else {
  10215. return undefined;
  10216. }
  10217. };
  10218. /**
  10219. * @param {number|undefined} rotation Rotation.
  10220. * @param {number} delta Delta.
  10221. * @return {number|undefined} Rotation.
  10222. */
  10223. ol.RotationConstraint.none = function(rotation, delta) {
  10224. if (rotation !== undefined) {
  10225. return rotation + delta;
  10226. } else {
  10227. return undefined;
  10228. }
  10229. };
  10230. /**
  10231. * @param {number} n N.
  10232. * @return {ol.RotationConstraintType} Rotation constraint.
  10233. */
  10234. ol.RotationConstraint.createSnapToN = function(n) {
  10235. var theta = 2 * Math.PI / n;
  10236. return (
  10237. /**
  10238. * @param {number|undefined} rotation Rotation.
  10239. * @param {number} delta Delta.
  10240. * @return {number|undefined} Rotation.
  10241. */
  10242. function(rotation, delta) {
  10243. if (rotation !== undefined) {
  10244. rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
  10245. return rotation;
  10246. } else {
  10247. return undefined;
  10248. }
  10249. });
  10250. };
  10251. /**
  10252. * @param {number=} opt_tolerance Tolerance.
  10253. * @return {ol.RotationConstraintType} Rotation constraint.
  10254. */
  10255. ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
  10256. var tolerance = opt_tolerance || ol.math.toRadians(5);
  10257. return (
  10258. /**
  10259. * @param {number|undefined} rotation Rotation.
  10260. * @param {number} delta Delta.
  10261. * @return {number|undefined} Rotation.
  10262. */
  10263. function(rotation, delta) {
  10264. if (rotation !== undefined) {
  10265. if (Math.abs(rotation + delta) <= tolerance) {
  10266. return 0;
  10267. } else {
  10268. return rotation + delta;
  10269. }
  10270. } else {
  10271. return undefined;
  10272. }
  10273. });
  10274. };
  10275. goog.provide('ol.ViewHint');
  10276. /**
  10277. * @enum {number}
  10278. */
  10279. ol.ViewHint = {
  10280. ANIMATING: 0,
  10281. INTERACTING: 1
  10282. };
  10283. goog.provide('ol.ViewProperty');
  10284. /**
  10285. * @enum {string}
  10286. */
  10287. ol.ViewProperty = {
  10288. CENTER: 'center',
  10289. RESOLUTION: 'resolution',
  10290. ROTATION: 'rotation'
  10291. };
  10292. goog.provide('ol.string');
  10293. /**
  10294. * @param {number} number Number to be formatted
  10295. * @param {number} width The desired width
  10296. * @param {number=} opt_precision Precision of the output string (i.e. number of decimal places)
  10297. * @returns {string} Formatted string
  10298. */
  10299. ol.string.padNumber = function(number, width, opt_precision) {
  10300. var numberString = opt_precision !== undefined ? number.toFixed(opt_precision) : '' + number;
  10301. var decimal = numberString.indexOf('.');
  10302. decimal = decimal === -1 ? numberString.length : decimal;
  10303. return decimal > width ? numberString : new Array(1 + width - decimal).join('0') + numberString;
  10304. };
  10305. /**
  10306. * Adapted from https://github.com/omichelsen/compare-versions/blob/master/index.js
  10307. * @param {string|number} v1 First version
  10308. * @param {string|number} v2 Second version
  10309. * @returns {number} Value
  10310. */
  10311. ol.string.compareVersions = function(v1, v2) {
  10312. var s1 = ('' + v1).split('.');
  10313. var s2 = ('' + v2).split('.');
  10314. for (var i = 0; i < Math.max(s1.length, s2.length); i++) {
  10315. var n1 = parseInt(s1[i] || '0', 10);
  10316. var n2 = parseInt(s2[i] || '0', 10);
  10317. if (n1 > n2) {
  10318. return 1;
  10319. }
  10320. if (n2 > n1) {
  10321. return -1;
  10322. }
  10323. }
  10324. return 0;
  10325. };
  10326. goog.provide('ol.coordinate');
  10327. goog.require('ol.math');
  10328. goog.require('ol.string');
  10329. /**
  10330. * Add `delta` to `coordinate`. `coordinate` is modified in place and returned
  10331. * by the function.
  10332. *
  10333. * Example:
  10334. *
  10335. * var coord = [7.85, 47.983333];
  10336. * ol.coordinate.add(coord, [-2, 4]);
  10337. * // coord is now [5.85, 51.983333]
  10338. *
  10339. * @param {ol.Coordinate} coordinate Coordinate.
  10340. * @param {ol.Coordinate} delta Delta.
  10341. * @return {ol.Coordinate} The input coordinate adjusted by the given delta.
  10342. * @api
  10343. */
  10344. ol.coordinate.add = function(coordinate, delta) {
  10345. coordinate[0] += delta[0];
  10346. coordinate[1] += delta[1];
  10347. return coordinate;
  10348. };
  10349. /**
  10350. * Calculates the point closest to the passed coordinate on the passed circle.
  10351. *
  10352. * @param {ol.Coordinate} coordinate The coordinate.
  10353. * @param {ol.geom.Circle} circle The circle.
  10354. * @return {ol.Coordinate} Closest point on the circumference
  10355. */
  10356. ol.coordinate.closestOnCircle = function(coordinate, circle) {
  10357. var r = circle.getRadius();
  10358. var center = circle.getCenter();
  10359. var x0 = center[0];
  10360. var y0 = center[1];
  10361. var x1 = coordinate[0];
  10362. var y1 = coordinate[1];
  10363. var dx = x1 - x0;
  10364. var dy = y1 - y0;
  10365. if (dx === 0 && dy === 0) {
  10366. dx = 1;
  10367. }
  10368. var d = Math.sqrt(dx * dx + dy * dy);
  10369. var x, y;
  10370. x = x0 + r * dx / d;
  10371. y = y0 + r * dy / d;
  10372. return [x, y];
  10373. };
  10374. /**
  10375. * Calculates the point closest to the passed coordinate on the passed segment.
  10376. * This is the foot of the perpendicular of the coordinate to the segment when
  10377. * the foot is on the segment, or the closest segment coordinate when the foot
  10378. * is outside the segment.
  10379. *
  10380. * @param {ol.Coordinate} coordinate The coordinate.
  10381. * @param {Array.<ol.Coordinate>} segment The two coordinates of the segment.
  10382. * @return {ol.Coordinate} The foot of the perpendicular of the coordinate to
  10383. * the segment.
  10384. */
  10385. ol.coordinate.closestOnSegment = function(coordinate, segment) {
  10386. var x0 = coordinate[0];
  10387. var y0 = coordinate[1];
  10388. var start = segment[0];
  10389. var end = segment[1];
  10390. var x1 = start[0];
  10391. var y1 = start[1];
  10392. var x2 = end[0];
  10393. var y2 = end[1];
  10394. var dx = x2 - x1;
  10395. var dy = y2 - y1;
  10396. var along = (dx === 0 && dy === 0) ? 0 :
  10397. ((dx * (x0 - x1)) + (dy * (y0 - y1))) / ((dx * dx + dy * dy) || 0);
  10398. var x, y;
  10399. if (along <= 0) {
  10400. x = x1;
  10401. y = y1;
  10402. } else if (along >= 1) {
  10403. x = x2;
  10404. y = y2;
  10405. } else {
  10406. x = x1 + along * dx;
  10407. y = y1 + along * dy;
  10408. }
  10409. return [x, y];
  10410. };
  10411. /**
  10412. * Returns a {@link ol.CoordinateFormatType} function that can be used to format
  10413. * a {ol.Coordinate} to a string.
  10414. *
  10415. * Example without specifying the fractional digits:
  10416. *
  10417. * var coord = [7.85, 47.983333];
  10418. * var stringifyFunc = ol.coordinate.createStringXY();
  10419. * var out = stringifyFunc(coord);
  10420. * // out is now '8, 48'
  10421. *
  10422. * Example with explicitly specifying 2 fractional digits:
  10423. *
  10424. * var coord = [7.85, 47.983333];
  10425. * var stringifyFunc = ol.coordinate.createStringXY(2);
  10426. * var out = stringifyFunc(coord);
  10427. * // out is now '7.85, 47.98'
  10428. *
  10429. * @param {number=} opt_fractionDigits The number of digits to include
  10430. * after the decimal point. Default is `0`.
  10431. * @return {ol.CoordinateFormatType} Coordinate format.
  10432. * @api
  10433. */
  10434. ol.coordinate.createStringXY = function(opt_fractionDigits) {
  10435. return (
  10436. /**
  10437. * @param {ol.Coordinate|undefined} coordinate Coordinate.
  10438. * @return {string} String XY.
  10439. */
  10440. function(coordinate) {
  10441. return ol.coordinate.toStringXY(coordinate, opt_fractionDigits);
  10442. });
  10443. };
  10444. /**
  10445. * @param {string} hemispheres Hemispheres.
  10446. * @param {number} degrees Degrees.
  10447. * @param {number=} opt_fractionDigits The number of digits to include
  10448. * after the decimal point. Default is `0`.
  10449. * @return {string} String.
  10450. */
  10451. ol.coordinate.degreesToStringHDMS = function(hemispheres, degrees, opt_fractionDigits) {
  10452. var normalizedDegrees = ol.math.modulo(degrees + 180, 360) - 180;
  10453. var x = Math.abs(3600 * normalizedDegrees);
  10454. var dflPrecision = opt_fractionDigits || 0;
  10455. var precision = Math.pow(10, dflPrecision);
  10456. var deg = Math.floor(x / 3600);
  10457. var min = Math.floor((x - deg * 3600) / 60);
  10458. var sec = x - (deg * 3600) - (min * 60);
  10459. sec = Math.ceil(sec * precision) / precision;
  10460. if (sec >= 60) {
  10461. sec = 0;
  10462. min += 1;
  10463. }
  10464. if (min >= 60) {
  10465. min = 0;
  10466. deg += 1;
  10467. }
  10468. return deg + '\u00b0 ' + ol.string.padNumber(min, 2) + '\u2032 ' +
  10469. ol.string.padNumber(sec, 2, dflPrecision) + '\u2033' +
  10470. (normalizedDegrees == 0 ? '' : ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0));
  10471. };
  10472. /**
  10473. * Transforms the given {@link ol.Coordinate} to a string using the given string
  10474. * template. The strings `{x}` and `{y}` in the template will be replaced with
  10475. * the first and second coordinate values respectively.
  10476. *
  10477. * Example without specifying the fractional digits:
  10478. *
  10479. * var coord = [7.85, 47.983333];
  10480. * var template = 'Coordinate is ({x}|{y}).';
  10481. * var out = ol.coordinate.format(coord, template);
  10482. * // out is now 'Coordinate is (8|48).'
  10483. *
  10484. * Example explicitly specifying the fractional digits:
  10485. *
  10486. * var coord = [7.85, 47.983333];
  10487. * var template = 'Coordinate is ({x}|{y}).';
  10488. * var out = ol.coordinate.format(coord, template, 2);
  10489. * // out is now 'Coordinate is (7.85|47.98).'
  10490. *
  10491. * @param {ol.Coordinate|undefined} coordinate Coordinate.
  10492. * @param {string} template A template string with `{x}` and `{y}` placeholders
  10493. * that will be replaced by first and second coordinate values.
  10494. * @param {number=} opt_fractionDigits The number of digits to include
  10495. * after the decimal point. Default is `0`.
  10496. * @return {string} Formatted coordinate.
  10497. * @api
  10498. */
  10499. ol.coordinate.format = function(coordinate, template, opt_fractionDigits) {
  10500. if (coordinate) {
  10501. return template
  10502. .replace('{x}', coordinate[0].toFixed(opt_fractionDigits))
  10503. .replace('{y}', coordinate[1].toFixed(opt_fractionDigits));
  10504. } else {
  10505. return '';
  10506. }
  10507. };
  10508. /**
  10509. * @param {ol.Coordinate} coordinate1 First coordinate.
  10510. * @param {ol.Coordinate} coordinate2 Second coordinate.
  10511. * @return {boolean} Whether the passed coordinates are equal.
  10512. */
  10513. ol.coordinate.equals = function(coordinate1, coordinate2) {
  10514. var equals = true;
  10515. for (var i = coordinate1.length - 1; i >= 0; --i) {
  10516. if (coordinate1[i] != coordinate2[i]) {
  10517. equals = false;
  10518. break;
  10519. }
  10520. }
  10521. return equals;
  10522. };
  10523. /**
  10524. * Rotate `coordinate` by `angle`. `coordinate` is modified in place and
  10525. * returned by the function.
  10526. *
  10527. * Example:
  10528. *
  10529. * var coord = [7.85, 47.983333];
  10530. * var rotateRadians = Math.PI / 2; // 90 degrees
  10531. * ol.coordinate.rotate(coord, rotateRadians);
  10532. * // coord is now [-47.983333, 7.85]
  10533. *
  10534. * @param {ol.Coordinate} coordinate Coordinate.
  10535. * @param {number} angle Angle in radian.
  10536. * @return {ol.Coordinate} Coordinate.
  10537. * @api
  10538. */
  10539. ol.coordinate.rotate = function(coordinate, angle) {
  10540. var cosAngle = Math.cos(angle);
  10541. var sinAngle = Math.sin(angle);
  10542. var x = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
  10543. var y = coordinate[1] * cosAngle + coordinate[0] * sinAngle;
  10544. coordinate[0] = x;
  10545. coordinate[1] = y;
  10546. return coordinate;
  10547. };
  10548. /**
  10549. * Scale `coordinate` by `scale`. `coordinate` is modified in place and returned
  10550. * by the function.
  10551. *
  10552. * Example:
  10553. *
  10554. * var coord = [7.85, 47.983333];
  10555. * var scale = 1.2;
  10556. * ol.coordinate.scale(coord, scale);
  10557. * // coord is now [9.42, 57.5799996]
  10558. *
  10559. * @param {ol.Coordinate} coordinate Coordinate.
  10560. * @param {number} scale Scale factor.
  10561. * @return {ol.Coordinate} Coordinate.
  10562. */
  10563. ol.coordinate.scale = function(coordinate, scale) {
  10564. coordinate[0] *= scale;
  10565. coordinate[1] *= scale;
  10566. return coordinate;
  10567. };
  10568. /**
  10569. * Subtract `delta` to `coordinate`. `coordinate` is modified in place and
  10570. * returned by the function.
  10571. *
  10572. * @param {ol.Coordinate} coordinate Coordinate.
  10573. * @param {ol.Coordinate} delta Delta.
  10574. * @return {ol.Coordinate} Coordinate.
  10575. */
  10576. ol.coordinate.sub = function(coordinate, delta) {
  10577. coordinate[0] -= delta[0];
  10578. coordinate[1] -= delta[1];
  10579. return coordinate;
  10580. };
  10581. /**
  10582. * @param {ol.Coordinate} coord1 First coordinate.
  10583. * @param {ol.Coordinate} coord2 Second coordinate.
  10584. * @return {number} Squared distance between coord1 and coord2.
  10585. */
  10586. ol.coordinate.squaredDistance = function(coord1, coord2) {
  10587. var dx = coord1[0] - coord2[0];
  10588. var dy = coord1[1] - coord2[1];
  10589. return dx * dx + dy * dy;
  10590. };
  10591. /**
  10592. * @param {ol.Coordinate} coord1 First coordinate.
  10593. * @param {ol.Coordinate} coord2 Second coordinate.
  10594. * @return {number} Distance between coord1 and coord2.
  10595. */
  10596. ol.coordinate.distance = function(coord1, coord2) {
  10597. return Math.sqrt(ol.coordinate.squaredDistance(coord1, coord2));
  10598. };
  10599. /**
  10600. * Calculate the squared distance from a coordinate to a line segment.
  10601. *
  10602. * @param {ol.Coordinate} coordinate Coordinate of the point.
  10603. * @param {Array.<ol.Coordinate>} segment Line segment (2 coordinates).
  10604. * @return {number} Squared distance from the point to the line segment.
  10605. */
  10606. ol.coordinate.squaredDistanceToSegment = function(coordinate, segment) {
  10607. return ol.coordinate.squaredDistance(coordinate,
  10608. ol.coordinate.closestOnSegment(coordinate, segment));
  10609. };
  10610. /**
  10611. * Format a geographic coordinate with the hemisphere, degrees, minutes, and
  10612. * seconds.
  10613. *
  10614. * Example without specifying fractional digits:
  10615. *
  10616. * var coord = [7.85, 47.983333];
  10617. * var out = ol.coordinate.toStringHDMS(coord);
  10618. * // out is now '47° 58′ 60″ N 7° 50′ 60″ E'
  10619. *
  10620. * Example explicitly specifying 1 fractional digit:
  10621. *
  10622. * var coord = [7.85, 47.983333];
  10623. * var out = ol.coordinate.toStringHDMS(coord, 1);
  10624. * // out is now '47° 58′ 60.0″ N 7° 50′ 60.0″ E'
  10625. *
  10626. * @param {ol.Coordinate|undefined} coordinate Coordinate.
  10627. * @param {number=} opt_fractionDigits The number of digits to include
  10628. * after the decimal point. Default is `0`.
  10629. * @return {string} Hemisphere, degrees, minutes and seconds.
  10630. * @api
  10631. */
  10632. ol.coordinate.toStringHDMS = function(coordinate, opt_fractionDigits) {
  10633. if (coordinate) {
  10634. return ol.coordinate.degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) + ' ' +
  10635. ol.coordinate.degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits);
  10636. } else {
  10637. return '';
  10638. }
  10639. };
  10640. /**
  10641. * Format a coordinate as a comma delimited string.
  10642. *
  10643. * Example without specifying fractional digits:
  10644. *
  10645. * var coord = [7.85, 47.983333];
  10646. * var out = ol.coordinate.toStringXY(coord);
  10647. * // out is now '8, 48'
  10648. *
  10649. * Example explicitly specifying 1 fractional digit:
  10650. *
  10651. * var coord = [7.85, 47.983333];
  10652. * var out = ol.coordinate.toStringXY(coord, 1);
  10653. * // out is now '7.8, 48.0'
  10654. *
  10655. * @param {ol.Coordinate|undefined} coordinate Coordinate.
  10656. * @param {number=} opt_fractionDigits The number of digits to include
  10657. * after the decimal point. Default is `0`.
  10658. * @return {string} XY.
  10659. * @api
  10660. */
  10661. ol.coordinate.toStringXY = function(coordinate, opt_fractionDigits) {
  10662. return ol.coordinate.format(coordinate, '{x}, {y}', opt_fractionDigits);
  10663. };
  10664. goog.provide('ol.easing');
  10665. /**
  10666. * Start slow and speed up.
  10667. * @param {number} t Input between 0 and 1.
  10668. * @return {number} Output between 0 and 1.
  10669. * @api
  10670. */
  10671. ol.easing.easeIn = function(t) {
  10672. return Math.pow(t, 3);
  10673. };
  10674. /**
  10675. * Start fast and slow down.
  10676. * @param {number} t Input between 0 and 1.
  10677. * @return {number} Output between 0 and 1.
  10678. * @api
  10679. */
  10680. ol.easing.easeOut = function(t) {
  10681. return 1 - ol.easing.easeIn(1 - t);
  10682. };
  10683. /**
  10684. * Start slow, speed up, and then slow down again.
  10685. * @param {number} t Input between 0 and 1.
  10686. * @return {number} Output between 0 and 1.
  10687. * @api
  10688. */
  10689. ol.easing.inAndOut = function(t) {
  10690. return 3 * t * t - 2 * t * t * t;
  10691. };
  10692. /**
  10693. * Maintain a constant speed over time.
  10694. * @param {number} t Input between 0 and 1.
  10695. * @return {number} Output between 0 and 1.
  10696. * @api
  10697. */
  10698. ol.easing.linear = function(t) {
  10699. return t;
  10700. };
  10701. /**
  10702. * Start slow, speed up, and at the very end slow down again. This has the
  10703. * same general behavior as {@link ol.easing.inAndOut}, but the final slowdown
  10704. * is delayed.
  10705. * @param {number} t Input between 0 and 1.
  10706. * @return {number} Output between 0 and 1.
  10707. * @api
  10708. */
  10709. ol.easing.upAndDown = function(t) {
  10710. if (t < 0.5) {
  10711. return ol.easing.inAndOut(2 * t);
  10712. } else {
  10713. return 1 - ol.easing.inAndOut(2 * (t - 0.5));
  10714. }
  10715. };
  10716. goog.provide('ol.geom.GeometryLayout');
  10717. /**
  10718. * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z')
  10719. * or measure ('M') coordinate is available. Supported values are `'XY'`,
  10720. * `'XYZ'`, `'XYM'`, `'XYZM'`.
  10721. * @enum {string}
  10722. */
  10723. ol.geom.GeometryLayout = {
  10724. XY: 'XY',
  10725. XYZ: 'XYZ',
  10726. XYM: 'XYM',
  10727. XYZM: 'XYZM'
  10728. };
  10729. goog.provide('ol.functions');
  10730. /**
  10731. * Always returns true.
  10732. * @returns {boolean} true.
  10733. */
  10734. ol.functions.TRUE = function() {
  10735. return true;
  10736. };
  10737. /**
  10738. * Always returns false.
  10739. * @returns {boolean} false.
  10740. */
  10741. ol.functions.FALSE = function() {
  10742. return false;
  10743. };
  10744. goog.provide('ol.geom.flat.transform');
  10745. /**
  10746. * @param {Array.<number>} flatCoordinates Flat coordinates.
  10747. * @param {number} offset Offset.
  10748. * @param {number} end End.
  10749. * @param {number} stride Stride.
  10750. * @param {ol.Transform} transform Transform.
  10751. * @param {Array.<number>=} opt_dest Destination.
  10752. * @return {Array.<number>} Transformed coordinates.
  10753. */
  10754. ol.geom.flat.transform.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) {
  10755. var dest = opt_dest ? opt_dest : [];
  10756. var i = 0;
  10757. var j;
  10758. for (j = offset; j < end; j += stride) {
  10759. var x = flatCoordinates[j];
  10760. var y = flatCoordinates[j + 1];
  10761. dest[i++] = transform[0] * x + transform[2] * y + transform[4];
  10762. dest[i++] = transform[1] * x + transform[3] * y + transform[5];
  10763. }
  10764. if (opt_dest && dest.length != i) {
  10765. dest.length = i;
  10766. }
  10767. return dest;
  10768. };
  10769. /**
  10770. * @param {Array.<number>} flatCoordinates Flat coordinates.
  10771. * @param {number} offset Offset.
  10772. * @param {number} end End.
  10773. * @param {number} stride Stride.
  10774. * @param {number} angle Angle.
  10775. * @param {Array.<number>} anchor Rotation anchor point.
  10776. * @param {Array.<number>=} opt_dest Destination.
  10777. * @return {Array.<number>} Transformed coordinates.
  10778. */
  10779. ol.geom.flat.transform.rotate = function(flatCoordinates, offset, end, stride, angle, anchor, opt_dest) {
  10780. var dest = opt_dest ? opt_dest : [];
  10781. var cos = Math.cos(angle);
  10782. var sin = Math.sin(angle);
  10783. var anchorX = anchor[0];
  10784. var anchorY = anchor[1];
  10785. var i = 0;
  10786. for (var j = offset; j < end; j += stride) {
  10787. var deltaX = flatCoordinates[j] - anchorX;
  10788. var deltaY = flatCoordinates[j + 1] - anchorY;
  10789. dest[i++] = anchorX + deltaX * cos - deltaY * sin;
  10790. dest[i++] = anchorY + deltaX * sin + deltaY * cos;
  10791. for (var k = j + 2; k < j + stride; ++k) {
  10792. dest[i++] = flatCoordinates[k];
  10793. }
  10794. }
  10795. if (opt_dest && dest.length != i) {
  10796. dest.length = i;
  10797. }
  10798. return dest;
  10799. };
  10800. /**
  10801. * Scale the coordinates.
  10802. * @param {Array.<number>} flatCoordinates Flat coordinates.
  10803. * @param {number} offset Offset.
  10804. * @param {number} end End.
  10805. * @param {number} stride Stride.
  10806. * @param {number} sx Scale factor in the x-direction.
  10807. * @param {number} sy Scale factor in the y-direction.
  10808. * @param {Array.<number>} anchor Scale anchor point.
  10809. * @param {Array.<number>=} opt_dest Destination.
  10810. * @return {Array.<number>} Transformed coordinates.
  10811. */
  10812. ol.geom.flat.transform.scale = function(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_dest) {
  10813. var dest = opt_dest ? opt_dest : [];
  10814. var anchorX = anchor[0];
  10815. var anchorY = anchor[1];
  10816. var i = 0;
  10817. for (var j = offset; j < end; j += stride) {
  10818. var deltaX = flatCoordinates[j] - anchorX;
  10819. var deltaY = flatCoordinates[j + 1] - anchorY;
  10820. dest[i++] = anchorX + sx * deltaX;
  10821. dest[i++] = anchorY + sy * deltaY;
  10822. for (var k = j + 2; k < j + stride; ++k) {
  10823. dest[i++] = flatCoordinates[k];
  10824. }
  10825. }
  10826. if (opt_dest && dest.length != i) {
  10827. dest.length = i;
  10828. }
  10829. return dest;
  10830. };
  10831. /**
  10832. * @param {Array.<number>} flatCoordinates Flat coordinates.
  10833. * @param {number} offset Offset.
  10834. * @param {number} end End.
  10835. * @param {number} stride Stride.
  10836. * @param {number} deltaX Delta X.
  10837. * @param {number} deltaY Delta Y.
  10838. * @param {Array.<number>=} opt_dest Destination.
  10839. * @return {Array.<number>} Transformed coordinates.
  10840. */
  10841. ol.geom.flat.transform.translate = function(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) {
  10842. var dest = opt_dest ? opt_dest : [];
  10843. var i = 0;
  10844. var j, k;
  10845. for (j = offset; j < end; j += stride) {
  10846. dest[i++] = flatCoordinates[j] + deltaX;
  10847. dest[i++] = flatCoordinates[j + 1] + deltaY;
  10848. for (k = j + 2; k < j + stride; ++k) {
  10849. dest[i++] = flatCoordinates[k];
  10850. }
  10851. }
  10852. if (opt_dest && dest.length != i) {
  10853. dest.length = i;
  10854. }
  10855. return dest;
  10856. };
  10857. goog.provide('ol.transform');
  10858. goog.require('ol.asserts');
  10859. /**
  10860. * Collection of affine 2d transformation functions. The functions work on an
  10861. * array of 6 elements. The element order is compatible with the [SVGMatrix
  10862. * interface](https://developer.mozilla.org/en-US/docs/Web/API/SVGMatrix) and is
  10863. * a subset (elements a to f) of a 3x3 martrix:
  10864. * ```
  10865. * [ a c e ]
  10866. * [ b d f ]
  10867. * [ 0 0 1 ]
  10868. * ```
  10869. */
  10870. /**
  10871. * @private
  10872. * @type {ol.Transform}
  10873. */
  10874. ol.transform.tmp_ = new Array(6);
  10875. /**
  10876. * Create an identity transform.
  10877. * @return {!ol.Transform} Identity transform.
  10878. */
  10879. ol.transform.create = function() {
  10880. return [1, 0, 0, 1, 0, 0];
  10881. };
  10882. /**
  10883. * Resets the given transform to an identity transform.
  10884. * @param {!ol.Transform} transform Transform.
  10885. * @return {!ol.Transform} Transform.
  10886. */
  10887. ol.transform.reset = function(transform) {
  10888. return ol.transform.set(transform, 1, 0, 0, 1, 0, 0);
  10889. };
  10890. /**
  10891. * Multiply the underlying matrices of two transforms and return the result in
  10892. * the first transform.
  10893. * @param {!ol.Transform} transform1 Transform parameters of matrix 1.
  10894. * @param {!ol.Transform} transform2 Transform parameters of matrix 2.
  10895. * @return {!ol.Transform} transform1 multiplied with transform2.
  10896. */
  10897. ol.transform.multiply = function(transform1, transform2) {
  10898. var a1 = transform1[0];
  10899. var b1 = transform1[1];
  10900. var c1 = transform1[2];
  10901. var d1 = transform1[3];
  10902. var e1 = transform1[4];
  10903. var f1 = transform1[5];
  10904. var a2 = transform2[0];
  10905. var b2 = transform2[1];
  10906. var c2 = transform2[2];
  10907. var d2 = transform2[3];
  10908. var e2 = transform2[4];
  10909. var f2 = transform2[5];
  10910. transform1[0] = a1 * a2 + c1 * b2;
  10911. transform1[1] = b1 * a2 + d1 * b2;
  10912. transform1[2] = a1 * c2 + c1 * d2;
  10913. transform1[3] = b1 * c2 + d1 * d2;
  10914. transform1[4] = a1 * e2 + c1 * f2 + e1;
  10915. transform1[5] = b1 * e2 + d1 * f2 + f1;
  10916. return transform1;
  10917. };
  10918. /**
  10919. * Set the transform components a-f on a given transform.
  10920. * @param {!ol.Transform} transform Transform.
  10921. * @param {number} a The a component of the transform.
  10922. * @param {number} b The b component of the transform.
  10923. * @param {number} c The c component of the transform.
  10924. * @param {number} d The d component of the transform.
  10925. * @param {number} e The e component of the transform.
  10926. * @param {number} f The f component of the transform.
  10927. * @return {!ol.Transform} Matrix with transform applied.
  10928. */
  10929. ol.transform.set = function(transform, a, b, c, d, e, f) {
  10930. transform[0] = a;
  10931. transform[1] = b;
  10932. transform[2] = c;
  10933. transform[3] = d;
  10934. transform[4] = e;
  10935. transform[5] = f;
  10936. return transform;
  10937. };
  10938. /**
  10939. * Set transform on one matrix from another matrix.
  10940. * @param {!ol.Transform} transform1 Matrix to set transform to.
  10941. * @param {!ol.Transform} transform2 Matrix to set transform from.
  10942. * @return {!ol.Transform} transform1 with transform from transform2 applied.
  10943. */
  10944. ol.transform.setFromArray = function(transform1, transform2) {
  10945. transform1[0] = transform2[0];
  10946. transform1[1] = transform2[1];
  10947. transform1[2] = transform2[2];
  10948. transform1[3] = transform2[3];
  10949. transform1[4] = transform2[4];
  10950. transform1[5] = transform2[5];
  10951. return transform1;
  10952. };
  10953. /**
  10954. * Transforms the given coordinate with the given transform returning the
  10955. * resulting, transformed coordinate. The coordinate will be modified in-place.
  10956. *
  10957. * @param {ol.Transform} transform The transformation.
  10958. * @param {ol.Coordinate|ol.Pixel} coordinate The coordinate to transform.
  10959. * @return {ol.Coordinate|ol.Pixel} return coordinate so that operations can be
  10960. * chained together.
  10961. */
  10962. ol.transform.apply = function(transform, coordinate) {
  10963. var x = coordinate[0], y = coordinate[1];
  10964. coordinate[0] = transform[0] * x + transform[2] * y + transform[4];
  10965. coordinate[1] = transform[1] * x + transform[3] * y + transform[5];
  10966. return coordinate;
  10967. };
  10968. /**
  10969. * Applies rotation to the given transform.
  10970. * @param {!ol.Transform} transform Transform.
  10971. * @param {number} angle Angle in radians.
  10972. * @return {!ol.Transform} The rotated transform.
  10973. */
  10974. ol.transform.rotate = function(transform, angle) {
  10975. var cos = Math.cos(angle);
  10976. var sin = Math.sin(angle);
  10977. return ol.transform.multiply(transform,
  10978. ol.transform.set(ol.transform.tmp_, cos, sin, -sin, cos, 0, 0));
  10979. };
  10980. /**
  10981. * Applies scale to a given transform.
  10982. * @param {!ol.Transform} transform Transform.
  10983. * @param {number} x Scale factor x.
  10984. * @param {number} y Scale factor y.
  10985. * @return {!ol.Transform} The scaled transform.
  10986. */
  10987. ol.transform.scale = function(transform, x, y) {
  10988. return ol.transform.multiply(transform,
  10989. ol.transform.set(ol.transform.tmp_, x, 0, 0, y, 0, 0));
  10990. };
  10991. /**
  10992. * Applies translation to the given transform.
  10993. * @param {!ol.Transform} transform Transform.
  10994. * @param {number} dx Translation x.
  10995. * @param {number} dy Translation y.
  10996. * @return {!ol.Transform} The translated transform.
  10997. */
  10998. ol.transform.translate = function(transform, dx, dy) {
  10999. return ol.transform.multiply(transform,
  11000. ol.transform.set(ol.transform.tmp_, 1, 0, 0, 1, dx, dy));
  11001. };
  11002. /**
  11003. * Creates a composite transform given an initial translation, scale, rotation, and
  11004. * final translation (in that order only, not commutative).
  11005. * @param {!ol.Transform} transform The transform (will be modified in place).
  11006. * @param {number} dx1 Initial translation x.
  11007. * @param {number} dy1 Initial translation y.
  11008. * @param {number} sx Scale factor x.
  11009. * @param {number} sy Scale factor y.
  11010. * @param {number} angle Rotation (in counter-clockwise radians).
  11011. * @param {number} dx2 Final translation x.
  11012. * @param {number} dy2 Final translation y.
  11013. * @return {!ol.Transform} The composite transform.
  11014. */
  11015. ol.transform.compose = function(transform, dx1, dy1, sx, sy, angle, dx2, dy2) {
  11016. var sin = Math.sin(angle);
  11017. var cos = Math.cos(angle);
  11018. transform[0] = sx * cos;
  11019. transform[1] = sy * sin;
  11020. transform[2] = -sx * sin;
  11021. transform[3] = sy * cos;
  11022. transform[4] = dx2 * sx * cos - dy2 * sx * sin + dx1;
  11023. transform[5] = dx2 * sy * sin + dy2 * sy * cos + dy1;
  11024. return transform;
  11025. };
  11026. /**
  11027. * Invert the given transform.
  11028. * @param {!ol.Transform} transform Transform.
  11029. * @return {!ol.Transform} Inverse of the transform.
  11030. */
  11031. ol.transform.invert = function(transform) {
  11032. var det = ol.transform.determinant(transform);
  11033. ol.asserts.assert(det !== 0, 32); // Transformation matrix cannot be inverted
  11034. var a = transform[0];
  11035. var b = transform[1];
  11036. var c = transform[2];
  11037. var d = transform[3];
  11038. var e = transform[4];
  11039. var f = transform[5];
  11040. transform[0] = d / det;
  11041. transform[1] = -b / det;
  11042. transform[2] = -c / det;
  11043. transform[3] = a / det;
  11044. transform[4] = (c * f - d * e) / det;
  11045. transform[5] = -(a * f - b * e) / det;
  11046. return transform;
  11047. };
  11048. /**
  11049. * Returns the determinant of the given matrix.
  11050. * @param {!ol.Transform} mat Matrix.
  11051. * @return {number} Determinant.
  11052. */
  11053. ol.transform.determinant = function(mat) {
  11054. return mat[0] * mat[3] - mat[1] * mat[2];
  11055. };
  11056. goog.provide('ol.geom.Geometry');
  11057. goog.require('ol');
  11058. goog.require('ol.Object');
  11059. goog.require('ol.extent');
  11060. goog.require('ol.functions');
  11061. goog.require('ol.geom.flat.transform');
  11062. goog.require('ol.proj');
  11063. goog.require('ol.proj.Units');
  11064. goog.require('ol.transform');
  11065. /**
  11066. * @classdesc
  11067. * Abstract base class; normally only used for creating subclasses and not
  11068. * instantiated in apps.
  11069. * Base class for vector geometries.
  11070. *
  11071. * To get notified of changes to the geometry, register a listener for the
  11072. * generic `change` event on your geometry instance.
  11073. *
  11074. * @constructor
  11075. * @abstract
  11076. * @extends {ol.Object}
  11077. * @api
  11078. */
  11079. ol.geom.Geometry = function() {
  11080. ol.Object.call(this);
  11081. /**
  11082. * @private
  11083. * @type {ol.Extent}
  11084. */
  11085. this.extent_ = ol.extent.createEmpty();
  11086. /**
  11087. * @private
  11088. * @type {number}
  11089. */
  11090. this.extentRevision_ = -1;
  11091. /**
  11092. * @protected
  11093. * @type {Object.<string, ol.geom.Geometry>}
  11094. */
  11095. this.simplifiedGeometryCache = {};
  11096. /**
  11097. * @protected
  11098. * @type {number}
  11099. */
  11100. this.simplifiedGeometryMaxMinSquaredTolerance = 0;
  11101. /**
  11102. * @protected
  11103. * @type {number}
  11104. */
  11105. this.simplifiedGeometryRevision = 0;
  11106. /**
  11107. * @private
  11108. * @type {ol.Transform}
  11109. */
  11110. this.tmpTransform_ = ol.transform.create();
  11111. };
  11112. ol.inherits(ol.geom.Geometry, ol.Object);
  11113. /**
  11114. * Make a complete copy of the geometry.
  11115. * @abstract
  11116. * @return {!ol.geom.Geometry} Clone.
  11117. */
  11118. ol.geom.Geometry.prototype.clone = function() {};
  11119. /**
  11120. * @abstract
  11121. * @param {number} x X.
  11122. * @param {number} y Y.
  11123. * @param {ol.Coordinate} closestPoint Closest point.
  11124. * @param {number} minSquaredDistance Minimum squared distance.
  11125. * @return {number} Minimum squared distance.
  11126. */
  11127. ol.geom.Geometry.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {};
  11128. /**
  11129. * Return the closest point of the geometry to the passed point as
  11130. * {@link ol.Coordinate coordinate}.
  11131. * @param {ol.Coordinate} point Point.
  11132. * @param {ol.Coordinate=} opt_closestPoint Closest point.
  11133. * @return {ol.Coordinate} Closest point.
  11134. * @api
  11135. */
  11136. ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
  11137. var closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN];
  11138. this.closestPointXY(point[0], point[1], closestPoint, Infinity);
  11139. return closestPoint;
  11140. };
  11141. /**
  11142. * Returns true if this geometry includes the specified coordinate. If the
  11143. * coordinate is on the boundary of the geometry, returns false.
  11144. * @param {ol.Coordinate} coordinate Coordinate.
  11145. * @return {boolean} Contains coordinate.
  11146. * @api
  11147. */
  11148. ol.geom.Geometry.prototype.intersectsCoordinate = function(coordinate) {
  11149. return this.containsXY(coordinate[0], coordinate[1]);
  11150. };
  11151. /**
  11152. * @abstract
  11153. * @param {ol.Extent} extent Extent.
  11154. * @protected
  11155. * @return {ol.Extent} extent Extent.
  11156. */
  11157. ol.geom.Geometry.prototype.computeExtent = function(extent) {};
  11158. /**
  11159. * @param {number} x X.
  11160. * @param {number} y Y.
  11161. * @return {boolean} Contains (x, y).
  11162. */
  11163. ol.geom.Geometry.prototype.containsXY = ol.functions.FALSE;
  11164. /**
  11165. * Get the extent of the geometry.
  11166. * @param {ol.Extent=} opt_extent Extent.
  11167. * @return {ol.Extent} extent Extent.
  11168. * @api
  11169. */
  11170. ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
  11171. if (this.extentRevision_ != this.getRevision()) {
  11172. this.extent_ = this.computeExtent(this.extent_);
  11173. this.extentRevision_ = this.getRevision();
  11174. }
  11175. return ol.extent.returnOrUpdate(this.extent_, opt_extent);
  11176. };
  11177. /**
  11178. * Rotate the geometry around a given coordinate. This modifies the geometry
  11179. * coordinates in place.
  11180. * @abstract
  11181. * @param {number} angle Rotation angle in radians.
  11182. * @param {ol.Coordinate} anchor The rotation center.
  11183. * @api
  11184. */
  11185. ol.geom.Geometry.prototype.rotate = function(angle, anchor) {};
  11186. /**
  11187. * Scale the geometry (with an optional origin). This modifies the geometry
  11188. * coordinates in place.
  11189. * @abstract
  11190. * @param {number} sx The scaling factor in the x-direction.
  11191. * @param {number=} opt_sy The scaling factor in the y-direction (defaults to
  11192. * sx).
  11193. * @param {ol.Coordinate=} opt_anchor The scale origin (defaults to the center
  11194. * of the geometry extent).
  11195. * @api
  11196. */
  11197. ol.geom.Geometry.prototype.scale = function(sx, opt_sy, opt_anchor) {};
  11198. /**
  11199. * Create a simplified version of this geometry. For linestrings, this uses
  11200. * the the {@link
  11201. * https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
  11202. * Douglas Peucker} algorithm. For polygons, a quantization-based
  11203. * simplification is used to preserve topology.
  11204. * @function
  11205. * @param {number} tolerance The tolerance distance for simplification.
  11206. * @return {ol.geom.Geometry} A new, simplified version of the original
  11207. * geometry.
  11208. * @api
  11209. */
  11210. ol.geom.Geometry.prototype.simplify = function(tolerance) {
  11211. return this.getSimplifiedGeometry(tolerance * tolerance);
  11212. };
  11213. /**
  11214. * Create a simplified version of this geometry using the Douglas Peucker
  11215. * algorithm.
  11216. * @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
  11217. * @abstract
  11218. * @param {number} squaredTolerance Squared tolerance.
  11219. * @return {ol.geom.Geometry} Simplified geometry.
  11220. */
  11221. ol.geom.Geometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {};
  11222. /**
  11223. * Get the type of this geometry.
  11224. * @abstract
  11225. * @return {ol.geom.GeometryType} Geometry type.
  11226. */
  11227. ol.geom.Geometry.prototype.getType = function() {};
  11228. /**
  11229. * Apply a transform function to each coordinate of the geometry.
  11230. * The geometry is modified in place.
  11231. * If you do not want the geometry modified in place, first `clone()` it and
  11232. * then use this function on the clone.
  11233. * @abstract
  11234. * @param {ol.TransformFunction} transformFn Transform.
  11235. */
  11236. ol.geom.Geometry.prototype.applyTransform = function(transformFn) {};
  11237. /**
  11238. * Test if the geometry and the passed extent intersect.
  11239. * @abstract
  11240. * @param {ol.Extent} extent Extent.
  11241. * @return {boolean} `true` if the geometry and the extent intersect.
  11242. */
  11243. ol.geom.Geometry.prototype.intersectsExtent = function(extent) {};
  11244. /**
  11245. * Translate the geometry. This modifies the geometry coordinates in place. If
  11246. * instead you want a new geometry, first `clone()` this geometry.
  11247. * @abstract
  11248. * @param {number} deltaX Delta X.
  11249. * @param {number} deltaY Delta Y.
  11250. */
  11251. ol.geom.Geometry.prototype.translate = function(deltaX, deltaY) {};
  11252. /**
  11253. * Transform each coordinate of the geometry from one coordinate reference
  11254. * system to another. The geometry is modified in place.
  11255. * For example, a line will be transformed to a line and a circle to a circle.
  11256. * If you do not want the geometry modified in place, first `clone()` it and
  11257. * then use this function on the clone.
  11258. *
  11259. * @param {ol.ProjectionLike} source The current projection. Can be a
  11260. * string identifier or a {@link ol.proj.Projection} object.
  11261. * @param {ol.ProjectionLike} destination The desired projection. Can be a
  11262. * string identifier or a {@link ol.proj.Projection} object.
  11263. * @return {ol.geom.Geometry} This geometry. Note that original geometry is
  11264. * modified in place.
  11265. * @api
  11266. */
  11267. ol.geom.Geometry.prototype.transform = function(source, destination) {
  11268. var tmpTransform = this.tmpTransform_;
  11269. source = ol.proj.get(source);
  11270. var transformFn = source.getUnits() == ol.proj.Units.TILE_PIXELS ?
  11271. function(inCoordinates, outCoordinates, stride) {
  11272. var pixelExtent = source.getExtent();
  11273. var projectedExtent = source.getWorldExtent();
  11274. var scale = ol.extent.getHeight(projectedExtent) / ol.extent.getHeight(pixelExtent);
  11275. ol.transform.compose(tmpTransform,
  11276. projectedExtent[0], projectedExtent[3],
  11277. scale, -scale, 0,
  11278. 0, 0);
  11279. ol.geom.flat.transform.transform2D(inCoordinates, 0, inCoordinates.length, stride,
  11280. tmpTransform, outCoordinates);
  11281. return ol.proj.getTransform(source, destination)(inCoordinates, outCoordinates, stride);
  11282. } :
  11283. ol.proj.getTransform(source, destination);
  11284. this.applyTransform(transformFn);
  11285. return this;
  11286. };
  11287. goog.provide('ol.geom.SimpleGeometry');
  11288. goog.require('ol');
  11289. goog.require('ol.functions');
  11290. goog.require('ol.extent');
  11291. goog.require('ol.geom.Geometry');
  11292. goog.require('ol.geom.GeometryLayout');
  11293. goog.require('ol.geom.flat.transform');
  11294. goog.require('ol.obj');
  11295. /**
  11296. * @classdesc
  11297. * Abstract base class; only used for creating subclasses; do not instantiate
  11298. * in apps, as cannot be rendered.
  11299. *
  11300. * @constructor
  11301. * @abstract
  11302. * @extends {ol.geom.Geometry}
  11303. * @api
  11304. */
  11305. ol.geom.SimpleGeometry = function() {
  11306. ol.geom.Geometry.call(this);
  11307. /**
  11308. * @protected
  11309. * @type {ol.geom.GeometryLayout}
  11310. */
  11311. this.layout = ol.geom.GeometryLayout.XY;
  11312. /**
  11313. * @protected
  11314. * @type {number}
  11315. */
  11316. this.stride = 2;
  11317. /**
  11318. * @protected
  11319. * @type {Array.<number>}
  11320. */
  11321. this.flatCoordinates = null;
  11322. };
  11323. ol.inherits(ol.geom.SimpleGeometry, ol.geom.Geometry);
  11324. /**
  11325. * @param {number} stride Stride.
  11326. * @private
  11327. * @return {ol.geom.GeometryLayout} layout Layout.
  11328. */
  11329. ol.geom.SimpleGeometry.getLayoutForStride_ = function(stride) {
  11330. var layout;
  11331. if (stride == 2) {
  11332. layout = ol.geom.GeometryLayout.XY;
  11333. } else if (stride == 3) {
  11334. layout = ol.geom.GeometryLayout.XYZ;
  11335. } else if (stride == 4) {
  11336. layout = ol.geom.GeometryLayout.XYZM;
  11337. }
  11338. return /** @type {ol.geom.GeometryLayout} */ (layout);
  11339. };
  11340. /**
  11341. * @param {ol.geom.GeometryLayout} layout Layout.
  11342. * @return {number} Stride.
  11343. */
  11344. ol.geom.SimpleGeometry.getStrideForLayout = function(layout) {
  11345. var stride;
  11346. if (layout == ol.geom.GeometryLayout.XY) {
  11347. stride = 2;
  11348. } else if (layout == ol.geom.GeometryLayout.XYZ || layout == ol.geom.GeometryLayout.XYM) {
  11349. stride = 3;
  11350. } else if (layout == ol.geom.GeometryLayout.XYZM) {
  11351. stride = 4;
  11352. }
  11353. return /** @type {number} */ (stride);
  11354. };
  11355. /**
  11356. * @inheritDoc
  11357. */
  11358. ol.geom.SimpleGeometry.prototype.containsXY = ol.functions.FALSE;
  11359. /**
  11360. * @inheritDoc
  11361. */
  11362. ol.geom.SimpleGeometry.prototype.computeExtent = function(extent) {
  11363. return ol.extent.createOrUpdateFromFlatCoordinates(
  11364. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  11365. extent);
  11366. };
  11367. /**
  11368. * @abstract
  11369. * @return {Array} Coordinates.
  11370. */
  11371. ol.geom.SimpleGeometry.prototype.getCoordinates = function() {};
  11372. /**
  11373. * Return the first coordinate of the geometry.
  11374. * @return {ol.Coordinate} First coordinate.
  11375. * @api
  11376. */
  11377. ol.geom.SimpleGeometry.prototype.getFirstCoordinate = function() {
  11378. return this.flatCoordinates.slice(0, this.stride);
  11379. };
  11380. /**
  11381. * @return {Array.<number>} Flat coordinates.
  11382. */
  11383. ol.geom.SimpleGeometry.prototype.getFlatCoordinates = function() {
  11384. return this.flatCoordinates;
  11385. };
  11386. /**
  11387. * Return the last coordinate of the geometry.
  11388. * @return {ol.Coordinate} Last point.
  11389. * @api
  11390. */
  11391. ol.geom.SimpleGeometry.prototype.getLastCoordinate = function() {
  11392. return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
  11393. };
  11394. /**
  11395. * Return the {@link ol.geom.GeometryLayout layout} of the geometry.
  11396. * @return {ol.geom.GeometryLayout} Layout.
  11397. * @api
  11398. */
  11399. ol.geom.SimpleGeometry.prototype.getLayout = function() {
  11400. return this.layout;
  11401. };
  11402. /**
  11403. * @inheritDoc
  11404. */
  11405. ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
  11406. if (this.simplifiedGeometryRevision != this.getRevision()) {
  11407. ol.obj.clear(this.simplifiedGeometryCache);
  11408. this.simplifiedGeometryMaxMinSquaredTolerance = 0;
  11409. this.simplifiedGeometryRevision = this.getRevision();
  11410. }
  11411. // If squaredTolerance is negative or if we know that simplification will not
  11412. // have any effect then just return this.
  11413. if (squaredTolerance < 0 ||
  11414. (this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
  11415. squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
  11416. return this;
  11417. }
  11418. var key = squaredTolerance.toString();
  11419. if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
  11420. return this.simplifiedGeometryCache[key];
  11421. } else {
  11422. var simplifiedGeometry =
  11423. this.getSimplifiedGeometryInternal(squaredTolerance);
  11424. var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
  11425. if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
  11426. this.simplifiedGeometryCache[key] = simplifiedGeometry;
  11427. return simplifiedGeometry;
  11428. } else {
  11429. // Simplification did not actually remove any coordinates. We now know
  11430. // that any calls to getSimplifiedGeometry with a squaredTolerance less
  11431. // than or equal to the current squaredTolerance will also not have any
  11432. // effect. This allows us to short circuit simplification (saving CPU
  11433. // cycles) and prevents the cache of simplified geometries from filling
  11434. // up with useless identical copies of this geometry (saving memory).
  11435. this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
  11436. return this;
  11437. }
  11438. }
  11439. };
  11440. /**
  11441. * @param {number} squaredTolerance Squared tolerance.
  11442. * @return {ol.geom.SimpleGeometry} Simplified geometry.
  11443. * @protected
  11444. */
  11445. ol.geom.SimpleGeometry.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
  11446. return this;
  11447. };
  11448. /**
  11449. * @return {number} Stride.
  11450. */
  11451. ol.geom.SimpleGeometry.prototype.getStride = function() {
  11452. return this.stride;
  11453. };
  11454. /**
  11455. * @param {ol.geom.GeometryLayout} layout Layout.
  11456. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11457. * @protected
  11458. */
  11459. ol.geom.SimpleGeometry.prototype.setFlatCoordinatesInternal = function(layout, flatCoordinates) {
  11460. this.stride = ol.geom.SimpleGeometry.getStrideForLayout(layout);
  11461. this.layout = layout;
  11462. this.flatCoordinates = flatCoordinates;
  11463. };
  11464. /**
  11465. * @abstract
  11466. * @param {Array} coordinates Coordinates.
  11467. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  11468. */
  11469. ol.geom.SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {};
  11470. /**
  11471. * @param {ol.geom.GeometryLayout|undefined} layout Layout.
  11472. * @param {Array} coordinates Coordinates.
  11473. * @param {number} nesting Nesting.
  11474. * @protected
  11475. */
  11476. ol.geom.SimpleGeometry.prototype.setLayout = function(layout, coordinates, nesting) {
  11477. /** @type {number} */
  11478. var stride;
  11479. if (layout) {
  11480. stride = ol.geom.SimpleGeometry.getStrideForLayout(layout);
  11481. } else {
  11482. var i;
  11483. for (i = 0; i < nesting; ++i) {
  11484. if (coordinates.length === 0) {
  11485. this.layout = ol.geom.GeometryLayout.XY;
  11486. this.stride = 2;
  11487. return;
  11488. } else {
  11489. coordinates = /** @type {Array} */ (coordinates[0]);
  11490. }
  11491. }
  11492. stride = coordinates.length;
  11493. layout = ol.geom.SimpleGeometry.getLayoutForStride_(stride);
  11494. }
  11495. this.layout = layout;
  11496. this.stride = stride;
  11497. };
  11498. /**
  11499. * @inheritDoc
  11500. * @api
  11501. */
  11502. ol.geom.SimpleGeometry.prototype.applyTransform = function(transformFn) {
  11503. if (this.flatCoordinates) {
  11504. transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
  11505. this.changed();
  11506. }
  11507. };
  11508. /**
  11509. * @inheritDoc
  11510. * @api
  11511. */
  11512. ol.geom.SimpleGeometry.prototype.rotate = function(angle, anchor) {
  11513. var flatCoordinates = this.getFlatCoordinates();
  11514. if (flatCoordinates) {
  11515. var stride = this.getStride();
  11516. ol.geom.flat.transform.rotate(
  11517. flatCoordinates, 0, flatCoordinates.length,
  11518. stride, angle, anchor, flatCoordinates);
  11519. this.changed();
  11520. }
  11521. };
  11522. /**
  11523. * @inheritDoc
  11524. * @api
  11525. */
  11526. ol.geom.SimpleGeometry.prototype.scale = function(sx, opt_sy, opt_anchor) {
  11527. var sy = opt_sy;
  11528. if (sy === undefined) {
  11529. sy = sx;
  11530. }
  11531. var anchor = opt_anchor;
  11532. if (!anchor) {
  11533. anchor = ol.extent.getCenter(this.getExtent());
  11534. }
  11535. var flatCoordinates = this.getFlatCoordinates();
  11536. if (flatCoordinates) {
  11537. var stride = this.getStride();
  11538. ol.geom.flat.transform.scale(
  11539. flatCoordinates, 0, flatCoordinates.length,
  11540. stride, sx, sy, anchor, flatCoordinates);
  11541. this.changed();
  11542. }
  11543. };
  11544. /**
  11545. * @inheritDoc
  11546. * @api
  11547. */
  11548. ol.geom.SimpleGeometry.prototype.translate = function(deltaX, deltaY) {
  11549. var flatCoordinates = this.getFlatCoordinates();
  11550. if (flatCoordinates) {
  11551. var stride = this.getStride();
  11552. ol.geom.flat.transform.translate(
  11553. flatCoordinates, 0, flatCoordinates.length, stride,
  11554. deltaX, deltaY, flatCoordinates);
  11555. this.changed();
  11556. }
  11557. };
  11558. /**
  11559. * @param {ol.geom.SimpleGeometry} simpleGeometry Simple geometry.
  11560. * @param {ol.Transform} transform Transform.
  11561. * @param {Array.<number>=} opt_dest Destination.
  11562. * @return {Array.<number>} Transformed flat coordinates.
  11563. */
  11564. ol.geom.SimpleGeometry.transform2D = function(simpleGeometry, transform, opt_dest) {
  11565. var flatCoordinates = simpleGeometry.getFlatCoordinates();
  11566. if (!flatCoordinates) {
  11567. return null;
  11568. } else {
  11569. var stride = simpleGeometry.getStride();
  11570. return ol.geom.flat.transform.transform2D(
  11571. flatCoordinates, 0, flatCoordinates.length, stride,
  11572. transform, opt_dest);
  11573. }
  11574. };
  11575. goog.provide('ol.geom.flat.area');
  11576. /**
  11577. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11578. * @param {number} offset Offset.
  11579. * @param {number} end End.
  11580. * @param {number} stride Stride.
  11581. * @return {number} Area.
  11582. */
  11583. ol.geom.flat.area.linearRing = function(flatCoordinates, offset, end, stride) {
  11584. var twiceArea = 0;
  11585. var x1 = flatCoordinates[end - stride];
  11586. var y1 = flatCoordinates[end - stride + 1];
  11587. for (; offset < end; offset += stride) {
  11588. var x2 = flatCoordinates[offset];
  11589. var y2 = flatCoordinates[offset + 1];
  11590. twiceArea += y1 * x2 - x1 * y2;
  11591. x1 = x2;
  11592. y1 = y2;
  11593. }
  11594. return twiceArea / 2;
  11595. };
  11596. /**
  11597. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11598. * @param {number} offset Offset.
  11599. * @param {Array.<number>} ends Ends.
  11600. * @param {number} stride Stride.
  11601. * @return {number} Area.
  11602. */
  11603. ol.geom.flat.area.linearRings = function(flatCoordinates, offset, ends, stride) {
  11604. var area = 0;
  11605. var i, ii;
  11606. for (i = 0, ii = ends.length; i < ii; ++i) {
  11607. var end = ends[i];
  11608. area += ol.geom.flat.area.linearRing(flatCoordinates, offset, end, stride);
  11609. offset = end;
  11610. }
  11611. return area;
  11612. };
  11613. /**
  11614. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11615. * @param {number} offset Offset.
  11616. * @param {Array.<Array.<number>>} endss Endss.
  11617. * @param {number} stride Stride.
  11618. * @return {number} Area.
  11619. */
  11620. ol.geom.flat.area.linearRingss = function(flatCoordinates, offset, endss, stride) {
  11621. var area = 0;
  11622. var i, ii;
  11623. for (i = 0, ii = endss.length; i < ii; ++i) {
  11624. var ends = endss[i];
  11625. area +=
  11626. ol.geom.flat.area.linearRings(flatCoordinates, offset, ends, stride);
  11627. offset = ends[ends.length - 1];
  11628. }
  11629. return area;
  11630. };
  11631. goog.provide('ol.geom.flat.closest');
  11632. goog.require('ol.math');
  11633. /**
  11634. * Returns the point on the 2D line segment flatCoordinates[offset1] to
  11635. * flatCoordinates[offset2] that is closest to the point (x, y). Extra
  11636. * dimensions are linearly interpolated.
  11637. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11638. * @param {number} offset1 Offset 1.
  11639. * @param {number} offset2 Offset 2.
  11640. * @param {number} stride Stride.
  11641. * @param {number} x X.
  11642. * @param {number} y Y.
  11643. * @param {Array.<number>} closestPoint Closest point.
  11644. */
  11645. ol.geom.flat.closest.point = function(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) {
  11646. var x1 = flatCoordinates[offset1];
  11647. var y1 = flatCoordinates[offset1 + 1];
  11648. var dx = flatCoordinates[offset2] - x1;
  11649. var dy = flatCoordinates[offset2 + 1] - y1;
  11650. var i, offset;
  11651. if (dx === 0 && dy === 0) {
  11652. offset = offset1;
  11653. } else {
  11654. var t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
  11655. if (t > 1) {
  11656. offset = offset2;
  11657. } else if (t > 0) {
  11658. for (i = 0; i < stride; ++i) {
  11659. closestPoint[i] = ol.math.lerp(flatCoordinates[offset1 + i],
  11660. flatCoordinates[offset2 + i], t);
  11661. }
  11662. closestPoint.length = stride;
  11663. return;
  11664. } else {
  11665. offset = offset1;
  11666. }
  11667. }
  11668. for (i = 0; i < stride; ++i) {
  11669. closestPoint[i] = flatCoordinates[offset + i];
  11670. }
  11671. closestPoint.length = stride;
  11672. };
  11673. /**
  11674. * Return the squared of the largest distance between any pair of consecutive
  11675. * coordinates.
  11676. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11677. * @param {number} offset Offset.
  11678. * @param {number} end End.
  11679. * @param {number} stride Stride.
  11680. * @param {number} maxSquaredDelta Max squared delta.
  11681. * @return {number} Max squared delta.
  11682. */
  11683. ol.geom.flat.closest.getMaxSquaredDelta = function(flatCoordinates, offset, end, stride, maxSquaredDelta) {
  11684. var x1 = flatCoordinates[offset];
  11685. var y1 = flatCoordinates[offset + 1];
  11686. for (offset += stride; offset < end; offset += stride) {
  11687. var x2 = flatCoordinates[offset];
  11688. var y2 = flatCoordinates[offset + 1];
  11689. var squaredDelta = ol.math.squaredDistance(x1, y1, x2, y2);
  11690. if (squaredDelta > maxSquaredDelta) {
  11691. maxSquaredDelta = squaredDelta;
  11692. }
  11693. x1 = x2;
  11694. y1 = y2;
  11695. }
  11696. return maxSquaredDelta;
  11697. };
  11698. /**
  11699. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11700. * @param {number} offset Offset.
  11701. * @param {Array.<number>} ends Ends.
  11702. * @param {number} stride Stride.
  11703. * @param {number} maxSquaredDelta Max squared delta.
  11704. * @return {number} Max squared delta.
  11705. */
  11706. ol.geom.flat.closest.getsMaxSquaredDelta = function(flatCoordinates, offset, ends, stride, maxSquaredDelta) {
  11707. var i, ii;
  11708. for (i = 0, ii = ends.length; i < ii; ++i) {
  11709. var end = ends[i];
  11710. maxSquaredDelta = ol.geom.flat.closest.getMaxSquaredDelta(
  11711. flatCoordinates, offset, end, stride, maxSquaredDelta);
  11712. offset = end;
  11713. }
  11714. return maxSquaredDelta;
  11715. };
  11716. /**
  11717. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11718. * @param {number} offset Offset.
  11719. * @param {Array.<Array.<number>>} endss Endss.
  11720. * @param {number} stride Stride.
  11721. * @param {number} maxSquaredDelta Max squared delta.
  11722. * @return {number} Max squared delta.
  11723. */
  11724. ol.geom.flat.closest.getssMaxSquaredDelta = function(flatCoordinates, offset, endss, stride, maxSquaredDelta) {
  11725. var i, ii;
  11726. for (i = 0, ii = endss.length; i < ii; ++i) {
  11727. var ends = endss[i];
  11728. maxSquaredDelta = ol.geom.flat.closest.getsMaxSquaredDelta(
  11729. flatCoordinates, offset, ends, stride, maxSquaredDelta);
  11730. offset = ends[ends.length - 1];
  11731. }
  11732. return maxSquaredDelta;
  11733. };
  11734. /**
  11735. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11736. * @param {number} offset Offset.
  11737. * @param {number} end End.
  11738. * @param {number} stride Stride.
  11739. * @param {number} maxDelta Max delta.
  11740. * @param {boolean} isRing Is ring.
  11741. * @param {number} x X.
  11742. * @param {number} y Y.
  11743. * @param {Array.<number>} closestPoint Closest point.
  11744. * @param {number} minSquaredDistance Minimum squared distance.
  11745. * @param {Array.<number>=} opt_tmpPoint Temporary point object.
  11746. * @return {number} Minimum squared distance.
  11747. */
  11748. ol.geom.flat.closest.getClosestPoint = function(flatCoordinates, offset, end,
  11749. stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
  11750. opt_tmpPoint) {
  11751. if (offset == end) {
  11752. return minSquaredDistance;
  11753. }
  11754. var i, squaredDistance;
  11755. if (maxDelta === 0) {
  11756. // All points are identical, so just test the first point.
  11757. squaredDistance = ol.math.squaredDistance(
  11758. x, y, flatCoordinates[offset], flatCoordinates[offset + 1]);
  11759. if (squaredDistance < minSquaredDistance) {
  11760. for (i = 0; i < stride; ++i) {
  11761. closestPoint[i] = flatCoordinates[offset + i];
  11762. }
  11763. closestPoint.length = stride;
  11764. return squaredDistance;
  11765. } else {
  11766. return minSquaredDistance;
  11767. }
  11768. }
  11769. var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
  11770. var index = offset + stride;
  11771. while (index < end) {
  11772. ol.geom.flat.closest.point(
  11773. flatCoordinates, index - stride, index, stride, x, y, tmpPoint);
  11774. squaredDistance = ol.math.squaredDistance(x, y, tmpPoint[0], tmpPoint[1]);
  11775. if (squaredDistance < minSquaredDistance) {
  11776. minSquaredDistance = squaredDistance;
  11777. for (i = 0; i < stride; ++i) {
  11778. closestPoint[i] = tmpPoint[i];
  11779. }
  11780. closestPoint.length = stride;
  11781. index += stride;
  11782. } else {
  11783. // Skip ahead multiple points, because we know that all the skipped
  11784. // points cannot be any closer than the closest point we have found so
  11785. // far. We know this because we know how close the current point is, how
  11786. // close the closest point we have found so far is, and the maximum
  11787. // distance between consecutive points. For example, if we're currently
  11788. // at distance 10, the best we've found so far is 3, and that the maximum
  11789. // distance between consecutive points is 2, then we'll need to skip at
  11790. // least (10 - 3) / 2 == 3 (rounded down) points to have any chance of
  11791. // finding a closer point. We use Math.max(..., 1) to ensure that we
  11792. // always advance at least one point, to avoid an infinite loop.
  11793. index += stride * Math.max(
  11794. ((Math.sqrt(squaredDistance) -
  11795. Math.sqrt(minSquaredDistance)) / maxDelta) | 0, 1);
  11796. }
  11797. }
  11798. if (isRing) {
  11799. // Check the closing segment.
  11800. ol.geom.flat.closest.point(
  11801. flatCoordinates, end - stride, offset, stride, x, y, tmpPoint);
  11802. squaredDistance = ol.math.squaredDistance(x, y, tmpPoint[0], tmpPoint[1]);
  11803. if (squaredDistance < minSquaredDistance) {
  11804. minSquaredDistance = squaredDistance;
  11805. for (i = 0; i < stride; ++i) {
  11806. closestPoint[i] = tmpPoint[i];
  11807. }
  11808. closestPoint.length = stride;
  11809. }
  11810. }
  11811. return minSquaredDistance;
  11812. };
  11813. /**
  11814. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11815. * @param {number} offset Offset.
  11816. * @param {Array.<number>} ends Ends.
  11817. * @param {number} stride Stride.
  11818. * @param {number} maxDelta Max delta.
  11819. * @param {boolean} isRing Is ring.
  11820. * @param {number} x X.
  11821. * @param {number} y Y.
  11822. * @param {Array.<number>} closestPoint Closest point.
  11823. * @param {number} minSquaredDistance Minimum squared distance.
  11824. * @param {Array.<number>=} opt_tmpPoint Temporary point object.
  11825. * @return {number} Minimum squared distance.
  11826. */
  11827. ol.geom.flat.closest.getsClosestPoint = function(flatCoordinates, offset, ends,
  11828. stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
  11829. opt_tmpPoint) {
  11830. var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
  11831. var i, ii;
  11832. for (i = 0, ii = ends.length; i < ii; ++i) {
  11833. var end = ends[i];
  11834. minSquaredDistance = ol.geom.flat.closest.getClosestPoint(
  11835. flatCoordinates, offset, end, stride,
  11836. maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
  11837. offset = end;
  11838. }
  11839. return minSquaredDistance;
  11840. };
  11841. /**
  11842. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11843. * @param {number} offset Offset.
  11844. * @param {Array.<Array.<number>>} endss Endss.
  11845. * @param {number} stride Stride.
  11846. * @param {number} maxDelta Max delta.
  11847. * @param {boolean} isRing Is ring.
  11848. * @param {number} x X.
  11849. * @param {number} y Y.
  11850. * @param {Array.<number>} closestPoint Closest point.
  11851. * @param {number} minSquaredDistance Minimum squared distance.
  11852. * @param {Array.<number>=} opt_tmpPoint Temporary point object.
  11853. * @return {number} Minimum squared distance.
  11854. */
  11855. ol.geom.flat.closest.getssClosestPoint = function(flatCoordinates, offset,
  11856. endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
  11857. opt_tmpPoint) {
  11858. var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
  11859. var i, ii;
  11860. for (i = 0, ii = endss.length; i < ii; ++i) {
  11861. var ends = endss[i];
  11862. minSquaredDistance = ol.geom.flat.closest.getsClosestPoint(
  11863. flatCoordinates, offset, ends, stride,
  11864. maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
  11865. offset = ends[ends.length - 1];
  11866. }
  11867. return minSquaredDistance;
  11868. };
  11869. goog.provide('ol.geom.flat.deflate');
  11870. /**
  11871. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11872. * @param {number} offset Offset.
  11873. * @param {ol.Coordinate} coordinate Coordinate.
  11874. * @param {number} stride Stride.
  11875. * @return {number} offset Offset.
  11876. */
  11877. ol.geom.flat.deflate.coordinate = function(flatCoordinates, offset, coordinate, stride) {
  11878. var i, ii;
  11879. for (i = 0, ii = coordinate.length; i < ii; ++i) {
  11880. flatCoordinates[offset++] = coordinate[i];
  11881. }
  11882. return offset;
  11883. };
  11884. /**
  11885. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11886. * @param {number} offset Offset.
  11887. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  11888. * @param {number} stride Stride.
  11889. * @return {number} offset Offset.
  11890. */
  11891. ol.geom.flat.deflate.coordinates = function(flatCoordinates, offset, coordinates, stride) {
  11892. var i, ii;
  11893. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  11894. var coordinate = coordinates[i];
  11895. var j;
  11896. for (j = 0; j < stride; ++j) {
  11897. flatCoordinates[offset++] = coordinate[j];
  11898. }
  11899. }
  11900. return offset;
  11901. };
  11902. /**
  11903. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11904. * @param {number} offset Offset.
  11905. * @param {Array.<Array.<ol.Coordinate>>} coordinatess Coordinatess.
  11906. * @param {number} stride Stride.
  11907. * @param {Array.<number>=} opt_ends Ends.
  11908. * @return {Array.<number>} Ends.
  11909. */
  11910. ol.geom.flat.deflate.coordinatess = function(flatCoordinates, offset, coordinatess, stride, opt_ends) {
  11911. var ends = opt_ends ? opt_ends : [];
  11912. var i = 0;
  11913. var j, jj;
  11914. for (j = 0, jj = coordinatess.length; j < jj; ++j) {
  11915. var end = ol.geom.flat.deflate.coordinates(
  11916. flatCoordinates, offset, coordinatess[j], stride);
  11917. ends[i++] = end;
  11918. offset = end;
  11919. }
  11920. ends.length = i;
  11921. return ends;
  11922. };
  11923. /**
  11924. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11925. * @param {number} offset Offset.
  11926. * @param {Array.<Array.<Array.<ol.Coordinate>>>} coordinatesss Coordinatesss.
  11927. * @param {number} stride Stride.
  11928. * @param {Array.<Array.<number>>=} opt_endss Endss.
  11929. * @return {Array.<Array.<number>>} Endss.
  11930. */
  11931. ol.geom.flat.deflate.coordinatesss = function(flatCoordinates, offset, coordinatesss, stride, opt_endss) {
  11932. var endss = opt_endss ? opt_endss : [];
  11933. var i = 0;
  11934. var j, jj;
  11935. for (j = 0, jj = coordinatesss.length; j < jj; ++j) {
  11936. var ends = ol.geom.flat.deflate.coordinatess(
  11937. flatCoordinates, offset, coordinatesss[j], stride, endss[i]);
  11938. endss[i++] = ends;
  11939. offset = ends[ends.length - 1];
  11940. }
  11941. endss.length = i;
  11942. return endss;
  11943. };
  11944. goog.provide('ol.geom.flat.inflate');
  11945. /**
  11946. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11947. * @param {number} offset Offset.
  11948. * @param {number} end End.
  11949. * @param {number} stride Stride.
  11950. * @param {Array.<ol.Coordinate>=} opt_coordinates Coordinates.
  11951. * @return {Array.<ol.Coordinate>} Coordinates.
  11952. */
  11953. ol.geom.flat.inflate.coordinates = function(flatCoordinates, offset, end, stride, opt_coordinates) {
  11954. var coordinates = opt_coordinates !== undefined ? opt_coordinates : [];
  11955. var i = 0;
  11956. var j;
  11957. for (j = offset; j < end; j += stride) {
  11958. coordinates[i++] = flatCoordinates.slice(j, j + stride);
  11959. }
  11960. coordinates.length = i;
  11961. return coordinates;
  11962. };
  11963. /**
  11964. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11965. * @param {number} offset Offset.
  11966. * @param {Array.<number>} ends Ends.
  11967. * @param {number} stride Stride.
  11968. * @param {Array.<Array.<ol.Coordinate>>=} opt_coordinatess Coordinatess.
  11969. * @return {Array.<Array.<ol.Coordinate>>} Coordinatess.
  11970. */
  11971. ol.geom.flat.inflate.coordinatess = function(flatCoordinates, offset, ends, stride, opt_coordinatess) {
  11972. var coordinatess = opt_coordinatess !== undefined ? opt_coordinatess : [];
  11973. var i = 0;
  11974. var j, jj;
  11975. for (j = 0, jj = ends.length; j < jj; ++j) {
  11976. var end = ends[j];
  11977. coordinatess[i++] = ol.geom.flat.inflate.coordinates(
  11978. flatCoordinates, offset, end, stride, coordinatess[i]);
  11979. offset = end;
  11980. }
  11981. coordinatess.length = i;
  11982. return coordinatess;
  11983. };
  11984. /**
  11985. * @param {Array.<number>} flatCoordinates Flat coordinates.
  11986. * @param {number} offset Offset.
  11987. * @param {Array.<Array.<number>>} endss Endss.
  11988. * @param {number} stride Stride.
  11989. * @param {Array.<Array.<Array.<ol.Coordinate>>>=} opt_coordinatesss
  11990. * Coordinatesss.
  11991. * @return {Array.<Array.<Array.<ol.Coordinate>>>} Coordinatesss.
  11992. */
  11993. ol.geom.flat.inflate.coordinatesss = function(flatCoordinates, offset, endss, stride, opt_coordinatesss) {
  11994. var coordinatesss = opt_coordinatesss !== undefined ? opt_coordinatesss : [];
  11995. var i = 0;
  11996. var j, jj;
  11997. for (j = 0, jj = endss.length; j < jj; ++j) {
  11998. var ends = endss[j];
  11999. coordinatesss[i++] = ol.geom.flat.inflate.coordinatess(
  12000. flatCoordinates, offset, ends, stride, coordinatesss[i]);
  12001. offset = ends[ends.length - 1];
  12002. }
  12003. coordinatesss.length = i;
  12004. return coordinatesss;
  12005. };
  12006. // Based on simplify-js https://github.com/mourner/simplify-js
  12007. // Copyright (c) 2012, Vladimir Agafonkin
  12008. // All rights reserved.
  12009. //
  12010. // Redistribution and use in source and binary forms, with or without
  12011. // modification, are permitted provided that the following conditions are met:
  12012. //
  12013. // 1. Redistributions of source code must retain the above copyright notice,
  12014. // this list of conditions and the following disclaimer.
  12015. //
  12016. // 2. Redistributions in binary form must reproduce the above copyright
  12017. // notice, this list of conditions and the following disclaimer in the
  12018. // documentation and/or other materials provided with the distribution.
  12019. //
  12020. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  12021. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  12022. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  12023. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  12024. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  12025. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  12026. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  12027. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  12028. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  12029. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  12030. // POSSIBILITY OF SUCH DAMAGE.
  12031. goog.provide('ol.geom.flat.simplify');
  12032. goog.require('ol.math');
  12033. /**
  12034. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12035. * @param {number} offset Offset.
  12036. * @param {number} end End.
  12037. * @param {number} stride Stride.
  12038. * @param {number} squaredTolerance Squared tolerance.
  12039. * @param {boolean} highQuality Highest quality.
  12040. * @param {Array.<number>=} opt_simplifiedFlatCoordinates Simplified flat
  12041. * coordinates.
  12042. * @return {Array.<number>} Simplified line string.
  12043. */
  12044. ol.geom.flat.simplify.lineString = function(flatCoordinates, offset, end,
  12045. stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
  12046. var simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
  12047. opt_simplifiedFlatCoordinates : [];
  12048. if (!highQuality) {
  12049. end = ol.geom.flat.simplify.radialDistance(flatCoordinates, offset, end,
  12050. stride, squaredTolerance,
  12051. simplifiedFlatCoordinates, 0);
  12052. flatCoordinates = simplifiedFlatCoordinates;
  12053. offset = 0;
  12054. stride = 2;
  12055. }
  12056. simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker(
  12057. flatCoordinates, offset, end, stride, squaredTolerance,
  12058. simplifiedFlatCoordinates, 0);
  12059. return simplifiedFlatCoordinates;
  12060. };
  12061. /**
  12062. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12063. * @param {number} offset Offset.
  12064. * @param {number} end End.
  12065. * @param {number} stride Stride.
  12066. * @param {number} squaredTolerance Squared tolerance.
  12067. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12068. * coordinates.
  12069. * @param {number} simplifiedOffset Simplified offset.
  12070. * @return {number} Simplified offset.
  12071. */
  12072. ol.geom.flat.simplify.douglasPeucker = function(flatCoordinates, offset, end,
  12073. stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
  12074. var n = (end - offset) / stride;
  12075. if (n < 3) {
  12076. for (; offset < end; offset += stride) {
  12077. simplifiedFlatCoordinates[simplifiedOffset++] =
  12078. flatCoordinates[offset];
  12079. simplifiedFlatCoordinates[simplifiedOffset++] =
  12080. flatCoordinates[offset + 1];
  12081. }
  12082. return simplifiedOffset;
  12083. }
  12084. /** @type {Array.<number>} */
  12085. var markers = new Array(n);
  12086. markers[0] = 1;
  12087. markers[n - 1] = 1;
  12088. /** @type {Array.<number>} */
  12089. var stack = [offset, end - stride];
  12090. var index = 0;
  12091. var i;
  12092. while (stack.length > 0) {
  12093. var last = stack.pop();
  12094. var first = stack.pop();
  12095. var maxSquaredDistance = 0;
  12096. var x1 = flatCoordinates[first];
  12097. var y1 = flatCoordinates[first + 1];
  12098. var x2 = flatCoordinates[last];
  12099. var y2 = flatCoordinates[last + 1];
  12100. for (i = first + stride; i < last; i += stride) {
  12101. var x = flatCoordinates[i];
  12102. var y = flatCoordinates[i + 1];
  12103. var squaredDistance = ol.math.squaredSegmentDistance(
  12104. x, y, x1, y1, x2, y2);
  12105. if (squaredDistance > maxSquaredDistance) {
  12106. index = i;
  12107. maxSquaredDistance = squaredDistance;
  12108. }
  12109. }
  12110. if (maxSquaredDistance > squaredTolerance) {
  12111. markers[(index - offset) / stride] = 1;
  12112. if (first + stride < index) {
  12113. stack.push(first, index);
  12114. }
  12115. if (index + stride < last) {
  12116. stack.push(index, last);
  12117. }
  12118. }
  12119. }
  12120. for (i = 0; i < n; ++i) {
  12121. if (markers[i]) {
  12122. simplifiedFlatCoordinates[simplifiedOffset++] =
  12123. flatCoordinates[offset + i * stride];
  12124. simplifiedFlatCoordinates[simplifiedOffset++] =
  12125. flatCoordinates[offset + i * stride + 1];
  12126. }
  12127. }
  12128. return simplifiedOffset;
  12129. };
  12130. /**
  12131. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12132. * @param {number} offset Offset.
  12133. * @param {Array.<number>} ends Ends.
  12134. * @param {number} stride Stride.
  12135. * @param {number} squaredTolerance Squared tolerance.
  12136. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12137. * coordinates.
  12138. * @param {number} simplifiedOffset Simplified offset.
  12139. * @param {Array.<number>} simplifiedEnds Simplified ends.
  12140. * @return {number} Simplified offset.
  12141. */
  12142. ol.geom.flat.simplify.douglasPeuckers = function(flatCoordinates, offset,
  12143. ends, stride, squaredTolerance, simplifiedFlatCoordinates,
  12144. simplifiedOffset, simplifiedEnds) {
  12145. var i, ii;
  12146. for (i = 0, ii = ends.length; i < ii; ++i) {
  12147. var end = ends[i];
  12148. simplifiedOffset = ol.geom.flat.simplify.douglasPeucker(
  12149. flatCoordinates, offset, end, stride, squaredTolerance,
  12150. simplifiedFlatCoordinates, simplifiedOffset);
  12151. simplifiedEnds.push(simplifiedOffset);
  12152. offset = end;
  12153. }
  12154. return simplifiedOffset;
  12155. };
  12156. /**
  12157. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12158. * @param {number} offset Offset.
  12159. * @param {Array.<Array.<number>>} endss Endss.
  12160. * @param {number} stride Stride.
  12161. * @param {number} squaredTolerance Squared tolerance.
  12162. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12163. * coordinates.
  12164. * @param {number} simplifiedOffset Simplified offset.
  12165. * @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
  12166. * @return {number} Simplified offset.
  12167. */
  12168. ol.geom.flat.simplify.douglasPeuckerss = function(
  12169. flatCoordinates, offset, endss, stride, squaredTolerance,
  12170. simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
  12171. var i, ii;
  12172. for (i = 0, ii = endss.length; i < ii; ++i) {
  12173. var ends = endss[i];
  12174. var simplifiedEnds = [];
  12175. simplifiedOffset = ol.geom.flat.simplify.douglasPeuckers(
  12176. flatCoordinates, offset, ends, stride, squaredTolerance,
  12177. simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
  12178. simplifiedEndss.push(simplifiedEnds);
  12179. offset = ends[ends.length - 1];
  12180. }
  12181. return simplifiedOffset;
  12182. };
  12183. /**
  12184. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12185. * @param {number} offset Offset.
  12186. * @param {number} end End.
  12187. * @param {number} stride Stride.
  12188. * @param {number} squaredTolerance Squared tolerance.
  12189. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12190. * coordinates.
  12191. * @param {number} simplifiedOffset Simplified offset.
  12192. * @return {number} Simplified offset.
  12193. */
  12194. ol.geom.flat.simplify.radialDistance = function(flatCoordinates, offset, end,
  12195. stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
  12196. if (end <= offset + stride) {
  12197. // zero or one point, no simplification possible, so copy and return
  12198. for (; offset < end; offset += stride) {
  12199. simplifiedFlatCoordinates[simplifiedOffset++] = flatCoordinates[offset];
  12200. simplifiedFlatCoordinates[simplifiedOffset++] =
  12201. flatCoordinates[offset + 1];
  12202. }
  12203. return simplifiedOffset;
  12204. }
  12205. var x1 = flatCoordinates[offset];
  12206. var y1 = flatCoordinates[offset + 1];
  12207. // copy first point
  12208. simplifiedFlatCoordinates[simplifiedOffset++] = x1;
  12209. simplifiedFlatCoordinates[simplifiedOffset++] = y1;
  12210. var x2 = x1;
  12211. var y2 = y1;
  12212. for (offset += stride; offset < end; offset += stride) {
  12213. x2 = flatCoordinates[offset];
  12214. y2 = flatCoordinates[offset + 1];
  12215. if (ol.math.squaredDistance(x1, y1, x2, y2) > squaredTolerance) {
  12216. // copy point at offset
  12217. simplifiedFlatCoordinates[simplifiedOffset++] = x2;
  12218. simplifiedFlatCoordinates[simplifiedOffset++] = y2;
  12219. x1 = x2;
  12220. y1 = y2;
  12221. }
  12222. }
  12223. if (x2 != x1 || y2 != y1) {
  12224. // copy last point
  12225. simplifiedFlatCoordinates[simplifiedOffset++] = x2;
  12226. simplifiedFlatCoordinates[simplifiedOffset++] = y2;
  12227. }
  12228. return simplifiedOffset;
  12229. };
  12230. /**
  12231. * @param {number} value Value.
  12232. * @param {number} tolerance Tolerance.
  12233. * @return {number} Rounded value.
  12234. */
  12235. ol.geom.flat.simplify.snap = function(value, tolerance) {
  12236. return tolerance * Math.round(value / tolerance);
  12237. };
  12238. /**
  12239. * Simplifies a line string using an algorithm designed by Tim Schaub.
  12240. * Coordinates are snapped to the nearest value in a virtual grid and
  12241. * consecutive duplicate coordinates are discarded. This effectively preserves
  12242. * topology as the simplification of any subsection of a line string is
  12243. * independent of the rest of the line string. This means that, for examples,
  12244. * the common edge between two polygons will be simplified to the same line
  12245. * string independently in both polygons. This implementation uses a single
  12246. * pass over the coordinates and eliminates intermediate collinear points.
  12247. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12248. * @param {number} offset Offset.
  12249. * @param {number} end End.
  12250. * @param {number} stride Stride.
  12251. * @param {number} tolerance Tolerance.
  12252. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12253. * coordinates.
  12254. * @param {number} simplifiedOffset Simplified offset.
  12255. * @return {number} Simplified offset.
  12256. */
  12257. ol.geom.flat.simplify.quantize = function(flatCoordinates, offset, end, stride,
  12258. tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
  12259. // do nothing if the line is empty
  12260. if (offset == end) {
  12261. return simplifiedOffset;
  12262. }
  12263. // snap the first coordinate (P1)
  12264. var x1 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance);
  12265. var y1 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance);
  12266. offset += stride;
  12267. // add the first coordinate to the output
  12268. simplifiedFlatCoordinates[simplifiedOffset++] = x1;
  12269. simplifiedFlatCoordinates[simplifiedOffset++] = y1;
  12270. // find the next coordinate that does not snap to the same value as the first
  12271. // coordinate (P2)
  12272. var x2, y2;
  12273. do {
  12274. x2 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance);
  12275. y2 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance);
  12276. offset += stride;
  12277. if (offset == end) {
  12278. // all coordinates snap to the same value, the line collapses to a point
  12279. // push the last snapped value anyway to ensure that the output contains
  12280. // at least two points
  12281. // FIXME should we really return at least two points anyway?
  12282. simplifiedFlatCoordinates[simplifiedOffset++] = x2;
  12283. simplifiedFlatCoordinates[simplifiedOffset++] = y2;
  12284. return simplifiedOffset;
  12285. }
  12286. } while (x2 == x1 && y2 == y1);
  12287. while (offset < end) {
  12288. var x3, y3;
  12289. // snap the next coordinate (P3)
  12290. x3 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance);
  12291. y3 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance);
  12292. offset += stride;
  12293. // skip P3 if it is equal to P2
  12294. if (x3 == x2 && y3 == y2) {
  12295. continue;
  12296. }
  12297. // calculate the delta between P1 and P2
  12298. var dx1 = x2 - x1;
  12299. var dy1 = y2 - y1;
  12300. // calculate the delta between P3 and P1
  12301. var dx2 = x3 - x1;
  12302. var dy2 = y3 - y1;
  12303. // if P1, P2, and P3 are colinear and P3 is further from P1 than P2 is from
  12304. // P1 in the same direction then P2 is on the straight line between P1 and
  12305. // P3
  12306. if ((dx1 * dy2 == dy1 * dx2) &&
  12307. ((dx1 < 0 && dx2 < dx1) || dx1 == dx2 || (dx1 > 0 && dx2 > dx1)) &&
  12308. ((dy1 < 0 && dy2 < dy1) || dy1 == dy2 || (dy1 > 0 && dy2 > dy1))) {
  12309. // discard P2 and set P2 = P3
  12310. x2 = x3;
  12311. y2 = y3;
  12312. continue;
  12313. }
  12314. // either P1, P2, and P3 are not colinear, or they are colinear but P3 is
  12315. // between P3 and P1 or on the opposite half of the line to P2. add P2,
  12316. // and continue with P1 = P2 and P2 = P3
  12317. simplifiedFlatCoordinates[simplifiedOffset++] = x2;
  12318. simplifiedFlatCoordinates[simplifiedOffset++] = y2;
  12319. x1 = x2;
  12320. y1 = y2;
  12321. x2 = x3;
  12322. y2 = y3;
  12323. }
  12324. // add the last point (P2)
  12325. simplifiedFlatCoordinates[simplifiedOffset++] = x2;
  12326. simplifiedFlatCoordinates[simplifiedOffset++] = y2;
  12327. return simplifiedOffset;
  12328. };
  12329. /**
  12330. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12331. * @param {number} offset Offset.
  12332. * @param {Array.<number>} ends Ends.
  12333. * @param {number} stride Stride.
  12334. * @param {number} tolerance Tolerance.
  12335. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12336. * coordinates.
  12337. * @param {number} simplifiedOffset Simplified offset.
  12338. * @param {Array.<number>} simplifiedEnds Simplified ends.
  12339. * @return {number} Simplified offset.
  12340. */
  12341. ol.geom.flat.simplify.quantizes = function(
  12342. flatCoordinates, offset, ends, stride,
  12343. tolerance,
  12344. simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
  12345. var i, ii;
  12346. for (i = 0, ii = ends.length; i < ii; ++i) {
  12347. var end = ends[i];
  12348. simplifiedOffset = ol.geom.flat.simplify.quantize(
  12349. flatCoordinates, offset, end, stride,
  12350. tolerance,
  12351. simplifiedFlatCoordinates, simplifiedOffset);
  12352. simplifiedEnds.push(simplifiedOffset);
  12353. offset = end;
  12354. }
  12355. return simplifiedOffset;
  12356. };
  12357. /**
  12358. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12359. * @param {number} offset Offset.
  12360. * @param {Array.<Array.<number>>} endss Endss.
  12361. * @param {number} stride Stride.
  12362. * @param {number} tolerance Tolerance.
  12363. * @param {Array.<number>} simplifiedFlatCoordinates Simplified flat
  12364. * coordinates.
  12365. * @param {number} simplifiedOffset Simplified offset.
  12366. * @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
  12367. * @return {number} Simplified offset.
  12368. */
  12369. ol.geom.flat.simplify.quantizess = function(
  12370. flatCoordinates, offset, endss, stride,
  12371. tolerance,
  12372. simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
  12373. var i, ii;
  12374. for (i = 0, ii = endss.length; i < ii; ++i) {
  12375. var ends = endss[i];
  12376. var simplifiedEnds = [];
  12377. simplifiedOffset = ol.geom.flat.simplify.quantizes(
  12378. flatCoordinates, offset, ends, stride,
  12379. tolerance,
  12380. simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
  12381. simplifiedEndss.push(simplifiedEnds);
  12382. offset = ends[ends.length - 1];
  12383. }
  12384. return simplifiedOffset;
  12385. };
  12386. goog.provide('ol.geom.LinearRing');
  12387. goog.require('ol');
  12388. goog.require('ol.extent');
  12389. goog.require('ol.geom.GeometryLayout');
  12390. goog.require('ol.geom.GeometryType');
  12391. goog.require('ol.geom.SimpleGeometry');
  12392. goog.require('ol.geom.flat.area');
  12393. goog.require('ol.geom.flat.closest');
  12394. goog.require('ol.geom.flat.deflate');
  12395. goog.require('ol.geom.flat.inflate');
  12396. goog.require('ol.geom.flat.simplify');
  12397. /**
  12398. * @classdesc
  12399. * Linear ring geometry. Only used as part of polygon; cannot be rendered
  12400. * on its own.
  12401. *
  12402. * @constructor
  12403. * @extends {ol.geom.SimpleGeometry}
  12404. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  12405. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  12406. * @api
  12407. */
  12408. ol.geom.LinearRing = function(coordinates, opt_layout) {
  12409. ol.geom.SimpleGeometry.call(this);
  12410. /**
  12411. * @private
  12412. * @type {number}
  12413. */
  12414. this.maxDelta_ = -1;
  12415. /**
  12416. * @private
  12417. * @type {number}
  12418. */
  12419. this.maxDeltaRevision_ = -1;
  12420. this.setCoordinates(coordinates, opt_layout);
  12421. };
  12422. ol.inherits(ol.geom.LinearRing, ol.geom.SimpleGeometry);
  12423. /**
  12424. * Make a complete copy of the geometry.
  12425. * @return {!ol.geom.LinearRing} Clone.
  12426. * @override
  12427. * @api
  12428. */
  12429. ol.geom.LinearRing.prototype.clone = function() {
  12430. var linearRing = new ol.geom.LinearRing(null);
  12431. linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
  12432. return linearRing;
  12433. };
  12434. /**
  12435. * @inheritDoc
  12436. */
  12437. ol.geom.LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  12438. if (minSquaredDistance <
  12439. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  12440. return minSquaredDistance;
  12441. }
  12442. if (this.maxDeltaRevision_ != this.getRevision()) {
  12443. this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getMaxSquaredDelta(
  12444. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
  12445. this.maxDeltaRevision_ = this.getRevision();
  12446. }
  12447. return ol.geom.flat.closest.getClosestPoint(
  12448. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  12449. this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
  12450. };
  12451. /**
  12452. * Return the area of the linear ring on projected plane.
  12453. * @return {number} Area (on projected plane).
  12454. * @api
  12455. */
  12456. ol.geom.LinearRing.prototype.getArea = function() {
  12457. return ol.geom.flat.area.linearRing(
  12458. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
  12459. };
  12460. /**
  12461. * Return the coordinates of the linear ring.
  12462. * @return {Array.<ol.Coordinate>} Coordinates.
  12463. * @override
  12464. * @api
  12465. */
  12466. ol.geom.LinearRing.prototype.getCoordinates = function() {
  12467. return ol.geom.flat.inflate.coordinates(
  12468. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
  12469. };
  12470. /**
  12471. * @inheritDoc
  12472. */
  12473. ol.geom.LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
  12474. var simplifiedFlatCoordinates = [];
  12475. simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker(
  12476. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  12477. squaredTolerance, simplifiedFlatCoordinates, 0);
  12478. var simplifiedLinearRing = new ol.geom.LinearRing(null);
  12479. simplifiedLinearRing.setFlatCoordinates(
  12480. ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates);
  12481. return simplifiedLinearRing;
  12482. };
  12483. /**
  12484. * @inheritDoc
  12485. * @api
  12486. */
  12487. ol.geom.LinearRing.prototype.getType = function() {
  12488. return ol.geom.GeometryType.LINEAR_RING;
  12489. };
  12490. /**
  12491. * @inheritDoc
  12492. */
  12493. ol.geom.LinearRing.prototype.intersectsExtent = function(extent) {};
  12494. /**
  12495. * Set the coordinates of the linear ring.
  12496. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  12497. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  12498. * @override
  12499. * @api
  12500. */
  12501. ol.geom.LinearRing.prototype.setCoordinates = function(coordinates, opt_layout) {
  12502. if (!coordinates) {
  12503. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null);
  12504. } else {
  12505. this.setLayout(opt_layout, coordinates, 1);
  12506. if (!this.flatCoordinates) {
  12507. this.flatCoordinates = [];
  12508. }
  12509. this.flatCoordinates.length = ol.geom.flat.deflate.coordinates(
  12510. this.flatCoordinates, 0, coordinates, this.stride);
  12511. this.changed();
  12512. }
  12513. };
  12514. /**
  12515. * @param {ol.geom.GeometryLayout} layout Layout.
  12516. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12517. */
  12518. ol.geom.LinearRing.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
  12519. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  12520. this.changed();
  12521. };
  12522. goog.provide('ol.geom.Point');
  12523. goog.require('ol');
  12524. goog.require('ol.extent');
  12525. goog.require('ol.geom.GeometryLayout');
  12526. goog.require('ol.geom.GeometryType');
  12527. goog.require('ol.geom.SimpleGeometry');
  12528. goog.require('ol.geom.flat.deflate');
  12529. goog.require('ol.math');
  12530. /**
  12531. * @classdesc
  12532. * Point geometry.
  12533. *
  12534. * @constructor
  12535. * @extends {ol.geom.SimpleGeometry}
  12536. * @param {ol.Coordinate} coordinates Coordinates.
  12537. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  12538. * @api
  12539. */
  12540. ol.geom.Point = function(coordinates, opt_layout) {
  12541. ol.geom.SimpleGeometry.call(this);
  12542. this.setCoordinates(coordinates, opt_layout);
  12543. };
  12544. ol.inherits(ol.geom.Point, ol.geom.SimpleGeometry);
  12545. /**
  12546. * Make a complete copy of the geometry.
  12547. * @return {!ol.geom.Point} Clone.
  12548. * @override
  12549. * @api
  12550. */
  12551. ol.geom.Point.prototype.clone = function() {
  12552. var point = new ol.geom.Point(null);
  12553. point.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
  12554. return point;
  12555. };
  12556. /**
  12557. * @inheritDoc
  12558. */
  12559. ol.geom.Point.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  12560. var flatCoordinates = this.flatCoordinates;
  12561. var squaredDistance = ol.math.squaredDistance(
  12562. x, y, flatCoordinates[0], flatCoordinates[1]);
  12563. if (squaredDistance < minSquaredDistance) {
  12564. var stride = this.stride;
  12565. var i;
  12566. for (i = 0; i < stride; ++i) {
  12567. closestPoint[i] = flatCoordinates[i];
  12568. }
  12569. closestPoint.length = stride;
  12570. return squaredDistance;
  12571. } else {
  12572. return minSquaredDistance;
  12573. }
  12574. };
  12575. /**
  12576. * Return the coordinate of the point.
  12577. * @return {ol.Coordinate} Coordinates.
  12578. * @override
  12579. * @api
  12580. */
  12581. ol.geom.Point.prototype.getCoordinates = function() {
  12582. return !this.flatCoordinates ? [] : this.flatCoordinates.slice();
  12583. };
  12584. /**
  12585. * @inheritDoc
  12586. */
  12587. ol.geom.Point.prototype.computeExtent = function(extent) {
  12588. return ol.extent.createOrUpdateFromCoordinate(this.flatCoordinates, extent);
  12589. };
  12590. /**
  12591. * @inheritDoc
  12592. * @api
  12593. */
  12594. ol.geom.Point.prototype.getType = function() {
  12595. return ol.geom.GeometryType.POINT;
  12596. };
  12597. /**
  12598. * @inheritDoc
  12599. * @api
  12600. */
  12601. ol.geom.Point.prototype.intersectsExtent = function(extent) {
  12602. return ol.extent.containsXY(extent,
  12603. this.flatCoordinates[0], this.flatCoordinates[1]);
  12604. };
  12605. /**
  12606. * @inheritDoc
  12607. * @api
  12608. */
  12609. ol.geom.Point.prototype.setCoordinates = function(coordinates, opt_layout) {
  12610. if (!coordinates) {
  12611. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null);
  12612. } else {
  12613. this.setLayout(opt_layout, coordinates, 0);
  12614. if (!this.flatCoordinates) {
  12615. this.flatCoordinates = [];
  12616. }
  12617. this.flatCoordinates.length = ol.geom.flat.deflate.coordinate(
  12618. this.flatCoordinates, 0, coordinates, this.stride);
  12619. this.changed();
  12620. }
  12621. };
  12622. /**
  12623. * @param {ol.geom.GeometryLayout} layout Layout.
  12624. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12625. */
  12626. ol.geom.Point.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
  12627. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  12628. this.changed();
  12629. };
  12630. goog.provide('ol.geom.flat.contains');
  12631. goog.require('ol.extent');
  12632. /**
  12633. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12634. * @param {number} offset Offset.
  12635. * @param {number} end End.
  12636. * @param {number} stride Stride.
  12637. * @param {ol.Extent} extent Extent.
  12638. * @return {boolean} Contains extent.
  12639. */
  12640. ol.geom.flat.contains.linearRingContainsExtent = function(flatCoordinates, offset, end, stride, extent) {
  12641. var outside = ol.extent.forEachCorner(extent,
  12642. /**
  12643. * @param {ol.Coordinate} coordinate Coordinate.
  12644. * @return {boolean} Contains (x, y).
  12645. */
  12646. function(coordinate) {
  12647. return !ol.geom.flat.contains.linearRingContainsXY(flatCoordinates,
  12648. offset, end, stride, coordinate[0], coordinate[1]);
  12649. });
  12650. return !outside;
  12651. };
  12652. /**
  12653. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12654. * @param {number} offset Offset.
  12655. * @param {number} end End.
  12656. * @param {number} stride Stride.
  12657. * @param {number} x X.
  12658. * @param {number} y Y.
  12659. * @return {boolean} Contains (x, y).
  12660. */
  12661. ol.geom.flat.contains.linearRingContainsXY = function(flatCoordinates, offset, end, stride, x, y) {
  12662. // http://geomalgorithms.com/a03-_inclusion.html
  12663. // Copyright 2000 softSurfer, 2012 Dan Sunday
  12664. // This code may be freely used and modified for any purpose
  12665. // providing that this copyright notice is included with it.
  12666. // SoftSurfer makes no warranty for this code, and cannot be held
  12667. // liable for any real or imagined damage resulting from its use.
  12668. // Users of this code must verify correctness for their application.
  12669. var wn = 0;
  12670. var x1 = flatCoordinates[end - stride];
  12671. var y1 = flatCoordinates[end - stride + 1];
  12672. for (; offset < end; offset += stride) {
  12673. var x2 = flatCoordinates[offset];
  12674. var y2 = flatCoordinates[offset + 1];
  12675. if (y1 <= y) {
  12676. if (y2 > y && ((x2 - x1) * (y - y1)) - ((x - x1) * (y2 - y1)) > 0) {
  12677. wn++;
  12678. }
  12679. } else if (y2 <= y && ((x2 - x1) * (y - y1)) - ((x - x1) * (y2 - y1)) < 0) {
  12680. wn--;
  12681. }
  12682. x1 = x2;
  12683. y1 = y2;
  12684. }
  12685. return wn !== 0;
  12686. };
  12687. /**
  12688. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12689. * @param {number} offset Offset.
  12690. * @param {Array.<number>} ends Ends.
  12691. * @param {number} stride Stride.
  12692. * @param {number} x X.
  12693. * @param {number} y Y.
  12694. * @return {boolean} Contains (x, y).
  12695. */
  12696. ol.geom.flat.contains.linearRingsContainsXY = function(flatCoordinates, offset, ends, stride, x, y) {
  12697. if (ends.length === 0) {
  12698. return false;
  12699. }
  12700. if (!ol.geom.flat.contains.linearRingContainsXY(
  12701. flatCoordinates, offset, ends[0], stride, x, y)) {
  12702. return false;
  12703. }
  12704. var i, ii;
  12705. for (i = 1, ii = ends.length; i < ii; ++i) {
  12706. if (ol.geom.flat.contains.linearRingContainsXY(
  12707. flatCoordinates, ends[i - 1], ends[i], stride, x, y)) {
  12708. return false;
  12709. }
  12710. }
  12711. return true;
  12712. };
  12713. /**
  12714. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12715. * @param {number} offset Offset.
  12716. * @param {Array.<Array.<number>>} endss Endss.
  12717. * @param {number} stride Stride.
  12718. * @param {number} x X.
  12719. * @param {number} y Y.
  12720. * @return {boolean} Contains (x, y).
  12721. */
  12722. ol.geom.flat.contains.linearRingssContainsXY = function(flatCoordinates, offset, endss, stride, x, y) {
  12723. if (endss.length === 0) {
  12724. return false;
  12725. }
  12726. var i, ii;
  12727. for (i = 0, ii = endss.length; i < ii; ++i) {
  12728. var ends = endss[i];
  12729. if (ol.geom.flat.contains.linearRingsContainsXY(
  12730. flatCoordinates, offset, ends, stride, x, y)) {
  12731. return true;
  12732. }
  12733. offset = ends[ends.length - 1];
  12734. }
  12735. return false;
  12736. };
  12737. goog.provide('ol.geom.flat.interiorpoint');
  12738. goog.require('ol.array');
  12739. goog.require('ol.geom.flat.contains');
  12740. /**
  12741. * Calculates a point that is likely to lie in the interior of the linear rings.
  12742. * Inspired by JTS's com.vividsolutions.jts.geom.Geometry#getInteriorPoint.
  12743. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12744. * @param {number} offset Offset.
  12745. * @param {Array.<number>} ends Ends.
  12746. * @param {number} stride Stride.
  12747. * @param {Array.<number>} flatCenters Flat centers.
  12748. * @param {number} flatCentersOffset Flat center offset.
  12749. * @param {Array.<number>=} opt_dest Destination.
  12750. * @return {Array.<number>} Destination point as XYM coordinate, where M is the
  12751. * length of the horizontal intersection that the point belongs to.
  12752. */
  12753. ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset,
  12754. ends, stride, flatCenters, flatCentersOffset, opt_dest) {
  12755. var i, ii, x, x1, x2, y1, y2;
  12756. var y = flatCenters[flatCentersOffset + 1];
  12757. /** @type {Array.<number>} */
  12758. var intersections = [];
  12759. // Calculate intersections with the horizontal line
  12760. for (var r = 0, rr = ends.length; r < rr; ++r) {
  12761. var end = ends[r];
  12762. x1 = flatCoordinates[end - stride];
  12763. y1 = flatCoordinates[end - stride + 1];
  12764. for (i = offset; i < end; i += stride) {
  12765. x2 = flatCoordinates[i];
  12766. y2 = flatCoordinates[i + 1];
  12767. if ((y <= y1 && y2 <= y) || (y1 <= y && y <= y2)) {
  12768. x = (y - y1) / (y2 - y1) * (x2 - x1) + x1;
  12769. intersections.push(x);
  12770. }
  12771. x1 = x2;
  12772. y1 = y2;
  12773. }
  12774. }
  12775. // Find the longest segment of the horizontal line that has its center point
  12776. // inside the linear ring.
  12777. var pointX = NaN;
  12778. var maxSegmentLength = -Infinity;
  12779. intersections.sort(ol.array.numberSafeCompareFunction);
  12780. x1 = intersections[0];
  12781. for (i = 1, ii = intersections.length; i < ii; ++i) {
  12782. x2 = intersections[i];
  12783. var segmentLength = Math.abs(x2 - x1);
  12784. if (segmentLength > maxSegmentLength) {
  12785. x = (x1 + x2) / 2;
  12786. if (ol.geom.flat.contains.linearRingsContainsXY(
  12787. flatCoordinates, offset, ends, stride, x, y)) {
  12788. pointX = x;
  12789. maxSegmentLength = segmentLength;
  12790. }
  12791. }
  12792. x1 = x2;
  12793. }
  12794. if (isNaN(pointX)) {
  12795. // There is no horizontal line that has its center point inside the linear
  12796. // ring. Use the center of the the linear ring's extent.
  12797. pointX = flatCenters[flatCentersOffset];
  12798. }
  12799. if (opt_dest) {
  12800. opt_dest.push(pointX, y, maxSegmentLength);
  12801. return opt_dest;
  12802. } else {
  12803. return [pointX, y, maxSegmentLength];
  12804. }
  12805. };
  12806. /**
  12807. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12808. * @param {number} offset Offset.
  12809. * @param {Array.<Array.<number>>} endss Endss.
  12810. * @param {number} stride Stride.
  12811. * @param {Array.<number>} flatCenters Flat centers.
  12812. * @return {Array.<number>} Interior points as XYM coordinates, where M is the
  12813. * length of the horizontal intersection that the point belongs to.
  12814. */
  12815. ol.geom.flat.interiorpoint.linearRingss = function(flatCoordinates, offset, endss, stride, flatCenters) {
  12816. var interiorPoints = [];
  12817. var i, ii;
  12818. for (i = 0, ii = endss.length; i < ii; ++i) {
  12819. var ends = endss[i];
  12820. interiorPoints = ol.geom.flat.interiorpoint.linearRings(flatCoordinates,
  12821. offset, ends, stride, flatCenters, 2 * i, interiorPoints);
  12822. offset = ends[ends.length - 1];
  12823. }
  12824. return interiorPoints;
  12825. };
  12826. goog.provide('ol.geom.flat.segments');
  12827. /**
  12828. * This function calls `callback` for each segment of the flat coordinates
  12829. * array. If the callback returns a truthy value the function returns that
  12830. * value immediately. Otherwise the function returns `false`.
  12831. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12832. * @param {number} offset Offset.
  12833. * @param {number} end End.
  12834. * @param {number} stride Stride.
  12835. * @param {function(this: S, ol.Coordinate, ol.Coordinate): T} callback Function
  12836. * called for each segment.
  12837. * @param {S=} opt_this The object to be used as the value of 'this'
  12838. * within callback.
  12839. * @return {T|boolean} Value.
  12840. * @template T,S
  12841. */
  12842. ol.geom.flat.segments.forEach = function(flatCoordinates, offset, end, stride, callback, opt_this) {
  12843. var point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]];
  12844. var point2 = [];
  12845. var ret;
  12846. for (; (offset + stride) < end; offset += stride) {
  12847. point2[0] = flatCoordinates[offset + stride];
  12848. point2[1] = flatCoordinates[offset + stride + 1];
  12849. ret = callback.call(opt_this, point1, point2);
  12850. if (ret) {
  12851. return ret;
  12852. }
  12853. point1[0] = point2[0];
  12854. point1[1] = point2[1];
  12855. }
  12856. return false;
  12857. };
  12858. goog.provide('ol.geom.flat.intersectsextent');
  12859. goog.require('ol.extent');
  12860. goog.require('ol.geom.flat.contains');
  12861. goog.require('ol.geom.flat.segments');
  12862. /**
  12863. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12864. * @param {number} offset Offset.
  12865. * @param {number} end End.
  12866. * @param {number} stride Stride.
  12867. * @param {ol.Extent} extent Extent.
  12868. * @return {boolean} True if the geometry and the extent intersect.
  12869. */
  12870. ol.geom.flat.intersectsextent.lineString = function(flatCoordinates, offset, end, stride, extent) {
  12871. var coordinatesExtent = ol.extent.extendFlatCoordinates(
  12872. ol.extent.createEmpty(), flatCoordinates, offset, end, stride);
  12873. if (!ol.extent.intersects(extent, coordinatesExtent)) {
  12874. return false;
  12875. }
  12876. if (ol.extent.containsExtent(extent, coordinatesExtent)) {
  12877. return true;
  12878. }
  12879. if (coordinatesExtent[0] >= extent[0] &&
  12880. coordinatesExtent[2] <= extent[2]) {
  12881. return true;
  12882. }
  12883. if (coordinatesExtent[1] >= extent[1] &&
  12884. coordinatesExtent[3] <= extent[3]) {
  12885. return true;
  12886. }
  12887. return ol.geom.flat.segments.forEach(flatCoordinates, offset, end, stride,
  12888. /**
  12889. * @param {ol.Coordinate} point1 Start point.
  12890. * @param {ol.Coordinate} point2 End point.
  12891. * @return {boolean} `true` if the segment and the extent intersect,
  12892. * `false` otherwise.
  12893. */
  12894. function(point1, point2) {
  12895. return ol.extent.intersectsSegment(extent, point1, point2);
  12896. });
  12897. };
  12898. /**
  12899. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12900. * @param {number} offset Offset.
  12901. * @param {Array.<number>} ends Ends.
  12902. * @param {number} stride Stride.
  12903. * @param {ol.Extent} extent Extent.
  12904. * @return {boolean} True if the geometry and the extent intersect.
  12905. */
  12906. ol.geom.flat.intersectsextent.lineStrings = function(flatCoordinates, offset, ends, stride, extent) {
  12907. var i, ii;
  12908. for (i = 0, ii = ends.length; i < ii; ++i) {
  12909. if (ol.geom.flat.intersectsextent.lineString(
  12910. flatCoordinates, offset, ends[i], stride, extent)) {
  12911. return true;
  12912. }
  12913. offset = ends[i];
  12914. }
  12915. return false;
  12916. };
  12917. /**
  12918. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12919. * @param {number} offset Offset.
  12920. * @param {number} end End.
  12921. * @param {number} stride Stride.
  12922. * @param {ol.Extent} extent Extent.
  12923. * @return {boolean} True if the geometry and the extent intersect.
  12924. */
  12925. ol.geom.flat.intersectsextent.linearRing = function(flatCoordinates, offset, end, stride, extent) {
  12926. if (ol.geom.flat.intersectsextent.lineString(
  12927. flatCoordinates, offset, end, stride, extent)) {
  12928. return true;
  12929. }
  12930. if (ol.geom.flat.contains.linearRingContainsXY(
  12931. flatCoordinates, offset, end, stride, extent[0], extent[1])) {
  12932. return true;
  12933. }
  12934. if (ol.geom.flat.contains.linearRingContainsXY(
  12935. flatCoordinates, offset, end, stride, extent[0], extent[3])) {
  12936. return true;
  12937. }
  12938. if (ol.geom.flat.contains.linearRingContainsXY(
  12939. flatCoordinates, offset, end, stride, extent[2], extent[1])) {
  12940. return true;
  12941. }
  12942. if (ol.geom.flat.contains.linearRingContainsXY(
  12943. flatCoordinates, offset, end, stride, extent[2], extent[3])) {
  12944. return true;
  12945. }
  12946. return false;
  12947. };
  12948. /**
  12949. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12950. * @param {number} offset Offset.
  12951. * @param {Array.<number>} ends Ends.
  12952. * @param {number} stride Stride.
  12953. * @param {ol.Extent} extent Extent.
  12954. * @return {boolean} True if the geometry and the extent intersect.
  12955. */
  12956. ol.geom.flat.intersectsextent.linearRings = function(flatCoordinates, offset, ends, stride, extent) {
  12957. if (!ol.geom.flat.intersectsextent.linearRing(
  12958. flatCoordinates, offset, ends[0], stride, extent)) {
  12959. return false;
  12960. }
  12961. if (ends.length === 1) {
  12962. return true;
  12963. }
  12964. var i, ii;
  12965. for (i = 1, ii = ends.length; i < ii; ++i) {
  12966. if (ol.geom.flat.contains.linearRingContainsExtent(
  12967. flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
  12968. return false;
  12969. }
  12970. }
  12971. return true;
  12972. };
  12973. /**
  12974. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12975. * @param {number} offset Offset.
  12976. * @param {Array.<Array.<number>>} endss Endss.
  12977. * @param {number} stride Stride.
  12978. * @param {ol.Extent} extent Extent.
  12979. * @return {boolean} True if the geometry and the extent intersect.
  12980. */
  12981. ol.geom.flat.intersectsextent.linearRingss = function(flatCoordinates, offset, endss, stride, extent) {
  12982. var i, ii;
  12983. for (i = 0, ii = endss.length; i < ii; ++i) {
  12984. var ends = endss[i];
  12985. if (ol.geom.flat.intersectsextent.linearRings(
  12986. flatCoordinates, offset, ends, stride, extent)) {
  12987. return true;
  12988. }
  12989. offset = ends[ends.length - 1];
  12990. }
  12991. return false;
  12992. };
  12993. goog.provide('ol.geom.flat.reverse');
  12994. /**
  12995. * @param {Array.<number>} flatCoordinates Flat coordinates.
  12996. * @param {number} offset Offset.
  12997. * @param {number} end End.
  12998. * @param {number} stride Stride.
  12999. */
  13000. ol.geom.flat.reverse.coordinates = function(flatCoordinates, offset, end, stride) {
  13001. while (offset < end - stride) {
  13002. var i;
  13003. for (i = 0; i < stride; ++i) {
  13004. var tmp = flatCoordinates[offset + i];
  13005. flatCoordinates[offset + i] = flatCoordinates[end - stride + i];
  13006. flatCoordinates[end - stride + i] = tmp;
  13007. }
  13008. offset += stride;
  13009. end -= stride;
  13010. }
  13011. };
  13012. goog.provide('ol.geom.flat.orient');
  13013. goog.require('ol.geom.flat.reverse');
  13014. /**
  13015. * @param {Array.<number>} flatCoordinates Flat coordinates.
  13016. * @param {number} offset Offset.
  13017. * @param {number} end End.
  13018. * @param {number} stride Stride.
  13019. * @return {boolean} Is clockwise.
  13020. */
  13021. ol.geom.flat.orient.linearRingIsClockwise = function(flatCoordinates, offset, end, stride) {
  13022. // http://tinyurl.com/clockwise-method
  13023. // https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrlinearring.cpp
  13024. var edge = 0;
  13025. var x1 = flatCoordinates[end - stride];
  13026. var y1 = flatCoordinates[end - stride + 1];
  13027. for (; offset < end; offset += stride) {
  13028. var x2 = flatCoordinates[offset];
  13029. var y2 = flatCoordinates[offset + 1];
  13030. edge += (x2 - x1) * (y2 + y1);
  13031. x1 = x2;
  13032. y1 = y2;
  13033. }
  13034. return edge > 0;
  13035. };
  13036. /**
  13037. * Determines if linear rings are oriented. By default, left-hand orientation
  13038. * is tested (first ring must be clockwise, remaining rings counter-clockwise).
  13039. * To test for right-hand orientation, use the `opt_right` argument.
  13040. *
  13041. * @param {Array.<number>} flatCoordinates Flat coordinates.
  13042. * @param {number} offset Offset.
  13043. * @param {Array.<number>} ends Array of end indexes.
  13044. * @param {number} stride Stride.
  13045. * @param {boolean=} opt_right Test for right-hand orientation
  13046. * (counter-clockwise exterior ring and clockwise interior rings).
  13047. * @return {boolean} Rings are correctly oriented.
  13048. */
  13049. ol.geom.flat.orient.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) {
  13050. var right = opt_right !== undefined ? opt_right : false;
  13051. var i, ii;
  13052. for (i = 0, ii = ends.length; i < ii; ++i) {
  13053. var end = ends[i];
  13054. var isClockwise = ol.geom.flat.orient.linearRingIsClockwise(
  13055. flatCoordinates, offset, end, stride);
  13056. if (i === 0) {
  13057. if ((right && isClockwise) || (!right && !isClockwise)) {
  13058. return false;
  13059. }
  13060. } else {
  13061. if ((right && !isClockwise) || (!right && isClockwise)) {
  13062. return false;
  13063. }
  13064. }
  13065. offset = end;
  13066. }
  13067. return true;
  13068. };
  13069. /**
  13070. * Determines if linear rings are oriented. By default, left-hand orientation
  13071. * is tested (first ring must be clockwise, remaining rings counter-clockwise).
  13072. * To test for right-hand orientation, use the `opt_right` argument.
  13073. *
  13074. * @param {Array.<number>} flatCoordinates Flat coordinates.
  13075. * @param {number} offset Offset.
  13076. * @param {Array.<Array.<number>>} endss Array of array of end indexes.
  13077. * @param {number} stride Stride.
  13078. * @param {boolean=} opt_right Test for right-hand orientation
  13079. * (counter-clockwise exterior ring and clockwise interior rings).
  13080. * @return {boolean} Rings are correctly oriented.
  13081. */
  13082. ol.geom.flat.orient.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) {
  13083. var i, ii;
  13084. for (i = 0, ii = endss.length; i < ii; ++i) {
  13085. if (!ol.geom.flat.orient.linearRingsAreOriented(
  13086. flatCoordinates, offset, endss[i], stride, opt_right)) {
  13087. return false;
  13088. }
  13089. }
  13090. return true;
  13091. };
  13092. /**
  13093. * Orient coordinates in a flat array of linear rings. By default, rings
  13094. * are oriented following the left-hand rule (clockwise for exterior and
  13095. * counter-clockwise for interior rings). To orient according to the
  13096. * right-hand rule, use the `opt_right` argument.
  13097. *
  13098. * @param {Array.<number>} flatCoordinates Flat coordinates.
  13099. * @param {number} offset Offset.
  13100. * @param {Array.<number>} ends Ends.
  13101. * @param {number} stride Stride.
  13102. * @param {boolean=} opt_right Follow the right-hand rule for orientation.
  13103. * @return {number} End.
  13104. */
  13105. ol.geom.flat.orient.orientLinearRings = function(flatCoordinates, offset, ends, stride, opt_right) {
  13106. var right = opt_right !== undefined ? opt_right : false;
  13107. var i, ii;
  13108. for (i = 0, ii = ends.length; i < ii; ++i) {
  13109. var end = ends[i];
  13110. var isClockwise = ol.geom.flat.orient.linearRingIsClockwise(
  13111. flatCoordinates, offset, end, stride);
  13112. var reverse = i === 0 ?
  13113. (right && isClockwise) || (!right && !isClockwise) :
  13114. (right && !isClockwise) || (!right && isClockwise);
  13115. if (reverse) {
  13116. ol.geom.flat.reverse.coordinates(flatCoordinates, offset, end, stride);
  13117. }
  13118. offset = end;
  13119. }
  13120. return offset;
  13121. };
  13122. /**
  13123. * Orient coordinates in a flat array of linear rings. By default, rings
  13124. * are oriented following the left-hand rule (clockwise for exterior and
  13125. * counter-clockwise for interior rings). To orient according to the
  13126. * right-hand rule, use the `opt_right` argument.
  13127. *
  13128. * @param {Array.<number>} flatCoordinates Flat coordinates.
  13129. * @param {number} offset Offset.
  13130. * @param {Array.<Array.<number>>} endss Array of array of end indexes.
  13131. * @param {number} stride Stride.
  13132. * @param {boolean=} opt_right Follow the right-hand rule for orientation.
  13133. * @return {number} End.
  13134. */
  13135. ol.geom.flat.orient.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) {
  13136. var i, ii;
  13137. for (i = 0, ii = endss.length; i < ii; ++i) {
  13138. offset = ol.geom.flat.orient.orientLinearRings(
  13139. flatCoordinates, offset, endss[i], stride, opt_right);
  13140. }
  13141. return offset;
  13142. };
  13143. goog.provide('ol.geom.Polygon');
  13144. goog.require('ol');
  13145. goog.require('ol.array');
  13146. goog.require('ol.extent');
  13147. goog.require('ol.geom.GeometryLayout');
  13148. goog.require('ol.geom.GeometryType');
  13149. goog.require('ol.geom.LinearRing');
  13150. goog.require('ol.geom.Point');
  13151. goog.require('ol.geom.SimpleGeometry');
  13152. goog.require('ol.geom.flat.area');
  13153. goog.require('ol.geom.flat.closest');
  13154. goog.require('ol.geom.flat.contains');
  13155. goog.require('ol.geom.flat.deflate');
  13156. goog.require('ol.geom.flat.inflate');
  13157. goog.require('ol.geom.flat.interiorpoint');
  13158. goog.require('ol.geom.flat.intersectsextent');
  13159. goog.require('ol.geom.flat.orient');
  13160. goog.require('ol.geom.flat.simplify');
  13161. goog.require('ol.math');
  13162. /**
  13163. * @classdesc
  13164. * Polygon geometry.
  13165. *
  13166. * @constructor
  13167. * @extends {ol.geom.SimpleGeometry}
  13168. * @param {Array.<Array.<ol.Coordinate>>} coordinates Array of linear
  13169. * rings that define the polygon. The first linear ring of the array
  13170. * defines the outer-boundary or surface of the polygon. Each subsequent
  13171. * linear ring defines a hole in the surface of the polygon. A linear ring
  13172. * is an array of vertices' coordinates where the first coordinate and the
  13173. * last are equivalent.
  13174. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  13175. * @api
  13176. */
  13177. ol.geom.Polygon = function(coordinates, opt_layout) {
  13178. ol.geom.SimpleGeometry.call(this);
  13179. /**
  13180. * @type {Array.<number>}
  13181. * @private
  13182. */
  13183. this.ends_ = [];
  13184. /**
  13185. * @private
  13186. * @type {number}
  13187. */
  13188. this.flatInteriorPointRevision_ = -1;
  13189. /**
  13190. * @private
  13191. * @type {ol.Coordinate}
  13192. */
  13193. this.flatInteriorPoint_ = null;
  13194. /**
  13195. * @private
  13196. * @type {number}
  13197. */
  13198. this.maxDelta_ = -1;
  13199. /**
  13200. * @private
  13201. * @type {number}
  13202. */
  13203. this.maxDeltaRevision_ = -1;
  13204. /**
  13205. * @private
  13206. * @type {number}
  13207. */
  13208. this.orientedRevision_ = -1;
  13209. /**
  13210. * @private
  13211. * @type {Array.<number>}
  13212. */
  13213. this.orientedFlatCoordinates_ = null;
  13214. this.setCoordinates(coordinates, opt_layout);
  13215. };
  13216. ol.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
  13217. /**
  13218. * Append the passed linear ring to this polygon.
  13219. * @param {ol.geom.LinearRing} linearRing Linear ring.
  13220. * @api
  13221. */
  13222. ol.geom.Polygon.prototype.appendLinearRing = function(linearRing) {
  13223. if (!this.flatCoordinates) {
  13224. this.flatCoordinates = linearRing.getFlatCoordinates().slice();
  13225. } else {
  13226. ol.array.extend(this.flatCoordinates, linearRing.getFlatCoordinates());
  13227. }
  13228. this.ends_.push(this.flatCoordinates.length);
  13229. this.changed();
  13230. };
  13231. /**
  13232. * Make a complete copy of the geometry.
  13233. * @return {!ol.geom.Polygon} Clone.
  13234. * @override
  13235. * @api
  13236. */
  13237. ol.geom.Polygon.prototype.clone = function() {
  13238. var polygon = new ol.geom.Polygon(null);
  13239. polygon.setFlatCoordinates(
  13240. this.layout, this.flatCoordinates.slice(), this.ends_.slice());
  13241. return polygon;
  13242. };
  13243. /**
  13244. * @inheritDoc
  13245. */
  13246. ol.geom.Polygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  13247. if (minSquaredDistance <
  13248. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  13249. return minSquaredDistance;
  13250. }
  13251. if (this.maxDeltaRevision_ != this.getRevision()) {
  13252. this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getsMaxSquaredDelta(
  13253. this.flatCoordinates, 0, this.ends_, this.stride, 0));
  13254. this.maxDeltaRevision_ = this.getRevision();
  13255. }
  13256. return ol.geom.flat.closest.getsClosestPoint(
  13257. this.flatCoordinates, 0, this.ends_, this.stride,
  13258. this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
  13259. };
  13260. /**
  13261. * @inheritDoc
  13262. */
  13263. ol.geom.Polygon.prototype.containsXY = function(x, y) {
  13264. return ol.geom.flat.contains.linearRingsContainsXY(
  13265. this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
  13266. };
  13267. /**
  13268. * Return the area of the polygon on projected plane.
  13269. * @return {number} Area (on projected plane).
  13270. * @api
  13271. */
  13272. ol.geom.Polygon.prototype.getArea = function() {
  13273. return ol.geom.flat.area.linearRings(
  13274. this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
  13275. };
  13276. /**
  13277. * Get the coordinate array for this geometry. This array has the structure
  13278. * of a GeoJSON coordinate array for polygons.
  13279. *
  13280. * @param {boolean=} opt_right Orient coordinates according to the right-hand
  13281. * rule (counter-clockwise for exterior and clockwise for interior rings).
  13282. * If `false`, coordinates will be oriented according to the left-hand rule
  13283. * (clockwise for exterior and counter-clockwise for interior rings).
  13284. * By default, coordinate orientation will depend on how the geometry was
  13285. * constructed.
  13286. * @return {Array.<Array.<ol.Coordinate>>} Coordinates.
  13287. * @override
  13288. * @api
  13289. */
  13290. ol.geom.Polygon.prototype.getCoordinates = function(opt_right) {
  13291. var flatCoordinates;
  13292. if (opt_right !== undefined) {
  13293. flatCoordinates = this.getOrientedFlatCoordinates().slice();
  13294. ol.geom.flat.orient.orientLinearRings(
  13295. flatCoordinates, 0, this.ends_, this.stride, opt_right);
  13296. } else {
  13297. flatCoordinates = this.flatCoordinates;
  13298. }
  13299. return ol.geom.flat.inflate.coordinatess(
  13300. flatCoordinates, 0, this.ends_, this.stride);
  13301. };
  13302. /**
  13303. * @return {Array.<number>} Ends.
  13304. */
  13305. ol.geom.Polygon.prototype.getEnds = function() {
  13306. return this.ends_;
  13307. };
  13308. /**
  13309. * @return {Array.<number>} Interior point.
  13310. */
  13311. ol.geom.Polygon.prototype.getFlatInteriorPoint = function() {
  13312. if (this.flatInteriorPointRevision_ != this.getRevision()) {
  13313. var flatCenter = ol.extent.getCenter(this.getExtent());
  13314. this.flatInteriorPoint_ = ol.geom.flat.interiorpoint.linearRings(
  13315. this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride,
  13316. flatCenter, 0);
  13317. this.flatInteriorPointRevision_ = this.getRevision();
  13318. }
  13319. return this.flatInteriorPoint_;
  13320. };
  13321. /**
  13322. * Return an interior point of the polygon.
  13323. * @return {ol.geom.Point} Interior point as XYM coordinate, where M is the
  13324. * length of the horizontal intersection that the point belongs to.
  13325. * @api
  13326. */
  13327. ol.geom.Polygon.prototype.getInteriorPoint = function() {
  13328. return new ol.geom.Point(this.getFlatInteriorPoint(), ol.geom.GeometryLayout.XYM);
  13329. };
  13330. /**
  13331. * Return the number of rings of the polygon, this includes the exterior
  13332. * ring and any interior rings.
  13333. *
  13334. * @return {number} Number of rings.
  13335. * @api
  13336. */
  13337. ol.geom.Polygon.prototype.getLinearRingCount = function() {
  13338. return this.ends_.length;
  13339. };
  13340. /**
  13341. * Return the Nth linear ring of the polygon geometry. Return `null` if the
  13342. * given index is out of range.
  13343. * The exterior linear ring is available at index `0` and the interior rings
  13344. * at index `1` and beyond.
  13345. *
  13346. * @param {number} index Index.
  13347. * @return {ol.geom.LinearRing} Linear ring.
  13348. * @api
  13349. */
  13350. ol.geom.Polygon.prototype.getLinearRing = function(index) {
  13351. if (index < 0 || this.ends_.length <= index) {
  13352. return null;
  13353. }
  13354. var linearRing = new ol.geom.LinearRing(null);
  13355. linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
  13356. index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
  13357. return linearRing;
  13358. };
  13359. /**
  13360. * Return the linear rings of the polygon.
  13361. * @return {Array.<ol.geom.LinearRing>} Linear rings.
  13362. * @api
  13363. */
  13364. ol.geom.Polygon.prototype.getLinearRings = function() {
  13365. var layout = this.layout;
  13366. var flatCoordinates = this.flatCoordinates;
  13367. var ends = this.ends_;
  13368. var linearRings = [];
  13369. var offset = 0;
  13370. var i, ii;
  13371. for (i = 0, ii = ends.length; i < ii; ++i) {
  13372. var end = ends[i];
  13373. var linearRing = new ol.geom.LinearRing(null);
  13374. linearRing.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
  13375. linearRings.push(linearRing);
  13376. offset = end;
  13377. }
  13378. return linearRings;
  13379. };
  13380. /**
  13381. * @return {Array.<number>} Oriented flat coordinates.
  13382. */
  13383. ol.geom.Polygon.prototype.getOrientedFlatCoordinates = function() {
  13384. if (this.orientedRevision_ != this.getRevision()) {
  13385. var flatCoordinates = this.flatCoordinates;
  13386. if (ol.geom.flat.orient.linearRingsAreOriented(
  13387. flatCoordinates, 0, this.ends_, this.stride)) {
  13388. this.orientedFlatCoordinates_ = flatCoordinates;
  13389. } else {
  13390. this.orientedFlatCoordinates_ = flatCoordinates.slice();
  13391. this.orientedFlatCoordinates_.length =
  13392. ol.geom.flat.orient.orientLinearRings(
  13393. this.orientedFlatCoordinates_, 0, this.ends_, this.stride);
  13394. }
  13395. this.orientedRevision_ = this.getRevision();
  13396. }
  13397. return this.orientedFlatCoordinates_;
  13398. };
  13399. /**
  13400. * @inheritDoc
  13401. */
  13402. ol.geom.Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
  13403. var simplifiedFlatCoordinates = [];
  13404. var simplifiedEnds = [];
  13405. simplifiedFlatCoordinates.length = ol.geom.flat.simplify.quantizes(
  13406. this.flatCoordinates, 0, this.ends_, this.stride,
  13407. Math.sqrt(squaredTolerance),
  13408. simplifiedFlatCoordinates, 0, simplifiedEnds);
  13409. var simplifiedPolygon = new ol.geom.Polygon(null);
  13410. simplifiedPolygon.setFlatCoordinates(
  13411. ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEnds);
  13412. return simplifiedPolygon;
  13413. };
  13414. /**
  13415. * @inheritDoc
  13416. * @api
  13417. */
  13418. ol.geom.Polygon.prototype.getType = function() {
  13419. return ol.geom.GeometryType.POLYGON;
  13420. };
  13421. /**
  13422. * @inheritDoc
  13423. * @api
  13424. */
  13425. ol.geom.Polygon.prototype.intersectsExtent = function(extent) {
  13426. return ol.geom.flat.intersectsextent.linearRings(
  13427. this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, extent);
  13428. };
  13429. /**
  13430. * Set the coordinates of the polygon.
  13431. * @param {Array.<Array.<ol.Coordinate>>} coordinates Coordinates.
  13432. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  13433. * @override
  13434. * @api
  13435. */
  13436. ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
  13437. if (!coordinates) {
  13438. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null, this.ends_);
  13439. } else {
  13440. this.setLayout(opt_layout, coordinates, 2);
  13441. if (!this.flatCoordinates) {
  13442. this.flatCoordinates = [];
  13443. }
  13444. var ends = ol.geom.flat.deflate.coordinatess(
  13445. this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
  13446. this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
  13447. this.changed();
  13448. }
  13449. };
  13450. /**
  13451. * @param {ol.geom.GeometryLayout} layout Layout.
  13452. * @param {Array.<number>} flatCoordinates Flat coordinates.
  13453. * @param {Array.<number>} ends Ends.
  13454. */
  13455. ol.geom.Polygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
  13456. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  13457. this.ends_ = ends;
  13458. this.changed();
  13459. };
  13460. /**
  13461. * Create an approximation of a circle on the surface of a sphere.
  13462. * @param {ol.Sphere} sphere The sphere.
  13463. * @param {ol.Coordinate} center Center (`[lon, lat]` in degrees).
  13464. * @param {number} radius The great-circle distance from the center to
  13465. * the polygon vertices.
  13466. * @param {number=} opt_n Optional number of vertices for the resulting
  13467. * polygon. Default is `32`.
  13468. * @return {ol.geom.Polygon} The "circular" polygon.
  13469. * @api
  13470. */
  13471. ol.geom.Polygon.circular = function(sphere, center, radius, opt_n) {
  13472. var n = opt_n ? opt_n : 32;
  13473. /** @type {Array.<number>} */
  13474. var flatCoordinates = [];
  13475. var i;
  13476. for (i = 0; i < n; ++i) {
  13477. ol.array.extend(
  13478. flatCoordinates, sphere.offset(center, radius, 2 * Math.PI * i / n));
  13479. }
  13480. flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
  13481. var polygon = new ol.geom.Polygon(null);
  13482. polygon.setFlatCoordinates(
  13483. ol.geom.GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
  13484. return polygon;
  13485. };
  13486. /**
  13487. * Create a polygon from an extent. The layout used is `XY`.
  13488. * @param {ol.Extent} extent The extent.
  13489. * @return {ol.geom.Polygon} The polygon.
  13490. * @api
  13491. */
  13492. ol.geom.Polygon.fromExtent = function(extent) {
  13493. var minX = extent[0];
  13494. var minY = extent[1];
  13495. var maxX = extent[2];
  13496. var maxY = extent[3];
  13497. var flatCoordinates =
  13498. [minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY];
  13499. var polygon = new ol.geom.Polygon(null);
  13500. polygon.setFlatCoordinates(
  13501. ol.geom.GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
  13502. return polygon;
  13503. };
  13504. /**
  13505. * Create a regular polygon from a circle.
  13506. * @param {ol.geom.Circle} circle Circle geometry.
  13507. * @param {number=} opt_sides Number of sides of the polygon. Default is 32.
  13508. * @param {number=} opt_angle Start angle for the first vertex of the polygon in
  13509. * radians. Default is 0.
  13510. * @return {ol.geom.Polygon} Polygon geometry.
  13511. * @api
  13512. */
  13513. ol.geom.Polygon.fromCircle = function(circle, opt_sides, opt_angle) {
  13514. var sides = opt_sides ? opt_sides : 32;
  13515. var stride = circle.getStride();
  13516. var layout = circle.getLayout();
  13517. var polygon = new ol.geom.Polygon(null, layout);
  13518. var arrayLength = stride * (sides + 1);
  13519. var flatCoordinates = new Array(arrayLength);
  13520. for (var i = 0; i < arrayLength; i++) {
  13521. flatCoordinates[i] = 0;
  13522. }
  13523. var ends = [flatCoordinates.length];
  13524. polygon.setFlatCoordinates(layout, flatCoordinates, ends);
  13525. ol.geom.Polygon.makeRegular(
  13526. polygon, circle.getCenter(), circle.getRadius(), opt_angle);
  13527. return polygon;
  13528. };
  13529. /**
  13530. * Modify the coordinates of a polygon to make it a regular polygon.
  13531. * @param {ol.geom.Polygon} polygon Polygon geometry.
  13532. * @param {ol.Coordinate} center Center of the regular polygon.
  13533. * @param {number} radius Radius of the regular polygon.
  13534. * @param {number=} opt_angle Start angle for the first vertex of the polygon in
  13535. * radians. Default is 0.
  13536. */
  13537. ol.geom.Polygon.makeRegular = function(polygon, center, radius, opt_angle) {
  13538. var flatCoordinates = polygon.getFlatCoordinates();
  13539. var layout = polygon.getLayout();
  13540. var stride = polygon.getStride();
  13541. var ends = polygon.getEnds();
  13542. var sides = flatCoordinates.length / stride - 1;
  13543. var startAngle = opt_angle ? opt_angle : 0;
  13544. var angle, offset;
  13545. for (var i = 0; i <= sides; ++i) {
  13546. offset = i * stride;
  13547. angle = startAngle + (ol.math.modulo(i, sides) * 2 * Math.PI / sides);
  13548. flatCoordinates[offset] = center[0] + (radius * Math.cos(angle));
  13549. flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle));
  13550. }
  13551. polygon.setFlatCoordinates(layout, flatCoordinates, ends);
  13552. };
  13553. goog.provide('ol.View');
  13554. goog.require('ol');
  13555. goog.require('ol.CenterConstraint');
  13556. goog.require('ol.Object');
  13557. goog.require('ol.ResolutionConstraint');
  13558. goog.require('ol.RotationConstraint');
  13559. goog.require('ol.ViewHint');
  13560. goog.require('ol.ViewProperty');
  13561. goog.require('ol.array');
  13562. goog.require('ol.asserts');
  13563. goog.require('ol.coordinate');
  13564. goog.require('ol.easing');
  13565. goog.require('ol.extent');
  13566. goog.require('ol.geom.GeometryType');
  13567. goog.require('ol.geom.Polygon');
  13568. goog.require('ol.geom.SimpleGeometry');
  13569. goog.require('ol.math');
  13570. goog.require('ol.obj');
  13571. goog.require('ol.proj');
  13572. goog.require('ol.proj.Units');
  13573. /**
  13574. * @classdesc
  13575. * An ol.View object represents a simple 2D view of the map.
  13576. *
  13577. * This is the object to act upon to change the center, resolution,
  13578. * and rotation of the map.
  13579. *
  13580. * ### The view states
  13581. *
  13582. * An `ol.View` is determined by three states: `center`, `resolution`,
  13583. * and `rotation`. Each state has a corresponding getter and setter, e.g.
  13584. * `getCenter` and `setCenter` for the `center` state.
  13585. *
  13586. * An `ol.View` has a `projection`. The projection determines the
  13587. * coordinate system of the center, and its units determine the units of the
  13588. * resolution (projection units per pixel). The default projection is
  13589. * Spherical Mercator (EPSG:3857).
  13590. *
  13591. * ### The constraints
  13592. *
  13593. * `setCenter`, `setResolution` and `setRotation` can be used to change the
  13594. * states of the view. Any value can be passed to the setters. And the value
  13595. * that is passed to a setter will effectively be the value set in the view,
  13596. * and returned by the corresponding getter.
  13597. *
  13598. * But an `ol.View` object also has a *resolution constraint*, a
  13599. * *rotation constraint* and a *center constraint*.
  13600. *
  13601. * As said above, no constraints are applied when the setters are used to set
  13602. * new states for the view. Applying constraints is done explicitly through
  13603. * the use of the `constrain*` functions (`constrainResolution` and
  13604. * `constrainRotation` and `constrainCenter`).
  13605. *
  13606. * The main users of the constraints are the interactions and the
  13607. * controls. For example, double-clicking on the map changes the view to
  13608. * the "next" resolution. And releasing the fingers after pinch-zooming
  13609. * snaps to the closest resolution (with an animation).
  13610. *
  13611. * The *resolution constraint* snaps to specific resolutions. It is
  13612. * determined by the following options: `resolutions`, `maxResolution`,
  13613. * `maxZoom`, and `zoomFactor`. If `resolutions` is set, the other three
  13614. * options are ignored. See documentation for each option for more
  13615. * information.
  13616. *
  13617. * The *rotation constraint* snaps to specific angles. It is determined
  13618. * by the following options: `enableRotation` and `constrainRotation`.
  13619. * By default the rotation value is snapped to zero when approaching the
  13620. * horizontal.
  13621. *
  13622. * The *center constraint* is determined by the `extent` option. By
  13623. * default the center is not constrained at all.
  13624. *
  13625. * @constructor
  13626. * @extends {ol.Object}
  13627. * @param {olx.ViewOptions=} opt_options View options.
  13628. * @api
  13629. */
  13630. ol.View = function(opt_options) {
  13631. ol.Object.call(this);
  13632. var options = ol.obj.assign({}, opt_options);
  13633. /**
  13634. * @private
  13635. * @type {Array.<number>}
  13636. */
  13637. this.hints_ = [0, 0];
  13638. /**
  13639. * @private
  13640. * @type {Array.<Array.<ol.ViewAnimation>>}
  13641. */
  13642. this.animations_ = [];
  13643. /**
  13644. * @private
  13645. * @type {number|undefined}
  13646. */
  13647. this.updateAnimationKey_;
  13648. this.updateAnimations_ = this.updateAnimations_.bind(this);
  13649. /**
  13650. * @private
  13651. * @const
  13652. * @type {ol.proj.Projection}
  13653. */
  13654. this.projection_ = ol.proj.createProjection(options.projection, 'EPSG:3857');
  13655. this.applyOptions_(options);
  13656. };
  13657. ol.inherits(ol.View, ol.Object);
  13658. /**
  13659. * Set up the view with the given options.
  13660. * @param {olx.ViewOptions} options View options.
  13661. */
  13662. ol.View.prototype.applyOptions_ = function(options) {
  13663. /**
  13664. * @type {Object.<string, *>}
  13665. */
  13666. var properties = {};
  13667. properties[ol.ViewProperty.CENTER] = options.center !== undefined ?
  13668. options.center : null;
  13669. var resolutionConstraintInfo = ol.View.createResolutionConstraint_(
  13670. options);
  13671. /**
  13672. * @private
  13673. * @type {number}
  13674. */
  13675. this.maxResolution_ = resolutionConstraintInfo.maxResolution;
  13676. /**
  13677. * @private
  13678. * @type {number}
  13679. */
  13680. this.minResolution_ = resolutionConstraintInfo.minResolution;
  13681. /**
  13682. * @private
  13683. * @type {number}
  13684. */
  13685. this.zoomFactor_ = resolutionConstraintInfo.zoomFactor;
  13686. /**
  13687. * @private
  13688. * @type {Array.<number>|undefined}
  13689. */
  13690. this.resolutions_ = options.resolutions;
  13691. /**
  13692. * @private
  13693. * @type {number}
  13694. */
  13695. this.minZoom_ = resolutionConstraintInfo.minZoom;
  13696. var centerConstraint = ol.View.createCenterConstraint_(options);
  13697. var resolutionConstraint = resolutionConstraintInfo.constraint;
  13698. var rotationConstraint = ol.View.createRotationConstraint_(options);
  13699. /**
  13700. * @private
  13701. * @type {ol.Constraints}
  13702. */
  13703. this.constraints_ = {
  13704. center: centerConstraint,
  13705. resolution: resolutionConstraint,
  13706. rotation: rotationConstraint
  13707. };
  13708. if (options.resolution !== undefined) {
  13709. properties[ol.ViewProperty.RESOLUTION] = options.resolution;
  13710. } else if (options.zoom !== undefined) {
  13711. properties[ol.ViewProperty.RESOLUTION] = this.constrainResolution(
  13712. this.maxResolution_, options.zoom - this.minZoom_);
  13713. if (this.resolutions_) { // in case map zoom is out of min/max zoom range
  13714. properties[ol.ViewProperty.RESOLUTION] = ol.math.clamp(
  13715. Number(this.getResolution() || properties[ol.ViewProperty.RESOLUTION]),
  13716. this.minResolution_, this.maxResolution_);
  13717. }
  13718. }
  13719. properties[ol.ViewProperty.ROTATION] =
  13720. options.rotation !== undefined ? options.rotation : 0;
  13721. this.setProperties(properties);
  13722. /**
  13723. * @private
  13724. * @type {olx.ViewOptions}
  13725. */
  13726. this.options_ = options;
  13727. };
  13728. /**
  13729. * Get an updated version of the view options used to construct the view. The
  13730. * current resolution (or zoom), center, and rotation are applied to any stored
  13731. * options. The provided options can be uesd to apply new min/max zoom or
  13732. * resolution limits.
  13733. * @param {olx.ViewOptions} newOptions New options to be applied.
  13734. * @return {olx.ViewOptions} New options updated with the current view state.
  13735. */
  13736. ol.View.prototype.getUpdatedOptions_ = function(newOptions) {
  13737. var options = ol.obj.assign({}, this.options_);
  13738. // preserve resolution (or zoom)
  13739. if (options.resolution !== undefined) {
  13740. options.resolution = this.getResolution();
  13741. } else {
  13742. options.zoom = this.getZoom();
  13743. }
  13744. // preserve center
  13745. options.center = this.getCenter();
  13746. // preserve rotation
  13747. options.rotation = this.getRotation();
  13748. return ol.obj.assign({}, options, newOptions);
  13749. };
  13750. /**
  13751. * Animate the view. The view's center, zoom (or resolution), and rotation
  13752. * can be animated for smooth transitions between view states. For example,
  13753. * to animate the view to a new zoom level:
  13754. *
  13755. * view.animate({zoom: view.getZoom() + 1});
  13756. *
  13757. * By default, the animation lasts one second and uses in-and-out easing. You
  13758. * can customize this behavior by including `duration` (in milliseconds) and
  13759. * `easing` options (see {@link ol.easing}).
  13760. *
  13761. * To chain together multiple animations, call the method with multiple
  13762. * animation objects. For example, to first zoom and then pan:
  13763. *
  13764. * view.animate({zoom: 10}, {center: [0, 0]});
  13765. *
  13766. * If you provide a function as the last argument to the animate method, it
  13767. * will get called at the end of an animation series. The callback will be
  13768. * called with `true` if the animation series completed on its own or `false`
  13769. * if it was cancelled.
  13770. *
  13771. * Animations are cancelled by user interactions (e.g. dragging the map) or by
  13772. * calling `view.setCenter()`, `view.setResolution()`, or `view.setRotation()`
  13773. * (or another method that calls one of these).
  13774. *
  13775. * @param {...(olx.AnimationOptions|function(boolean))} var_args Animation
  13776. * options. Multiple animations can be run in series by passing multiple
  13777. * options objects. To run multiple animations in parallel, call the method
  13778. * multiple times. An optional callback can be provided as a final
  13779. * argument. The callback will be called with a boolean indicating whether
  13780. * the animation completed without being cancelled.
  13781. * @api
  13782. */
  13783. ol.View.prototype.animate = function(var_args) {
  13784. var animationCount = arguments.length;
  13785. var callback;
  13786. if (animationCount > 1 && typeof arguments[animationCount - 1] === 'function') {
  13787. callback = arguments[animationCount - 1];
  13788. --animationCount;
  13789. }
  13790. if (!this.isDef()) {
  13791. // if view properties are not yet set, shortcut to the final state
  13792. var state = arguments[animationCount - 1];
  13793. if (state.center) {
  13794. this.setCenter(state.center);
  13795. }
  13796. if (state.zoom !== undefined) {
  13797. this.setZoom(state.zoom);
  13798. }
  13799. if (state.rotation !== undefined) {
  13800. this.setRotation(state.rotation);
  13801. }
  13802. if (callback) {
  13803. callback(true);
  13804. }
  13805. return;
  13806. }
  13807. var start = Date.now();
  13808. var center = this.getCenter().slice();
  13809. var resolution = this.getResolution();
  13810. var rotation = this.getRotation();
  13811. var series = [];
  13812. for (var i = 0; i < animationCount; ++i) {
  13813. var options = /** @type {olx.AnimationOptions} */ (arguments[i]);
  13814. var animation = /** @type {ol.ViewAnimation} */ ({
  13815. start: start,
  13816. complete: false,
  13817. anchor: options.anchor,
  13818. duration: options.duration !== undefined ? options.duration : 1000,
  13819. easing: options.easing || ol.easing.inAndOut
  13820. });
  13821. if (options.center) {
  13822. animation.sourceCenter = center;
  13823. animation.targetCenter = options.center;
  13824. center = animation.targetCenter;
  13825. }
  13826. if (options.zoom !== undefined) {
  13827. animation.sourceResolution = resolution;
  13828. animation.targetResolution = this.constrainResolution(
  13829. this.maxResolution_, options.zoom - this.minZoom_, 0);
  13830. resolution = animation.targetResolution;
  13831. } else if (options.resolution) {
  13832. animation.sourceResolution = resolution;
  13833. animation.targetResolution = options.resolution;
  13834. resolution = animation.targetResolution;
  13835. }
  13836. if (options.rotation !== undefined) {
  13837. animation.sourceRotation = rotation;
  13838. var delta = ol.math.modulo(options.rotation - rotation + Math.PI, 2 * Math.PI) - Math.PI;
  13839. animation.targetRotation = rotation + delta;
  13840. rotation = animation.targetRotation;
  13841. }
  13842. animation.callback = callback;
  13843. // check if animation is a no-op
  13844. if (ol.View.isNoopAnimation(animation)) {
  13845. animation.complete = true;
  13846. // we still push it onto the series for callback handling
  13847. } else {
  13848. start += animation.duration;
  13849. }
  13850. series.push(animation);
  13851. }
  13852. this.animations_.push(series);
  13853. this.setHint(ol.ViewHint.ANIMATING, 1);
  13854. this.updateAnimations_();
  13855. };
  13856. /**
  13857. * Determine if the view is being animated.
  13858. * @return {boolean} The view is being animated.
  13859. * @api
  13860. */
  13861. ol.View.prototype.getAnimating = function() {
  13862. return this.hints_[ol.ViewHint.ANIMATING] > 0;
  13863. };
  13864. /**
  13865. * Determine if the user is interacting with the view, such as panning or zooming.
  13866. * @return {boolean} The view is being interacted with.
  13867. * @api
  13868. */
  13869. ol.View.prototype.getInteracting = function() {
  13870. return this.hints_[ol.ViewHint.INTERACTING] > 0;
  13871. };
  13872. /**
  13873. * Cancel any ongoing animations.
  13874. * @api
  13875. */
  13876. ol.View.prototype.cancelAnimations = function() {
  13877. this.setHint(ol.ViewHint.ANIMATING, -this.hints_[ol.ViewHint.ANIMATING]);
  13878. for (var i = 0, ii = this.animations_.length; i < ii; ++i) {
  13879. var series = this.animations_[i];
  13880. if (series[0].callback) {
  13881. series[0].callback(false);
  13882. }
  13883. }
  13884. this.animations_.length = 0;
  13885. };
  13886. /**
  13887. * Update all animations.
  13888. */
  13889. ol.View.prototype.updateAnimations_ = function() {
  13890. if (this.updateAnimationKey_ !== undefined) {
  13891. cancelAnimationFrame(this.updateAnimationKey_);
  13892. this.updateAnimationKey_ = undefined;
  13893. }
  13894. if (!this.getAnimating()) {
  13895. return;
  13896. }
  13897. var now = Date.now();
  13898. var more = false;
  13899. for (var i = this.animations_.length - 1; i >= 0; --i) {
  13900. var series = this.animations_[i];
  13901. var seriesComplete = true;
  13902. for (var j = 0, jj = series.length; j < jj; ++j) {
  13903. var animation = series[j];
  13904. if (animation.complete) {
  13905. continue;
  13906. }
  13907. var elapsed = now - animation.start;
  13908. var fraction = animation.duration > 0 ? elapsed / animation.duration : 1;
  13909. if (fraction >= 1) {
  13910. animation.complete = true;
  13911. fraction = 1;
  13912. } else {
  13913. seriesComplete = false;
  13914. }
  13915. var progress = animation.easing(fraction);
  13916. if (animation.sourceCenter) {
  13917. var x0 = animation.sourceCenter[0];
  13918. var y0 = animation.sourceCenter[1];
  13919. var x1 = animation.targetCenter[0];
  13920. var y1 = animation.targetCenter[1];
  13921. var x = x0 + progress * (x1 - x0);
  13922. var y = y0 + progress * (y1 - y0);
  13923. this.set(ol.ViewProperty.CENTER, [x, y]);
  13924. }
  13925. if (animation.sourceResolution && animation.targetResolution) {
  13926. var resolution = progress === 1 ?
  13927. animation.targetResolution :
  13928. animation.sourceResolution + progress * (animation.targetResolution - animation.sourceResolution);
  13929. if (animation.anchor) {
  13930. this.set(ol.ViewProperty.CENTER,
  13931. this.calculateCenterZoom(resolution, animation.anchor));
  13932. }
  13933. this.set(ol.ViewProperty.RESOLUTION, resolution);
  13934. }
  13935. if (animation.sourceRotation !== undefined && animation.targetRotation !== undefined) {
  13936. var rotation = progress === 1 ?
  13937. ol.math.modulo(animation.targetRotation + Math.PI, 2 * Math.PI) - Math.PI :
  13938. animation.sourceRotation + progress * (animation.targetRotation - animation.sourceRotation);
  13939. if (animation.anchor) {
  13940. this.set(ol.ViewProperty.CENTER,
  13941. this.calculateCenterRotate(rotation, animation.anchor));
  13942. }
  13943. this.set(ol.ViewProperty.ROTATION, rotation);
  13944. }
  13945. more = true;
  13946. if (!animation.complete) {
  13947. break;
  13948. }
  13949. }
  13950. if (seriesComplete) {
  13951. this.animations_[i] = null;
  13952. this.setHint(ol.ViewHint.ANIMATING, -1);
  13953. var callback = series[0].callback;
  13954. if (callback) {
  13955. callback(true);
  13956. }
  13957. }
  13958. }
  13959. // prune completed series
  13960. this.animations_ = this.animations_.filter(Boolean);
  13961. if (more && this.updateAnimationKey_ === undefined) {
  13962. this.updateAnimationKey_ = requestAnimationFrame(this.updateAnimations_);
  13963. }
  13964. };
  13965. /**
  13966. * @param {number} rotation Target rotation.
  13967. * @param {ol.Coordinate} anchor Rotation anchor.
  13968. * @return {ol.Coordinate|undefined} Center for rotation and anchor.
  13969. */
  13970. ol.View.prototype.calculateCenterRotate = function(rotation, anchor) {
  13971. var center;
  13972. var currentCenter = this.getCenter();
  13973. if (currentCenter !== undefined) {
  13974. center = [currentCenter[0] - anchor[0], currentCenter[1] - anchor[1]];
  13975. ol.coordinate.rotate(center, rotation - this.getRotation());
  13976. ol.coordinate.add(center, anchor);
  13977. }
  13978. return center;
  13979. };
  13980. /**
  13981. * @param {number} resolution Target resolution.
  13982. * @param {ol.Coordinate} anchor Zoom anchor.
  13983. * @return {ol.Coordinate|undefined} Center for resolution and anchor.
  13984. */
  13985. ol.View.prototype.calculateCenterZoom = function(resolution, anchor) {
  13986. var center;
  13987. var currentCenter = this.getCenter();
  13988. var currentResolution = this.getResolution();
  13989. if (currentCenter !== undefined && currentResolution !== undefined) {
  13990. var x = anchor[0] -
  13991. resolution * (anchor[0] - currentCenter[0]) / currentResolution;
  13992. var y = anchor[1] -
  13993. resolution * (anchor[1] - currentCenter[1]) / currentResolution;
  13994. center = [x, y];
  13995. }
  13996. return center;
  13997. };
  13998. /**
  13999. * @private
  14000. * @return {ol.Size} Viewport size or `[100, 100]` when no viewport is found.
  14001. */
  14002. ol.View.prototype.getSizeFromViewport_ = function() {
  14003. var size = [100, 100];
  14004. var selector = '.ol-viewport[data-view="' + ol.getUid(this) + '"]';
  14005. var element = document.querySelector(selector);
  14006. if (element) {
  14007. var metrics = getComputedStyle(element);
  14008. size[0] = parseInt(metrics.width, 10);
  14009. size[1] = parseInt(metrics.height, 10);
  14010. }
  14011. return size;
  14012. };
  14013. /**
  14014. * Get the constrained center of this view.
  14015. * @param {ol.Coordinate|undefined} center Center.
  14016. * @return {ol.Coordinate|undefined} Constrained center.
  14017. * @api
  14018. */
  14019. ol.View.prototype.constrainCenter = function(center) {
  14020. return this.constraints_.center(center);
  14021. };
  14022. /**
  14023. * Get the constrained resolution of this view.
  14024. * @param {number|undefined} resolution Resolution.
  14025. * @param {number=} opt_delta Delta. Default is `0`.
  14026. * @param {number=} opt_direction Direction. Default is `0`.
  14027. * @return {number|undefined} Constrained resolution.
  14028. * @api
  14029. */
  14030. ol.View.prototype.constrainResolution = function(
  14031. resolution, opt_delta, opt_direction) {
  14032. var delta = opt_delta || 0;
  14033. var direction = opt_direction || 0;
  14034. return this.constraints_.resolution(resolution, delta, direction);
  14035. };
  14036. /**
  14037. * Get the constrained rotation of this view.
  14038. * @param {number|undefined} rotation Rotation.
  14039. * @param {number=} opt_delta Delta. Default is `0`.
  14040. * @return {number|undefined} Constrained rotation.
  14041. * @api
  14042. */
  14043. ol.View.prototype.constrainRotation = function(rotation, opt_delta) {
  14044. var delta = opt_delta || 0;
  14045. return this.constraints_.rotation(rotation, delta);
  14046. };
  14047. /**
  14048. * Get the view center.
  14049. * @return {ol.Coordinate|undefined} The center of the view.
  14050. * @observable
  14051. * @api
  14052. */
  14053. ol.View.prototype.getCenter = function() {
  14054. return /** @type {ol.Coordinate|undefined} */ (
  14055. this.get(ol.ViewProperty.CENTER));
  14056. };
  14057. /**
  14058. * @return {ol.Constraints} Constraints.
  14059. */
  14060. ol.View.prototype.getConstraints = function() {
  14061. return this.constraints_;
  14062. };
  14063. /**
  14064. * @param {Array.<number>=} opt_hints Destination array.
  14065. * @return {Array.<number>} Hint.
  14066. */
  14067. ol.View.prototype.getHints = function(opt_hints) {
  14068. if (opt_hints !== undefined) {
  14069. opt_hints[0] = this.hints_[0];
  14070. opt_hints[1] = this.hints_[1];
  14071. return opt_hints;
  14072. } else {
  14073. return this.hints_.slice();
  14074. }
  14075. };
  14076. /**
  14077. * Calculate the extent for the current view state and the passed size.
  14078. * The size is the pixel dimensions of the box into which the calculated extent
  14079. * should fit. In most cases you want to get the extent of the entire map,
  14080. * that is `map.getSize()`.
  14081. * @param {ol.Size=} opt_size Box pixel size. If not provided, the size of the
  14082. * first map that uses this view will be used.
  14083. * @return {ol.Extent} Extent.
  14084. * @api
  14085. */
  14086. ol.View.prototype.calculateExtent = function(opt_size) {
  14087. var size = opt_size || this.getSizeFromViewport_();
  14088. var center = /** @type {!ol.Coordinate} */ (this.getCenter());
  14089. ol.asserts.assert(center, 1); // The view center is not defined
  14090. var resolution = /** @type {!number} */ (this.getResolution());
  14091. ol.asserts.assert(resolution !== undefined, 2); // The view resolution is not defined
  14092. var rotation = /** @type {!number} */ (this.getRotation());
  14093. ol.asserts.assert(rotation !== undefined, 3); // The view rotation is not defined
  14094. return ol.extent.getForViewAndSize(center, resolution, rotation, size);
  14095. };
  14096. /**
  14097. * Get the maximum resolution of the view.
  14098. * @return {number} The maximum resolution of the view.
  14099. * @api
  14100. */
  14101. ol.View.prototype.getMaxResolution = function() {
  14102. return this.maxResolution_;
  14103. };
  14104. /**
  14105. * Get the minimum resolution of the view.
  14106. * @return {number} The minimum resolution of the view.
  14107. * @api
  14108. */
  14109. ol.View.prototype.getMinResolution = function() {
  14110. return this.minResolution_;
  14111. };
  14112. /**
  14113. * Get the maximum zoom level for the view.
  14114. * @return {number} The maximum zoom level.
  14115. * @api
  14116. */
  14117. ol.View.prototype.getMaxZoom = function() {
  14118. return /** @type {number} */ (this.getZoomForResolution(this.minResolution_));
  14119. };
  14120. /**
  14121. * Set a new maximum zoom level for the view.
  14122. * @param {number} zoom The maximum zoom level.
  14123. * @api
  14124. */
  14125. ol.View.prototype.setMaxZoom = function(zoom) {
  14126. this.applyOptions_(this.getUpdatedOptions_({maxZoom: zoom}));
  14127. };
  14128. /**
  14129. * Get the minimum zoom level for the view.
  14130. * @return {number} The minimum zoom level.
  14131. * @api
  14132. */
  14133. ol.View.prototype.getMinZoom = function() {
  14134. return /** @type {number} */ (this.getZoomForResolution(this.maxResolution_));
  14135. };
  14136. /**
  14137. * Set a new minimum zoom level for the view.
  14138. * @param {number} zoom The minimum zoom level.
  14139. * @api
  14140. */
  14141. ol.View.prototype.setMinZoom = function(zoom) {
  14142. this.applyOptions_(this.getUpdatedOptions_({minZoom: zoom}));
  14143. };
  14144. /**
  14145. * Get the view projection.
  14146. * @return {ol.proj.Projection} The projection of the view.
  14147. * @api
  14148. */
  14149. ol.View.prototype.getProjection = function() {
  14150. return this.projection_;
  14151. };
  14152. /**
  14153. * Get the view resolution.
  14154. * @return {number|undefined} The resolution of the view.
  14155. * @observable
  14156. * @api
  14157. */
  14158. ol.View.prototype.getResolution = function() {
  14159. return /** @type {number|undefined} */ (
  14160. this.get(ol.ViewProperty.RESOLUTION));
  14161. };
  14162. /**
  14163. * Get the resolutions for the view. This returns the array of resolutions
  14164. * passed to the constructor of the {ol.View}, or undefined if none were given.
  14165. * @return {Array.<number>|undefined} The resolutions of the view.
  14166. * @api
  14167. */
  14168. ol.View.prototype.getResolutions = function() {
  14169. return this.resolutions_;
  14170. };
  14171. /**
  14172. * Get the resolution for a provided extent (in map units) and size (in pixels).
  14173. * @param {ol.Extent} extent Extent.
  14174. * @param {ol.Size=} opt_size Box pixel size.
  14175. * @return {number} The resolution at which the provided extent will render at
  14176. * the given size.
  14177. * @api
  14178. */
  14179. ol.View.prototype.getResolutionForExtent = function(extent, opt_size) {
  14180. var size = opt_size || this.getSizeFromViewport_();
  14181. var xResolution = ol.extent.getWidth(extent) / size[0];
  14182. var yResolution = ol.extent.getHeight(extent) / size[1];
  14183. return Math.max(xResolution, yResolution);
  14184. };
  14185. /**
  14186. * Return a function that returns a value between 0 and 1 for a
  14187. * resolution. Exponential scaling is assumed.
  14188. * @param {number=} opt_power Power.
  14189. * @return {function(number): number} Resolution for value function.
  14190. */
  14191. ol.View.prototype.getResolutionForValueFunction = function(opt_power) {
  14192. var power = opt_power || 2;
  14193. var maxResolution = this.maxResolution_;
  14194. var minResolution = this.minResolution_;
  14195. var max = Math.log(maxResolution / minResolution) / Math.log(power);
  14196. return (
  14197. /**
  14198. * @param {number} value Value.
  14199. * @return {number} Resolution.
  14200. */
  14201. function(value) {
  14202. var resolution = maxResolution / Math.pow(power, value * max);
  14203. return resolution;
  14204. });
  14205. };
  14206. /**
  14207. * Get the view rotation.
  14208. * @return {number} The rotation of the view in radians.
  14209. * @observable
  14210. * @api
  14211. */
  14212. ol.View.prototype.getRotation = function() {
  14213. return /** @type {number} */ (this.get(ol.ViewProperty.ROTATION));
  14214. };
  14215. /**
  14216. * Return a function that returns a resolution for a value between
  14217. * 0 and 1. Exponential scaling is assumed.
  14218. * @param {number=} opt_power Power.
  14219. * @return {function(number): number} Value for resolution function.
  14220. */
  14221. ol.View.prototype.getValueForResolutionFunction = function(opt_power) {
  14222. var power = opt_power || 2;
  14223. var maxResolution = this.maxResolution_;
  14224. var minResolution = this.minResolution_;
  14225. var max = Math.log(maxResolution / minResolution) / Math.log(power);
  14226. return (
  14227. /**
  14228. * @param {number} resolution Resolution.
  14229. * @return {number} Value.
  14230. */
  14231. function(resolution) {
  14232. var value =
  14233. (Math.log(maxResolution / resolution) / Math.log(power)) / max;
  14234. return value;
  14235. });
  14236. };
  14237. /**
  14238. * @return {olx.ViewState} View state.
  14239. */
  14240. ol.View.prototype.getState = function() {
  14241. var center = /** @type {ol.Coordinate} */ (this.getCenter());
  14242. var projection = this.getProjection();
  14243. var resolution = /** @type {number} */ (this.getResolution());
  14244. var rotation = this.getRotation();
  14245. return /** @type {olx.ViewState} */ ({
  14246. center: center.slice(),
  14247. projection: projection !== undefined ? projection : null,
  14248. resolution: resolution,
  14249. rotation: rotation,
  14250. zoom: this.getZoom()
  14251. });
  14252. };
  14253. /**
  14254. * Get the current zoom level. If you configured your view with a resolutions
  14255. * array (this is rare), this method may return non-integer zoom levels (so
  14256. * the zoom level is not safe to use as an index into a resolutions array).
  14257. * @return {number|undefined} Zoom.
  14258. * @api
  14259. */
  14260. ol.View.prototype.getZoom = function() {
  14261. var zoom;
  14262. var resolution = this.getResolution();
  14263. if (resolution !== undefined) {
  14264. zoom = this.getZoomForResolution(resolution);
  14265. }
  14266. return zoom;
  14267. };
  14268. /**
  14269. * Get the zoom level for a resolution.
  14270. * @param {number} resolution The resolution.
  14271. * @return {number|undefined} The zoom level for the provided resolution.
  14272. * @api
  14273. */
  14274. ol.View.prototype.getZoomForResolution = function(resolution) {
  14275. var offset = this.minZoom_ || 0;
  14276. var max, zoomFactor;
  14277. if (this.resolutions_) {
  14278. var nearest = ol.array.linearFindNearest(this.resolutions_, resolution, 1);
  14279. offset = nearest;
  14280. max = this.resolutions_[nearest];
  14281. if (nearest == this.resolutions_.length - 1) {
  14282. zoomFactor = 2;
  14283. } else {
  14284. zoomFactor = max / this.resolutions_[nearest + 1];
  14285. }
  14286. } else {
  14287. max = this.maxResolution_;
  14288. zoomFactor = this.zoomFactor_;
  14289. }
  14290. return offset + Math.log(max / resolution) / Math.log(zoomFactor);
  14291. };
  14292. /**
  14293. * Get the resolution for a zoom level.
  14294. * @param {number} zoom Zoom level.
  14295. * @return {number} The view resolution for the provided zoom level.
  14296. * @api
  14297. */
  14298. ol.View.prototype.getResolutionForZoom = function(zoom) {
  14299. return /** @type {number} */ (this.constrainResolution(
  14300. this.maxResolution_, zoom - this.minZoom_, 0));
  14301. };
  14302. /**
  14303. * Fit the given geometry or extent based on the given map size and border.
  14304. * The size is pixel dimensions of the box to fit the extent into.
  14305. * In most cases you will want to use the map size, that is `map.getSize()`.
  14306. * Takes care of the map angle.
  14307. * @param {ol.geom.SimpleGeometry|ol.Extent} geometryOrExtent The geometry or
  14308. * extent to fit the view to.
  14309. * @param {olx.view.FitOptions=} opt_options Options.
  14310. * @api
  14311. */
  14312. ol.View.prototype.fit = function(geometryOrExtent, opt_options) {
  14313. var options = opt_options || {};
  14314. var size = options.size;
  14315. if (!size) {
  14316. size = this.getSizeFromViewport_();
  14317. }
  14318. /** @type {ol.geom.SimpleGeometry} */
  14319. var geometry;
  14320. if (!(geometryOrExtent instanceof ol.geom.SimpleGeometry)) {
  14321. ol.asserts.assert(Array.isArray(geometryOrExtent),
  14322. 24); // Invalid extent or geometry provided as `geometry`
  14323. ol.asserts.assert(!ol.extent.isEmpty(geometryOrExtent),
  14324. 25); // Cannot fit empty extent provided as `geometry`
  14325. geometry = ol.geom.Polygon.fromExtent(geometryOrExtent);
  14326. } else if (geometryOrExtent.getType() === ol.geom.GeometryType.CIRCLE) {
  14327. geometryOrExtent = geometryOrExtent.getExtent();
  14328. geometry = ol.geom.Polygon.fromExtent(geometryOrExtent);
  14329. geometry.rotate(this.getRotation(), ol.extent.getCenter(geometryOrExtent));
  14330. } else {
  14331. geometry = geometryOrExtent;
  14332. }
  14333. var padding = options.padding !== undefined ? options.padding : [0, 0, 0, 0];
  14334. var constrainResolution = options.constrainResolution !== undefined ?
  14335. options.constrainResolution : true;
  14336. var nearest = options.nearest !== undefined ? options.nearest : false;
  14337. var minResolution;
  14338. if (options.minResolution !== undefined) {
  14339. minResolution = options.minResolution;
  14340. } else if (options.maxZoom !== undefined) {
  14341. minResolution = this.constrainResolution(
  14342. this.maxResolution_, options.maxZoom - this.minZoom_, 0);
  14343. } else {
  14344. minResolution = 0;
  14345. }
  14346. var coords = geometry.getFlatCoordinates();
  14347. // calculate rotated extent
  14348. var rotation = this.getRotation();
  14349. var cosAngle = Math.cos(-rotation);
  14350. var sinAngle = Math.sin(-rotation);
  14351. var minRotX = +Infinity;
  14352. var minRotY = +Infinity;
  14353. var maxRotX = -Infinity;
  14354. var maxRotY = -Infinity;
  14355. var stride = geometry.getStride();
  14356. for (var i = 0, ii = coords.length; i < ii; i += stride) {
  14357. var rotX = coords[i] * cosAngle - coords[i + 1] * sinAngle;
  14358. var rotY = coords[i] * sinAngle + coords[i + 1] * cosAngle;
  14359. minRotX = Math.min(minRotX, rotX);
  14360. minRotY = Math.min(minRotY, rotY);
  14361. maxRotX = Math.max(maxRotX, rotX);
  14362. maxRotY = Math.max(maxRotY, rotY);
  14363. }
  14364. // calculate resolution
  14365. var resolution = this.getResolutionForExtent(
  14366. [minRotX, minRotY, maxRotX, maxRotY],
  14367. [size[0] - padding[1] - padding[3], size[1] - padding[0] - padding[2]]);
  14368. resolution = isNaN(resolution) ? minResolution :
  14369. Math.max(resolution, minResolution);
  14370. if (constrainResolution) {
  14371. var constrainedResolution = this.constrainResolution(resolution, 0, 0);
  14372. if (!nearest && constrainedResolution < resolution) {
  14373. constrainedResolution = this.constrainResolution(
  14374. constrainedResolution, -1, 0);
  14375. }
  14376. resolution = constrainedResolution;
  14377. }
  14378. // calculate center
  14379. sinAngle = -sinAngle; // go back to original rotation
  14380. var centerRotX = (minRotX + maxRotX) / 2;
  14381. var centerRotY = (minRotY + maxRotY) / 2;
  14382. centerRotX += (padding[1] - padding[3]) / 2 * resolution;
  14383. centerRotY += (padding[0] - padding[2]) / 2 * resolution;
  14384. var centerX = centerRotX * cosAngle - centerRotY * sinAngle;
  14385. var centerY = centerRotY * cosAngle + centerRotX * sinAngle;
  14386. var center = [centerX, centerY];
  14387. var callback = options.callback ? options.callback : ol.nullFunction;
  14388. if (options.duration !== undefined) {
  14389. this.animate({
  14390. resolution: resolution,
  14391. center: center,
  14392. duration: options.duration,
  14393. easing: options.easing
  14394. }, callback);
  14395. } else {
  14396. this.setResolution(resolution);
  14397. this.setCenter(center);
  14398. setTimeout(callback.bind(undefined, true), 0);
  14399. }
  14400. };
  14401. /**
  14402. * Center on coordinate and view position.
  14403. * @param {ol.Coordinate} coordinate Coordinate.
  14404. * @param {ol.Size} size Box pixel size.
  14405. * @param {ol.Pixel} position Position on the view to center on.
  14406. * @api
  14407. */
  14408. ol.View.prototype.centerOn = function(coordinate, size, position) {
  14409. // calculate rotated position
  14410. var rotation = this.getRotation();
  14411. var cosAngle = Math.cos(-rotation);
  14412. var sinAngle = Math.sin(-rotation);
  14413. var rotX = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
  14414. var rotY = coordinate[1] * cosAngle + coordinate[0] * sinAngle;
  14415. var resolution = this.getResolution();
  14416. rotX += (size[0] / 2 - position[0]) * resolution;
  14417. rotY += (position[1] - size[1] / 2) * resolution;
  14418. // go back to original angle
  14419. sinAngle = -sinAngle; // go back to original rotation
  14420. var centerX = rotX * cosAngle - rotY * sinAngle;
  14421. var centerY = rotY * cosAngle + rotX * sinAngle;
  14422. this.setCenter([centerX, centerY]);
  14423. };
  14424. /**
  14425. * @return {boolean} Is defined.
  14426. */
  14427. ol.View.prototype.isDef = function() {
  14428. return !!this.getCenter() && this.getResolution() !== undefined;
  14429. };
  14430. /**
  14431. * Rotate the view around a given coordinate.
  14432. * @param {number} rotation New rotation value for the view.
  14433. * @param {ol.Coordinate=} opt_anchor The rotation center.
  14434. * @api
  14435. */
  14436. ol.View.prototype.rotate = function(rotation, opt_anchor) {
  14437. if (opt_anchor !== undefined) {
  14438. var center = this.calculateCenterRotate(rotation, opt_anchor);
  14439. this.setCenter(center);
  14440. }
  14441. this.setRotation(rotation);
  14442. };
  14443. /**
  14444. * Set the center of the current view.
  14445. * @param {ol.Coordinate|undefined} center The center of the view.
  14446. * @observable
  14447. * @api
  14448. */
  14449. ol.View.prototype.setCenter = function(center) {
  14450. this.set(ol.ViewProperty.CENTER, center);
  14451. if (this.getAnimating()) {
  14452. this.cancelAnimations();
  14453. }
  14454. };
  14455. /**
  14456. * @param {ol.ViewHint} hint Hint.
  14457. * @param {number} delta Delta.
  14458. * @return {number} New value.
  14459. */
  14460. ol.View.prototype.setHint = function(hint, delta) {
  14461. this.hints_[hint] += delta;
  14462. this.changed();
  14463. return this.hints_[hint];
  14464. };
  14465. /**
  14466. * Set the resolution for this view.
  14467. * @param {number|undefined} resolution The resolution of the view.
  14468. * @observable
  14469. * @api
  14470. */
  14471. ol.View.prototype.setResolution = function(resolution) {
  14472. this.set(ol.ViewProperty.RESOLUTION, resolution);
  14473. if (this.getAnimating()) {
  14474. this.cancelAnimations();
  14475. }
  14476. };
  14477. /**
  14478. * Set the rotation for this view.
  14479. * @param {number} rotation The rotation of the view in radians.
  14480. * @observable
  14481. * @api
  14482. */
  14483. ol.View.prototype.setRotation = function(rotation) {
  14484. this.set(ol.ViewProperty.ROTATION, rotation);
  14485. if (this.getAnimating()) {
  14486. this.cancelAnimations();
  14487. }
  14488. };
  14489. /**
  14490. * Zoom to a specific zoom level.
  14491. * @param {number} zoom Zoom level.
  14492. * @api
  14493. */
  14494. ol.View.prototype.setZoom = function(zoom) {
  14495. this.setResolution(this.getResolutionForZoom(zoom));
  14496. };
  14497. /**
  14498. * @param {olx.ViewOptions} options View options.
  14499. * @private
  14500. * @return {ol.CenterConstraintType} The constraint.
  14501. */
  14502. ol.View.createCenterConstraint_ = function(options) {
  14503. if (options.extent !== undefined) {
  14504. return ol.CenterConstraint.createExtent(options.extent);
  14505. } else {
  14506. return ol.CenterConstraint.none;
  14507. }
  14508. };
  14509. /**
  14510. * @private
  14511. * @param {olx.ViewOptions} options View options.
  14512. * @return {{constraint: ol.ResolutionConstraintType, maxResolution: number,
  14513. * minResolution: number, zoomFactor: number}} The constraint.
  14514. */
  14515. ol.View.createResolutionConstraint_ = function(options) {
  14516. var resolutionConstraint;
  14517. var maxResolution;
  14518. var minResolution;
  14519. // TODO: move these to be ol constants
  14520. // see https://github.com/openlayers/openlayers/issues/2076
  14521. var defaultMaxZoom = 28;
  14522. var defaultZoomFactor = 2;
  14523. var minZoom = options.minZoom !== undefined ?
  14524. options.minZoom : ol.DEFAULT_MIN_ZOOM;
  14525. var maxZoom = options.maxZoom !== undefined ?
  14526. options.maxZoom : defaultMaxZoom;
  14527. var zoomFactor = options.zoomFactor !== undefined ?
  14528. options.zoomFactor : defaultZoomFactor;
  14529. if (options.resolutions !== undefined) {
  14530. var resolutions = options.resolutions;
  14531. maxResolution = resolutions[minZoom];
  14532. minResolution = resolutions[maxZoom] !== undefined ?
  14533. resolutions[maxZoom] : resolutions[resolutions.length - 1];
  14534. resolutionConstraint = ol.ResolutionConstraint.createSnapToResolutions(
  14535. resolutions);
  14536. } else {
  14537. // calculate the default min and max resolution
  14538. var projection = ol.proj.createProjection(options.projection, 'EPSG:3857');
  14539. var extent = projection.getExtent();
  14540. var size = !extent ?
  14541. // use an extent that can fit the whole world if need be
  14542. 360 * ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES] /
  14543. projection.getMetersPerUnit() :
  14544. Math.max(ol.extent.getWidth(extent), ol.extent.getHeight(extent));
  14545. var defaultMaxResolution = size / ol.DEFAULT_TILE_SIZE / Math.pow(
  14546. defaultZoomFactor, ol.DEFAULT_MIN_ZOOM);
  14547. var defaultMinResolution = defaultMaxResolution / Math.pow(
  14548. defaultZoomFactor, defaultMaxZoom - ol.DEFAULT_MIN_ZOOM);
  14549. // user provided maxResolution takes precedence
  14550. maxResolution = options.maxResolution;
  14551. if (maxResolution !== undefined) {
  14552. minZoom = 0;
  14553. } else {
  14554. maxResolution = defaultMaxResolution / Math.pow(zoomFactor, minZoom);
  14555. }
  14556. // user provided minResolution takes precedence
  14557. minResolution = options.minResolution;
  14558. if (minResolution === undefined) {
  14559. if (options.maxZoom !== undefined) {
  14560. if (options.maxResolution !== undefined) {
  14561. minResolution = maxResolution / Math.pow(zoomFactor, maxZoom);
  14562. } else {
  14563. minResolution = defaultMaxResolution / Math.pow(zoomFactor, maxZoom);
  14564. }
  14565. } else {
  14566. minResolution = defaultMinResolution;
  14567. }
  14568. }
  14569. // given discrete zoom levels, minResolution may be different than provided
  14570. maxZoom = minZoom + Math.floor(
  14571. Math.log(maxResolution / minResolution) / Math.log(zoomFactor));
  14572. minResolution = maxResolution / Math.pow(zoomFactor, maxZoom - minZoom);
  14573. resolutionConstraint = ol.ResolutionConstraint.createSnapToPower(
  14574. zoomFactor, maxResolution, maxZoom - minZoom);
  14575. }
  14576. return {constraint: resolutionConstraint, maxResolution: maxResolution,
  14577. minResolution: minResolution, minZoom: minZoom, zoomFactor: zoomFactor};
  14578. };
  14579. /**
  14580. * @private
  14581. * @param {olx.ViewOptions} options View options.
  14582. * @return {ol.RotationConstraintType} Rotation constraint.
  14583. */
  14584. ol.View.createRotationConstraint_ = function(options) {
  14585. var enableRotation = options.enableRotation !== undefined ?
  14586. options.enableRotation : true;
  14587. if (enableRotation) {
  14588. var constrainRotation = options.constrainRotation;
  14589. if (constrainRotation === undefined || constrainRotation === true) {
  14590. return ol.RotationConstraint.createSnapToZero();
  14591. } else if (constrainRotation === false) {
  14592. return ol.RotationConstraint.none;
  14593. } else if (typeof constrainRotation === 'number') {
  14594. return ol.RotationConstraint.createSnapToN(constrainRotation);
  14595. } else {
  14596. return ol.RotationConstraint.none;
  14597. }
  14598. } else {
  14599. return ol.RotationConstraint.disable;
  14600. }
  14601. };
  14602. /**
  14603. * Determine if an animation involves no view change.
  14604. * @param {ol.ViewAnimation} animation The animation.
  14605. * @return {boolean} The animation involves no view change.
  14606. */
  14607. ol.View.isNoopAnimation = function(animation) {
  14608. if (animation.sourceCenter && animation.targetCenter) {
  14609. if (!ol.coordinate.equals(animation.sourceCenter, animation.targetCenter)) {
  14610. return false;
  14611. }
  14612. }
  14613. if (animation.sourceResolution !== animation.targetResolution) {
  14614. return false;
  14615. }
  14616. if (animation.sourceRotation !== animation.targetRotation) {
  14617. return false;
  14618. }
  14619. return true;
  14620. };
  14621. goog.provide('ol.dom');
  14622. /**
  14623. * Create an html canvas element and returns its 2d context.
  14624. * @param {number=} opt_width Canvas width.
  14625. * @param {number=} opt_height Canvas height.
  14626. * @return {CanvasRenderingContext2D} The context.
  14627. */
  14628. ol.dom.createCanvasContext2D = function(opt_width, opt_height) {
  14629. var canvas = document.createElement('CANVAS');
  14630. if (opt_width) {
  14631. canvas.width = opt_width;
  14632. }
  14633. if (opt_height) {
  14634. canvas.height = opt_height;
  14635. }
  14636. return canvas.getContext('2d');
  14637. };
  14638. /**
  14639. * Get the current computed width for the given element including margin,
  14640. * padding and border.
  14641. * Equivalent to jQuery's `$(el).outerWidth(true)`.
  14642. * @param {!Element} element Element.
  14643. * @return {number} The width.
  14644. */
  14645. ol.dom.outerWidth = function(element) {
  14646. var width = element.offsetWidth;
  14647. var style = getComputedStyle(element);
  14648. width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10);
  14649. return width;
  14650. };
  14651. /**
  14652. * Get the current computed height for the given element including margin,
  14653. * padding and border.
  14654. * Equivalent to jQuery's `$(el).outerHeight(true)`.
  14655. * @param {!Element} element Element.
  14656. * @return {number} The height.
  14657. */
  14658. ol.dom.outerHeight = function(element) {
  14659. var height = element.offsetHeight;
  14660. var style = getComputedStyle(element);
  14661. height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10);
  14662. return height;
  14663. };
  14664. /**
  14665. * @param {Node} newNode Node to replace old node
  14666. * @param {Node} oldNode The node to be replaced
  14667. */
  14668. ol.dom.replaceNode = function(newNode, oldNode) {
  14669. var parent = oldNode.parentNode;
  14670. if (parent) {
  14671. parent.replaceChild(newNode, oldNode);
  14672. }
  14673. };
  14674. /**
  14675. * @param {Node} node The node to remove.
  14676. * @returns {Node} The node that was removed or null.
  14677. */
  14678. ol.dom.removeNode = function(node) {
  14679. return node && node.parentNode ? node.parentNode.removeChild(node) : null;
  14680. };
  14681. /**
  14682. * @param {Node} node The node to remove the children from.
  14683. */
  14684. ol.dom.removeChildren = function(node) {
  14685. while (node.lastChild) {
  14686. node.removeChild(node.lastChild);
  14687. }
  14688. };
  14689. goog.provide('ol.layer.Property');
  14690. /**
  14691. * @enum {string}
  14692. */
  14693. ol.layer.Property = {
  14694. OPACITY: 'opacity',
  14695. VISIBLE: 'visible',
  14696. EXTENT: 'extent',
  14697. Z_INDEX: 'zIndex',
  14698. MAX_RESOLUTION: 'maxResolution',
  14699. MIN_RESOLUTION: 'minResolution',
  14700. SOURCE: 'source'
  14701. };
  14702. goog.provide('ol.layer.Base');
  14703. goog.require('ol');
  14704. goog.require('ol.Object');
  14705. goog.require('ol.layer.Property');
  14706. goog.require('ol.math');
  14707. goog.require('ol.obj');
  14708. /**
  14709. * @classdesc
  14710. * Abstract base class; normally only used for creating subclasses and not
  14711. * instantiated in apps.
  14712. * Note that with `ol.layer.Base` and all its subclasses, any property set in
  14713. * the options is set as a {@link ol.Object} property on the layer object, so
  14714. * is observable, and has get/set accessors.
  14715. *
  14716. * @constructor
  14717. * @abstract
  14718. * @extends {ol.Object}
  14719. * @param {olx.layer.BaseOptions} options Layer options.
  14720. * @api
  14721. */
  14722. ol.layer.Base = function(options) {
  14723. ol.Object.call(this);
  14724. /**
  14725. * @type {Object.<string, *>}
  14726. */
  14727. var properties = ol.obj.assign({}, options);
  14728. properties[ol.layer.Property.OPACITY] =
  14729. options.opacity !== undefined ? options.opacity : 1;
  14730. properties[ol.layer.Property.VISIBLE] =
  14731. options.visible !== undefined ? options.visible : true;
  14732. properties[ol.layer.Property.Z_INDEX] =
  14733. options.zIndex !== undefined ? options.zIndex : 0;
  14734. properties[ol.layer.Property.MAX_RESOLUTION] =
  14735. options.maxResolution !== undefined ? options.maxResolution : Infinity;
  14736. properties[ol.layer.Property.MIN_RESOLUTION] =
  14737. options.minResolution !== undefined ? options.minResolution : 0;
  14738. this.setProperties(properties);
  14739. /**
  14740. * @type {ol.LayerState}
  14741. * @private
  14742. */
  14743. this.state_ = /** @type {ol.LayerState} */ ({
  14744. layer: /** @type {ol.layer.Layer} */ (this),
  14745. managed: true
  14746. });
  14747. /**
  14748. * The layer type.
  14749. * @type {ol.LayerType}
  14750. * @protected;
  14751. */
  14752. this.type;
  14753. };
  14754. ol.inherits(ol.layer.Base, ol.Object);
  14755. /**
  14756. * Get the layer type (used when creating a layer renderer).
  14757. * @return {ol.LayerType} The layer type.
  14758. */
  14759. ol.layer.Base.prototype.getType = function() {
  14760. return this.type;
  14761. };
  14762. /**
  14763. * @return {ol.LayerState} Layer state.
  14764. */
  14765. ol.layer.Base.prototype.getLayerState = function() {
  14766. this.state_.opacity = ol.math.clamp(this.getOpacity(), 0, 1);
  14767. this.state_.sourceState = this.getSourceState();
  14768. this.state_.visible = this.getVisible();
  14769. this.state_.extent = this.getExtent();
  14770. this.state_.zIndex = this.getZIndex();
  14771. this.state_.maxResolution = this.getMaxResolution();
  14772. this.state_.minResolution = Math.max(this.getMinResolution(), 0);
  14773. return this.state_;
  14774. };
  14775. /**
  14776. * @abstract
  14777. * @param {Array.<ol.layer.Layer>=} opt_array Array of layers (to be
  14778. * modified in place).
  14779. * @return {Array.<ol.layer.Layer>} Array of layers.
  14780. */
  14781. ol.layer.Base.prototype.getLayersArray = function(opt_array) {};
  14782. /**
  14783. * @abstract
  14784. * @param {Array.<ol.LayerState>=} opt_states Optional list of layer
  14785. * states (to be modified in place).
  14786. * @return {Array.<ol.LayerState>} List of layer states.
  14787. */
  14788. ol.layer.Base.prototype.getLayerStatesArray = function(opt_states) {};
  14789. /**
  14790. * Return the {@link ol.Extent extent} of the layer or `undefined` if it
  14791. * will be visible regardless of extent.
  14792. * @return {ol.Extent|undefined} The layer extent.
  14793. * @observable
  14794. * @api
  14795. */
  14796. ol.layer.Base.prototype.getExtent = function() {
  14797. return /** @type {ol.Extent|undefined} */ (
  14798. this.get(ol.layer.Property.EXTENT));
  14799. };
  14800. /**
  14801. * Return the maximum resolution of the layer.
  14802. * @return {number} The maximum resolution of the layer.
  14803. * @observable
  14804. * @api
  14805. */
  14806. ol.layer.Base.prototype.getMaxResolution = function() {
  14807. return /** @type {number} */ (
  14808. this.get(ol.layer.Property.MAX_RESOLUTION));
  14809. };
  14810. /**
  14811. * Return the minimum resolution of the layer.
  14812. * @return {number} The minimum resolution of the layer.
  14813. * @observable
  14814. * @api
  14815. */
  14816. ol.layer.Base.prototype.getMinResolution = function() {
  14817. return /** @type {number} */ (
  14818. this.get(ol.layer.Property.MIN_RESOLUTION));
  14819. };
  14820. /**
  14821. * Return the opacity of the layer (between 0 and 1).
  14822. * @return {number} The opacity of the layer.
  14823. * @observable
  14824. * @api
  14825. */
  14826. ol.layer.Base.prototype.getOpacity = function() {
  14827. return /** @type {number} */ (this.get(ol.layer.Property.OPACITY));
  14828. };
  14829. /**
  14830. * @abstract
  14831. * @return {ol.source.State} Source state.
  14832. */
  14833. ol.layer.Base.prototype.getSourceState = function() {};
  14834. /**
  14835. * Return the visibility of the layer (`true` or `false`).
  14836. * @return {boolean} The visibility of the layer.
  14837. * @observable
  14838. * @api
  14839. */
  14840. ol.layer.Base.prototype.getVisible = function() {
  14841. return /** @type {boolean} */ (this.get(ol.layer.Property.VISIBLE));
  14842. };
  14843. /**
  14844. * Return the Z-index of the layer, which is used to order layers before
  14845. * rendering. The default Z-index is 0.
  14846. * @return {number} The Z-index of the layer.
  14847. * @observable
  14848. * @api
  14849. */
  14850. ol.layer.Base.prototype.getZIndex = function() {
  14851. return /** @type {number} */ (this.get(ol.layer.Property.Z_INDEX));
  14852. };
  14853. /**
  14854. * Set the extent at which the layer is visible. If `undefined`, the layer
  14855. * will be visible at all extents.
  14856. * @param {ol.Extent|undefined} extent The extent of the layer.
  14857. * @observable
  14858. * @api
  14859. */
  14860. ol.layer.Base.prototype.setExtent = function(extent) {
  14861. this.set(ol.layer.Property.EXTENT, extent);
  14862. };
  14863. /**
  14864. * Set the maximum resolution at which the layer is visible.
  14865. * @param {number} maxResolution The maximum resolution of the layer.
  14866. * @observable
  14867. * @api
  14868. */
  14869. ol.layer.Base.prototype.setMaxResolution = function(maxResolution) {
  14870. this.set(ol.layer.Property.MAX_RESOLUTION, maxResolution);
  14871. };
  14872. /**
  14873. * Set the minimum resolution at which the layer is visible.
  14874. * @param {number} minResolution The minimum resolution of the layer.
  14875. * @observable
  14876. * @api
  14877. */
  14878. ol.layer.Base.prototype.setMinResolution = function(minResolution) {
  14879. this.set(ol.layer.Property.MIN_RESOLUTION, minResolution);
  14880. };
  14881. /**
  14882. * Set the opacity of the layer, allowed values range from 0 to 1.
  14883. * @param {number} opacity The opacity of the layer.
  14884. * @observable
  14885. * @api
  14886. */
  14887. ol.layer.Base.prototype.setOpacity = function(opacity) {
  14888. this.set(ol.layer.Property.OPACITY, opacity);
  14889. };
  14890. /**
  14891. * Set the visibility of the layer (`true` or `false`).
  14892. * @param {boolean} visible The visibility of the layer.
  14893. * @observable
  14894. * @api
  14895. */
  14896. ol.layer.Base.prototype.setVisible = function(visible) {
  14897. this.set(ol.layer.Property.VISIBLE, visible);
  14898. };
  14899. /**
  14900. * Set Z-index of the layer, which is used to order layers before rendering.
  14901. * The default Z-index is 0.
  14902. * @param {number} zindex The z-index of the layer.
  14903. * @observable
  14904. * @api
  14905. */
  14906. ol.layer.Base.prototype.setZIndex = function(zindex) {
  14907. this.set(ol.layer.Property.Z_INDEX, zindex);
  14908. };
  14909. goog.provide('ol.source.State');
  14910. /**
  14911. * State of the source, one of 'undefined', 'loading', 'ready' or 'error'.
  14912. * @enum {string}
  14913. */
  14914. ol.source.State = {
  14915. UNDEFINED: 'undefined',
  14916. LOADING: 'loading',
  14917. READY: 'ready',
  14918. ERROR: 'error'
  14919. };
  14920. goog.provide('ol.layer.Group');
  14921. goog.require('ol');
  14922. goog.require('ol.Collection');
  14923. goog.require('ol.CollectionEventType');
  14924. goog.require('ol.Object');
  14925. goog.require('ol.ObjectEventType');
  14926. goog.require('ol.asserts');
  14927. goog.require('ol.events');
  14928. goog.require('ol.events.EventType');
  14929. goog.require('ol.extent');
  14930. goog.require('ol.layer.Base');
  14931. goog.require('ol.obj');
  14932. goog.require('ol.source.State');
  14933. /**
  14934. * @classdesc
  14935. * A {@link ol.Collection} of layers that are handled together.
  14936. *
  14937. * A generic `change` event is triggered when the group/Collection changes.
  14938. *
  14939. * @constructor
  14940. * @extends {ol.layer.Base}
  14941. * @param {olx.layer.GroupOptions=} opt_options Layer options.
  14942. * @api
  14943. */
  14944. ol.layer.Group = function(opt_options) {
  14945. var options = opt_options || {};
  14946. var baseOptions = /** @type {olx.layer.GroupOptions} */
  14947. (ol.obj.assign({}, options));
  14948. delete baseOptions.layers;
  14949. var layers = options.layers;
  14950. ol.layer.Base.call(this, baseOptions);
  14951. /**
  14952. * @private
  14953. * @type {Array.<ol.EventsKey>}
  14954. */
  14955. this.layersListenerKeys_ = [];
  14956. /**
  14957. * @private
  14958. * @type {Object.<string, Array.<ol.EventsKey>>}
  14959. */
  14960. this.listenerKeys_ = {};
  14961. ol.events.listen(this,
  14962. ol.Object.getChangeEventType(ol.layer.Group.Property_.LAYERS),
  14963. this.handleLayersChanged_, this);
  14964. if (layers) {
  14965. if (Array.isArray(layers)) {
  14966. layers = new ol.Collection(layers.slice(), {unique: true});
  14967. } else {
  14968. ol.asserts.assert(layers instanceof ol.Collection,
  14969. 43); // Expected `layers` to be an array or an `ol.Collection`
  14970. layers = layers;
  14971. }
  14972. } else {
  14973. layers = new ol.Collection(undefined, {unique: true});
  14974. }
  14975. this.setLayers(layers);
  14976. };
  14977. ol.inherits(ol.layer.Group, ol.layer.Base);
  14978. /**
  14979. * @private
  14980. */
  14981. ol.layer.Group.prototype.handleLayerChange_ = function() {
  14982. this.changed();
  14983. };
  14984. /**
  14985. * @param {ol.events.Event} event Event.
  14986. * @private
  14987. */
  14988. ol.layer.Group.prototype.handleLayersChanged_ = function(event) {
  14989. this.layersListenerKeys_.forEach(ol.events.unlistenByKey);
  14990. this.layersListenerKeys_.length = 0;
  14991. var layers = this.getLayers();
  14992. this.layersListenerKeys_.push(
  14993. ol.events.listen(layers, ol.CollectionEventType.ADD,
  14994. this.handleLayersAdd_, this),
  14995. ol.events.listen(layers, ol.CollectionEventType.REMOVE,
  14996. this.handleLayersRemove_, this));
  14997. for (var id in this.listenerKeys_) {
  14998. this.listenerKeys_[id].forEach(ol.events.unlistenByKey);
  14999. }
  15000. ol.obj.clear(this.listenerKeys_);
  15001. var layersArray = layers.getArray();
  15002. var i, ii, layer;
  15003. for (i = 0, ii = layersArray.length; i < ii; i++) {
  15004. layer = layersArray[i];
  15005. this.listenerKeys_[ol.getUid(layer).toString()] = [
  15006. ol.events.listen(layer, ol.ObjectEventType.PROPERTYCHANGE,
  15007. this.handleLayerChange_, this),
  15008. ol.events.listen(layer, ol.events.EventType.CHANGE,
  15009. this.handleLayerChange_, this)
  15010. ];
  15011. }
  15012. this.changed();
  15013. };
  15014. /**
  15015. * @param {ol.Collection.Event} collectionEvent Collection event.
  15016. * @private
  15017. */
  15018. ol.layer.Group.prototype.handleLayersAdd_ = function(collectionEvent) {
  15019. var layer = /** @type {ol.layer.Base} */ (collectionEvent.element);
  15020. var key = ol.getUid(layer).toString();
  15021. this.listenerKeys_[key] = [
  15022. ol.events.listen(layer, ol.ObjectEventType.PROPERTYCHANGE,
  15023. this.handleLayerChange_, this),
  15024. ol.events.listen(layer, ol.events.EventType.CHANGE,
  15025. this.handleLayerChange_, this)
  15026. ];
  15027. this.changed();
  15028. };
  15029. /**
  15030. * @param {ol.Collection.Event} collectionEvent Collection event.
  15031. * @private
  15032. */
  15033. ol.layer.Group.prototype.handleLayersRemove_ = function(collectionEvent) {
  15034. var layer = /** @type {ol.layer.Base} */ (collectionEvent.element);
  15035. var key = ol.getUid(layer).toString();
  15036. this.listenerKeys_[key].forEach(ol.events.unlistenByKey);
  15037. delete this.listenerKeys_[key];
  15038. this.changed();
  15039. };
  15040. /**
  15041. * Returns the {@link ol.Collection collection} of {@link ol.layer.Layer layers}
  15042. * in this group.
  15043. * @return {!ol.Collection.<ol.layer.Base>} Collection of
  15044. * {@link ol.layer.Base layers} that are part of this group.
  15045. * @observable
  15046. * @api
  15047. */
  15048. ol.layer.Group.prototype.getLayers = function() {
  15049. return /** @type {!ol.Collection.<ol.layer.Base>} */ (this.get(
  15050. ol.layer.Group.Property_.LAYERS));
  15051. };
  15052. /**
  15053. * Set the {@link ol.Collection collection} of {@link ol.layer.Layer layers}
  15054. * in this group.
  15055. * @param {!ol.Collection.<ol.layer.Base>} layers Collection of
  15056. * {@link ol.layer.Base layers} that are part of this group.
  15057. * @observable
  15058. * @api
  15059. */
  15060. ol.layer.Group.prototype.setLayers = function(layers) {
  15061. this.set(ol.layer.Group.Property_.LAYERS, layers);
  15062. };
  15063. /**
  15064. * @inheritDoc
  15065. */
  15066. ol.layer.Group.prototype.getLayersArray = function(opt_array) {
  15067. var array = opt_array !== undefined ? opt_array : [];
  15068. this.getLayers().forEach(function(layer) {
  15069. layer.getLayersArray(array);
  15070. });
  15071. return array;
  15072. };
  15073. /**
  15074. * @inheritDoc
  15075. */
  15076. ol.layer.Group.prototype.getLayerStatesArray = function(opt_states) {
  15077. var states = opt_states !== undefined ? opt_states : [];
  15078. var pos = states.length;
  15079. this.getLayers().forEach(function(layer) {
  15080. layer.getLayerStatesArray(states);
  15081. });
  15082. var ownLayerState = this.getLayerState();
  15083. var i, ii, layerState;
  15084. for (i = pos, ii = states.length; i < ii; i++) {
  15085. layerState = states[i];
  15086. layerState.opacity *= ownLayerState.opacity;
  15087. layerState.visible = layerState.visible && ownLayerState.visible;
  15088. layerState.maxResolution = Math.min(
  15089. layerState.maxResolution, ownLayerState.maxResolution);
  15090. layerState.minResolution = Math.max(
  15091. layerState.minResolution, ownLayerState.minResolution);
  15092. if (ownLayerState.extent !== undefined) {
  15093. if (layerState.extent !== undefined) {
  15094. layerState.extent = ol.extent.getIntersection(
  15095. layerState.extent, ownLayerState.extent);
  15096. } else {
  15097. layerState.extent = ownLayerState.extent;
  15098. }
  15099. }
  15100. }
  15101. return states;
  15102. };
  15103. /**
  15104. * @inheritDoc
  15105. */
  15106. ol.layer.Group.prototype.getSourceState = function() {
  15107. return ol.source.State.READY;
  15108. };
  15109. /**
  15110. * @enum {string}
  15111. * @private
  15112. */
  15113. ol.layer.Group.Property_ = {
  15114. LAYERS: 'layers'
  15115. };
  15116. goog.provide('ol.PluginType');
  15117. /**
  15118. * A plugin type used when registering a plugin. The supported plugin types are
  15119. * 'MAP_RENDERER', and 'LAYER_RENDERER'.
  15120. * @enum {string}
  15121. */
  15122. ol.PluginType = {
  15123. MAP_RENDERER: 'MAP_RENDERER',
  15124. LAYER_RENDERER: 'LAYER_RENDERER'
  15125. };
  15126. goog.provide('ol.plugins');
  15127. goog.require('ol.PluginType');
  15128. /**
  15129. * The registry of map renderer plugins.
  15130. * @type {Array<olx.MapRendererPlugin>}
  15131. * @private
  15132. */
  15133. ol.plugins.mapRendererPlugins_ = [];
  15134. /**
  15135. * Get all registered map renderer plugins.
  15136. * @return {Array<olx.MapRendererPlugin>} The registered map renderer plugins.
  15137. */
  15138. ol.plugins.getMapRendererPlugins = function() {
  15139. return ol.plugins.mapRendererPlugins_;
  15140. };
  15141. /**
  15142. * The registry of layer renderer plugins.
  15143. * @type {Array<olx.LayerRendererPlugin>}
  15144. * @private
  15145. */
  15146. ol.plugins.layerRendererPlugins_ = [];
  15147. /**
  15148. * Get all registered layer renderer plugins.
  15149. * @return {Array<olx.LayerRendererPlugin>} The registered layer renderer plugins.
  15150. */
  15151. ol.plugins.getLayerRendererPlugins = function() {
  15152. return ol.plugins.layerRendererPlugins_;
  15153. };
  15154. /**
  15155. * Register a plugin.
  15156. * @param {ol.PluginType} type The plugin type.
  15157. * @param {*} plugin The plugin.
  15158. */
  15159. ol.plugins.register = function(type, plugin) {
  15160. var plugins;
  15161. switch (type) {
  15162. case ol.PluginType.MAP_RENDERER: {
  15163. plugins = ol.plugins.mapRendererPlugins_;
  15164. plugins.push(/** @type {olx.MapRendererPlugin} */ (plugin));
  15165. break;
  15166. }
  15167. case ol.PluginType.LAYER_RENDERER: {
  15168. plugins = ol.plugins.layerRendererPlugins_;
  15169. plugins.push(/** @type {olx.LayerRendererPlugin} */ (plugin));
  15170. break;
  15171. }
  15172. default: {
  15173. throw new Error('Unsupported plugin type: ' + type);
  15174. }
  15175. }
  15176. };
  15177. /**
  15178. * Register multiple plugins.
  15179. * @param {ol.PluginType} type The plugin type.
  15180. * @param {Array} plugins The plugins.
  15181. */
  15182. ol.plugins.registerMultiple = function(type, plugins) {
  15183. for (var i = 0, ii = plugins.length; i < ii; ++i) {
  15184. ol.plugins.register(type, plugins[i]);
  15185. }
  15186. };
  15187. goog.provide('ol.renderer.Type');
  15188. /**
  15189. * Available renderers: `'canvas'` or `'webgl'`.
  15190. * @enum {string}
  15191. */
  15192. ol.renderer.Type = {
  15193. CANVAS: 'canvas',
  15194. WEBGL: 'webgl'
  15195. };
  15196. goog.provide('ol.PluggableMap');
  15197. goog.require('ol');
  15198. goog.require('ol.Collection');
  15199. goog.require('ol.CollectionEventType');
  15200. goog.require('ol.MapBrowserEvent');
  15201. goog.require('ol.MapBrowserEventHandler');
  15202. goog.require('ol.MapBrowserEventType');
  15203. goog.require('ol.MapEvent');
  15204. goog.require('ol.MapEventType');
  15205. goog.require('ol.MapProperty');
  15206. goog.require('ol.Object');
  15207. goog.require('ol.ObjectEventType');
  15208. goog.require('ol.TileQueue');
  15209. goog.require('ol.View');
  15210. goog.require('ol.ViewHint');
  15211. goog.require('ol.asserts');
  15212. goog.require('ol.dom');
  15213. goog.require('ol.events');
  15214. goog.require('ol.events.Event');
  15215. goog.require('ol.events.EventType');
  15216. goog.require('ol.extent');
  15217. goog.require('ol.functions');
  15218. goog.require('ol.has');
  15219. goog.require('ol.layer.Group');
  15220. goog.require('ol.obj');
  15221. goog.require('ol.plugins');
  15222. goog.require('ol.renderer.Type');
  15223. goog.require('ol.size');
  15224. goog.require('ol.structs.PriorityQueue');
  15225. goog.require('ol.transform');
  15226. /**
  15227. * @constructor
  15228. * @extends {ol.Object}
  15229. * @param {olx.MapOptions} options Map options.
  15230. * @fires ol.MapBrowserEvent
  15231. * @fires ol.MapEvent
  15232. * @fires ol.render.Event#postcompose
  15233. * @fires ol.render.Event#precompose
  15234. * @api
  15235. */
  15236. ol.PluggableMap = function(options) {
  15237. ol.Object.call(this);
  15238. var optionsInternal = ol.PluggableMap.createOptionsInternal(options);
  15239. /**
  15240. * @type {boolean}
  15241. * @private
  15242. */
  15243. this.loadTilesWhileAnimating_ =
  15244. options.loadTilesWhileAnimating !== undefined ?
  15245. options.loadTilesWhileAnimating : false;
  15246. /**
  15247. * @type {boolean}
  15248. * @private
  15249. */
  15250. this.loadTilesWhileInteracting_ =
  15251. options.loadTilesWhileInteracting !== undefined ?
  15252. options.loadTilesWhileInteracting : false;
  15253. /**
  15254. * @private
  15255. * @type {number}
  15256. */
  15257. this.pixelRatio_ = options.pixelRatio !== undefined ?
  15258. options.pixelRatio : ol.has.DEVICE_PIXEL_RATIO;
  15259. /**
  15260. * @private
  15261. * @type {Object.<string, string>}
  15262. */
  15263. this.logos_ = optionsInternal.logos;
  15264. /**
  15265. * @private
  15266. * @type {number|undefined}
  15267. */
  15268. this.animationDelayKey_;
  15269. /**
  15270. * @private
  15271. */
  15272. this.animationDelay_ = function() {
  15273. this.animationDelayKey_ = undefined;
  15274. this.renderFrame_.call(this, Date.now());
  15275. }.bind(this);
  15276. /**
  15277. * @private
  15278. * @type {ol.Transform}
  15279. */
  15280. this.coordinateToPixelTransform_ = ol.transform.create();
  15281. /**
  15282. * @private
  15283. * @type {ol.Transform}
  15284. */
  15285. this.pixelToCoordinateTransform_ = ol.transform.create();
  15286. /**
  15287. * @private
  15288. * @type {number}
  15289. */
  15290. this.frameIndex_ = 0;
  15291. /**
  15292. * @private
  15293. * @type {?olx.FrameState}
  15294. */
  15295. this.frameState_ = null;
  15296. /**
  15297. * The extent at the previous 'moveend' event.
  15298. * @private
  15299. * @type {ol.Extent}
  15300. */
  15301. this.previousExtent_ = null;
  15302. /**
  15303. * @private
  15304. * @type {?ol.EventsKey}
  15305. */
  15306. this.viewPropertyListenerKey_ = null;
  15307. /**
  15308. * @private
  15309. * @type {?ol.EventsKey}
  15310. */
  15311. this.viewChangeListenerKey_ = null;
  15312. /**
  15313. * @private
  15314. * @type {Array.<ol.EventsKey>}
  15315. */
  15316. this.layerGroupPropertyListenerKeys_ = null;
  15317. /**
  15318. * @private
  15319. * @type {Element}
  15320. */
  15321. this.viewport_ = document.createElement('DIV');
  15322. this.viewport_.className = 'ol-viewport' + (ol.has.TOUCH ? ' ol-touch' : '');
  15323. this.viewport_.style.position = 'relative';
  15324. this.viewport_.style.overflow = 'hidden';
  15325. this.viewport_.style.width = '100%';
  15326. this.viewport_.style.height = '100%';
  15327. // prevent page zoom on IE >= 10 browsers
  15328. this.viewport_.style.msTouchAction = 'none';
  15329. this.viewport_.style.touchAction = 'none';
  15330. /**
  15331. * @private
  15332. * @type {!Element}
  15333. */
  15334. this.overlayContainer_ = document.createElement('DIV');
  15335. this.overlayContainer_.className = 'ol-overlaycontainer';
  15336. this.viewport_.appendChild(this.overlayContainer_);
  15337. /**
  15338. * @private
  15339. * @type {!Element}
  15340. */
  15341. this.overlayContainerStopEvent_ = document.createElement('DIV');
  15342. this.overlayContainerStopEvent_.className = 'ol-overlaycontainer-stopevent';
  15343. var overlayEvents = [
  15344. ol.events.EventType.CLICK,
  15345. ol.events.EventType.DBLCLICK,
  15346. ol.events.EventType.MOUSEDOWN,
  15347. ol.events.EventType.TOUCHSTART,
  15348. ol.events.EventType.MSPOINTERDOWN,
  15349. ol.MapBrowserEventType.POINTERDOWN,
  15350. ol.events.EventType.MOUSEWHEEL,
  15351. ol.events.EventType.WHEEL
  15352. ];
  15353. for (var i = 0, ii = overlayEvents.length; i < ii; ++i) {
  15354. ol.events.listen(this.overlayContainerStopEvent_, overlayEvents[i],
  15355. ol.events.Event.stopPropagation);
  15356. }
  15357. this.viewport_.appendChild(this.overlayContainerStopEvent_);
  15358. /**
  15359. * @private
  15360. * @type {ol.MapBrowserEventHandler}
  15361. */
  15362. this.mapBrowserEventHandler_ = new ol.MapBrowserEventHandler(this, options.moveTolerance);
  15363. for (var key in ol.MapBrowserEventType) {
  15364. ol.events.listen(this.mapBrowserEventHandler_, ol.MapBrowserEventType[key],
  15365. this.handleMapBrowserEvent, this);
  15366. }
  15367. /**
  15368. * @private
  15369. * @type {Element|Document}
  15370. */
  15371. this.keyboardEventTarget_ = optionsInternal.keyboardEventTarget;
  15372. /**
  15373. * @private
  15374. * @type {Array.<ol.EventsKey>}
  15375. */
  15376. this.keyHandlerKeys_ = null;
  15377. ol.events.listen(this.viewport_, ol.events.EventType.WHEEL,
  15378. this.handleBrowserEvent, this);
  15379. ol.events.listen(this.viewport_, ol.events.EventType.MOUSEWHEEL,
  15380. this.handleBrowserEvent, this);
  15381. /**
  15382. * @type {ol.Collection.<ol.control.Control>}
  15383. * @protected
  15384. */
  15385. this.controls = optionsInternal.controls || new ol.Collection();
  15386. /**
  15387. * @type {ol.Collection.<ol.interaction.Interaction>}
  15388. * @protected
  15389. */
  15390. this.interactions = optionsInternal.interactions || new ol.Collection();
  15391. /**
  15392. * @type {ol.Collection.<ol.Overlay>}
  15393. * @private
  15394. */
  15395. this.overlays_ = optionsInternal.overlays;
  15396. /**
  15397. * A lookup of overlays by id.
  15398. * @private
  15399. * @type {Object.<string, ol.Overlay>}
  15400. */
  15401. this.overlayIdIndex_ = {};
  15402. /**
  15403. * @type {ol.renderer.Map}
  15404. * @private
  15405. */
  15406. this.renderer_ = optionsInternal.mapRendererPlugin['create'](this.viewport_, this);
  15407. /**
  15408. * @type {function(Event)|undefined}
  15409. * @private
  15410. */
  15411. this.handleResize_;
  15412. /**
  15413. * @private
  15414. * @type {ol.Coordinate}
  15415. */
  15416. this.focus_ = null;
  15417. /**
  15418. * @private
  15419. * @type {Array.<ol.PostRenderFunction>}
  15420. */
  15421. this.postRenderFunctions_ = [];
  15422. /**
  15423. * @private
  15424. * @type {ol.TileQueue}
  15425. */
  15426. this.tileQueue_ = new ol.TileQueue(
  15427. this.getTilePriority.bind(this),
  15428. this.handleTileChange_.bind(this));
  15429. /**
  15430. * Uids of features to skip at rendering time.
  15431. * @type {Object.<string, boolean>}
  15432. * @private
  15433. */
  15434. this.skippedFeatureUids_ = {};
  15435. ol.events.listen(
  15436. this, ol.Object.getChangeEventType(ol.MapProperty.LAYERGROUP),
  15437. this.handleLayerGroupChanged_, this);
  15438. ol.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.VIEW),
  15439. this.handleViewChanged_, this);
  15440. ol.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.SIZE),
  15441. this.handleSizeChanged_, this);
  15442. ol.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.TARGET),
  15443. this.handleTargetChanged_, this);
  15444. // setProperties will trigger the rendering of the map if the map
  15445. // is "defined" already.
  15446. this.setProperties(optionsInternal.values);
  15447. this.controls.forEach(
  15448. /**
  15449. * @param {ol.control.Control} control Control.
  15450. * @this {ol.PluggableMap}
  15451. */
  15452. function(control) {
  15453. control.setMap(this);
  15454. }, this);
  15455. ol.events.listen(this.controls, ol.CollectionEventType.ADD,
  15456. /**
  15457. * @param {ol.Collection.Event} event Collection event.
  15458. */
  15459. function(event) {
  15460. event.element.setMap(this);
  15461. }, this);
  15462. ol.events.listen(this.controls, ol.CollectionEventType.REMOVE,
  15463. /**
  15464. * @param {ol.Collection.Event} event Collection event.
  15465. */
  15466. function(event) {
  15467. event.element.setMap(null);
  15468. }, this);
  15469. this.interactions.forEach(
  15470. /**
  15471. * @param {ol.interaction.Interaction} interaction Interaction.
  15472. * @this {ol.PluggableMap}
  15473. */
  15474. function(interaction) {
  15475. interaction.setMap(this);
  15476. }, this);
  15477. ol.events.listen(this.interactions, ol.CollectionEventType.ADD,
  15478. /**
  15479. * @param {ol.Collection.Event} event Collection event.
  15480. */
  15481. function(event) {
  15482. event.element.setMap(this);
  15483. }, this);
  15484. ol.events.listen(this.interactions, ol.CollectionEventType.REMOVE,
  15485. /**
  15486. * @param {ol.Collection.Event} event Collection event.
  15487. */
  15488. function(event) {
  15489. event.element.setMap(null);
  15490. }, this);
  15491. this.overlays_.forEach(this.addOverlayInternal_, this);
  15492. ol.events.listen(this.overlays_, ol.CollectionEventType.ADD,
  15493. /**
  15494. * @param {ol.Collection.Event} event Collection event.
  15495. */
  15496. function(event) {
  15497. this.addOverlayInternal_(/** @type {ol.Overlay} */ (event.element));
  15498. }, this);
  15499. ol.events.listen(this.overlays_, ol.CollectionEventType.REMOVE,
  15500. /**
  15501. * @param {ol.Collection.Event} event Collection event.
  15502. */
  15503. function(event) {
  15504. var overlay = /** @type {ol.Overlay} */ (event.element);
  15505. var id = overlay.getId();
  15506. if (id !== undefined) {
  15507. delete this.overlayIdIndex_[id.toString()];
  15508. }
  15509. event.element.setMap(null);
  15510. }, this);
  15511. };
  15512. ol.inherits(ol.PluggableMap, ol.Object);
  15513. /**
  15514. * Add the given control to the map.
  15515. * @param {ol.control.Control} control Control.
  15516. * @api
  15517. */
  15518. ol.PluggableMap.prototype.addControl = function(control) {
  15519. this.getControls().push(control);
  15520. };
  15521. /**
  15522. * Add the given interaction to the map.
  15523. * @param {ol.interaction.Interaction} interaction Interaction to add.
  15524. * @api
  15525. */
  15526. ol.PluggableMap.prototype.addInteraction = function(interaction) {
  15527. this.getInteractions().push(interaction);
  15528. };
  15529. /**
  15530. * Adds the given layer to the top of this map. If you want to add a layer
  15531. * elsewhere in the stack, use `getLayers()` and the methods available on
  15532. * {@link ol.Collection}.
  15533. * @param {ol.layer.Base} layer Layer.
  15534. * @api
  15535. */
  15536. ol.PluggableMap.prototype.addLayer = function(layer) {
  15537. var layers = this.getLayerGroup().getLayers();
  15538. layers.push(layer);
  15539. };
  15540. /**
  15541. * Add the given overlay to the map.
  15542. * @param {ol.Overlay} overlay Overlay.
  15543. * @api
  15544. */
  15545. ol.PluggableMap.prototype.addOverlay = function(overlay) {
  15546. this.getOverlays().push(overlay);
  15547. };
  15548. /**
  15549. * This deals with map's overlay collection changes.
  15550. * @param {ol.Overlay} overlay Overlay.
  15551. * @private
  15552. */
  15553. ol.PluggableMap.prototype.addOverlayInternal_ = function(overlay) {
  15554. var id = overlay.getId();
  15555. if (id !== undefined) {
  15556. this.overlayIdIndex_[id.toString()] = overlay;
  15557. }
  15558. overlay.setMap(this);
  15559. };
  15560. /**
  15561. *
  15562. * @inheritDoc
  15563. */
  15564. ol.PluggableMap.prototype.disposeInternal = function() {
  15565. this.mapBrowserEventHandler_.dispose();
  15566. ol.events.unlisten(this.viewport_, ol.events.EventType.WHEEL,
  15567. this.handleBrowserEvent, this);
  15568. ol.events.unlisten(this.viewport_, ol.events.EventType.MOUSEWHEEL,
  15569. this.handleBrowserEvent, this);
  15570. if (this.handleResize_ !== undefined) {
  15571. window.removeEventListener(ol.events.EventType.RESIZE,
  15572. this.handleResize_, false);
  15573. this.handleResize_ = undefined;
  15574. }
  15575. if (this.animationDelayKey_) {
  15576. cancelAnimationFrame(this.animationDelayKey_);
  15577. this.animationDelayKey_ = undefined;
  15578. }
  15579. this.setTarget(null);
  15580. ol.Object.prototype.disposeInternal.call(this);
  15581. };
  15582. /**
  15583. * Detect features that intersect a pixel on the viewport, and execute a
  15584. * callback with each intersecting feature. Layers included in the detection can
  15585. * be configured through the `layerFilter` option in `opt_options`.
  15586. * @param {ol.Pixel} pixel Pixel.
  15587. * @param {function(this: S, (ol.Feature|ol.render.Feature),
  15588. * ol.layer.Layer): T} callback Feature callback. The callback will be
  15589. * called with two arguments. The first argument is one
  15590. * {@link ol.Feature feature} or
  15591. * {@link ol.render.Feature render feature} at the pixel, the second is
  15592. * the {@link ol.layer.Layer layer} of the feature and will be null for
  15593. * unmanaged layers. To stop detection, callback functions can return a
  15594. * truthy value.
  15595. * @param {olx.AtPixelOptions=} opt_options Optional options.
  15596. * @return {T|undefined} Callback result, i.e. the return value of last
  15597. * callback execution, or the first truthy callback return value.
  15598. * @template S,T
  15599. * @api
  15600. */
  15601. ol.PluggableMap.prototype.forEachFeatureAtPixel = function(pixel, callback, opt_options) {
  15602. if (!this.frameState_) {
  15603. return;
  15604. }
  15605. var coordinate = this.getCoordinateFromPixel(pixel);
  15606. opt_options = opt_options !== undefined ? opt_options : {};
  15607. var hitTolerance = opt_options.hitTolerance !== undefined ?
  15608. opt_options.hitTolerance * this.frameState_.pixelRatio : 0;
  15609. var layerFilter = opt_options.layerFilter !== undefined ?
  15610. opt_options.layerFilter : ol.functions.TRUE;
  15611. return this.renderer_.forEachFeatureAtCoordinate(
  15612. coordinate, this.frameState_, hitTolerance, callback, null,
  15613. layerFilter, null);
  15614. };
  15615. /**
  15616. * Get all features that intersect a pixel on the viewport.
  15617. * @param {ol.Pixel} pixel Pixel.
  15618. * @param {olx.AtPixelOptions=} opt_options Optional options.
  15619. * @return {Array.<ol.Feature|ol.render.Feature>} The detected features or
  15620. * `null` if none were found.
  15621. * @api
  15622. */
  15623. ol.PluggableMap.prototype.getFeaturesAtPixel = function(pixel, opt_options) {
  15624. var features = null;
  15625. this.forEachFeatureAtPixel(pixel, function(feature) {
  15626. if (!features) {
  15627. features = [];
  15628. }
  15629. features.push(feature);
  15630. }, opt_options);
  15631. return features;
  15632. };
  15633. /**
  15634. * Detect layers that have a color value at a pixel on the viewport, and
  15635. * execute a callback with each matching layer. Layers included in the
  15636. * detection can be configured through `opt_layerFilter`.
  15637. * @param {ol.Pixel} pixel Pixel.
  15638. * @param {function(this: S, ol.layer.Layer, (Uint8ClampedArray|Uint8Array)): T} callback
  15639. * Layer callback. This callback will receive two arguments: first is the
  15640. * {@link ol.layer.Layer layer}, second argument is an array representing
  15641. * [R, G, B, A] pixel values (0 - 255) and will be `null` for layer types
  15642. * that do not currently support this argument. To stop detection, callback
  15643. * functions can return a truthy value.
  15644. * @param {S=} opt_this Value to use as `this` when executing `callback`.
  15645. * @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
  15646. * filter function. The filter function will receive one argument, the
  15647. * {@link ol.layer.Layer layer-candidate} and it should return a boolean
  15648. * value. Only layers which are visible and for which this function returns
  15649. * `true` will be tested for features. By default, all visible layers will
  15650. * be tested.
  15651. * @param {U=} opt_this2 Value to use as `this` when executing `layerFilter`.
  15652. * @return {T|undefined} Callback result, i.e. the return value of last
  15653. * callback execution, or the first truthy callback return value.
  15654. * @template S,T,U
  15655. * @api
  15656. */
  15657. ol.PluggableMap.prototype.forEachLayerAtPixel = function(pixel, callback, opt_this, opt_layerFilter, opt_this2) {
  15658. if (!this.frameState_) {
  15659. return;
  15660. }
  15661. var thisArg = opt_this !== undefined ? opt_this : null;
  15662. var layerFilter = opt_layerFilter !== undefined ?
  15663. opt_layerFilter : ol.functions.TRUE;
  15664. var thisArg2 = opt_this2 !== undefined ? opt_this2 : null;
  15665. return this.renderer_.forEachLayerAtPixel(
  15666. pixel, this.frameState_, callback, thisArg,
  15667. layerFilter, thisArg2);
  15668. };
  15669. /**
  15670. * Detect if features intersect a pixel on the viewport. Layers included in the
  15671. * detection can be configured through `opt_layerFilter`.
  15672. * @param {ol.Pixel} pixel Pixel.
  15673. * @param {olx.AtPixelOptions=} opt_options Optional options.
  15674. * @return {boolean} Is there a feature at the given pixel?
  15675. * @template U
  15676. * @api
  15677. */
  15678. ol.PluggableMap.prototype.hasFeatureAtPixel = function(pixel, opt_options) {
  15679. if (!this.frameState_) {
  15680. return false;
  15681. }
  15682. var coordinate = this.getCoordinateFromPixel(pixel);
  15683. opt_options = opt_options !== undefined ? opt_options : {};
  15684. var layerFilter = opt_options.layerFilter !== undefined ?
  15685. opt_options.layerFilter : ol.functions.TRUE;
  15686. var hitTolerance = opt_options.hitTolerance !== undefined ?
  15687. opt_options.hitTolerance * this.frameState_.pixelRatio : 0;
  15688. return this.renderer_.hasFeatureAtCoordinate(
  15689. coordinate, this.frameState_, hitTolerance, layerFilter, null);
  15690. };
  15691. /**
  15692. * Returns the coordinate in view projection for a browser event.
  15693. * @param {Event} event Event.
  15694. * @return {ol.Coordinate} Coordinate.
  15695. * @api
  15696. */
  15697. ol.PluggableMap.prototype.getEventCoordinate = function(event) {
  15698. return this.getCoordinateFromPixel(this.getEventPixel(event));
  15699. };
  15700. /**
  15701. * Returns the map pixel position for a browser event relative to the viewport.
  15702. * @param {Event} event Event.
  15703. * @return {ol.Pixel} Pixel.
  15704. * @api
  15705. */
  15706. ol.PluggableMap.prototype.getEventPixel = function(event) {
  15707. var viewportPosition = this.viewport_.getBoundingClientRect();
  15708. var eventPosition = event.changedTouches ? event.changedTouches[0] : event;
  15709. return [
  15710. eventPosition.clientX - viewportPosition.left,
  15711. eventPosition.clientY - viewportPosition.top
  15712. ];
  15713. };
  15714. /**
  15715. * Get the target in which this map is rendered.
  15716. * Note that this returns what is entered as an option or in setTarget:
  15717. * if that was an element, it returns an element; if a string, it returns that.
  15718. * @return {Element|string|undefined} The Element or id of the Element that the
  15719. * map is rendered in.
  15720. * @observable
  15721. * @api
  15722. */
  15723. ol.PluggableMap.prototype.getTarget = function() {
  15724. return /** @type {Element|string|undefined} */ (
  15725. this.get(ol.MapProperty.TARGET));
  15726. };
  15727. /**
  15728. * Get the DOM element into which this map is rendered. In contrast to
  15729. * `getTarget` this method always return an `Element`, or `null` if the
  15730. * map has no target.
  15731. * @return {Element} The element that the map is rendered in.
  15732. * @api
  15733. */
  15734. ol.PluggableMap.prototype.getTargetElement = function() {
  15735. var target = this.getTarget();
  15736. if (target !== undefined) {
  15737. return typeof target === 'string' ?
  15738. document.getElementById(target) :
  15739. target;
  15740. } else {
  15741. return null;
  15742. }
  15743. };
  15744. /**
  15745. * Get the coordinate for a given pixel. This returns a coordinate in the
  15746. * map view projection.
  15747. * @param {ol.Pixel} pixel Pixel position in the map viewport.
  15748. * @return {ol.Coordinate} The coordinate for the pixel position.
  15749. * @api
  15750. */
  15751. ol.PluggableMap.prototype.getCoordinateFromPixel = function(pixel) {
  15752. var frameState = this.frameState_;
  15753. if (!frameState) {
  15754. return null;
  15755. } else {
  15756. return ol.transform.apply(frameState.pixelToCoordinateTransform, pixel.slice());
  15757. }
  15758. };
  15759. /**
  15760. * Get the map controls. Modifying this collection changes the controls
  15761. * associated with the map.
  15762. * @return {ol.Collection.<ol.control.Control>} Controls.
  15763. * @api
  15764. */
  15765. ol.PluggableMap.prototype.getControls = function() {
  15766. return this.controls;
  15767. };
  15768. /**
  15769. * Get the map overlays. Modifying this collection changes the overlays
  15770. * associated with the map.
  15771. * @return {ol.Collection.<ol.Overlay>} Overlays.
  15772. * @api
  15773. */
  15774. ol.PluggableMap.prototype.getOverlays = function() {
  15775. return this.overlays_;
  15776. };
  15777. /**
  15778. * Get an overlay by its identifier (the value returned by overlay.getId()).
  15779. * Note that the index treats string and numeric identifiers as the same. So
  15780. * `map.getOverlayById(2)` will return an overlay with id `'2'` or `2`.
  15781. * @param {string|number} id Overlay identifier.
  15782. * @return {ol.Overlay} Overlay.
  15783. * @api
  15784. */
  15785. ol.PluggableMap.prototype.getOverlayById = function(id) {
  15786. var overlay = this.overlayIdIndex_[id.toString()];
  15787. return overlay !== undefined ? overlay : null;
  15788. };
  15789. /**
  15790. * Get the map interactions. Modifying this collection changes the interactions
  15791. * associated with the map.
  15792. *
  15793. * Interactions are used for e.g. pan, zoom and rotate.
  15794. * @return {ol.Collection.<ol.interaction.Interaction>} Interactions.
  15795. * @api
  15796. */
  15797. ol.PluggableMap.prototype.getInteractions = function() {
  15798. return this.interactions;
  15799. };
  15800. /**
  15801. * Get the layergroup associated with this map.
  15802. * @return {ol.layer.Group} A layer group containing the layers in this map.
  15803. * @observable
  15804. * @api
  15805. */
  15806. ol.PluggableMap.prototype.getLayerGroup = function() {
  15807. return /** @type {ol.layer.Group} */ (this.get(ol.MapProperty.LAYERGROUP));
  15808. };
  15809. /**
  15810. * Get the collection of layers associated with this map.
  15811. * @return {!ol.Collection.<ol.layer.Base>} Layers.
  15812. * @api
  15813. */
  15814. ol.PluggableMap.prototype.getLayers = function() {
  15815. var layers = this.getLayerGroup().getLayers();
  15816. return layers;
  15817. };
  15818. /**
  15819. * Get the pixel for a coordinate. This takes a coordinate in the map view
  15820. * projection and returns the corresponding pixel.
  15821. * @param {ol.Coordinate} coordinate A map coordinate.
  15822. * @return {ol.Pixel} A pixel position in the map viewport.
  15823. * @api
  15824. */
  15825. ol.PluggableMap.prototype.getPixelFromCoordinate = function(coordinate) {
  15826. var frameState = this.frameState_;
  15827. if (!frameState) {
  15828. return null;
  15829. } else {
  15830. return ol.transform.apply(frameState.coordinateToPixelTransform,
  15831. coordinate.slice(0, 2));
  15832. }
  15833. };
  15834. /**
  15835. * Get the map renderer.
  15836. * @return {ol.renderer.Map} Renderer
  15837. */
  15838. ol.PluggableMap.prototype.getRenderer = function() {
  15839. return this.renderer_;
  15840. };
  15841. /**
  15842. * Get the size of this map.
  15843. * @return {ol.Size|undefined} The size in pixels of the map in the DOM.
  15844. * @observable
  15845. * @api
  15846. */
  15847. ol.PluggableMap.prototype.getSize = function() {
  15848. return /** @type {ol.Size|undefined} */ (this.get(ol.MapProperty.SIZE));
  15849. };
  15850. /**
  15851. * Get the view associated with this map. A view manages properties such as
  15852. * center and resolution.
  15853. * @return {ol.View} The view that controls this map.
  15854. * @observable
  15855. * @api
  15856. */
  15857. ol.PluggableMap.prototype.getView = function() {
  15858. return /** @type {ol.View} */ (this.get(ol.MapProperty.VIEW));
  15859. };
  15860. /**
  15861. * Get the element that serves as the map viewport.
  15862. * @return {Element} Viewport.
  15863. * @api
  15864. */
  15865. ol.PluggableMap.prototype.getViewport = function() {
  15866. return this.viewport_;
  15867. };
  15868. /**
  15869. * Get the element that serves as the container for overlays. Elements added to
  15870. * this container will let mousedown and touchstart events through to the map,
  15871. * so clicks and gestures on an overlay will trigger {@link ol.MapBrowserEvent}
  15872. * events.
  15873. * @return {!Element} The map's overlay container.
  15874. */
  15875. ol.PluggableMap.prototype.getOverlayContainer = function() {
  15876. return this.overlayContainer_;
  15877. };
  15878. /**
  15879. * Get the element that serves as a container for overlays that don't allow
  15880. * event propagation. Elements added to this container won't let mousedown and
  15881. * touchstart events through to the map, so clicks and gestures on an overlay
  15882. * don't trigger any {@link ol.MapBrowserEvent}.
  15883. * @return {!Element} The map's overlay container that stops events.
  15884. */
  15885. ol.PluggableMap.prototype.getOverlayContainerStopEvent = function() {
  15886. return this.overlayContainerStopEvent_;
  15887. };
  15888. /**
  15889. * @param {ol.Tile} tile Tile.
  15890. * @param {string} tileSourceKey Tile source key.
  15891. * @param {ol.Coordinate} tileCenter Tile center.
  15892. * @param {number} tileResolution Tile resolution.
  15893. * @return {number} Tile priority.
  15894. */
  15895. ol.PluggableMap.prototype.getTilePriority = function(tile, tileSourceKey, tileCenter, tileResolution) {
  15896. // Filter out tiles at higher zoom levels than the current zoom level, or that
  15897. // are outside the visible extent.
  15898. var frameState = this.frameState_;
  15899. if (!frameState || !(tileSourceKey in frameState.wantedTiles)) {
  15900. return ol.structs.PriorityQueue.DROP;
  15901. }
  15902. if (!frameState.wantedTiles[tileSourceKey][tile.getKey()]) {
  15903. return ol.structs.PriorityQueue.DROP;
  15904. }
  15905. // Prioritize the highest zoom level tiles closest to the focus.
  15906. // Tiles at higher zoom levels are prioritized using Math.log(tileResolution).
  15907. // Within a zoom level, tiles are prioritized by the distance in pixels
  15908. // between the center of the tile and the focus. The factor of 65536 means
  15909. // that the prioritization should behave as desired for tiles up to
  15910. // 65536 * Math.log(2) = 45426 pixels from the focus.
  15911. var deltaX = tileCenter[0] - frameState.focus[0];
  15912. var deltaY = tileCenter[1] - frameState.focus[1];
  15913. return 65536 * Math.log(tileResolution) +
  15914. Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
  15915. };
  15916. /**
  15917. * @param {Event} browserEvent Browser event.
  15918. * @param {string=} opt_type Type.
  15919. */
  15920. ol.PluggableMap.prototype.handleBrowserEvent = function(browserEvent, opt_type) {
  15921. var type = opt_type || browserEvent.type;
  15922. var mapBrowserEvent = new ol.MapBrowserEvent(type, this, browserEvent);
  15923. this.handleMapBrowserEvent(mapBrowserEvent);
  15924. };
  15925. /**
  15926. * @param {ol.MapBrowserEvent} mapBrowserEvent The event to handle.
  15927. */
  15928. ol.PluggableMap.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
  15929. if (!this.frameState_) {
  15930. // With no view defined, we cannot translate pixels into geographical
  15931. // coordinates so interactions cannot be used.
  15932. return;
  15933. }
  15934. this.focus_ = mapBrowserEvent.coordinate;
  15935. mapBrowserEvent.frameState = this.frameState_;
  15936. var interactionsArray = this.getInteractions().getArray();
  15937. var i;
  15938. if (this.dispatchEvent(mapBrowserEvent) !== false) {
  15939. for (i = interactionsArray.length - 1; i >= 0; i--) {
  15940. var interaction = interactionsArray[i];
  15941. if (!interaction.getActive()) {
  15942. continue;
  15943. }
  15944. var cont = interaction.handleEvent(mapBrowserEvent);
  15945. if (!cont) {
  15946. break;
  15947. }
  15948. }
  15949. }
  15950. };
  15951. /**
  15952. * @protected
  15953. */
  15954. ol.PluggableMap.prototype.handlePostRender = function() {
  15955. var frameState = this.frameState_;
  15956. // Manage the tile queue
  15957. // Image loads are expensive and a limited resource, so try to use them
  15958. // efficiently:
  15959. // * When the view is static we allow a large number of parallel tile loads
  15960. // to complete the frame as quickly as possible.
  15961. // * When animating or interacting, image loads can cause janks, so we reduce
  15962. // the maximum number of loads per frame and limit the number of parallel
  15963. // tile loads to remain reactive to view changes and to reduce the chance of
  15964. // loading tiles that will quickly disappear from view.
  15965. var tileQueue = this.tileQueue_;
  15966. if (!tileQueue.isEmpty()) {
  15967. var maxTotalLoading = 16;
  15968. var maxNewLoads = maxTotalLoading;
  15969. if (frameState) {
  15970. var hints = frameState.viewHints;
  15971. if (hints[ol.ViewHint.ANIMATING]) {
  15972. maxTotalLoading = this.loadTilesWhileAnimating_ ? 8 : 0;
  15973. maxNewLoads = 2;
  15974. }
  15975. if (hints[ol.ViewHint.INTERACTING]) {
  15976. maxTotalLoading = this.loadTilesWhileInteracting_ ? 8 : 0;
  15977. maxNewLoads = 2;
  15978. }
  15979. }
  15980. if (tileQueue.getTilesLoading() < maxTotalLoading) {
  15981. tileQueue.reprioritize(); // FIXME only call if view has changed
  15982. tileQueue.loadMoreTiles(maxTotalLoading, maxNewLoads);
  15983. }
  15984. }
  15985. var postRenderFunctions = this.postRenderFunctions_;
  15986. var i, ii;
  15987. for (i = 0, ii = postRenderFunctions.length; i < ii; ++i) {
  15988. postRenderFunctions[i](this, frameState);
  15989. }
  15990. postRenderFunctions.length = 0;
  15991. };
  15992. /**
  15993. * @private
  15994. */
  15995. ol.PluggableMap.prototype.handleSizeChanged_ = function() {
  15996. this.render();
  15997. };
  15998. /**
  15999. * @private
  16000. */
  16001. ol.PluggableMap.prototype.handleTargetChanged_ = function() {
  16002. // target may be undefined, null, a string or an Element.
  16003. // If it's a string we convert it to an Element before proceeding.
  16004. // If it's not now an Element we remove the viewport from the DOM.
  16005. // If it's an Element we append the viewport element to it.
  16006. var targetElement;
  16007. if (this.getTarget()) {
  16008. targetElement = this.getTargetElement();
  16009. }
  16010. if (this.keyHandlerKeys_) {
  16011. for (var i = 0, ii = this.keyHandlerKeys_.length; i < ii; ++i) {
  16012. ol.events.unlistenByKey(this.keyHandlerKeys_[i]);
  16013. }
  16014. this.keyHandlerKeys_ = null;
  16015. }
  16016. if (!targetElement) {
  16017. this.renderer_.removeLayerRenderers();
  16018. ol.dom.removeNode(this.viewport_);
  16019. if (this.handleResize_ !== undefined) {
  16020. window.removeEventListener(ol.events.EventType.RESIZE,
  16021. this.handleResize_, false);
  16022. this.handleResize_ = undefined;
  16023. }
  16024. } else {
  16025. targetElement.appendChild(this.viewport_);
  16026. var keyboardEventTarget = !this.keyboardEventTarget_ ?
  16027. targetElement : this.keyboardEventTarget_;
  16028. this.keyHandlerKeys_ = [
  16029. ol.events.listen(keyboardEventTarget, ol.events.EventType.KEYDOWN,
  16030. this.handleBrowserEvent, this),
  16031. ol.events.listen(keyboardEventTarget, ol.events.EventType.KEYPRESS,
  16032. this.handleBrowserEvent, this)
  16033. ];
  16034. if (!this.handleResize_) {
  16035. this.handleResize_ = this.updateSize.bind(this);
  16036. window.addEventListener(ol.events.EventType.RESIZE,
  16037. this.handleResize_, false);
  16038. }
  16039. }
  16040. this.updateSize();
  16041. // updateSize calls setSize, so no need to call this.render
  16042. // ourselves here.
  16043. };
  16044. /**
  16045. * @private
  16046. */
  16047. ol.PluggableMap.prototype.handleTileChange_ = function() {
  16048. this.render();
  16049. };
  16050. /**
  16051. * @private
  16052. */
  16053. ol.PluggableMap.prototype.handleViewPropertyChanged_ = function() {
  16054. this.render();
  16055. };
  16056. /**
  16057. * @private
  16058. */
  16059. ol.PluggableMap.prototype.handleViewChanged_ = function() {
  16060. if (this.viewPropertyListenerKey_) {
  16061. ol.events.unlistenByKey(this.viewPropertyListenerKey_);
  16062. this.viewPropertyListenerKey_ = null;
  16063. }
  16064. if (this.viewChangeListenerKey_) {
  16065. ol.events.unlistenByKey(this.viewChangeListenerKey_);
  16066. this.viewChangeListenerKey_ = null;
  16067. }
  16068. var view = this.getView();
  16069. if (view) {
  16070. this.viewport_.setAttribute('data-view', ol.getUid(view));
  16071. this.viewPropertyListenerKey_ = ol.events.listen(
  16072. view, ol.ObjectEventType.PROPERTYCHANGE,
  16073. this.handleViewPropertyChanged_, this);
  16074. this.viewChangeListenerKey_ = ol.events.listen(
  16075. view, ol.events.EventType.CHANGE,
  16076. this.handleViewPropertyChanged_, this);
  16077. }
  16078. this.render();
  16079. };
  16080. /**
  16081. * @private
  16082. */
  16083. ol.PluggableMap.prototype.handleLayerGroupChanged_ = function() {
  16084. if (this.layerGroupPropertyListenerKeys_) {
  16085. this.layerGroupPropertyListenerKeys_.forEach(ol.events.unlistenByKey);
  16086. this.layerGroupPropertyListenerKeys_ = null;
  16087. }
  16088. var layerGroup = this.getLayerGroup();
  16089. if (layerGroup) {
  16090. this.layerGroupPropertyListenerKeys_ = [
  16091. ol.events.listen(
  16092. layerGroup, ol.ObjectEventType.PROPERTYCHANGE,
  16093. this.render, this),
  16094. ol.events.listen(
  16095. layerGroup, ol.events.EventType.CHANGE,
  16096. this.render, this)
  16097. ];
  16098. }
  16099. this.render();
  16100. };
  16101. /**
  16102. * @return {boolean} Is rendered.
  16103. */
  16104. ol.PluggableMap.prototype.isRendered = function() {
  16105. return !!this.frameState_;
  16106. };
  16107. /**
  16108. * Requests an immediate render in a synchronous manner.
  16109. * @api
  16110. */
  16111. ol.PluggableMap.prototype.renderSync = function() {
  16112. if (this.animationDelayKey_) {
  16113. cancelAnimationFrame(this.animationDelayKey_);
  16114. }
  16115. this.animationDelay_();
  16116. };
  16117. /**
  16118. * Request a map rendering (at the next animation frame).
  16119. * @api
  16120. */
  16121. ol.PluggableMap.prototype.render = function() {
  16122. if (this.animationDelayKey_ === undefined) {
  16123. this.animationDelayKey_ = requestAnimationFrame(
  16124. this.animationDelay_);
  16125. }
  16126. };
  16127. /**
  16128. * Remove the given control from the map.
  16129. * @param {ol.control.Control} control Control.
  16130. * @return {ol.control.Control|undefined} The removed control (or undefined
  16131. * if the control was not found).
  16132. * @api
  16133. */
  16134. ol.PluggableMap.prototype.removeControl = function(control) {
  16135. return this.getControls().remove(control);
  16136. };
  16137. /**
  16138. * Remove the given interaction from the map.
  16139. * @param {ol.interaction.Interaction} interaction Interaction to remove.
  16140. * @return {ol.interaction.Interaction|undefined} The removed interaction (or
  16141. * undefined if the interaction was not found).
  16142. * @api
  16143. */
  16144. ol.PluggableMap.prototype.removeInteraction = function(interaction) {
  16145. return this.getInteractions().remove(interaction);
  16146. };
  16147. /**
  16148. * Removes the given layer from the map.
  16149. * @param {ol.layer.Base} layer Layer.
  16150. * @return {ol.layer.Base|undefined} The removed layer (or undefined if the
  16151. * layer was not found).
  16152. * @api
  16153. */
  16154. ol.PluggableMap.prototype.removeLayer = function(layer) {
  16155. var layers = this.getLayerGroup().getLayers();
  16156. return layers.remove(layer);
  16157. };
  16158. /**
  16159. * Remove the given overlay from the map.
  16160. * @param {ol.Overlay} overlay Overlay.
  16161. * @return {ol.Overlay|undefined} The removed overlay (or undefined
  16162. * if the overlay was not found).
  16163. * @api
  16164. */
  16165. ol.PluggableMap.prototype.removeOverlay = function(overlay) {
  16166. return this.getOverlays().remove(overlay);
  16167. };
  16168. /**
  16169. * @param {number} time Time.
  16170. * @private
  16171. */
  16172. ol.PluggableMap.prototype.renderFrame_ = function(time) {
  16173. var i, ii, viewState;
  16174. var size = this.getSize();
  16175. var view = this.getView();
  16176. var extent = ol.extent.createEmpty();
  16177. var previousFrameState = this.frameState_;
  16178. /** @type {?olx.FrameState} */
  16179. var frameState = null;
  16180. if (size !== undefined && ol.size.hasArea(size) && view && view.isDef()) {
  16181. var viewHints = view.getHints(this.frameState_ ? this.frameState_.viewHints : undefined);
  16182. var layerStatesArray = this.getLayerGroup().getLayerStatesArray();
  16183. var layerStates = {};
  16184. for (i = 0, ii = layerStatesArray.length; i < ii; ++i) {
  16185. layerStates[ol.getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
  16186. }
  16187. viewState = view.getState();
  16188. var center = viewState.center;
  16189. var pixelResolution = viewState.resolution / this.pixelRatio_;
  16190. center[0] = Math.round(center[0] / pixelResolution) * pixelResolution;
  16191. center[1] = Math.round(center[1] / pixelResolution) * pixelResolution;
  16192. frameState = /** @type {olx.FrameState} */ ({
  16193. animate: false,
  16194. coordinateToPixelTransform: this.coordinateToPixelTransform_,
  16195. extent: extent,
  16196. focus: !this.focus_ ? center : this.focus_,
  16197. index: this.frameIndex_++,
  16198. layerStates: layerStates,
  16199. layerStatesArray: layerStatesArray,
  16200. logos: ol.obj.assign({}, this.logos_),
  16201. pixelRatio: this.pixelRatio_,
  16202. pixelToCoordinateTransform: this.pixelToCoordinateTransform_,
  16203. postRenderFunctions: [],
  16204. size: size,
  16205. skippedFeatureUids: this.skippedFeatureUids_,
  16206. tileQueue: this.tileQueue_,
  16207. time: time,
  16208. usedTiles: {},
  16209. viewState: viewState,
  16210. viewHints: viewHints,
  16211. wantedTiles: {}
  16212. });
  16213. }
  16214. if (frameState) {
  16215. frameState.extent = ol.extent.getForViewAndSize(viewState.center,
  16216. viewState.resolution, viewState.rotation, frameState.size, extent);
  16217. }
  16218. this.frameState_ = frameState;
  16219. this.renderer_.renderFrame(frameState);
  16220. if (frameState) {
  16221. if (frameState.animate) {
  16222. this.render();
  16223. }
  16224. Array.prototype.push.apply(
  16225. this.postRenderFunctions_, frameState.postRenderFunctions);
  16226. if (previousFrameState) {
  16227. var moveStart = !this.previousExtent_ ||
  16228. (!ol.extent.isEmpty(this.previousExtent_) &&
  16229. !ol.extent.equals(frameState.extent, this.previousExtent_));
  16230. if (moveStart) {
  16231. this.dispatchEvent(
  16232. new ol.MapEvent(ol.MapEventType.MOVESTART, this, previousFrameState));
  16233. this.previousExtent_ = ol.extent.createOrUpdateEmpty(this.previousExtent_);
  16234. }
  16235. }
  16236. var idle = this.previousExtent_ &&
  16237. !frameState.viewHints[ol.ViewHint.ANIMATING] &&
  16238. !frameState.viewHints[ol.ViewHint.INTERACTING] &&
  16239. !ol.extent.equals(frameState.extent, this.previousExtent_);
  16240. if (idle) {
  16241. this.dispatchEvent(
  16242. new ol.MapEvent(ol.MapEventType.MOVEEND, this, frameState));
  16243. ol.extent.clone(frameState.extent, this.previousExtent_);
  16244. }
  16245. }
  16246. this.dispatchEvent(
  16247. new ol.MapEvent(ol.MapEventType.POSTRENDER, this, frameState));
  16248. setTimeout(this.handlePostRender.bind(this), 0);
  16249. };
  16250. /**
  16251. * Sets the layergroup of this map.
  16252. * @param {ol.layer.Group} layerGroup A layer group containing the layers in
  16253. * this map.
  16254. * @observable
  16255. * @api
  16256. */
  16257. ol.PluggableMap.prototype.setLayerGroup = function(layerGroup) {
  16258. this.set(ol.MapProperty.LAYERGROUP, layerGroup);
  16259. };
  16260. /**
  16261. * Set the size of this map.
  16262. * @param {ol.Size|undefined} size The size in pixels of the map in the DOM.
  16263. * @observable
  16264. * @api
  16265. */
  16266. ol.PluggableMap.prototype.setSize = function(size) {
  16267. this.set(ol.MapProperty.SIZE, size);
  16268. };
  16269. /**
  16270. * Set the target element to render this map into.
  16271. * @param {Element|string|undefined} target The Element or id of the Element
  16272. * that the map is rendered in.
  16273. * @observable
  16274. * @api
  16275. */
  16276. ol.PluggableMap.prototype.setTarget = function(target) {
  16277. this.set(ol.MapProperty.TARGET, target);
  16278. };
  16279. /**
  16280. * Set the view for this map.
  16281. * @param {ol.View} view The view that controls this map.
  16282. * @observable
  16283. * @api
  16284. */
  16285. ol.PluggableMap.prototype.setView = function(view) {
  16286. this.set(ol.MapProperty.VIEW, view);
  16287. };
  16288. /**
  16289. * @param {ol.Feature} feature Feature.
  16290. */
  16291. ol.PluggableMap.prototype.skipFeature = function(feature) {
  16292. var featureUid = ol.getUid(feature).toString();
  16293. this.skippedFeatureUids_[featureUid] = true;
  16294. this.render();
  16295. };
  16296. /**
  16297. * Force a recalculation of the map viewport size. This should be called when
  16298. * third-party code changes the size of the map viewport.
  16299. * @api
  16300. */
  16301. ol.PluggableMap.prototype.updateSize = function() {
  16302. var targetElement = this.getTargetElement();
  16303. if (!targetElement) {
  16304. this.setSize(undefined);
  16305. } else {
  16306. var computedStyle = getComputedStyle(targetElement);
  16307. this.setSize([
  16308. targetElement.offsetWidth -
  16309. parseFloat(computedStyle['borderLeftWidth']) -
  16310. parseFloat(computedStyle['paddingLeft']) -
  16311. parseFloat(computedStyle['paddingRight']) -
  16312. parseFloat(computedStyle['borderRightWidth']),
  16313. targetElement.offsetHeight -
  16314. parseFloat(computedStyle['borderTopWidth']) -
  16315. parseFloat(computedStyle['paddingTop']) -
  16316. parseFloat(computedStyle['paddingBottom']) -
  16317. parseFloat(computedStyle['borderBottomWidth'])
  16318. ]);
  16319. }
  16320. };
  16321. /**
  16322. * @param {ol.Feature} feature Feature.
  16323. */
  16324. ol.PluggableMap.prototype.unskipFeature = function(feature) {
  16325. var featureUid = ol.getUid(feature).toString();
  16326. delete this.skippedFeatureUids_[featureUid];
  16327. this.render();
  16328. };
  16329. /**
  16330. * @type {Array.<ol.renderer.Type>}
  16331. * @const
  16332. */
  16333. ol.PluggableMap.DEFAULT_RENDERER_TYPES = [
  16334. ol.renderer.Type.CANVAS,
  16335. ol.renderer.Type.WEBGL
  16336. ];
  16337. /**
  16338. * @const
  16339. * @type {string}
  16340. */
  16341. ol.PluggableMap.LOGO_URL = 'data:image/png;base64,' +
  16342. 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAA3NCSVQICAjb4U/gAAAACXBI' +
  16343. 'WXMAAAHGAAABxgEXwfpGAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAA' +
  16344. 'AhNQTFRF////AP//AICAgP//AFVVQECA////K1VVSbbbYL/fJ05idsTYJFtbbcjbJllmZszW' +
  16345. 'WMTOIFhoHlNiZszTa9DdUcHNHlNlV8XRIVdiasrUHlZjIVZjaMnVH1RlIFRkH1RkH1ZlasvY' +
  16346. 'asvXVsPQH1VkacnVa8vWIVZjIFRjVMPQa8rXIVVkXsXRsNveIFVkIFZlIVVj3eDeh6GmbMvX' +
  16347. 'H1ZkIFRka8rWbMvXIFVkIFVjIFVkbMvWH1VjbMvWIFVlbcvWIFVla8vVIFVkbMvWbMvVH1Vk' +
  16348. 'bMvWIFVlbcvWIFVkbcvVbMvWjNPbIFVkU8LPwMzNIFVkbczWIFVkbsvWbMvXIFVkRnB8bcvW' +
  16349. '2+TkW8XRIFVkIlZlJVloJlpoKlxrLl9tMmJwOWd0Omh1RXF8TneCT3iDUHiDU8LPVMLPVcLP' +
  16350. 'VcPQVsPPVsPQV8PQWMTQWsTQW8TQXMXSXsXRX4SNX8bSYMfTYcfTYsfTY8jUZcfSZsnUaIqT' +
  16351. 'acrVasrVa8jTa8rWbI2VbMvWbcvWdJObdcvUdszUd8vVeJaee87Yfc3WgJyjhqGnitDYjaar' +
  16352. 'ldPZnrK2oNbborW5o9bbo9fbpLa6q9ndrL3ArtndscDDutzfu8fJwN7gwt7gxc/QyuHhy+Hi' +
  16353. 'zeHi0NfX0+Pj19zb1+Tj2uXk29/e3uLg3+Lh3+bl4uXj4ufl4+fl5Ofl5ufl5ujm5+jmySDn' +
  16354. 'BAAAAFp0Uk5TAAECAgMEBAYHCA0NDg4UGRogIiMmKSssLzU7PkJJT1JTVFliY2hrdHZ3foSF' +
  16355. 'hYeJjY2QkpugqbG1tre5w8zQ09XY3uXn6+zx8vT09vf4+Pj5+fr6/P39/f3+gz7SsAAAAVVJ' +
  16356. 'REFUOMtjYKA7EBDnwCPLrObS1BRiLoJLnte6CQy8FLHLCzs2QUG4FjZ5GbcmBDDjxJBXDWxC' +
  16357. 'Brb8aM4zbkIDzpLYnAcE9VXlJSWlZRU13koIeW57mGx5XjoMZEUqwxWYQaQbSzLSkYGfKFSe' +
  16358. '0QMsX5WbjgY0YS4MBplemI4BdGBW+DQ11eZiymfqQuXZIjqwyadPNoSZ4L+0FVM6e+oGI6g8' +
  16359. 'a9iKNT3o8kVzNkzRg5lgl7p4wyRUL9Yt2jAxVh6mQCogae6GmflI8p0r13VFWTHBQ0rWPW7a' +
  16360. 'hgWVcPm+9cuLoyy4kCJDzCm6d8PSFoh0zvQNC5OjDJhQopPPJqph1doJBUD5tnkbZiUEqaCn' +
  16361. 'B3bTqLTFG1bPn71kw4b+GFdpLElKIzRxxgYgWNYc5SCENVHKeUaltHdXx0dZ8uBI1hJ2UUDg' +
  16362. 'q82CM2MwKeibqAvSO7MCABq0wXEPiqWEAAAAAElFTkSuQmCC';
  16363. /**
  16364. * @param {olx.MapOptions} options Map options.
  16365. * @return {ol.MapOptionsInternal} Internal map options.
  16366. */
  16367. ol.PluggableMap.createOptionsInternal = function(options) {
  16368. /**
  16369. * @type {Element|Document}
  16370. */
  16371. var keyboardEventTarget = null;
  16372. if (options.keyboardEventTarget !== undefined) {
  16373. keyboardEventTarget = typeof options.keyboardEventTarget === 'string' ?
  16374. document.getElementById(options.keyboardEventTarget) :
  16375. options.keyboardEventTarget;
  16376. }
  16377. /**
  16378. * @type {Object.<string, *>}
  16379. */
  16380. var values = {};
  16381. var logos = {};
  16382. if (options.logo === undefined ||
  16383. (typeof options.logo === 'boolean' && options.logo)) {
  16384. logos[ol.PluggableMap.LOGO_URL] = 'https://openlayers.org/';
  16385. } else {
  16386. var logo = options.logo;
  16387. if (typeof logo === 'string') {
  16388. logos[logo] = '';
  16389. } else if (logo instanceof HTMLElement) {
  16390. logos[ol.getUid(logo).toString()] = logo;
  16391. } else if (logo) {
  16392. ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
  16393. ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
  16394. logos[logo.src] = logo.href;
  16395. }
  16396. }
  16397. var layerGroup = (options.layers instanceof ol.layer.Group) ?
  16398. options.layers : new ol.layer.Group({layers: options.layers});
  16399. values[ol.MapProperty.LAYERGROUP] = layerGroup;
  16400. values[ol.MapProperty.TARGET] = options.target;
  16401. values[ol.MapProperty.VIEW] = options.view !== undefined ?
  16402. options.view : new ol.View();
  16403. /**
  16404. * @type {Array.<ol.renderer.Type>}
  16405. */
  16406. var rendererTypes;
  16407. if (options.renderer !== undefined) {
  16408. if (Array.isArray(options.renderer)) {
  16409. rendererTypes = options.renderer;
  16410. } else if (typeof options.renderer === 'string') {
  16411. rendererTypes = [options.renderer];
  16412. } else {
  16413. ol.asserts.assert(false, 46); // Incorrect format for `renderer` option
  16414. }
  16415. if (rendererTypes.indexOf(/** @type {ol.renderer.Type} */ ('dom')) >= 0) {
  16416. rendererTypes = rendererTypes.concat(ol.PluggableMap.DEFAULT_RENDERER_TYPES);
  16417. }
  16418. } else {
  16419. rendererTypes = ol.PluggableMap.DEFAULT_RENDERER_TYPES;
  16420. }
  16421. /**
  16422. * @type {olx.MapRendererPlugin}
  16423. */
  16424. var mapRendererPlugin;
  16425. var mapRendererPlugins = ol.plugins.getMapRendererPlugins();
  16426. outer: for (var i = 0, ii = rendererTypes.length; i < ii; ++i) {
  16427. var rendererType = rendererTypes[i];
  16428. for (var j = 0, jj = mapRendererPlugins.length; j < jj; ++j) {
  16429. var candidate = mapRendererPlugins[j];
  16430. if (candidate['handles'](rendererType)) {
  16431. mapRendererPlugin = candidate;
  16432. break outer;
  16433. }
  16434. }
  16435. }
  16436. if (!mapRendererPlugin) {
  16437. throw new Error('Unable to create a map renderer for types: ' + rendererTypes.join(', '));
  16438. }
  16439. var controls;
  16440. if (options.controls !== undefined) {
  16441. if (Array.isArray(options.controls)) {
  16442. controls = new ol.Collection(options.controls.slice());
  16443. } else {
  16444. ol.asserts.assert(options.controls instanceof ol.Collection,
  16445. 47); // Expected `controls` to be an array or an `ol.Collection`
  16446. controls = options.controls;
  16447. }
  16448. }
  16449. var interactions;
  16450. if (options.interactions !== undefined) {
  16451. if (Array.isArray(options.interactions)) {
  16452. interactions = new ol.Collection(options.interactions.slice());
  16453. } else {
  16454. ol.asserts.assert(options.interactions instanceof ol.Collection,
  16455. 48); // Expected `interactions` to be an array or an `ol.Collection`
  16456. interactions = options.interactions;
  16457. }
  16458. }
  16459. var overlays;
  16460. if (options.overlays !== undefined) {
  16461. if (Array.isArray(options.overlays)) {
  16462. overlays = new ol.Collection(options.overlays.slice());
  16463. } else {
  16464. ol.asserts.assert(options.overlays instanceof ol.Collection,
  16465. 49); // Expected `overlays` to be an array or an `ol.Collection`
  16466. overlays = options.overlays;
  16467. }
  16468. } else {
  16469. overlays = new ol.Collection();
  16470. }
  16471. return {
  16472. controls: controls,
  16473. interactions: interactions,
  16474. keyboardEventTarget: keyboardEventTarget,
  16475. logos: logos,
  16476. overlays: overlays,
  16477. mapRendererPlugin: mapRendererPlugin,
  16478. values: values
  16479. };
  16480. };
  16481. goog.provide('ol.control.Control');
  16482. goog.require('ol');
  16483. goog.require('ol.MapEventType');
  16484. goog.require('ol.Object');
  16485. goog.require('ol.dom');
  16486. goog.require('ol.events');
  16487. /**
  16488. * @classdesc
  16489. * A control is a visible widget with a DOM element in a fixed position on the
  16490. * screen. They can involve user input (buttons), or be informational only;
  16491. * the position is determined using CSS. By default these are placed in the
  16492. * container with CSS class name `ol-overlaycontainer-stopevent`, but can use
  16493. * any outside DOM element.
  16494. *
  16495. * This is the base class for controls. You can use it for simple custom
  16496. * controls by creating the element with listeners, creating an instance:
  16497. * ```js
  16498. * var myControl = new ol.control.Control({element: myElement});
  16499. * ```
  16500. * and then adding this to the map.
  16501. *
  16502. * The main advantage of having this as a control rather than a simple separate
  16503. * DOM element is that preventing propagation is handled for you. Controls
  16504. * will also be `ol.Object`s in a `ol.Collection`, so you can use their
  16505. * methods.
  16506. *
  16507. * You can also extend this base for your own control class. See
  16508. * examples/custom-controls for an example of how to do this.
  16509. *
  16510. * @constructor
  16511. * @extends {ol.Object}
  16512. * @implements {oli.control.Control}
  16513. * @param {olx.control.ControlOptions} options Control options.
  16514. * @api
  16515. */
  16516. ol.control.Control = function(options) {
  16517. ol.Object.call(this);
  16518. /**
  16519. * @protected
  16520. * @type {Element}
  16521. */
  16522. this.element = options.element ? options.element : null;
  16523. /**
  16524. * @private
  16525. * @type {Element}
  16526. */
  16527. this.target_ = null;
  16528. /**
  16529. * @private
  16530. * @type {ol.PluggableMap}
  16531. */
  16532. this.map_ = null;
  16533. /**
  16534. * @protected
  16535. * @type {!Array.<ol.EventsKey>}
  16536. */
  16537. this.listenerKeys = [];
  16538. /**
  16539. * @type {function(ol.MapEvent)}
  16540. */
  16541. this.render = options.render ? options.render : ol.nullFunction;
  16542. if (options.target) {
  16543. this.setTarget(options.target);
  16544. }
  16545. };
  16546. ol.inherits(ol.control.Control, ol.Object);
  16547. /**
  16548. * @inheritDoc
  16549. */
  16550. ol.control.Control.prototype.disposeInternal = function() {
  16551. ol.dom.removeNode(this.element);
  16552. ol.Object.prototype.disposeInternal.call(this);
  16553. };
  16554. /**
  16555. * Get the map associated with this control.
  16556. * @return {ol.PluggableMap} Map.
  16557. * @api
  16558. */
  16559. ol.control.Control.prototype.getMap = function() {
  16560. return this.map_;
  16561. };
  16562. /**
  16563. * Remove the control from its current map and attach it to the new map.
  16564. * Subclasses may set up event handlers to get notified about changes to
  16565. * the map here.
  16566. * @param {ol.PluggableMap} map Map.
  16567. * @override
  16568. * @api
  16569. */
  16570. ol.control.Control.prototype.setMap = function(map) {
  16571. if (this.map_) {
  16572. ol.dom.removeNode(this.element);
  16573. }
  16574. for (var i = 0, ii = this.listenerKeys.length; i < ii; ++i) {
  16575. ol.events.unlistenByKey(this.listenerKeys[i]);
  16576. }
  16577. this.listenerKeys.length = 0;
  16578. this.map_ = map;
  16579. if (this.map_) {
  16580. var target = this.target_ ?
  16581. this.target_ : map.getOverlayContainerStopEvent();
  16582. target.appendChild(this.element);
  16583. if (this.render !== ol.nullFunction) {
  16584. this.listenerKeys.push(ol.events.listen(map,
  16585. ol.MapEventType.POSTRENDER, this.render, this));
  16586. }
  16587. map.render();
  16588. }
  16589. };
  16590. /**
  16591. * This function is used to set a target element for the control. It has no
  16592. * effect if it is called after the control has been added to the map (i.e.
  16593. * after `setMap` is called on the control). If no `target` is set in the
  16594. * options passed to the control constructor and if `setTarget` is not called
  16595. * then the control is added to the map's overlay container.
  16596. * @param {Element|string} target Target.
  16597. * @api
  16598. */
  16599. ol.control.Control.prototype.setTarget = function(target) {
  16600. this.target_ = typeof target === 'string' ?
  16601. document.getElementById(target) :
  16602. target;
  16603. };
  16604. goog.provide('ol.css');
  16605. /**
  16606. * The CSS class for hidden feature.
  16607. *
  16608. * @const
  16609. * @type {string}
  16610. */
  16611. ol.css.CLASS_HIDDEN = 'ol-hidden';
  16612. /**
  16613. * The CSS class that we'll give the DOM elements to have them selectable.
  16614. *
  16615. * @const
  16616. * @type {string}
  16617. */
  16618. ol.css.CLASS_SELECTABLE = 'ol-selectable';
  16619. /**
  16620. * The CSS class that we'll give the DOM elements to have them unselectable.
  16621. *
  16622. * @const
  16623. * @type {string}
  16624. */
  16625. ol.css.CLASS_UNSELECTABLE = 'ol-unselectable';
  16626. /**
  16627. * The CSS class for unsupported feature.
  16628. *
  16629. * @const
  16630. * @type {string}
  16631. */
  16632. ol.css.CLASS_UNSUPPORTED = 'ol-unsupported';
  16633. /**
  16634. * The CSS class for controls.
  16635. *
  16636. * @const
  16637. * @type {string}
  16638. */
  16639. ol.css.CLASS_CONTROL = 'ol-control';
  16640. /**
  16641. * Get the list of font families from a font spec. Note that this doesn't work
  16642. * for font families that have commas in them.
  16643. * @param {string} The CSS font property.
  16644. * @return {Object.<string>} The font families (or null if the input spec is invalid).
  16645. */
  16646. ol.css.getFontFamilies = (function() {
  16647. var style;
  16648. var cache = {};
  16649. return function(font) {
  16650. if (!style) {
  16651. style = document.createElement('div').style;
  16652. }
  16653. if (!(font in cache)) {
  16654. style.font = font;
  16655. var family = style.fontFamily;
  16656. style.font = '';
  16657. if (!family) {
  16658. return null;
  16659. }
  16660. cache[font] = family.split(/,\s?/);
  16661. }
  16662. return cache[font];
  16663. };
  16664. })();
  16665. goog.provide('ol.render.EventType');
  16666. /**
  16667. * @enum {string}
  16668. */
  16669. ol.render.EventType = {
  16670. /**
  16671. * @event ol.render.Event#postcompose
  16672. * @api
  16673. */
  16674. POSTCOMPOSE: 'postcompose',
  16675. /**
  16676. * @event ol.render.Event#precompose
  16677. * @api
  16678. */
  16679. PRECOMPOSE: 'precompose',
  16680. /**
  16681. * @event ol.render.Event#render
  16682. * @api
  16683. */
  16684. RENDER: 'render'
  16685. };
  16686. goog.provide('ol.layer.Layer');
  16687. goog.require('ol.events');
  16688. goog.require('ol.events.EventType');
  16689. goog.require('ol');
  16690. goog.require('ol.Object');
  16691. goog.require('ol.layer.Base');
  16692. goog.require('ol.layer.Property');
  16693. goog.require('ol.obj');
  16694. goog.require('ol.render.EventType');
  16695. goog.require('ol.source.State');
  16696. /**
  16697. * @classdesc
  16698. * Abstract base class; normally only used for creating subclasses and not
  16699. * instantiated in apps.
  16700. * A visual representation of raster or vector map data.
  16701. * Layers group together those properties that pertain to how the data is to be
  16702. * displayed, irrespective of the source of that data.
  16703. *
  16704. * Layers are usually added to a map with {@link ol.Map#addLayer}. Components
  16705. * like {@link ol.interaction.Select} use unmanaged layers internally. These
  16706. * unmanaged layers are associated with the map using
  16707. * {@link ol.layer.Layer#setMap} instead.
  16708. *
  16709. * A generic `change` event is fired when the state of the source changes.
  16710. *
  16711. * @constructor
  16712. * @abstract
  16713. * @extends {ol.layer.Base}
  16714. * @fires ol.render.Event
  16715. * @param {olx.layer.LayerOptions} options Layer options.
  16716. * @api
  16717. */
  16718. ol.layer.Layer = function(options) {
  16719. var baseOptions = ol.obj.assign({}, options);
  16720. delete baseOptions.source;
  16721. ol.layer.Base.call(this, /** @type {olx.layer.BaseOptions} */ (baseOptions));
  16722. /**
  16723. * @private
  16724. * @type {?ol.EventsKey}
  16725. */
  16726. this.mapPrecomposeKey_ = null;
  16727. /**
  16728. * @private
  16729. * @type {?ol.EventsKey}
  16730. */
  16731. this.mapRenderKey_ = null;
  16732. /**
  16733. * @private
  16734. * @type {?ol.EventsKey}
  16735. */
  16736. this.sourceChangeKey_ = null;
  16737. if (options.map) {
  16738. this.setMap(options.map);
  16739. }
  16740. ol.events.listen(this,
  16741. ol.Object.getChangeEventType(ol.layer.Property.SOURCE),
  16742. this.handleSourcePropertyChange_, this);
  16743. var source = options.source ? options.source : null;
  16744. this.setSource(source);
  16745. };
  16746. ol.inherits(ol.layer.Layer, ol.layer.Base);
  16747. /**
  16748. * Return `true` if the layer is visible, and if the passed resolution is
  16749. * between the layer's minResolution and maxResolution. The comparison is
  16750. * inclusive for `minResolution` and exclusive for `maxResolution`.
  16751. * @param {ol.LayerState} layerState Layer state.
  16752. * @param {number} resolution Resolution.
  16753. * @return {boolean} The layer is visible at the given resolution.
  16754. */
  16755. ol.layer.Layer.visibleAtResolution = function(layerState, resolution) {
  16756. return layerState.visible && resolution >= layerState.minResolution &&
  16757. resolution < layerState.maxResolution;
  16758. };
  16759. /**
  16760. * @inheritDoc
  16761. */
  16762. ol.layer.Layer.prototype.getLayersArray = function(opt_array) {
  16763. var array = opt_array ? opt_array : [];
  16764. array.push(this);
  16765. return array;
  16766. };
  16767. /**
  16768. * @inheritDoc
  16769. */
  16770. ol.layer.Layer.prototype.getLayerStatesArray = function(opt_states) {
  16771. var states = opt_states ? opt_states : [];
  16772. states.push(this.getLayerState());
  16773. return states;
  16774. };
  16775. /**
  16776. * Get the layer source.
  16777. * @return {ol.source.Source} The layer source (or `null` if not yet set).
  16778. * @observable
  16779. * @api
  16780. */
  16781. ol.layer.Layer.prototype.getSource = function() {
  16782. var source = this.get(ol.layer.Property.SOURCE);
  16783. return /** @type {ol.source.Source} */ (source) || null;
  16784. };
  16785. /**
  16786. * @inheritDoc
  16787. */
  16788. ol.layer.Layer.prototype.getSourceState = function() {
  16789. var source = this.getSource();
  16790. return !source ? ol.source.State.UNDEFINED : source.getState();
  16791. };
  16792. /**
  16793. * @private
  16794. */
  16795. ol.layer.Layer.prototype.handleSourceChange_ = function() {
  16796. this.changed();
  16797. };
  16798. /**
  16799. * @private
  16800. */
  16801. ol.layer.Layer.prototype.handleSourcePropertyChange_ = function() {
  16802. if (this.sourceChangeKey_) {
  16803. ol.events.unlistenByKey(this.sourceChangeKey_);
  16804. this.sourceChangeKey_ = null;
  16805. }
  16806. var source = this.getSource();
  16807. if (source) {
  16808. this.sourceChangeKey_ = ol.events.listen(source,
  16809. ol.events.EventType.CHANGE, this.handleSourceChange_, this);
  16810. }
  16811. this.changed();
  16812. };
  16813. /**
  16814. * Sets the layer to be rendered on top of other layers on a map. The map will
  16815. * not manage this layer in its layers collection, and the callback in
  16816. * {@link ol.Map#forEachLayerAtPixel} will receive `null` as layer. This
  16817. * is useful for temporary layers. To remove an unmanaged layer from the map,
  16818. * use `#setMap(null)`.
  16819. *
  16820. * To add the layer to a map and have it managed by the map, use
  16821. * {@link ol.Map#addLayer} instead.
  16822. * @param {ol.PluggableMap} map Map.
  16823. * @api
  16824. */
  16825. ol.layer.Layer.prototype.setMap = function(map) {
  16826. if (this.mapPrecomposeKey_) {
  16827. ol.events.unlistenByKey(this.mapPrecomposeKey_);
  16828. this.mapPrecomposeKey_ = null;
  16829. }
  16830. if (!map) {
  16831. this.changed();
  16832. }
  16833. if (this.mapRenderKey_) {
  16834. ol.events.unlistenByKey(this.mapRenderKey_);
  16835. this.mapRenderKey_ = null;
  16836. }
  16837. if (map) {
  16838. this.mapPrecomposeKey_ = ol.events.listen(
  16839. map, ol.render.EventType.PRECOMPOSE, function(evt) {
  16840. var layerState = this.getLayerState();
  16841. layerState.managed = false;
  16842. layerState.zIndex = Infinity;
  16843. evt.frameState.layerStatesArray.push(layerState);
  16844. evt.frameState.layerStates[ol.getUid(this)] = layerState;
  16845. }, this);
  16846. this.mapRenderKey_ = ol.events.listen(
  16847. this, ol.events.EventType.CHANGE, map.render, map);
  16848. this.changed();
  16849. }
  16850. };
  16851. /**
  16852. * Set the layer source.
  16853. * @param {ol.source.Source} source The layer source.
  16854. * @observable
  16855. * @api
  16856. */
  16857. ol.layer.Layer.prototype.setSource = function(source) {
  16858. this.set(ol.layer.Property.SOURCE, source);
  16859. };
  16860. // FIXME handle date line wrap
  16861. goog.provide('ol.control.Attribution');
  16862. goog.require('ol');
  16863. goog.require('ol.array');
  16864. goog.require('ol.control.Control');
  16865. goog.require('ol.css');
  16866. goog.require('ol.dom');
  16867. goog.require('ol.events');
  16868. goog.require('ol.events.EventType');
  16869. goog.require('ol.layer.Layer');
  16870. goog.require('ol.obj');
  16871. /**
  16872. * @classdesc
  16873. * Control to show all the attributions associated with the layer sources
  16874. * in the map. This control is one of the default controls included in maps.
  16875. * By default it will show in the bottom right portion of the map, but this can
  16876. * be changed by using a css selector for `.ol-attribution`.
  16877. *
  16878. * @constructor
  16879. * @extends {ol.control.Control}
  16880. * @param {olx.control.AttributionOptions=} opt_options Attribution options.
  16881. * @api
  16882. */
  16883. ol.control.Attribution = function(opt_options) {
  16884. var options = opt_options ? opt_options : {};
  16885. /**
  16886. * @private
  16887. * @type {Element}
  16888. */
  16889. this.ulElement_ = document.createElement('UL');
  16890. /**
  16891. * @private
  16892. * @type {Element}
  16893. */
  16894. this.logoLi_ = document.createElement('LI');
  16895. this.ulElement_.appendChild(this.logoLi_);
  16896. this.logoLi_.style.display = 'none';
  16897. /**
  16898. * @private
  16899. * @type {boolean}
  16900. */
  16901. this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true;
  16902. /**
  16903. * @private
  16904. * @type {boolean}
  16905. */
  16906. this.collapsible_ = options.collapsible !== undefined ?
  16907. options.collapsible : true;
  16908. if (!this.collapsible_) {
  16909. this.collapsed_ = false;
  16910. }
  16911. var className = options.className !== undefined ? options.className : 'ol-attribution';
  16912. var tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Attributions';
  16913. var collapseLabel = options.collapseLabel !== undefined ? options.collapseLabel : '\u00BB';
  16914. if (typeof collapseLabel === 'string') {
  16915. /**
  16916. * @private
  16917. * @type {Node}
  16918. */
  16919. this.collapseLabel_ = document.createElement('span');
  16920. this.collapseLabel_.textContent = collapseLabel;
  16921. } else {
  16922. this.collapseLabel_ = collapseLabel;
  16923. }
  16924. var label = options.label !== undefined ? options.label : 'i';
  16925. if (typeof label === 'string') {
  16926. /**
  16927. * @private
  16928. * @type {Node}
  16929. */
  16930. this.label_ = document.createElement('span');
  16931. this.label_.textContent = label;
  16932. } else {
  16933. this.label_ = label;
  16934. }
  16935. var activeLabel = (this.collapsible_ && !this.collapsed_) ?
  16936. this.collapseLabel_ : this.label_;
  16937. var button = document.createElement('button');
  16938. button.setAttribute('type', 'button');
  16939. button.title = tipLabel;
  16940. button.appendChild(activeLabel);
  16941. ol.events.listen(button, ol.events.EventType.CLICK, this.handleClick_, this);
  16942. var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
  16943. ol.css.CLASS_CONTROL +
  16944. (this.collapsed_ && this.collapsible_ ? ' ol-collapsed' : '') +
  16945. (this.collapsible_ ? '' : ' ol-uncollapsible');
  16946. var element = document.createElement('div');
  16947. element.className = cssClasses;
  16948. element.appendChild(this.ulElement_);
  16949. element.appendChild(button);
  16950. var render = options.render ? options.render : ol.control.Attribution.render;
  16951. ol.control.Control.call(this, {
  16952. element: element,
  16953. render: render,
  16954. target: options.target
  16955. });
  16956. /**
  16957. * A list of currently rendered resolutions.
  16958. * @type {Array.<string>}
  16959. * @private
  16960. */
  16961. this.renderedAttributions_ = [];
  16962. /**
  16963. * @private
  16964. * @type {boolean}
  16965. */
  16966. this.renderedVisible_ = true;
  16967. /**
  16968. * @private
  16969. * @type {Object.<string, Element>}
  16970. */
  16971. this.logoElements_ = {};
  16972. };
  16973. ol.inherits(ol.control.Attribution, ol.control.Control);
  16974. /**
  16975. * Get a list of visible attributions.
  16976. * @param {olx.FrameState} frameState Frame state.
  16977. * @return {Array.<string>} Attributions.
  16978. * @private
  16979. */
  16980. ol.control.Attribution.prototype.getSourceAttributions_ = function(frameState) {
  16981. /**
  16982. * Used to determine if an attribution already exists.
  16983. * @type {Object.<string, boolean>}
  16984. */
  16985. var lookup = {};
  16986. /**
  16987. * A list of visible attributions.
  16988. * @type {Array.<string>}
  16989. */
  16990. var visibleAttributions = [];
  16991. var layerStatesArray = frameState.layerStatesArray;
  16992. var resolution = frameState.viewState.resolution;
  16993. for (var i = 0, ii = layerStatesArray.length; i < ii; ++i) {
  16994. var layerState = layerStatesArray[i];
  16995. if (!ol.layer.Layer.visibleAtResolution(layerState, resolution)) {
  16996. continue;
  16997. }
  16998. var source = layerState.layer.getSource();
  16999. if (!source) {
  17000. continue;
  17001. }
  17002. var attributionGetter = source.getAttributions2();
  17003. if (!attributionGetter) {
  17004. continue;
  17005. }
  17006. var attributions = attributionGetter(frameState);
  17007. if (!attributions) {
  17008. continue;
  17009. }
  17010. if (Array.isArray(attributions)) {
  17011. for (var j = 0, jj = attributions.length; j < jj; ++j) {
  17012. if (!(attributions[j] in lookup)) {
  17013. visibleAttributions.push(attributions[j]);
  17014. lookup[attributions[j]] = true;
  17015. }
  17016. }
  17017. } else {
  17018. if (!(attributions in lookup)) {
  17019. visibleAttributions.push(attributions);
  17020. lookup[attributions] = true;
  17021. }
  17022. }
  17023. }
  17024. return visibleAttributions;
  17025. };
  17026. /**
  17027. * Update the attribution element.
  17028. * @param {ol.MapEvent} mapEvent Map event.
  17029. * @this {ol.control.Attribution}
  17030. * @api
  17031. */
  17032. ol.control.Attribution.render = function(mapEvent) {
  17033. this.updateElement_(mapEvent.frameState);
  17034. };
  17035. /**
  17036. * @private
  17037. * @param {?olx.FrameState} frameState Frame state.
  17038. */
  17039. ol.control.Attribution.prototype.updateElement_ = function(frameState) {
  17040. if (!frameState) {
  17041. if (this.renderedVisible_) {
  17042. this.element.style.display = 'none';
  17043. this.renderedVisible_ = false;
  17044. }
  17045. return;
  17046. }
  17047. var attributions = this.getSourceAttributions_(frameState);
  17048. if (ol.array.equals(attributions, this.renderedAttributions_)) {
  17049. return;
  17050. }
  17051. // remove everything but the logo
  17052. while (this.ulElement_.lastChild !== this.logoLi_) {
  17053. this.ulElement_.removeChild(this.ulElement_.lastChild);
  17054. }
  17055. // append the attributions
  17056. for (var i = 0, ii = attributions.length; i < ii; ++i) {
  17057. var element = document.createElement('LI');
  17058. element.innerHTML = attributions[i];
  17059. this.ulElement_.appendChild(element);
  17060. }
  17061. if (attributions.length === 0 && this.renderedAttributions_.length > 0) {
  17062. this.element.classList.add('ol-logo-only');
  17063. } else if (this.renderedAttributions_.length === 0 && attributions.length > 0) {
  17064. this.element.classList.remove('ol-logo-only');
  17065. }
  17066. var visible = attributions.length > 0 || !ol.obj.isEmpty(frameState.logos);
  17067. if (this.renderedVisible_ != visible) {
  17068. this.element.style.display = visible ? '' : 'none';
  17069. this.renderedVisible_ = visible;
  17070. }
  17071. this.renderedAttributions_ = attributions;
  17072. this.insertLogos_(frameState);
  17073. };
  17074. /**
  17075. * @param {?olx.FrameState} frameState Frame state.
  17076. * @private
  17077. */
  17078. ol.control.Attribution.prototype.insertLogos_ = function(frameState) {
  17079. var logo;
  17080. var logos = frameState.logos;
  17081. var logoElements = this.logoElements_;
  17082. for (logo in logoElements) {
  17083. if (!(logo in logos)) {
  17084. ol.dom.removeNode(logoElements[logo]);
  17085. delete logoElements[logo];
  17086. }
  17087. }
  17088. var image, logoElement, logoKey;
  17089. for (logoKey in logos) {
  17090. var logoValue = logos[logoKey];
  17091. if (logoValue instanceof HTMLElement) {
  17092. this.logoLi_.appendChild(logoValue);
  17093. logoElements[logoKey] = logoValue;
  17094. }
  17095. if (!(logoKey in logoElements)) {
  17096. image = new Image();
  17097. image.src = logoKey;
  17098. if (logoValue === '') {
  17099. logoElement = image;
  17100. } else {
  17101. logoElement = document.createElement('a');
  17102. logoElement.href = logoValue;
  17103. logoElement.appendChild(image);
  17104. }
  17105. this.logoLi_.appendChild(logoElement);
  17106. logoElements[logoKey] = logoElement;
  17107. }
  17108. }
  17109. this.logoLi_.style.display = !ol.obj.isEmpty(logos) ? '' : 'none';
  17110. };
  17111. /**
  17112. * @param {Event} event The event to handle
  17113. * @private
  17114. */
  17115. ol.control.Attribution.prototype.handleClick_ = function(event) {
  17116. event.preventDefault();
  17117. this.handleToggle_();
  17118. };
  17119. /**
  17120. * @private
  17121. */
  17122. ol.control.Attribution.prototype.handleToggle_ = function() {
  17123. this.element.classList.toggle('ol-collapsed');
  17124. if (this.collapsed_) {
  17125. ol.dom.replaceNode(this.collapseLabel_, this.label_);
  17126. } else {
  17127. ol.dom.replaceNode(this.label_, this.collapseLabel_);
  17128. }
  17129. this.collapsed_ = !this.collapsed_;
  17130. };
  17131. /**
  17132. * Return `true` if the attribution is collapsible, `false` otherwise.
  17133. * @return {boolean} True if the widget is collapsible.
  17134. * @api
  17135. */
  17136. ol.control.Attribution.prototype.getCollapsible = function() {
  17137. return this.collapsible_;
  17138. };
  17139. /**
  17140. * Set whether the attribution should be collapsible.
  17141. * @param {boolean} collapsible True if the widget is collapsible.
  17142. * @api
  17143. */
  17144. ol.control.Attribution.prototype.setCollapsible = function(collapsible) {
  17145. if (this.collapsible_ === collapsible) {
  17146. return;
  17147. }
  17148. this.collapsible_ = collapsible;
  17149. this.element.classList.toggle('ol-uncollapsible');
  17150. if (!collapsible && this.collapsed_) {
  17151. this.handleToggle_();
  17152. }
  17153. };
  17154. /**
  17155. * Collapse or expand the attribution according to the passed parameter. Will
  17156. * not do anything if the attribution isn't collapsible or if the current
  17157. * collapsed state is already the one requested.
  17158. * @param {boolean} collapsed True if the widget is collapsed.
  17159. * @api
  17160. */
  17161. ol.control.Attribution.prototype.setCollapsed = function(collapsed) {
  17162. if (!this.collapsible_ || this.collapsed_ === collapsed) {
  17163. return;
  17164. }
  17165. this.handleToggle_();
  17166. };
  17167. /**
  17168. * Return `true` when the attribution is currently collapsed or `false`
  17169. * otherwise.
  17170. * @return {boolean} True if the widget is collapsed.
  17171. * @api
  17172. */
  17173. ol.control.Attribution.prototype.getCollapsed = function() {
  17174. return this.collapsed_;
  17175. };
  17176. goog.provide('ol.control.Rotate');
  17177. goog.require('ol.events');
  17178. goog.require('ol.events.EventType');
  17179. goog.require('ol');
  17180. goog.require('ol.control.Control');
  17181. goog.require('ol.css');
  17182. goog.require('ol.easing');
  17183. /**
  17184. * @classdesc
  17185. * A button control to reset rotation to 0.
  17186. * To style this control use css selector `.ol-rotate`. A `.ol-hidden` css
  17187. * selector is added to the button when the rotation is 0.
  17188. *
  17189. * @constructor
  17190. * @extends {ol.control.Control}
  17191. * @param {olx.control.RotateOptions=} opt_options Rotate options.
  17192. * @api
  17193. */
  17194. ol.control.Rotate = function(opt_options) {
  17195. var options = opt_options ? opt_options : {};
  17196. var className = options.className !== undefined ? options.className : 'ol-rotate';
  17197. var label = options.label !== undefined ? options.label : '\u21E7';
  17198. /**
  17199. * @type {Element}
  17200. * @private
  17201. */
  17202. this.label_ = null;
  17203. if (typeof label === 'string') {
  17204. this.label_ = document.createElement('span');
  17205. this.label_.className = 'ol-compass';
  17206. this.label_.textContent = label;
  17207. } else {
  17208. this.label_ = label;
  17209. this.label_.classList.add('ol-compass');
  17210. }
  17211. var tipLabel = options.tipLabel ? options.tipLabel : 'Reset rotation';
  17212. var button = document.createElement('button');
  17213. button.className = className + '-reset';
  17214. button.setAttribute('type', 'button');
  17215. button.title = tipLabel;
  17216. button.appendChild(this.label_);
  17217. ol.events.listen(button, ol.events.EventType.CLICK,
  17218. ol.control.Rotate.prototype.handleClick_, this);
  17219. var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
  17220. ol.css.CLASS_CONTROL;
  17221. var element = document.createElement('div');
  17222. element.className = cssClasses;
  17223. element.appendChild(button);
  17224. var render = options.render ? options.render : ol.control.Rotate.render;
  17225. this.callResetNorth_ = options.resetNorth ? options.resetNorth : undefined;
  17226. ol.control.Control.call(this, {
  17227. element: element,
  17228. render: render,
  17229. target: options.target
  17230. });
  17231. /**
  17232. * @type {number}
  17233. * @private
  17234. */
  17235. this.duration_ = options.duration !== undefined ? options.duration : 250;
  17236. /**
  17237. * @type {boolean}
  17238. * @private
  17239. */
  17240. this.autoHide_ = options.autoHide !== undefined ? options.autoHide : true;
  17241. /**
  17242. * @private
  17243. * @type {number|undefined}
  17244. */
  17245. this.rotation_ = undefined;
  17246. if (this.autoHide_) {
  17247. this.element.classList.add(ol.css.CLASS_HIDDEN);
  17248. }
  17249. };
  17250. ol.inherits(ol.control.Rotate, ol.control.Control);
  17251. /**
  17252. * @param {Event} event The event to handle
  17253. * @private
  17254. */
  17255. ol.control.Rotate.prototype.handleClick_ = function(event) {
  17256. event.preventDefault();
  17257. if (this.callResetNorth_ !== undefined) {
  17258. this.callResetNorth_();
  17259. } else {
  17260. this.resetNorth_();
  17261. }
  17262. };
  17263. /**
  17264. * @private
  17265. */
  17266. ol.control.Rotate.prototype.resetNorth_ = function() {
  17267. var map = this.getMap();
  17268. var view = map.getView();
  17269. if (!view) {
  17270. // the map does not have a view, so we can't act
  17271. // upon it
  17272. return;
  17273. }
  17274. if (view.getRotation() !== undefined) {
  17275. if (this.duration_ > 0) {
  17276. view.animate({
  17277. rotation: 0,
  17278. duration: this.duration_,
  17279. easing: ol.easing.easeOut
  17280. });
  17281. } else {
  17282. view.setRotation(0);
  17283. }
  17284. }
  17285. };
  17286. /**
  17287. * Update the rotate control element.
  17288. * @param {ol.MapEvent} mapEvent Map event.
  17289. * @this {ol.control.Rotate}
  17290. * @api
  17291. */
  17292. ol.control.Rotate.render = function(mapEvent) {
  17293. var frameState = mapEvent.frameState;
  17294. if (!frameState) {
  17295. return;
  17296. }
  17297. var rotation = frameState.viewState.rotation;
  17298. if (rotation != this.rotation_) {
  17299. var transform = 'rotate(' + rotation + 'rad)';
  17300. if (this.autoHide_) {
  17301. var contains = this.element.classList.contains(ol.css.CLASS_HIDDEN);
  17302. if (!contains && rotation === 0) {
  17303. this.element.classList.add(ol.css.CLASS_HIDDEN);
  17304. } else if (contains && rotation !== 0) {
  17305. this.element.classList.remove(ol.css.CLASS_HIDDEN);
  17306. }
  17307. }
  17308. this.label_.style.msTransform = transform;
  17309. this.label_.style.webkitTransform = transform;
  17310. this.label_.style.transform = transform;
  17311. }
  17312. this.rotation_ = rotation;
  17313. };
  17314. goog.provide('ol.control.Zoom');
  17315. goog.require('ol');
  17316. goog.require('ol.events');
  17317. goog.require('ol.events.EventType');
  17318. goog.require('ol.control.Control');
  17319. goog.require('ol.css');
  17320. goog.require('ol.easing');
  17321. /**
  17322. * @classdesc
  17323. * A control with 2 buttons, one for zoom in and one for zoom out.
  17324. * This control is one of the default controls of a map. To style this control
  17325. * use css selectors `.ol-zoom-in` and `.ol-zoom-out`.
  17326. *
  17327. * @constructor
  17328. * @extends {ol.control.Control}
  17329. * @param {olx.control.ZoomOptions=} opt_options Zoom options.
  17330. * @api
  17331. */
  17332. ol.control.Zoom = function(opt_options) {
  17333. var options = opt_options ? opt_options : {};
  17334. var className = options.className !== undefined ? options.className : 'ol-zoom';
  17335. var delta = options.delta !== undefined ? options.delta : 1;
  17336. var zoomInLabel = options.zoomInLabel !== undefined ? options.zoomInLabel : '+';
  17337. var zoomOutLabel = options.zoomOutLabel !== undefined ? options.zoomOutLabel : '\u2212';
  17338. var zoomInTipLabel = options.zoomInTipLabel !== undefined ?
  17339. options.zoomInTipLabel : 'Zoom in';
  17340. var zoomOutTipLabel = options.zoomOutTipLabel !== undefined ?
  17341. options.zoomOutTipLabel : 'Zoom out';
  17342. var inElement = document.createElement('button');
  17343. inElement.className = className + '-in';
  17344. inElement.setAttribute('type', 'button');
  17345. inElement.title = zoomInTipLabel;
  17346. inElement.appendChild(
  17347. typeof zoomInLabel === 'string' ? document.createTextNode(zoomInLabel) : zoomInLabel
  17348. );
  17349. ol.events.listen(inElement, ol.events.EventType.CLICK,
  17350. ol.control.Zoom.prototype.handleClick_.bind(this, delta));
  17351. var outElement = document.createElement('button');
  17352. outElement.className = className + '-out';
  17353. outElement.setAttribute('type', 'button');
  17354. outElement.title = zoomOutTipLabel;
  17355. outElement.appendChild(
  17356. typeof zoomOutLabel === 'string' ? document.createTextNode(zoomOutLabel) : zoomOutLabel
  17357. );
  17358. ol.events.listen(outElement, ol.events.EventType.CLICK,
  17359. ol.control.Zoom.prototype.handleClick_.bind(this, -delta));
  17360. var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
  17361. ol.css.CLASS_CONTROL;
  17362. var element = document.createElement('div');
  17363. element.className = cssClasses;
  17364. element.appendChild(inElement);
  17365. element.appendChild(outElement);
  17366. ol.control.Control.call(this, {
  17367. element: element,
  17368. target: options.target
  17369. });
  17370. /**
  17371. * @type {number}
  17372. * @private
  17373. */
  17374. this.duration_ = options.duration !== undefined ? options.duration : 250;
  17375. };
  17376. ol.inherits(ol.control.Zoom, ol.control.Control);
  17377. /**
  17378. * @param {number} delta Zoom delta.
  17379. * @param {Event} event The event to handle
  17380. * @private
  17381. */
  17382. ol.control.Zoom.prototype.handleClick_ = function(delta, event) {
  17383. event.preventDefault();
  17384. this.zoomByDelta_(delta);
  17385. };
  17386. /**
  17387. * @param {number} delta Zoom delta.
  17388. * @private
  17389. */
  17390. ol.control.Zoom.prototype.zoomByDelta_ = function(delta) {
  17391. var map = this.getMap();
  17392. var view = map.getView();
  17393. if (!view) {
  17394. // the map does not have a view, so we can't act
  17395. // upon it
  17396. return;
  17397. }
  17398. var currentResolution = view.getResolution();
  17399. if (currentResolution) {
  17400. var newResolution = view.constrainResolution(currentResolution, delta);
  17401. if (this.duration_ > 0) {
  17402. if (view.getAnimating()) {
  17403. view.cancelAnimations();
  17404. }
  17405. view.animate({
  17406. resolution: newResolution,
  17407. duration: this.duration_,
  17408. easing: ol.easing.easeOut
  17409. });
  17410. } else {
  17411. view.setResolution(newResolution);
  17412. }
  17413. }
  17414. };
  17415. goog.provide('ol.control');
  17416. goog.require('ol.Collection');
  17417. goog.require('ol.control.Attribution');
  17418. goog.require('ol.control.Rotate');
  17419. goog.require('ol.control.Zoom');
  17420. /**
  17421. * Set of controls included in maps by default. Unless configured otherwise,
  17422. * this returns a collection containing an instance of each of the following
  17423. * controls:
  17424. * * {@link ol.control.Zoom}
  17425. * * {@link ol.control.Rotate}
  17426. * * {@link ol.control.Attribution}
  17427. *
  17428. * @param {olx.control.DefaultsOptions=} opt_options Defaults options.
  17429. * @return {ol.Collection.<ol.control.Control>} Controls.
  17430. * @api
  17431. */
  17432. ol.control.defaults = function(opt_options) {
  17433. var options = opt_options ? opt_options : {};
  17434. var controls = new ol.Collection();
  17435. var zoomControl = options.zoom !== undefined ? options.zoom : true;
  17436. if (zoomControl) {
  17437. controls.push(new ol.control.Zoom(options.zoomOptions));
  17438. }
  17439. var rotateControl = options.rotate !== undefined ? options.rotate : true;
  17440. if (rotateControl) {
  17441. controls.push(new ol.control.Rotate(options.rotateOptions));
  17442. }
  17443. var attributionControl = options.attribution !== undefined ?
  17444. options.attribution : true;
  17445. if (attributionControl) {
  17446. controls.push(new ol.control.Attribution(options.attributionOptions));
  17447. }
  17448. return controls;
  17449. };
  17450. goog.provide('ol.Kinetic');
  17451. /**
  17452. * @classdesc
  17453. * Implementation of inertial deceleration for map movement.
  17454. *
  17455. * @constructor
  17456. * @param {number} decay Rate of decay (must be negative).
  17457. * @param {number} minVelocity Minimum velocity (pixels/millisecond).
  17458. * @param {number} delay Delay to consider to calculate the kinetic
  17459. * initial values (milliseconds).
  17460. * @struct
  17461. * @api
  17462. */
  17463. ol.Kinetic = function(decay, minVelocity, delay) {
  17464. /**
  17465. * @private
  17466. * @type {number}
  17467. */
  17468. this.decay_ = decay;
  17469. /**
  17470. * @private
  17471. * @type {number}
  17472. */
  17473. this.minVelocity_ = minVelocity;
  17474. /**
  17475. * @private
  17476. * @type {number}
  17477. */
  17478. this.delay_ = delay;
  17479. /**
  17480. * @private
  17481. * @type {Array.<number>}
  17482. */
  17483. this.points_ = [];
  17484. /**
  17485. * @private
  17486. * @type {number}
  17487. */
  17488. this.angle_ = 0;
  17489. /**
  17490. * @private
  17491. * @type {number}
  17492. */
  17493. this.initialVelocity_ = 0;
  17494. };
  17495. /**
  17496. * FIXME empty description for jsdoc
  17497. */
  17498. ol.Kinetic.prototype.begin = function() {
  17499. this.points_.length = 0;
  17500. this.angle_ = 0;
  17501. this.initialVelocity_ = 0;
  17502. };
  17503. /**
  17504. * @param {number} x X.
  17505. * @param {number} y Y.
  17506. */
  17507. ol.Kinetic.prototype.update = function(x, y) {
  17508. this.points_.push(x, y, Date.now());
  17509. };
  17510. /**
  17511. * @return {boolean} Whether we should do kinetic animation.
  17512. */
  17513. ol.Kinetic.prototype.end = function() {
  17514. if (this.points_.length < 6) {
  17515. // at least 2 points are required (i.e. there must be at least 6 elements
  17516. // in the array)
  17517. return false;
  17518. }
  17519. var delay = Date.now() - this.delay_;
  17520. var lastIndex = this.points_.length - 3;
  17521. if (this.points_[lastIndex + 2] < delay) {
  17522. // the last tracked point is too old, which means that the user stopped
  17523. // panning before releasing the map
  17524. return false;
  17525. }
  17526. // get the first point which still falls into the delay time
  17527. var firstIndex = lastIndex - 3;
  17528. while (firstIndex > 0 && this.points_[firstIndex + 2] > delay) {
  17529. firstIndex -= 3;
  17530. }
  17531. var duration = this.points_[lastIndex + 2] - this.points_[firstIndex + 2];
  17532. // we don't want a duration of 0 (divide by zero)
  17533. // we also make sure the user panned for a duration of at least one frame
  17534. // (1/60s) to compute sane displacement values
  17535. if (duration < 1000 / 60) {
  17536. return false;
  17537. }
  17538. var dx = this.points_[lastIndex] - this.points_[firstIndex];
  17539. var dy = this.points_[lastIndex + 1] - this.points_[firstIndex + 1];
  17540. this.angle_ = Math.atan2(dy, dx);
  17541. this.initialVelocity_ = Math.sqrt(dx * dx + dy * dy) / duration;
  17542. return this.initialVelocity_ > this.minVelocity_;
  17543. };
  17544. /**
  17545. * @return {number} Total distance travelled (pixels).
  17546. */
  17547. ol.Kinetic.prototype.getDistance = function() {
  17548. return (this.minVelocity_ - this.initialVelocity_) / this.decay_;
  17549. };
  17550. /**
  17551. * @return {number} Angle of the kinetic panning animation (radians).
  17552. */
  17553. ol.Kinetic.prototype.getAngle = function() {
  17554. return this.angle_;
  17555. };
  17556. goog.provide('ol.interaction.Property');
  17557. /**
  17558. * @enum {string}
  17559. */
  17560. ol.interaction.Property = {
  17561. ACTIVE: 'active'
  17562. };
  17563. // FIXME factor out key precondition (shift et. al)
  17564. goog.provide('ol.interaction.Interaction');
  17565. goog.require('ol');
  17566. goog.require('ol.Object');
  17567. goog.require('ol.easing');
  17568. goog.require('ol.interaction.Property');
  17569. goog.require('ol.math');
  17570. /**
  17571. * @classdesc
  17572. * Abstract base class; normally only used for creating subclasses and not
  17573. * instantiated in apps.
  17574. * User actions that change the state of the map. Some are similar to controls,
  17575. * but are not associated with a DOM element.
  17576. * For example, {@link ol.interaction.KeyboardZoom} is functionally the same as
  17577. * {@link ol.control.Zoom}, but triggered by a keyboard event not a button
  17578. * element event.
  17579. * Although interactions do not have a DOM element, some of them do render
  17580. * vectors and so are visible on the screen.
  17581. *
  17582. * @constructor
  17583. * @param {olx.interaction.InteractionOptions} options Options.
  17584. * @extends {ol.Object}
  17585. * @api
  17586. */
  17587. ol.interaction.Interaction = function(options) {
  17588. ol.Object.call(this);
  17589. /**
  17590. * @private
  17591. * @type {ol.PluggableMap}
  17592. */
  17593. this.map_ = null;
  17594. this.setActive(true);
  17595. /**
  17596. * @type {function(ol.MapBrowserEvent):boolean}
  17597. */
  17598. this.handleEvent = options.handleEvent;
  17599. };
  17600. ol.inherits(ol.interaction.Interaction, ol.Object);
  17601. /**
  17602. * Return whether the interaction is currently active.
  17603. * @return {boolean} `true` if the interaction is active, `false` otherwise.
  17604. * @observable
  17605. * @api
  17606. */
  17607. ol.interaction.Interaction.prototype.getActive = function() {
  17608. return /** @type {boolean} */ (
  17609. this.get(ol.interaction.Property.ACTIVE));
  17610. };
  17611. /**
  17612. * Get the map associated with this interaction.
  17613. * @return {ol.PluggableMap} Map.
  17614. * @api
  17615. */
  17616. ol.interaction.Interaction.prototype.getMap = function() {
  17617. return this.map_;
  17618. };
  17619. /**
  17620. * Activate or deactivate the interaction.
  17621. * @param {boolean} active Active.
  17622. * @observable
  17623. * @api
  17624. */
  17625. ol.interaction.Interaction.prototype.setActive = function(active) {
  17626. this.set(ol.interaction.Property.ACTIVE, active);
  17627. };
  17628. /**
  17629. * Remove the interaction from its current map and attach it to the new map.
  17630. * Subclasses may set up event handlers to get notified about changes to
  17631. * the map here.
  17632. * @param {ol.PluggableMap} map Map.
  17633. */
  17634. ol.interaction.Interaction.prototype.setMap = function(map) {
  17635. this.map_ = map;
  17636. };
  17637. /**
  17638. * @param {ol.View} view View.
  17639. * @param {ol.Coordinate} delta Delta.
  17640. * @param {number=} opt_duration Duration.
  17641. */
  17642. ol.interaction.Interaction.pan = function(view, delta, opt_duration) {
  17643. var currentCenter = view.getCenter();
  17644. if (currentCenter) {
  17645. var center = view.constrainCenter(
  17646. [currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
  17647. if (opt_duration) {
  17648. view.animate({
  17649. duration: opt_duration,
  17650. easing: ol.easing.linear,
  17651. center: center
  17652. });
  17653. } else {
  17654. view.setCenter(center);
  17655. }
  17656. }
  17657. };
  17658. /**
  17659. * @param {ol.View} view View.
  17660. * @param {number|undefined} rotation Rotation.
  17661. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
  17662. * @param {number=} opt_duration Duration.
  17663. */
  17664. ol.interaction.Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) {
  17665. rotation = view.constrainRotation(rotation, 0);
  17666. ol.interaction.Interaction.rotateWithoutConstraints(
  17667. view, rotation, opt_anchor, opt_duration);
  17668. };
  17669. /**
  17670. * @param {ol.View} view View.
  17671. * @param {number|undefined} rotation Rotation.
  17672. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
  17673. * @param {number=} opt_duration Duration.
  17674. */
  17675. ol.interaction.Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_duration) {
  17676. if (rotation !== undefined) {
  17677. var currentRotation = view.getRotation();
  17678. var currentCenter = view.getCenter();
  17679. if (currentRotation !== undefined && currentCenter && opt_duration > 0) {
  17680. view.animate({
  17681. rotation: rotation,
  17682. anchor: opt_anchor,
  17683. duration: opt_duration,
  17684. easing: ol.easing.easeOut
  17685. });
  17686. } else {
  17687. view.rotate(rotation, opt_anchor);
  17688. }
  17689. }
  17690. };
  17691. /**
  17692. * @param {ol.View} view View.
  17693. * @param {number|undefined} resolution Resolution to go to.
  17694. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
  17695. * @param {number=} opt_duration Duration.
  17696. * @param {number=} opt_direction Zooming direction; > 0 indicates
  17697. * zooming out, in which case the constraints system will select
  17698. * the largest nearest resolution; < 0 indicates zooming in, in
  17699. * which case the constraints system will select the smallest
  17700. * nearest resolution; == 0 indicates that the zooming direction
  17701. * is unknown/not relevant, in which case the constraints system
  17702. * will select the nearest resolution. If not defined 0 is
  17703. * assumed.
  17704. */
  17705. ol.interaction.Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_direction) {
  17706. resolution = view.constrainResolution(resolution, 0, opt_direction);
  17707. ol.interaction.Interaction.zoomWithoutConstraints(
  17708. view, resolution, opt_anchor, opt_duration);
  17709. };
  17710. /**
  17711. * @param {ol.View} view View.
  17712. * @param {number} delta Delta from previous zoom level.
  17713. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
  17714. * @param {number=} opt_duration Duration.
  17715. */
  17716. ol.interaction.Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
  17717. var currentResolution = view.getResolution();
  17718. var resolution = view.constrainResolution(currentResolution, delta, 0);
  17719. if (resolution !== undefined) {
  17720. var resolutions = view.getResolutions();
  17721. resolution = ol.math.clamp(
  17722. resolution,
  17723. view.getMinResolution() || resolutions[resolutions.length - 1],
  17724. view.getMaxResolution() || resolutions[0]);
  17725. }
  17726. // If we have a constraint on center, we need to change the anchor so that the
  17727. // new center is within the extent. We first calculate the new center, apply
  17728. // the constraint to it, and then calculate back the anchor
  17729. if (opt_anchor && resolution !== undefined && resolution !== currentResolution) {
  17730. var currentCenter = view.getCenter();
  17731. var center = view.calculateCenterZoom(resolution, opt_anchor);
  17732. center = view.constrainCenter(center);
  17733. opt_anchor = [
  17734. (resolution * currentCenter[0] - currentResolution * center[0]) /
  17735. (resolution - currentResolution),
  17736. (resolution * currentCenter[1] - currentResolution * center[1]) /
  17737. (resolution - currentResolution)
  17738. ];
  17739. }
  17740. ol.interaction.Interaction.zoomWithoutConstraints(
  17741. view, resolution, opt_anchor, opt_duration);
  17742. };
  17743. /**
  17744. * @param {ol.View} view View.
  17745. * @param {number|undefined} resolution Resolution to go to.
  17746. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
  17747. * @param {number=} opt_duration Duration.
  17748. */
  17749. ol.interaction.Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_duration) {
  17750. if (resolution) {
  17751. var currentResolution = view.getResolution();
  17752. var currentCenter = view.getCenter();
  17753. if (currentResolution !== undefined && currentCenter &&
  17754. resolution !== currentResolution && opt_duration) {
  17755. view.animate({
  17756. resolution: resolution,
  17757. anchor: opt_anchor,
  17758. duration: opt_duration,
  17759. easing: ol.easing.easeOut
  17760. });
  17761. } else {
  17762. if (opt_anchor) {
  17763. var center = view.calculateCenterZoom(resolution, opt_anchor);
  17764. view.setCenter(center);
  17765. }
  17766. view.setResolution(resolution);
  17767. }
  17768. }
  17769. };
  17770. goog.provide('ol.interaction.DoubleClickZoom');
  17771. goog.require('ol');
  17772. goog.require('ol.MapBrowserEventType');
  17773. goog.require('ol.interaction.Interaction');
  17774. /**
  17775. * @classdesc
  17776. * Allows the user to zoom by double-clicking on the map.
  17777. *
  17778. * @constructor
  17779. * @extends {ol.interaction.Interaction}
  17780. * @param {olx.interaction.DoubleClickZoomOptions=} opt_options Options.
  17781. * @api
  17782. */
  17783. ol.interaction.DoubleClickZoom = function(opt_options) {
  17784. var options = opt_options ? opt_options : {};
  17785. /**
  17786. * @private
  17787. * @type {number}
  17788. */
  17789. this.delta_ = options.delta ? options.delta : 1;
  17790. ol.interaction.Interaction.call(this, {
  17791. handleEvent: ol.interaction.DoubleClickZoom.handleEvent
  17792. });
  17793. /**
  17794. * @private
  17795. * @type {number}
  17796. */
  17797. this.duration_ = options.duration !== undefined ? options.duration : 250;
  17798. };
  17799. ol.inherits(ol.interaction.DoubleClickZoom, ol.interaction.Interaction);
  17800. /**
  17801. * Handles the {@link ol.MapBrowserEvent map browser event} (if it was a
  17802. * doubleclick) and eventually zooms the map.
  17803. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17804. * @return {boolean} `false` to stop event propagation.
  17805. * @this {ol.interaction.DoubleClickZoom}
  17806. * @api
  17807. */
  17808. ol.interaction.DoubleClickZoom.handleEvent = function(mapBrowserEvent) {
  17809. var stopEvent = false;
  17810. var browserEvent = mapBrowserEvent.originalEvent;
  17811. if (mapBrowserEvent.type == ol.MapBrowserEventType.DBLCLICK) {
  17812. var map = mapBrowserEvent.map;
  17813. var anchor = mapBrowserEvent.coordinate;
  17814. var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
  17815. var view = map.getView();
  17816. ol.interaction.Interaction.zoomByDelta(
  17817. view, delta, anchor, this.duration_);
  17818. mapBrowserEvent.preventDefault();
  17819. stopEvent = true;
  17820. }
  17821. return !stopEvent;
  17822. };
  17823. goog.provide('ol.events.condition');
  17824. goog.require('ol.MapBrowserEventType');
  17825. goog.require('ol.asserts');
  17826. goog.require('ol.functions');
  17827. goog.require('ol.has');
  17828. /**
  17829. * Return `true` if only the alt-key is pressed, `false` otherwise (e.g. when
  17830. * additionally the shift-key is pressed).
  17831. *
  17832. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17833. * @return {boolean} True if only the alt key is pressed.
  17834. * @api
  17835. */
  17836. ol.events.condition.altKeyOnly = function(mapBrowserEvent) {
  17837. var originalEvent = mapBrowserEvent.originalEvent;
  17838. return (
  17839. originalEvent.altKey &&
  17840. !(originalEvent.metaKey || originalEvent.ctrlKey) &&
  17841. !originalEvent.shiftKey);
  17842. };
  17843. /**
  17844. * Return `true` if only the alt-key and shift-key is pressed, `false` otherwise
  17845. * (e.g. when additionally the platform-modifier-key is pressed).
  17846. *
  17847. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17848. * @return {boolean} True if only the alt and shift keys are pressed.
  17849. * @api
  17850. */
  17851. ol.events.condition.altShiftKeysOnly = function(mapBrowserEvent) {
  17852. var originalEvent = mapBrowserEvent.originalEvent;
  17853. return (
  17854. originalEvent.altKey &&
  17855. !(originalEvent.metaKey || originalEvent.ctrlKey) &&
  17856. originalEvent.shiftKey);
  17857. };
  17858. /**
  17859. * Return always true.
  17860. *
  17861. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17862. * @return {boolean} True.
  17863. * @function
  17864. * @api
  17865. */
  17866. ol.events.condition.always = ol.functions.TRUE;
  17867. /**
  17868. * Return `true` if the event is a `click` event, `false` otherwise.
  17869. *
  17870. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17871. * @return {boolean} True if the event is a map `click` event.
  17872. * @api
  17873. */
  17874. ol.events.condition.click = function(mapBrowserEvent) {
  17875. return mapBrowserEvent.type == ol.MapBrowserEventType.CLICK;
  17876. };
  17877. /**
  17878. * Return `true` if the event has an "action"-producing mouse button.
  17879. *
  17880. * By definition, this includes left-click on windows/linux, and left-click
  17881. * without the ctrl key on Macs.
  17882. *
  17883. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17884. * @return {boolean} The result.
  17885. */
  17886. ol.events.condition.mouseActionButton = function(mapBrowserEvent) {
  17887. var originalEvent = mapBrowserEvent.originalEvent;
  17888. return originalEvent.button == 0 &&
  17889. !(ol.has.WEBKIT && ol.has.MAC && originalEvent.ctrlKey);
  17890. };
  17891. /**
  17892. * Return always false.
  17893. *
  17894. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17895. * @return {boolean} False.
  17896. * @function
  17897. * @api
  17898. */
  17899. ol.events.condition.never = ol.functions.FALSE;
  17900. /**
  17901. * Return `true` if the browser event is a `pointermove` event, `false`
  17902. * otherwise.
  17903. *
  17904. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17905. * @return {boolean} True if the browser event is a `pointermove` event.
  17906. * @api
  17907. */
  17908. ol.events.condition.pointerMove = function(mapBrowserEvent) {
  17909. return mapBrowserEvent.type == 'pointermove';
  17910. };
  17911. /**
  17912. * Return `true` if the event is a map `singleclick` event, `false` otherwise.
  17913. *
  17914. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17915. * @return {boolean} True if the event is a map `singleclick` event.
  17916. * @api
  17917. */
  17918. ol.events.condition.singleClick = function(mapBrowserEvent) {
  17919. return mapBrowserEvent.type == ol.MapBrowserEventType.SINGLECLICK;
  17920. };
  17921. /**
  17922. * Return `true` if the event is a map `dblclick` event, `false` otherwise.
  17923. *
  17924. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17925. * @return {boolean} True if the event is a map `dblclick` event.
  17926. * @api
  17927. */
  17928. ol.events.condition.doubleClick = function(mapBrowserEvent) {
  17929. return mapBrowserEvent.type == ol.MapBrowserEventType.DBLCLICK;
  17930. };
  17931. /**
  17932. * Return `true` if no modifier key (alt-, shift- or platform-modifier-key) is
  17933. * pressed.
  17934. *
  17935. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17936. * @return {boolean} True only if there no modifier keys are pressed.
  17937. * @api
  17938. */
  17939. ol.events.condition.noModifierKeys = function(mapBrowserEvent) {
  17940. var originalEvent = mapBrowserEvent.originalEvent;
  17941. return (
  17942. !originalEvent.altKey &&
  17943. !(originalEvent.metaKey || originalEvent.ctrlKey) &&
  17944. !originalEvent.shiftKey);
  17945. };
  17946. /**
  17947. * Return `true` if only the platform-modifier-key (the meta-key on Mac,
  17948. * ctrl-key otherwise) is pressed, `false` otherwise (e.g. when additionally
  17949. * the shift-key is pressed).
  17950. *
  17951. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17952. * @return {boolean} True if only the platform modifier key is pressed.
  17953. * @api
  17954. */
  17955. ol.events.condition.platformModifierKeyOnly = function(mapBrowserEvent) {
  17956. var originalEvent = mapBrowserEvent.originalEvent;
  17957. return (
  17958. !originalEvent.altKey &&
  17959. (ol.has.MAC ? originalEvent.metaKey : originalEvent.ctrlKey) &&
  17960. !originalEvent.shiftKey);
  17961. };
  17962. /**
  17963. * Return `true` if only the shift-key is pressed, `false` otherwise (e.g. when
  17964. * additionally the alt-key is pressed).
  17965. *
  17966. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17967. * @return {boolean} True if only the shift key is pressed.
  17968. * @api
  17969. */
  17970. ol.events.condition.shiftKeyOnly = function(mapBrowserEvent) {
  17971. var originalEvent = mapBrowserEvent.originalEvent;
  17972. return (
  17973. !originalEvent.altKey &&
  17974. !(originalEvent.metaKey || originalEvent.ctrlKey) &&
  17975. originalEvent.shiftKey);
  17976. };
  17977. /**
  17978. * Return `true` if the target element is not editable, i.e. not a `<input>`-,
  17979. * `<select>`- or `<textarea>`-element, `false` otherwise.
  17980. *
  17981. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17982. * @return {boolean} True only if the target element is not editable.
  17983. * @api
  17984. */
  17985. ol.events.condition.targetNotEditable = function(mapBrowserEvent) {
  17986. var target = mapBrowserEvent.originalEvent.target;
  17987. var tagName = target.tagName;
  17988. return (
  17989. tagName !== 'INPUT' &&
  17990. tagName !== 'SELECT' &&
  17991. tagName !== 'TEXTAREA');
  17992. };
  17993. /**
  17994. * Return `true` if the event originates from a mouse device.
  17995. *
  17996. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  17997. * @return {boolean} True if the event originates from a mouse device.
  17998. * @api
  17999. */
  18000. ol.events.condition.mouseOnly = function(mapBrowserEvent) {
  18001. ol.asserts.assert(mapBrowserEvent.pointerEvent, 56); // mapBrowserEvent must originate from a pointer event
  18002. // see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
  18003. return /** @type {ol.MapBrowserEvent} */ (mapBrowserEvent).pointerEvent.pointerType == 'mouse';
  18004. };
  18005. /**
  18006. * Return `true` if the event originates from a primary pointer in
  18007. * contact with the surface or if the left mouse button is pressed.
  18008. * @see http://www.w3.org/TR/pointerevents/#button-states
  18009. *
  18010. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  18011. * @return {boolean} True if the event originates from a primary pointer.
  18012. * @api
  18013. */
  18014. ol.events.condition.primaryAction = function(mapBrowserEvent) {
  18015. var pointerEvent = mapBrowserEvent.pointerEvent;
  18016. return pointerEvent.isPrimary && pointerEvent.button === 0;
  18017. };
  18018. goog.provide('ol.interaction.Pointer');
  18019. goog.require('ol');
  18020. goog.require('ol.functions');
  18021. goog.require('ol.MapBrowserEventType');
  18022. goog.require('ol.MapBrowserPointerEvent');
  18023. goog.require('ol.interaction.Interaction');
  18024. goog.require('ol.obj');
  18025. /**
  18026. * @classdesc
  18027. * Base class that calls user-defined functions on `down`, `move` and `up`
  18028. * events. This class also manages "drag sequences".
  18029. *
  18030. * When the `handleDownEvent` user function returns `true` a drag sequence is
  18031. * started. During a drag sequence the `handleDragEvent` user function is
  18032. * called on `move` events. The drag sequence ends when the `handleUpEvent`
  18033. * user function is called and returns `false`.
  18034. *
  18035. * @constructor
  18036. * @param {olx.interaction.PointerOptions=} opt_options Options.
  18037. * @extends {ol.interaction.Interaction}
  18038. * @api
  18039. */
  18040. ol.interaction.Pointer = function(opt_options) {
  18041. var options = opt_options ? opt_options : {};
  18042. var handleEvent = options.handleEvent ?
  18043. options.handleEvent : ol.interaction.Pointer.handleEvent;
  18044. ol.interaction.Interaction.call(this, {
  18045. handleEvent: handleEvent
  18046. });
  18047. /**
  18048. * @type {function(ol.MapBrowserPointerEvent):boolean}
  18049. * @private
  18050. */
  18051. this.handleDownEvent_ = options.handleDownEvent ?
  18052. options.handleDownEvent : ol.interaction.Pointer.handleDownEvent;
  18053. /**
  18054. * @type {function(ol.MapBrowserPointerEvent)}
  18055. * @private
  18056. */
  18057. this.handleDragEvent_ = options.handleDragEvent ?
  18058. options.handleDragEvent : ol.interaction.Pointer.handleDragEvent;
  18059. /**
  18060. * @type {function(ol.MapBrowserPointerEvent)}
  18061. * @private
  18062. */
  18063. this.handleMoveEvent_ = options.handleMoveEvent ?
  18064. options.handleMoveEvent : ol.interaction.Pointer.handleMoveEvent;
  18065. /**
  18066. * @type {function(ol.MapBrowserPointerEvent):boolean}
  18067. * @private
  18068. */
  18069. this.handleUpEvent_ = options.handleUpEvent ?
  18070. options.handleUpEvent : ol.interaction.Pointer.handleUpEvent;
  18071. /**
  18072. * @type {boolean}
  18073. * @protected
  18074. */
  18075. this.handlingDownUpSequence = false;
  18076. /**
  18077. * @type {Object.<string, ol.pointer.PointerEvent>}
  18078. * @private
  18079. */
  18080. this.trackedPointers_ = {};
  18081. /**
  18082. * @type {Array.<ol.pointer.PointerEvent>}
  18083. * @protected
  18084. */
  18085. this.targetPointers = [];
  18086. };
  18087. ol.inherits(ol.interaction.Pointer, ol.interaction.Interaction);
  18088. /**
  18089. * @param {Array.<ol.pointer.PointerEvent>} pointerEvents List of events.
  18090. * @return {ol.Pixel} Centroid pixel.
  18091. */
  18092. ol.interaction.Pointer.centroid = function(pointerEvents) {
  18093. var length = pointerEvents.length;
  18094. var clientX = 0;
  18095. var clientY = 0;
  18096. for (var i = 0; i < length; i++) {
  18097. clientX += pointerEvents[i].clientX;
  18098. clientY += pointerEvents[i].clientY;
  18099. }
  18100. return [clientX / length, clientY / length];
  18101. };
  18102. /**
  18103. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18104. * @return {boolean} Whether the event is a pointerdown, pointerdrag
  18105. * or pointerup event.
  18106. * @private
  18107. */
  18108. ol.interaction.Pointer.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent) {
  18109. var type = mapBrowserEvent.type;
  18110. return (
  18111. type === ol.MapBrowserEventType.POINTERDOWN ||
  18112. type === ol.MapBrowserEventType.POINTERDRAG ||
  18113. type === ol.MapBrowserEventType.POINTERUP);
  18114. };
  18115. /**
  18116. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18117. * @private
  18118. */
  18119. ol.interaction.Pointer.prototype.updateTrackedPointers_ = function(mapBrowserEvent) {
  18120. if (this.isPointerDraggingEvent_(mapBrowserEvent)) {
  18121. var event = mapBrowserEvent.pointerEvent;
  18122. var id = event.pointerId.toString();
  18123. if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERUP) {
  18124. delete this.trackedPointers_[id];
  18125. } else if (mapBrowserEvent.type ==
  18126. ol.MapBrowserEventType.POINTERDOWN) {
  18127. this.trackedPointers_[id] = event;
  18128. } else if (id in this.trackedPointers_) {
  18129. // update only when there was a pointerdown event for this pointer
  18130. this.trackedPointers_[id] = event;
  18131. }
  18132. this.targetPointers = ol.obj.getValues(this.trackedPointers_);
  18133. }
  18134. };
  18135. /**
  18136. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18137. * @this {ol.interaction.Pointer}
  18138. */
  18139. ol.interaction.Pointer.handleDragEvent = ol.nullFunction;
  18140. /**
  18141. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18142. * @return {boolean} Capture dragging.
  18143. * @this {ol.interaction.Pointer}
  18144. */
  18145. ol.interaction.Pointer.handleUpEvent = ol.functions.FALSE;
  18146. /**
  18147. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18148. * @return {boolean} Capture dragging.
  18149. * @this {ol.interaction.Pointer}
  18150. */
  18151. ol.interaction.Pointer.handleDownEvent = ol.functions.FALSE;
  18152. /**
  18153. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18154. * @this {ol.interaction.Pointer}
  18155. */
  18156. ol.interaction.Pointer.handleMoveEvent = ol.nullFunction;
  18157. /**
  18158. * Handles the {@link ol.MapBrowserEvent map browser event} and may call into
  18159. * other functions, if event sequences like e.g. 'drag' or 'down-up' etc. are
  18160. * detected.
  18161. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  18162. * @return {boolean} `false` to stop event propagation.
  18163. * @this {ol.interaction.Pointer}
  18164. * @api
  18165. */
  18166. ol.interaction.Pointer.handleEvent = function(mapBrowserEvent) {
  18167. if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
  18168. return true;
  18169. }
  18170. var stopEvent = false;
  18171. this.updateTrackedPointers_(mapBrowserEvent);
  18172. if (this.handlingDownUpSequence) {
  18173. if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERDRAG) {
  18174. this.handleDragEvent_(mapBrowserEvent);
  18175. } else if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERUP) {
  18176. var handledUp = this.handleUpEvent_(mapBrowserEvent);
  18177. this.handlingDownUpSequence = handledUp && this.targetPointers.length > 0;
  18178. }
  18179. } else {
  18180. if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERDOWN) {
  18181. var handled = this.handleDownEvent_(mapBrowserEvent);
  18182. this.handlingDownUpSequence = handled;
  18183. stopEvent = this.shouldStopEvent(handled);
  18184. } else if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERMOVE) {
  18185. this.handleMoveEvent_(mapBrowserEvent);
  18186. }
  18187. }
  18188. return !stopEvent;
  18189. };
  18190. /**
  18191. * This method is used to determine if "down" events should be propagated to
  18192. * other interactions or should be stopped.
  18193. *
  18194. * The method receives the return code of the "handleDownEvent" function.
  18195. *
  18196. * By default this function is the "identity" function. It's overidden in
  18197. * child classes.
  18198. *
  18199. * @param {boolean} handled Was the event handled by the interaction?
  18200. * @return {boolean} Should the event be stopped?
  18201. * @protected
  18202. */
  18203. ol.interaction.Pointer.prototype.shouldStopEvent = function(handled) {
  18204. return handled;
  18205. };
  18206. goog.provide('ol.interaction.DragPan');
  18207. goog.require('ol');
  18208. goog.require('ol.ViewHint');
  18209. goog.require('ol.coordinate');
  18210. goog.require('ol.easing');
  18211. goog.require('ol.events.condition');
  18212. goog.require('ol.functions');
  18213. goog.require('ol.interaction.Pointer');
  18214. /**
  18215. * @classdesc
  18216. * Allows the user to pan the map by dragging the map.
  18217. *
  18218. * @constructor
  18219. * @extends {ol.interaction.Pointer}
  18220. * @param {olx.interaction.DragPanOptions=} opt_options Options.
  18221. * @api
  18222. */
  18223. ol.interaction.DragPan = function(opt_options) {
  18224. ol.interaction.Pointer.call(this, {
  18225. handleDownEvent: ol.interaction.DragPan.handleDownEvent_,
  18226. handleDragEvent: ol.interaction.DragPan.handleDragEvent_,
  18227. handleUpEvent: ol.interaction.DragPan.handleUpEvent_
  18228. });
  18229. var options = opt_options ? opt_options : {};
  18230. /**
  18231. * @private
  18232. * @type {ol.Kinetic|undefined}
  18233. */
  18234. this.kinetic_ = options.kinetic;
  18235. /**
  18236. * @type {ol.Pixel}
  18237. */
  18238. this.lastCentroid = null;
  18239. /**
  18240. * @type {number}
  18241. */
  18242. this.lastPointersCount_;
  18243. /**
  18244. * @private
  18245. * @type {ol.EventsConditionType}
  18246. */
  18247. this.condition_ = options.condition ?
  18248. options.condition : ol.events.condition.noModifierKeys;
  18249. /**
  18250. * @private
  18251. * @type {boolean}
  18252. */
  18253. this.noKinetic_ = false;
  18254. };
  18255. ol.inherits(ol.interaction.DragPan, ol.interaction.Pointer);
  18256. /**
  18257. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18258. * @this {ol.interaction.DragPan}
  18259. * @private
  18260. */
  18261. ol.interaction.DragPan.handleDragEvent_ = function(mapBrowserEvent) {
  18262. var targetPointers = this.targetPointers;
  18263. var centroid =
  18264. ol.interaction.Pointer.centroid(targetPointers);
  18265. if (targetPointers.length == this.lastPointersCount_) {
  18266. if (this.kinetic_) {
  18267. this.kinetic_.update(centroid[0], centroid[1]);
  18268. }
  18269. if (this.lastCentroid) {
  18270. var deltaX = this.lastCentroid[0] - centroid[0];
  18271. var deltaY = centroid[1] - this.lastCentroid[1];
  18272. var map = mapBrowserEvent.map;
  18273. var view = map.getView();
  18274. var viewState = view.getState();
  18275. var center = [deltaX, deltaY];
  18276. ol.coordinate.scale(center, viewState.resolution);
  18277. ol.coordinate.rotate(center, viewState.rotation);
  18278. ol.coordinate.add(center, viewState.center);
  18279. center = view.constrainCenter(center);
  18280. view.setCenter(center);
  18281. }
  18282. } else if (this.kinetic_) {
  18283. // reset so we don't overestimate the kinetic energy after
  18284. // after one finger down, tiny drag, second finger down
  18285. this.kinetic_.begin();
  18286. }
  18287. this.lastCentroid = centroid;
  18288. this.lastPointersCount_ = targetPointers.length;
  18289. };
  18290. /**
  18291. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18292. * @return {boolean} Stop drag sequence?
  18293. * @this {ol.interaction.DragPan}
  18294. * @private
  18295. */
  18296. ol.interaction.DragPan.handleUpEvent_ = function(mapBrowserEvent) {
  18297. var map = mapBrowserEvent.map;
  18298. var view = map.getView();
  18299. if (this.targetPointers.length === 0) {
  18300. if (!this.noKinetic_ && this.kinetic_ && this.kinetic_.end()) {
  18301. var distance = this.kinetic_.getDistance();
  18302. var angle = this.kinetic_.getAngle();
  18303. var center = /** @type {!ol.Coordinate} */ (view.getCenter());
  18304. var centerpx = map.getPixelFromCoordinate(center);
  18305. var dest = map.getCoordinateFromPixel([
  18306. centerpx[0] - distance * Math.cos(angle),
  18307. centerpx[1] - distance * Math.sin(angle)
  18308. ]);
  18309. view.animate({
  18310. center: view.constrainCenter(dest),
  18311. duration: 500,
  18312. easing: ol.easing.easeOut
  18313. });
  18314. }
  18315. view.setHint(ol.ViewHint.INTERACTING, -1);
  18316. return false;
  18317. } else {
  18318. if (this.kinetic_) {
  18319. // reset so we don't overestimate the kinetic energy after
  18320. // after one finger up, tiny drag, second finger up
  18321. this.kinetic_.begin();
  18322. }
  18323. this.lastCentroid = null;
  18324. return true;
  18325. }
  18326. };
  18327. /**
  18328. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18329. * @return {boolean} Start drag sequence?
  18330. * @this {ol.interaction.DragPan}
  18331. * @private
  18332. */
  18333. ol.interaction.DragPan.handleDownEvent_ = function(mapBrowserEvent) {
  18334. if (this.targetPointers.length > 0 && this.condition_(mapBrowserEvent)) {
  18335. var map = mapBrowserEvent.map;
  18336. var view = map.getView();
  18337. this.lastCentroid = null;
  18338. if (!this.handlingDownUpSequence) {
  18339. view.setHint(ol.ViewHint.INTERACTING, 1);
  18340. }
  18341. // stop any current animation
  18342. if (view.getAnimating()) {
  18343. view.setCenter(mapBrowserEvent.frameState.viewState.center);
  18344. }
  18345. if (this.kinetic_) {
  18346. this.kinetic_.begin();
  18347. }
  18348. // No kinetic as soon as more than one pointer on the screen is
  18349. // detected. This is to prevent nasty pans after pinch.
  18350. this.noKinetic_ = this.targetPointers.length > 1;
  18351. return true;
  18352. } else {
  18353. return false;
  18354. }
  18355. };
  18356. /**
  18357. * @inheritDoc
  18358. */
  18359. ol.interaction.DragPan.prototype.shouldStopEvent = ol.functions.FALSE;
  18360. goog.provide('ol.interaction.DragRotate');
  18361. goog.require('ol');
  18362. goog.require('ol.RotationConstraint');
  18363. goog.require('ol.ViewHint');
  18364. goog.require('ol.events.condition');
  18365. goog.require('ol.functions');
  18366. goog.require('ol.interaction.Interaction');
  18367. goog.require('ol.interaction.Pointer');
  18368. /**
  18369. * @classdesc
  18370. * Allows the user to rotate the map by clicking and dragging on the map,
  18371. * normally combined with an {@link ol.events.condition} that limits
  18372. * it to when the alt and shift keys are held down.
  18373. *
  18374. * This interaction is only supported for mouse devices.
  18375. *
  18376. * @constructor
  18377. * @extends {ol.interaction.Pointer}
  18378. * @param {olx.interaction.DragRotateOptions=} opt_options Options.
  18379. * @api
  18380. */
  18381. ol.interaction.DragRotate = function(opt_options) {
  18382. var options = opt_options ? opt_options : {};
  18383. ol.interaction.Pointer.call(this, {
  18384. handleDownEvent: ol.interaction.DragRotate.handleDownEvent_,
  18385. handleDragEvent: ol.interaction.DragRotate.handleDragEvent_,
  18386. handleUpEvent: ol.interaction.DragRotate.handleUpEvent_
  18387. });
  18388. /**
  18389. * @private
  18390. * @type {ol.EventsConditionType}
  18391. */
  18392. this.condition_ = options.condition ?
  18393. options.condition : ol.events.condition.altShiftKeysOnly;
  18394. /**
  18395. * @private
  18396. * @type {number|undefined}
  18397. */
  18398. this.lastAngle_ = undefined;
  18399. /**
  18400. * @private
  18401. * @type {number}
  18402. */
  18403. this.duration_ = options.duration !== undefined ? options.duration : 250;
  18404. };
  18405. ol.inherits(ol.interaction.DragRotate, ol.interaction.Pointer);
  18406. /**
  18407. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18408. * @this {ol.interaction.DragRotate}
  18409. * @private
  18410. */
  18411. ol.interaction.DragRotate.handleDragEvent_ = function(mapBrowserEvent) {
  18412. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  18413. return;
  18414. }
  18415. var map = mapBrowserEvent.map;
  18416. var view = map.getView();
  18417. if (view.getConstraints().rotation === ol.RotationConstraint.disable) {
  18418. return;
  18419. }
  18420. var size = map.getSize();
  18421. var offset = mapBrowserEvent.pixel;
  18422. var theta =
  18423. Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
  18424. if (this.lastAngle_ !== undefined) {
  18425. var delta = theta - this.lastAngle_;
  18426. var rotation = view.getRotation();
  18427. ol.interaction.Interaction.rotateWithoutConstraints(
  18428. view, rotation - delta);
  18429. }
  18430. this.lastAngle_ = theta;
  18431. };
  18432. /**
  18433. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18434. * @return {boolean} Stop drag sequence?
  18435. * @this {ol.interaction.DragRotate}
  18436. * @private
  18437. */
  18438. ol.interaction.DragRotate.handleUpEvent_ = function(mapBrowserEvent) {
  18439. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  18440. return true;
  18441. }
  18442. var map = mapBrowserEvent.map;
  18443. var view = map.getView();
  18444. view.setHint(ol.ViewHint.INTERACTING, -1);
  18445. var rotation = view.getRotation();
  18446. ol.interaction.Interaction.rotate(view, rotation,
  18447. undefined, this.duration_);
  18448. return false;
  18449. };
  18450. /**
  18451. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18452. * @return {boolean} Start drag sequence?
  18453. * @this {ol.interaction.DragRotate}
  18454. * @private
  18455. */
  18456. ol.interaction.DragRotate.handleDownEvent_ = function(mapBrowserEvent) {
  18457. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  18458. return false;
  18459. }
  18460. if (ol.events.condition.mouseActionButton(mapBrowserEvent) &&
  18461. this.condition_(mapBrowserEvent)) {
  18462. var map = mapBrowserEvent.map;
  18463. map.getView().setHint(ol.ViewHint.INTERACTING, 1);
  18464. this.lastAngle_ = undefined;
  18465. return true;
  18466. } else {
  18467. return false;
  18468. }
  18469. };
  18470. /**
  18471. * @inheritDoc
  18472. */
  18473. ol.interaction.DragRotate.prototype.shouldStopEvent = ol.functions.FALSE;
  18474. // FIXME add rotation
  18475. goog.provide('ol.render.Box');
  18476. goog.require('ol');
  18477. goog.require('ol.Disposable');
  18478. goog.require('ol.geom.Polygon');
  18479. /**
  18480. * @constructor
  18481. * @extends {ol.Disposable}
  18482. * @param {string} className CSS class name.
  18483. */
  18484. ol.render.Box = function(className) {
  18485. /**
  18486. * @type {ol.geom.Polygon}
  18487. * @private
  18488. */
  18489. this.geometry_ = null;
  18490. /**
  18491. * @type {HTMLDivElement}
  18492. * @private
  18493. */
  18494. this.element_ = /** @type {HTMLDivElement} */ (document.createElement('div'));
  18495. this.element_.style.position = 'absolute';
  18496. this.element_.className = 'ol-box ' + className;
  18497. /**
  18498. * @private
  18499. * @type {ol.PluggableMap}
  18500. */
  18501. this.map_ = null;
  18502. /**
  18503. * @private
  18504. * @type {ol.Pixel}
  18505. */
  18506. this.startPixel_ = null;
  18507. /**
  18508. * @private
  18509. * @type {ol.Pixel}
  18510. */
  18511. this.endPixel_ = null;
  18512. };
  18513. ol.inherits(ol.render.Box, ol.Disposable);
  18514. /**
  18515. * @inheritDoc
  18516. */
  18517. ol.render.Box.prototype.disposeInternal = function() {
  18518. this.setMap(null);
  18519. };
  18520. /**
  18521. * @private
  18522. */
  18523. ol.render.Box.prototype.render_ = function() {
  18524. var startPixel = this.startPixel_;
  18525. var endPixel = this.endPixel_;
  18526. var px = 'px';
  18527. var style = this.element_.style;
  18528. style.left = Math.min(startPixel[0], endPixel[0]) + px;
  18529. style.top = Math.min(startPixel[1], endPixel[1]) + px;
  18530. style.width = Math.abs(endPixel[0] - startPixel[0]) + px;
  18531. style.height = Math.abs(endPixel[1] - startPixel[1]) + px;
  18532. };
  18533. /**
  18534. * @param {ol.PluggableMap} map Map.
  18535. */
  18536. ol.render.Box.prototype.setMap = function(map) {
  18537. if (this.map_) {
  18538. this.map_.getOverlayContainer().removeChild(this.element_);
  18539. var style = this.element_.style;
  18540. style.left = style.top = style.width = style.height = 'inherit';
  18541. }
  18542. this.map_ = map;
  18543. if (this.map_) {
  18544. this.map_.getOverlayContainer().appendChild(this.element_);
  18545. }
  18546. };
  18547. /**
  18548. * @param {ol.Pixel} startPixel Start pixel.
  18549. * @param {ol.Pixel} endPixel End pixel.
  18550. */
  18551. ol.render.Box.prototype.setPixels = function(startPixel, endPixel) {
  18552. this.startPixel_ = startPixel;
  18553. this.endPixel_ = endPixel;
  18554. this.createOrUpdateGeometry();
  18555. this.render_();
  18556. };
  18557. /**
  18558. * Creates or updates the cached geometry.
  18559. */
  18560. ol.render.Box.prototype.createOrUpdateGeometry = function() {
  18561. var startPixel = this.startPixel_;
  18562. var endPixel = this.endPixel_;
  18563. var pixels = [
  18564. startPixel,
  18565. [startPixel[0], endPixel[1]],
  18566. endPixel,
  18567. [endPixel[0], startPixel[1]]
  18568. ];
  18569. var coordinates = pixels.map(this.map_.getCoordinateFromPixel, this.map_);
  18570. // close the polygon
  18571. coordinates[4] = coordinates[0].slice();
  18572. if (!this.geometry_) {
  18573. this.geometry_ = new ol.geom.Polygon([coordinates]);
  18574. } else {
  18575. this.geometry_.setCoordinates([coordinates]);
  18576. }
  18577. };
  18578. /**
  18579. * @return {ol.geom.Polygon} Geometry.
  18580. */
  18581. ol.render.Box.prototype.getGeometry = function() {
  18582. return this.geometry_;
  18583. };
  18584. // FIXME draw drag box
  18585. goog.provide('ol.interaction.DragBox');
  18586. goog.require('ol.events.Event');
  18587. goog.require('ol');
  18588. goog.require('ol.events.condition');
  18589. goog.require('ol.interaction.Pointer');
  18590. goog.require('ol.render.Box');
  18591. /**
  18592. * @classdesc
  18593. * Allows the user to draw a vector box by clicking and dragging on the map,
  18594. * normally combined with an {@link ol.events.condition} that limits
  18595. * it to when the shift or other key is held down. This is used, for example,
  18596. * for zooming to a specific area of the map
  18597. * (see {@link ol.interaction.DragZoom} and
  18598. * {@link ol.interaction.DragRotateAndZoom}).
  18599. *
  18600. * This interaction is only supported for mouse devices.
  18601. *
  18602. * @constructor
  18603. * @extends {ol.interaction.Pointer}
  18604. * @fires ol.interaction.DragBox.Event
  18605. * @param {olx.interaction.DragBoxOptions=} opt_options Options.
  18606. * @api
  18607. */
  18608. ol.interaction.DragBox = function(opt_options) {
  18609. ol.interaction.Pointer.call(this, {
  18610. handleDownEvent: ol.interaction.DragBox.handleDownEvent_,
  18611. handleDragEvent: ol.interaction.DragBox.handleDragEvent_,
  18612. handleUpEvent: ol.interaction.DragBox.handleUpEvent_
  18613. });
  18614. var options = opt_options ? opt_options : {};
  18615. /**
  18616. * @type {ol.render.Box}
  18617. * @private
  18618. */
  18619. this.box_ = new ol.render.Box(options.className || 'ol-dragbox');
  18620. /**
  18621. * @type {number}
  18622. * @private
  18623. */
  18624. this.minArea_ = options.minArea !== undefined ? options.minArea : 64;
  18625. /**
  18626. * @type {ol.Pixel}
  18627. * @private
  18628. */
  18629. this.startPixel_ = null;
  18630. /**
  18631. * @private
  18632. * @type {ol.EventsConditionType}
  18633. */
  18634. this.condition_ = options.condition ?
  18635. options.condition : ol.events.condition.always;
  18636. /**
  18637. * @private
  18638. * @type {ol.DragBoxEndConditionType}
  18639. */
  18640. this.boxEndCondition_ = options.boxEndCondition ?
  18641. options.boxEndCondition : ol.interaction.DragBox.defaultBoxEndCondition;
  18642. };
  18643. ol.inherits(ol.interaction.DragBox, ol.interaction.Pointer);
  18644. /**
  18645. * The default condition for determining whether the boxend event
  18646. * should fire.
  18647. * @param {ol.MapBrowserEvent} mapBrowserEvent The originating MapBrowserEvent
  18648. * leading to the box end.
  18649. * @param {ol.Pixel} startPixel The starting pixel of the box.
  18650. * @param {ol.Pixel} endPixel The end pixel of the box.
  18651. * @return {boolean} Whether or not the boxend condition should be fired.
  18652. * @this {ol.interaction.DragBox}
  18653. */
  18654. ol.interaction.DragBox.defaultBoxEndCondition = function(mapBrowserEvent, startPixel, endPixel) {
  18655. var width = endPixel[0] - startPixel[0];
  18656. var height = endPixel[1] - startPixel[1];
  18657. return width * width + height * height >= this.minArea_;
  18658. };
  18659. /**
  18660. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18661. * @this {ol.interaction.DragBox}
  18662. * @private
  18663. */
  18664. ol.interaction.DragBox.handleDragEvent_ = function(mapBrowserEvent) {
  18665. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  18666. return;
  18667. }
  18668. this.box_.setPixels(this.startPixel_, mapBrowserEvent.pixel);
  18669. this.dispatchEvent(new ol.interaction.DragBox.Event(ol.interaction.DragBox.EventType_.BOXDRAG,
  18670. mapBrowserEvent.coordinate, mapBrowserEvent));
  18671. };
  18672. /**
  18673. * Returns geometry of last drawn box.
  18674. * @return {ol.geom.Polygon} Geometry.
  18675. * @api
  18676. */
  18677. ol.interaction.DragBox.prototype.getGeometry = function() {
  18678. return this.box_.getGeometry();
  18679. };
  18680. /**
  18681. * To be overridden by child classes.
  18682. * FIXME: use constructor option instead of relying on overriding.
  18683. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  18684. * @protected
  18685. */
  18686. ol.interaction.DragBox.prototype.onBoxEnd = ol.nullFunction;
  18687. /**
  18688. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18689. * @return {boolean} Stop drag sequence?
  18690. * @this {ol.interaction.DragBox}
  18691. * @private
  18692. */
  18693. ol.interaction.DragBox.handleUpEvent_ = function(mapBrowserEvent) {
  18694. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  18695. return true;
  18696. }
  18697. this.box_.setMap(null);
  18698. if (this.boxEndCondition_(mapBrowserEvent,
  18699. this.startPixel_, mapBrowserEvent.pixel)) {
  18700. this.onBoxEnd(mapBrowserEvent);
  18701. this.dispatchEvent(new ol.interaction.DragBox.Event(ol.interaction.DragBox.EventType_.BOXEND,
  18702. mapBrowserEvent.coordinate, mapBrowserEvent));
  18703. }
  18704. return false;
  18705. };
  18706. /**
  18707. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  18708. * @return {boolean} Start drag sequence?
  18709. * @this {ol.interaction.DragBox}
  18710. * @private
  18711. */
  18712. ol.interaction.DragBox.handleDownEvent_ = function(mapBrowserEvent) {
  18713. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  18714. return false;
  18715. }
  18716. if (ol.events.condition.mouseActionButton(mapBrowserEvent) &&
  18717. this.condition_(mapBrowserEvent)) {
  18718. this.startPixel_ = mapBrowserEvent.pixel;
  18719. this.box_.setMap(mapBrowserEvent.map);
  18720. this.box_.setPixels(this.startPixel_, this.startPixel_);
  18721. this.dispatchEvent(new ol.interaction.DragBox.Event(ol.interaction.DragBox.EventType_.BOXSTART,
  18722. mapBrowserEvent.coordinate, mapBrowserEvent));
  18723. return true;
  18724. } else {
  18725. return false;
  18726. }
  18727. };
  18728. /**
  18729. * @enum {string}
  18730. * @private
  18731. */
  18732. ol.interaction.DragBox.EventType_ = {
  18733. /**
  18734. * Triggered upon drag box start.
  18735. * @event ol.interaction.DragBox.Event#boxstart
  18736. * @api
  18737. */
  18738. BOXSTART: 'boxstart',
  18739. /**
  18740. * Triggered on drag when box is active.
  18741. * @event ol.interaction.DragBox.Event#boxdrag
  18742. * @api
  18743. */
  18744. BOXDRAG: 'boxdrag',
  18745. /**
  18746. * Triggered upon drag box end.
  18747. * @event ol.interaction.DragBox.Event#boxend
  18748. * @api
  18749. */
  18750. BOXEND: 'boxend'
  18751. };
  18752. /**
  18753. * @classdesc
  18754. * Events emitted by {@link ol.interaction.DragBox} instances are instances of
  18755. * this type.
  18756. *
  18757. * @param {string} type The event type.
  18758. * @param {ol.Coordinate} coordinate The event coordinate.
  18759. * @param {ol.MapBrowserEvent} mapBrowserEvent Originating event.
  18760. * @extends {ol.events.Event}
  18761. * @constructor
  18762. * @implements {oli.DragBoxEvent}
  18763. */
  18764. ol.interaction.DragBox.Event = function(type, coordinate, mapBrowserEvent) {
  18765. ol.events.Event.call(this, type);
  18766. /**
  18767. * The coordinate of the drag event.
  18768. * @const
  18769. * @type {ol.Coordinate}
  18770. * @api
  18771. */
  18772. this.coordinate = coordinate;
  18773. /**
  18774. * @const
  18775. * @type {ol.MapBrowserEvent}
  18776. * @api
  18777. */
  18778. this.mapBrowserEvent = mapBrowserEvent;
  18779. };
  18780. ol.inherits(ol.interaction.DragBox.Event, ol.events.Event);
  18781. goog.provide('ol.interaction.DragZoom');
  18782. goog.require('ol');
  18783. goog.require('ol.easing');
  18784. goog.require('ol.events.condition');
  18785. goog.require('ol.extent');
  18786. goog.require('ol.interaction.DragBox');
  18787. /**
  18788. * @classdesc
  18789. * Allows the user to zoom the map by clicking and dragging on the map,
  18790. * normally combined with an {@link ol.events.condition} that limits
  18791. * it to when a key, shift by default, is held down.
  18792. *
  18793. * To change the style of the box, use CSS and the `.ol-dragzoom` selector, or
  18794. * your custom one configured with `className`.
  18795. *
  18796. * @constructor
  18797. * @extends {ol.interaction.DragBox}
  18798. * @param {olx.interaction.DragZoomOptions=} opt_options Options.
  18799. * @api
  18800. */
  18801. ol.interaction.DragZoom = function(opt_options) {
  18802. var options = opt_options ? opt_options : {};
  18803. var condition = options.condition ?
  18804. options.condition : ol.events.condition.shiftKeyOnly;
  18805. /**
  18806. * @private
  18807. * @type {number}
  18808. */
  18809. this.duration_ = options.duration !== undefined ? options.duration : 200;
  18810. /**
  18811. * @private
  18812. * @type {boolean}
  18813. */
  18814. this.out_ = options.out !== undefined ? options.out : false;
  18815. ol.interaction.DragBox.call(this, {
  18816. condition: condition,
  18817. className: options.className || 'ol-dragzoom'
  18818. });
  18819. };
  18820. ol.inherits(ol.interaction.DragZoom, ol.interaction.DragBox);
  18821. /**
  18822. * @inheritDoc
  18823. */
  18824. ol.interaction.DragZoom.prototype.onBoxEnd = function() {
  18825. var map = this.getMap();
  18826. var view = /** @type {!ol.View} */ (map.getView());
  18827. var size = /** @type {!ol.Size} */ (map.getSize());
  18828. var extent = this.getGeometry().getExtent();
  18829. if (this.out_) {
  18830. var mapExtent = view.calculateExtent(size);
  18831. var boxPixelExtent = ol.extent.createOrUpdateFromCoordinates([
  18832. map.getPixelFromCoordinate(ol.extent.getBottomLeft(extent)),
  18833. map.getPixelFromCoordinate(ol.extent.getTopRight(extent))]);
  18834. var factor = view.getResolutionForExtent(boxPixelExtent, size);
  18835. ol.extent.scaleFromCenter(mapExtent, 1 / factor);
  18836. extent = mapExtent;
  18837. }
  18838. var resolution = view.constrainResolution(
  18839. view.getResolutionForExtent(extent, size));
  18840. var center = ol.extent.getCenter(extent);
  18841. center = view.constrainCenter(center);
  18842. view.animate({
  18843. resolution: resolution,
  18844. center: center,
  18845. duration: this.duration_,
  18846. easing: ol.easing.easeOut
  18847. });
  18848. };
  18849. goog.provide('ol.events.KeyCode');
  18850. /**
  18851. * @enum {number}
  18852. * @const
  18853. */
  18854. ol.events.KeyCode = {
  18855. LEFT: 37,
  18856. UP: 38,
  18857. RIGHT: 39,
  18858. DOWN: 40
  18859. };
  18860. goog.provide('ol.interaction.KeyboardPan');
  18861. goog.require('ol');
  18862. goog.require('ol.coordinate');
  18863. goog.require('ol.events.EventType');
  18864. goog.require('ol.events.KeyCode');
  18865. goog.require('ol.events.condition');
  18866. goog.require('ol.interaction.Interaction');
  18867. /**
  18868. * @classdesc
  18869. * Allows the user to pan the map using keyboard arrows.
  18870. * Note that, although this interaction is by default included in maps,
  18871. * the keys can only be used when browser focus is on the element to which
  18872. * the keyboard events are attached. By default, this is the map div,
  18873. * though you can change this with the `keyboardEventTarget` in
  18874. * {@link ol.Map}. `document` never loses focus but, for any other element,
  18875. * focus will have to be on, and returned to, this element if the keys are to
  18876. * function.
  18877. * See also {@link ol.interaction.KeyboardZoom}.
  18878. *
  18879. * @constructor
  18880. * @extends {ol.interaction.Interaction}
  18881. * @param {olx.interaction.KeyboardPanOptions=} opt_options Options.
  18882. * @api
  18883. */
  18884. ol.interaction.KeyboardPan = function(opt_options) {
  18885. ol.interaction.Interaction.call(this, {
  18886. handleEvent: ol.interaction.KeyboardPan.handleEvent
  18887. });
  18888. var options = opt_options || {};
  18889. /**
  18890. * @private
  18891. * @param {ol.MapBrowserEvent} mapBrowserEvent Browser event.
  18892. * @return {boolean} Combined condition result.
  18893. */
  18894. this.defaultCondition_ = function(mapBrowserEvent) {
  18895. return ol.events.condition.noModifierKeys(mapBrowserEvent) &&
  18896. ol.events.condition.targetNotEditable(mapBrowserEvent);
  18897. };
  18898. /**
  18899. * @private
  18900. * @type {ol.EventsConditionType}
  18901. */
  18902. this.condition_ = options.condition !== undefined ?
  18903. options.condition : this.defaultCondition_;
  18904. /**
  18905. * @private
  18906. * @type {number}
  18907. */
  18908. this.duration_ = options.duration !== undefined ? options.duration : 100;
  18909. /**
  18910. * @private
  18911. * @type {number}
  18912. */
  18913. this.pixelDelta_ = options.pixelDelta !== undefined ?
  18914. options.pixelDelta : 128;
  18915. };
  18916. ol.inherits(ol.interaction.KeyboardPan, ol.interaction.Interaction);
  18917. /**
  18918. * Handles the {@link ol.MapBrowserEvent map browser event} if it was a
  18919. * `KeyEvent`, and decides the direction to pan to (if an arrow key was
  18920. * pressed).
  18921. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  18922. * @return {boolean} `false` to stop event propagation.
  18923. * @this {ol.interaction.KeyboardPan}
  18924. * @api
  18925. */
  18926. ol.interaction.KeyboardPan.handleEvent = function(mapBrowserEvent) {
  18927. var stopEvent = false;
  18928. if (mapBrowserEvent.type == ol.events.EventType.KEYDOWN) {
  18929. var keyEvent = mapBrowserEvent.originalEvent;
  18930. var keyCode = keyEvent.keyCode;
  18931. if (this.condition_(mapBrowserEvent) &&
  18932. (keyCode == ol.events.KeyCode.DOWN ||
  18933. keyCode == ol.events.KeyCode.LEFT ||
  18934. keyCode == ol.events.KeyCode.RIGHT ||
  18935. keyCode == ol.events.KeyCode.UP)) {
  18936. var map = mapBrowserEvent.map;
  18937. var view = map.getView();
  18938. var mapUnitsDelta = view.getResolution() * this.pixelDelta_;
  18939. var deltaX = 0, deltaY = 0;
  18940. if (keyCode == ol.events.KeyCode.DOWN) {
  18941. deltaY = -mapUnitsDelta;
  18942. } else if (keyCode == ol.events.KeyCode.LEFT) {
  18943. deltaX = -mapUnitsDelta;
  18944. } else if (keyCode == ol.events.KeyCode.RIGHT) {
  18945. deltaX = mapUnitsDelta;
  18946. } else {
  18947. deltaY = mapUnitsDelta;
  18948. }
  18949. var delta = [deltaX, deltaY];
  18950. ol.coordinate.rotate(delta, view.getRotation());
  18951. ol.interaction.Interaction.pan(view, delta, this.duration_);
  18952. mapBrowserEvent.preventDefault();
  18953. stopEvent = true;
  18954. }
  18955. }
  18956. return !stopEvent;
  18957. };
  18958. goog.provide('ol.interaction.KeyboardZoom');
  18959. goog.require('ol');
  18960. goog.require('ol.events.EventType');
  18961. goog.require('ol.events.condition');
  18962. goog.require('ol.interaction.Interaction');
  18963. /**
  18964. * @classdesc
  18965. * Allows the user to zoom the map using keyboard + and -.
  18966. * Note that, although this interaction is by default included in maps,
  18967. * the keys can only be used when browser focus is on the element to which
  18968. * the keyboard events are attached. By default, this is the map div,
  18969. * though you can change this with the `keyboardEventTarget` in
  18970. * {@link ol.Map}. `document` never loses focus but, for any other element,
  18971. * focus will have to be on, and returned to, this element if the keys are to
  18972. * function.
  18973. * See also {@link ol.interaction.KeyboardPan}.
  18974. *
  18975. * @constructor
  18976. * @param {olx.interaction.KeyboardZoomOptions=} opt_options Options.
  18977. * @extends {ol.interaction.Interaction}
  18978. * @api
  18979. */
  18980. ol.interaction.KeyboardZoom = function(opt_options) {
  18981. ol.interaction.Interaction.call(this, {
  18982. handleEvent: ol.interaction.KeyboardZoom.handleEvent
  18983. });
  18984. var options = opt_options ? opt_options : {};
  18985. /**
  18986. * @private
  18987. * @type {ol.EventsConditionType}
  18988. */
  18989. this.condition_ = options.condition ? options.condition :
  18990. ol.events.condition.targetNotEditable;
  18991. /**
  18992. * @private
  18993. * @type {number}
  18994. */
  18995. this.delta_ = options.delta ? options.delta : 1;
  18996. /**
  18997. * @private
  18998. * @type {number}
  18999. */
  19000. this.duration_ = options.duration !== undefined ? options.duration : 100;
  19001. };
  19002. ol.inherits(ol.interaction.KeyboardZoom, ol.interaction.Interaction);
  19003. /**
  19004. * Handles the {@link ol.MapBrowserEvent map browser event} if it was a
  19005. * `KeyEvent`, and decides whether to zoom in or out (depending on whether the
  19006. * key pressed was '+' or '-').
  19007. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  19008. * @return {boolean} `false` to stop event propagation.
  19009. * @this {ol.interaction.KeyboardZoom}
  19010. * @api
  19011. */
  19012. ol.interaction.KeyboardZoom.handleEvent = function(mapBrowserEvent) {
  19013. var stopEvent = false;
  19014. if (mapBrowserEvent.type == ol.events.EventType.KEYDOWN ||
  19015. mapBrowserEvent.type == ol.events.EventType.KEYPRESS) {
  19016. var keyEvent = mapBrowserEvent.originalEvent;
  19017. var charCode = keyEvent.charCode;
  19018. if (this.condition_(mapBrowserEvent) &&
  19019. (charCode == '+'.charCodeAt(0) || charCode == '-'.charCodeAt(0))) {
  19020. var map = mapBrowserEvent.map;
  19021. var delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_;
  19022. var view = map.getView();
  19023. ol.interaction.Interaction.zoomByDelta(
  19024. view, delta, undefined, this.duration_);
  19025. mapBrowserEvent.preventDefault();
  19026. stopEvent = true;
  19027. }
  19028. }
  19029. return !stopEvent;
  19030. };
  19031. goog.provide('ol.interaction.MouseWheelZoom');
  19032. goog.require('ol');
  19033. goog.require('ol.ViewHint');
  19034. goog.require('ol.easing');
  19035. goog.require('ol.events.EventType');
  19036. goog.require('ol.has');
  19037. goog.require('ol.interaction.Interaction');
  19038. goog.require('ol.math');
  19039. /**
  19040. * @classdesc
  19041. * Allows the user to zoom the map by scrolling the mouse wheel.
  19042. *
  19043. * @constructor
  19044. * @extends {ol.interaction.Interaction}
  19045. * @param {olx.interaction.MouseWheelZoomOptions=} opt_options Options.
  19046. * @api
  19047. */
  19048. ol.interaction.MouseWheelZoom = function(opt_options) {
  19049. ol.interaction.Interaction.call(this, {
  19050. handleEvent: ol.interaction.MouseWheelZoom.handleEvent
  19051. });
  19052. var options = opt_options || {};
  19053. /**
  19054. * @private
  19055. * @type {number}
  19056. */
  19057. this.delta_ = 0;
  19058. /**
  19059. * @private
  19060. * @type {number}
  19061. */
  19062. this.duration_ = options.duration !== undefined ? options.duration : 250;
  19063. /**
  19064. * @private
  19065. * @type {number}
  19066. */
  19067. this.timeout_ = options.timeout !== undefined ? options.timeout : 80;
  19068. /**
  19069. * @private
  19070. * @type {boolean}
  19071. */
  19072. this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true;
  19073. /**
  19074. * @private
  19075. * @type {boolean}
  19076. */
  19077. this.constrainResolution_ = options.constrainResolution || false;
  19078. /**
  19079. * @private
  19080. * @type {?ol.Coordinate}
  19081. */
  19082. this.lastAnchor_ = null;
  19083. /**
  19084. * @private
  19085. * @type {number|undefined}
  19086. */
  19087. this.startTime_ = undefined;
  19088. /**
  19089. * @private
  19090. * @type {number|undefined}
  19091. */
  19092. this.timeoutId_ = undefined;
  19093. /**
  19094. * @private
  19095. * @type {ol.interaction.MouseWheelZoom.Mode_|undefined}
  19096. */
  19097. this.mode_ = undefined;
  19098. /**
  19099. * Trackpad events separated by this delay will be considered separate
  19100. * interactions.
  19101. * @type {number}
  19102. */
  19103. this.trackpadEventGap_ = 400;
  19104. /**
  19105. * @type {number|undefined}
  19106. */
  19107. this.trackpadTimeoutId_ = undefined;
  19108. /**
  19109. * The number of delta values per zoom level
  19110. * @private
  19111. * @type {number}
  19112. */
  19113. this.trackpadDeltaPerZoom_ = 300;
  19114. /**
  19115. * The zoom factor by which scroll zooming is allowed to exceed the limits.
  19116. * @private
  19117. * @type {number}
  19118. */
  19119. this.trackpadZoomBuffer_ = 1.5;
  19120. };
  19121. ol.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
  19122. /**
  19123. * Handles the {@link ol.MapBrowserEvent map browser event} (if it was a
  19124. * mousewheel-event) and eventually zooms the map.
  19125. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  19126. * @return {boolean} Allow event propagation.
  19127. * @this {ol.interaction.MouseWheelZoom}
  19128. * @api
  19129. */
  19130. ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
  19131. var type = mapBrowserEvent.type;
  19132. if (type !== ol.events.EventType.WHEEL && type !== ol.events.EventType.MOUSEWHEEL) {
  19133. return true;
  19134. }
  19135. mapBrowserEvent.preventDefault();
  19136. var map = mapBrowserEvent.map;
  19137. var wheelEvent = /** @type {WheelEvent} */ (mapBrowserEvent.originalEvent);
  19138. if (this.useAnchor_) {
  19139. this.lastAnchor_ = mapBrowserEvent.coordinate;
  19140. }
  19141. // Delta normalisation inspired by
  19142. // https://github.com/mapbox/mapbox-gl-js/blob/001c7b9/js/ui/handler/scroll_zoom.js
  19143. var delta;
  19144. if (mapBrowserEvent.type == ol.events.EventType.WHEEL) {
  19145. delta = wheelEvent.deltaY;
  19146. if (ol.has.FIREFOX &&
  19147. wheelEvent.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  19148. delta /= ol.has.DEVICE_PIXEL_RATIO;
  19149. }
  19150. if (wheelEvent.deltaMode === WheelEvent.DOM_DELTA_LINE) {
  19151. delta *= 40;
  19152. }
  19153. } else if (mapBrowserEvent.type == ol.events.EventType.MOUSEWHEEL) {
  19154. delta = -wheelEvent.wheelDeltaY;
  19155. if (ol.has.SAFARI) {
  19156. delta /= 3;
  19157. }
  19158. }
  19159. if (delta === 0) {
  19160. return false;
  19161. }
  19162. var now = Date.now();
  19163. if (this.startTime_ === undefined) {
  19164. this.startTime_ = now;
  19165. }
  19166. if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) {
  19167. this.mode_ = Math.abs(delta) < 4 ?
  19168. ol.interaction.MouseWheelZoom.Mode_.TRACKPAD :
  19169. ol.interaction.MouseWheelZoom.Mode_.WHEEL;
  19170. }
  19171. if (this.mode_ === ol.interaction.MouseWheelZoom.Mode_.TRACKPAD) {
  19172. var view = map.getView();
  19173. if (this.trackpadTimeoutId_) {
  19174. clearTimeout(this.trackpadTimeoutId_);
  19175. } else {
  19176. view.setHint(ol.ViewHint.INTERACTING, 1);
  19177. }
  19178. this.trackpadTimeoutId_ = setTimeout(this.decrementInteractingHint_.bind(this), this.trackpadEventGap_);
  19179. var resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_);
  19180. var minResolution = view.getMinResolution();
  19181. var maxResolution = view.getMaxResolution();
  19182. var rebound = 0;
  19183. if (resolution < minResolution) {
  19184. resolution = Math.max(resolution, minResolution / this.trackpadZoomBuffer_);
  19185. rebound = 1;
  19186. } else if (resolution > maxResolution) {
  19187. resolution = Math.min(resolution, maxResolution * this.trackpadZoomBuffer_);
  19188. rebound = -1;
  19189. }
  19190. if (this.lastAnchor_) {
  19191. var center = view.calculateCenterZoom(resolution, this.lastAnchor_);
  19192. view.setCenter(view.constrainCenter(center));
  19193. }
  19194. view.setResolution(resolution);
  19195. if (rebound === 0 && this.constrainResolution_) {
  19196. view.animate({
  19197. resolution: view.constrainResolution(resolution, delta > 0 ? -1 : 1),
  19198. easing: ol.easing.easeOut,
  19199. anchor: this.lastAnchor_,
  19200. duration: this.duration_
  19201. });
  19202. }
  19203. if (rebound > 0) {
  19204. view.animate({
  19205. resolution: minResolution,
  19206. easing: ol.easing.easeOut,
  19207. anchor: this.lastAnchor_,
  19208. duration: 500
  19209. });
  19210. } else if (rebound < 0) {
  19211. view.animate({
  19212. resolution: maxResolution,
  19213. easing: ol.easing.easeOut,
  19214. anchor: this.lastAnchor_,
  19215. duration: 500
  19216. });
  19217. }
  19218. this.startTime_ = now;
  19219. return false;
  19220. }
  19221. this.delta_ += delta;
  19222. var timeLeft = Math.max(this.timeout_ - (now - this.startTime_), 0);
  19223. clearTimeout(this.timeoutId_);
  19224. this.timeoutId_ = setTimeout(this.handleWheelZoom_.bind(this, map), timeLeft);
  19225. return false;
  19226. };
  19227. /**
  19228. * @private
  19229. */
  19230. ol.interaction.MouseWheelZoom.prototype.decrementInteractingHint_ = function() {
  19231. this.trackpadTimeoutId_ = undefined;
  19232. var view = this.getMap().getView();
  19233. view.setHint(ol.ViewHint.INTERACTING, -1);
  19234. };
  19235. /**
  19236. * @private
  19237. * @param {ol.PluggableMap} map Map.
  19238. */
  19239. ol.interaction.MouseWheelZoom.prototype.handleWheelZoom_ = function(map) {
  19240. var view = map.getView();
  19241. if (view.getAnimating()) {
  19242. view.cancelAnimations();
  19243. }
  19244. var maxDelta = ol.MOUSEWHEELZOOM_MAXDELTA;
  19245. var delta = ol.math.clamp(this.delta_, -maxDelta, maxDelta);
  19246. ol.interaction.Interaction.zoomByDelta(view, -delta, this.lastAnchor_,
  19247. this.duration_);
  19248. this.mode_ = undefined;
  19249. this.delta_ = 0;
  19250. this.lastAnchor_ = null;
  19251. this.startTime_ = undefined;
  19252. this.timeoutId_ = undefined;
  19253. };
  19254. /**
  19255. * Enable or disable using the mouse's location as an anchor when zooming
  19256. * @param {boolean} useAnchor true to zoom to the mouse's location, false
  19257. * to zoom to the center of the map
  19258. * @api
  19259. */
  19260. ol.interaction.MouseWheelZoom.prototype.setMouseAnchor = function(useAnchor) {
  19261. this.useAnchor_ = useAnchor;
  19262. if (!useAnchor) {
  19263. this.lastAnchor_ = null;
  19264. }
  19265. };
  19266. /**
  19267. * @enum {string}
  19268. * @private
  19269. */
  19270. ol.interaction.MouseWheelZoom.Mode_ = {
  19271. TRACKPAD: 'trackpad',
  19272. WHEEL: 'wheel'
  19273. };
  19274. goog.provide('ol.interaction.PinchRotate');
  19275. goog.require('ol');
  19276. goog.require('ol.ViewHint');
  19277. goog.require('ol.functions');
  19278. goog.require('ol.interaction.Interaction');
  19279. goog.require('ol.interaction.Pointer');
  19280. goog.require('ol.RotationConstraint');
  19281. /**
  19282. * @classdesc
  19283. * Allows the user to rotate the map by twisting with two fingers
  19284. * on a touch screen.
  19285. *
  19286. * @constructor
  19287. * @extends {ol.interaction.Pointer}
  19288. * @param {olx.interaction.PinchRotateOptions=} opt_options Options.
  19289. * @api
  19290. */
  19291. ol.interaction.PinchRotate = function(opt_options) {
  19292. ol.interaction.Pointer.call(this, {
  19293. handleDownEvent: ol.interaction.PinchRotate.handleDownEvent_,
  19294. handleDragEvent: ol.interaction.PinchRotate.handleDragEvent_,
  19295. handleUpEvent: ol.interaction.PinchRotate.handleUpEvent_
  19296. });
  19297. var options = opt_options || {};
  19298. /**
  19299. * @private
  19300. * @type {ol.Coordinate}
  19301. */
  19302. this.anchor_ = null;
  19303. /**
  19304. * @private
  19305. * @type {number|undefined}
  19306. */
  19307. this.lastAngle_ = undefined;
  19308. /**
  19309. * @private
  19310. * @type {boolean}
  19311. */
  19312. this.rotating_ = false;
  19313. /**
  19314. * @private
  19315. * @type {number}
  19316. */
  19317. this.rotationDelta_ = 0.0;
  19318. /**
  19319. * @private
  19320. * @type {number}
  19321. */
  19322. this.threshold_ = options.threshold !== undefined ? options.threshold : 0.3;
  19323. /**
  19324. * @private
  19325. * @type {number}
  19326. */
  19327. this.duration_ = options.duration !== undefined ? options.duration : 250;
  19328. };
  19329. ol.inherits(ol.interaction.PinchRotate, ol.interaction.Pointer);
  19330. /**
  19331. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  19332. * @this {ol.interaction.PinchRotate}
  19333. * @private
  19334. */
  19335. ol.interaction.PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
  19336. var rotationDelta = 0.0;
  19337. var touch0 = this.targetPointers[0];
  19338. var touch1 = this.targetPointers[1];
  19339. // angle between touches
  19340. var angle = Math.atan2(
  19341. touch1.clientY - touch0.clientY,
  19342. touch1.clientX - touch0.clientX);
  19343. if (this.lastAngle_ !== undefined) {
  19344. var delta = angle - this.lastAngle_;
  19345. this.rotationDelta_ += delta;
  19346. if (!this.rotating_ &&
  19347. Math.abs(this.rotationDelta_) > this.threshold_) {
  19348. this.rotating_ = true;
  19349. }
  19350. rotationDelta = delta;
  19351. }
  19352. this.lastAngle_ = angle;
  19353. var map = mapBrowserEvent.map;
  19354. var view = map.getView();
  19355. if (view.getConstraints().rotation === ol.RotationConstraint.disable) {
  19356. return;
  19357. }
  19358. // rotate anchor point.
  19359. // FIXME: should be the intersection point between the lines:
  19360. // touch0,touch1 and previousTouch0,previousTouch1
  19361. var viewportPosition = map.getViewport().getBoundingClientRect();
  19362. var centroid = ol.interaction.Pointer.centroid(this.targetPointers);
  19363. centroid[0] -= viewportPosition.left;
  19364. centroid[1] -= viewportPosition.top;
  19365. this.anchor_ = map.getCoordinateFromPixel(centroid);
  19366. // rotate
  19367. if (this.rotating_) {
  19368. var rotation = view.getRotation();
  19369. map.render();
  19370. ol.interaction.Interaction.rotateWithoutConstraints(view,
  19371. rotation + rotationDelta, this.anchor_);
  19372. }
  19373. };
  19374. /**
  19375. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  19376. * @return {boolean} Stop drag sequence?
  19377. * @this {ol.interaction.PinchRotate}
  19378. * @private
  19379. */
  19380. ol.interaction.PinchRotate.handleUpEvent_ = function(mapBrowserEvent) {
  19381. if (this.targetPointers.length < 2) {
  19382. var map = mapBrowserEvent.map;
  19383. var view = map.getView();
  19384. view.setHint(ol.ViewHint.INTERACTING, -1);
  19385. if (this.rotating_) {
  19386. var rotation = view.getRotation();
  19387. ol.interaction.Interaction.rotate(
  19388. view, rotation, this.anchor_, this.duration_);
  19389. }
  19390. return false;
  19391. } else {
  19392. return true;
  19393. }
  19394. };
  19395. /**
  19396. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  19397. * @return {boolean} Start drag sequence?
  19398. * @this {ol.interaction.PinchRotate}
  19399. * @private
  19400. */
  19401. ol.interaction.PinchRotate.handleDownEvent_ = function(mapBrowserEvent) {
  19402. if (this.targetPointers.length >= 2) {
  19403. var map = mapBrowserEvent.map;
  19404. this.anchor_ = null;
  19405. this.lastAngle_ = undefined;
  19406. this.rotating_ = false;
  19407. this.rotationDelta_ = 0.0;
  19408. if (!this.handlingDownUpSequence) {
  19409. map.getView().setHint(ol.ViewHint.INTERACTING, 1);
  19410. }
  19411. return true;
  19412. } else {
  19413. return false;
  19414. }
  19415. };
  19416. /**
  19417. * @inheritDoc
  19418. */
  19419. ol.interaction.PinchRotate.prototype.shouldStopEvent = ol.functions.FALSE;
  19420. goog.provide('ol.interaction.PinchZoom');
  19421. goog.require('ol');
  19422. goog.require('ol.ViewHint');
  19423. goog.require('ol.functions');
  19424. goog.require('ol.interaction.Interaction');
  19425. goog.require('ol.interaction.Pointer');
  19426. /**
  19427. * @classdesc
  19428. * Allows the user to zoom the map by pinching with two fingers
  19429. * on a touch screen.
  19430. *
  19431. * @constructor
  19432. * @extends {ol.interaction.Pointer}
  19433. * @param {olx.interaction.PinchZoomOptions=} opt_options Options.
  19434. * @api
  19435. */
  19436. ol.interaction.PinchZoom = function(opt_options) {
  19437. ol.interaction.Pointer.call(this, {
  19438. handleDownEvent: ol.interaction.PinchZoom.handleDownEvent_,
  19439. handleDragEvent: ol.interaction.PinchZoom.handleDragEvent_,
  19440. handleUpEvent: ol.interaction.PinchZoom.handleUpEvent_
  19441. });
  19442. var options = opt_options ? opt_options : {};
  19443. /**
  19444. * @private
  19445. * @type {boolean}
  19446. */
  19447. this.constrainResolution_ = options.constrainResolution || false;
  19448. /**
  19449. * @private
  19450. * @type {ol.Coordinate}
  19451. */
  19452. this.anchor_ = null;
  19453. /**
  19454. * @private
  19455. * @type {number}
  19456. */
  19457. this.duration_ = options.duration !== undefined ? options.duration : 400;
  19458. /**
  19459. * @private
  19460. * @type {number|undefined}
  19461. */
  19462. this.lastDistance_ = undefined;
  19463. /**
  19464. * @private
  19465. * @type {number}
  19466. */
  19467. this.lastScaleDelta_ = 1;
  19468. };
  19469. ol.inherits(ol.interaction.PinchZoom, ol.interaction.Pointer);
  19470. /**
  19471. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  19472. * @this {ol.interaction.PinchZoom}
  19473. * @private
  19474. */
  19475. ol.interaction.PinchZoom.handleDragEvent_ = function(mapBrowserEvent) {
  19476. var scaleDelta = 1.0;
  19477. var touch0 = this.targetPointers[0];
  19478. var touch1 = this.targetPointers[1];
  19479. var dx = touch0.clientX - touch1.clientX;
  19480. var dy = touch0.clientY - touch1.clientY;
  19481. // distance between touches
  19482. var distance = Math.sqrt(dx * dx + dy * dy);
  19483. if (this.lastDistance_ !== undefined) {
  19484. scaleDelta = this.lastDistance_ / distance;
  19485. }
  19486. this.lastDistance_ = distance;
  19487. var map = mapBrowserEvent.map;
  19488. var view = map.getView();
  19489. var resolution = view.getResolution();
  19490. var maxResolution = view.getMaxResolution();
  19491. var minResolution = view.getMinResolution();
  19492. var newResolution = resolution * scaleDelta;
  19493. if (newResolution > maxResolution) {
  19494. scaleDelta = maxResolution / resolution;
  19495. newResolution = maxResolution;
  19496. } else if (newResolution < minResolution) {
  19497. scaleDelta = minResolution / resolution;
  19498. newResolution = minResolution;
  19499. }
  19500. if (scaleDelta != 1.0) {
  19501. this.lastScaleDelta_ = scaleDelta;
  19502. }
  19503. // scale anchor point.
  19504. var viewportPosition = map.getViewport().getBoundingClientRect();
  19505. var centroid = ol.interaction.Pointer.centroid(this.targetPointers);
  19506. centroid[0] -= viewportPosition.left;
  19507. centroid[1] -= viewportPosition.top;
  19508. this.anchor_ = map.getCoordinateFromPixel(centroid);
  19509. // scale, bypass the resolution constraint
  19510. map.render();
  19511. ol.interaction.Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_);
  19512. };
  19513. /**
  19514. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  19515. * @return {boolean} Stop drag sequence?
  19516. * @this {ol.interaction.PinchZoom}
  19517. * @private
  19518. */
  19519. ol.interaction.PinchZoom.handleUpEvent_ = function(mapBrowserEvent) {
  19520. if (this.targetPointers.length < 2) {
  19521. var map = mapBrowserEvent.map;
  19522. var view = map.getView();
  19523. view.setHint(ol.ViewHint.INTERACTING, -1);
  19524. var resolution = view.getResolution();
  19525. if (this.constrainResolution_ ||
  19526. resolution < view.getMinResolution() ||
  19527. resolution > view.getMaxResolution()) {
  19528. // Zoom to final resolution, with an animation, and provide a
  19529. // direction not to zoom out/in if user was pinching in/out.
  19530. // Direction is > 0 if pinching out, and < 0 if pinching in.
  19531. var direction = this.lastScaleDelta_ - 1;
  19532. ol.interaction.Interaction.zoom(view, resolution,
  19533. this.anchor_, this.duration_, direction);
  19534. }
  19535. return false;
  19536. } else {
  19537. return true;
  19538. }
  19539. };
  19540. /**
  19541. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  19542. * @return {boolean} Start drag sequence?
  19543. * @this {ol.interaction.PinchZoom}
  19544. * @private
  19545. */
  19546. ol.interaction.PinchZoom.handleDownEvent_ = function(mapBrowserEvent) {
  19547. if (this.targetPointers.length >= 2) {
  19548. var map = mapBrowserEvent.map;
  19549. this.anchor_ = null;
  19550. this.lastDistance_ = undefined;
  19551. this.lastScaleDelta_ = 1;
  19552. if (!this.handlingDownUpSequence) {
  19553. map.getView().setHint(ol.ViewHint.INTERACTING, 1);
  19554. }
  19555. return true;
  19556. } else {
  19557. return false;
  19558. }
  19559. };
  19560. /**
  19561. * @inheritDoc
  19562. */
  19563. ol.interaction.PinchZoom.prototype.shouldStopEvent = ol.functions.FALSE;
  19564. goog.provide('ol.interaction');
  19565. goog.require('ol.Collection');
  19566. goog.require('ol.Kinetic');
  19567. goog.require('ol.interaction.DoubleClickZoom');
  19568. goog.require('ol.interaction.DragPan');
  19569. goog.require('ol.interaction.DragRotate');
  19570. goog.require('ol.interaction.DragZoom');
  19571. goog.require('ol.interaction.KeyboardPan');
  19572. goog.require('ol.interaction.KeyboardZoom');
  19573. goog.require('ol.interaction.MouseWheelZoom');
  19574. goog.require('ol.interaction.PinchRotate');
  19575. goog.require('ol.interaction.PinchZoom');
  19576. /**
  19577. * Set of interactions included in maps by default. Specific interactions can be
  19578. * excluded by setting the appropriate option to false in the constructor
  19579. * options, but the order of the interactions is fixed. If you want to specify
  19580. * a different order for interactions, you will need to create your own
  19581. * {@link ol.interaction.Interaction} instances and insert them into a
  19582. * {@link ol.Collection} in the order you want before creating your
  19583. * {@link ol.Map} instance. The default set of interactions, in sequence, is:
  19584. * * {@link ol.interaction.DragRotate}
  19585. * * {@link ol.interaction.DoubleClickZoom}
  19586. * * {@link ol.interaction.DragPan}
  19587. * * {@link ol.interaction.PinchRotate}
  19588. * * {@link ol.interaction.PinchZoom}
  19589. * * {@link ol.interaction.KeyboardPan}
  19590. * * {@link ol.interaction.KeyboardZoom}
  19591. * * {@link ol.interaction.MouseWheelZoom}
  19592. * * {@link ol.interaction.DragZoom}
  19593. *
  19594. * @param {olx.interaction.DefaultsOptions=} opt_options Defaults options.
  19595. * @return {ol.Collection.<ol.interaction.Interaction>} A collection of
  19596. * interactions to be used with the ol.Map constructor's interactions option.
  19597. * @api
  19598. */
  19599. ol.interaction.defaults = function(opt_options) {
  19600. var options = opt_options ? opt_options : {};
  19601. var interactions = new ol.Collection();
  19602. var kinetic = new ol.Kinetic(-0.005, 0.05, 100);
  19603. var altShiftDragRotate = options.altShiftDragRotate !== undefined ?
  19604. options.altShiftDragRotate : true;
  19605. if (altShiftDragRotate) {
  19606. interactions.push(new ol.interaction.DragRotate());
  19607. }
  19608. var doubleClickZoom = options.doubleClickZoom !== undefined ?
  19609. options.doubleClickZoom : true;
  19610. if (doubleClickZoom) {
  19611. interactions.push(new ol.interaction.DoubleClickZoom({
  19612. delta: options.zoomDelta,
  19613. duration: options.zoomDuration
  19614. }));
  19615. }
  19616. var dragPan = options.dragPan !== undefined ? options.dragPan : true;
  19617. if (dragPan) {
  19618. interactions.push(new ol.interaction.DragPan({
  19619. kinetic: kinetic
  19620. }));
  19621. }
  19622. var pinchRotate = options.pinchRotate !== undefined ? options.pinchRotate :
  19623. true;
  19624. if (pinchRotate) {
  19625. interactions.push(new ol.interaction.PinchRotate());
  19626. }
  19627. var pinchZoom = options.pinchZoom !== undefined ? options.pinchZoom : true;
  19628. if (pinchZoom) {
  19629. interactions.push(new ol.interaction.PinchZoom({
  19630. constrainResolution: options.constrainResolution,
  19631. duration: options.zoomDuration
  19632. }));
  19633. }
  19634. var keyboard = options.keyboard !== undefined ? options.keyboard : true;
  19635. if (keyboard) {
  19636. interactions.push(new ol.interaction.KeyboardPan());
  19637. interactions.push(new ol.interaction.KeyboardZoom({
  19638. delta: options.zoomDelta,
  19639. duration: options.zoomDuration
  19640. }));
  19641. }
  19642. var mouseWheelZoom = options.mouseWheelZoom !== undefined ?
  19643. options.mouseWheelZoom : true;
  19644. if (mouseWheelZoom) {
  19645. interactions.push(new ol.interaction.MouseWheelZoom({
  19646. constrainResolution: options.constrainResolution,
  19647. duration: options.zoomDuration
  19648. }));
  19649. }
  19650. var shiftDragZoom = options.shiftDragZoom !== undefined ?
  19651. options.shiftDragZoom : true;
  19652. if (shiftDragZoom) {
  19653. interactions.push(new ol.interaction.DragZoom({
  19654. duration: options.zoomDuration
  19655. }));
  19656. }
  19657. return interactions;
  19658. };
  19659. goog.provide('ol.ImageBase');
  19660. goog.require('ol');
  19661. goog.require('ol.events.EventTarget');
  19662. goog.require('ol.events.EventType');
  19663. /**
  19664. * @constructor
  19665. * @abstract
  19666. * @extends {ol.events.EventTarget}
  19667. * @param {ol.Extent} extent Extent.
  19668. * @param {number|undefined} resolution Resolution.
  19669. * @param {number} pixelRatio Pixel ratio.
  19670. * @param {ol.ImageState} state State.
  19671. */
  19672. ol.ImageBase = function(extent, resolution, pixelRatio, state) {
  19673. ol.events.EventTarget.call(this);
  19674. /**
  19675. * @protected
  19676. * @type {ol.Extent}
  19677. */
  19678. this.extent = extent;
  19679. /**
  19680. * @private
  19681. * @type {number}
  19682. */
  19683. this.pixelRatio_ = pixelRatio;
  19684. /**
  19685. * @protected
  19686. * @type {number|undefined}
  19687. */
  19688. this.resolution = resolution;
  19689. /**
  19690. * @protected
  19691. * @type {ol.ImageState}
  19692. */
  19693. this.state = state;
  19694. };
  19695. ol.inherits(ol.ImageBase, ol.events.EventTarget);
  19696. /**
  19697. * @protected
  19698. */
  19699. ol.ImageBase.prototype.changed = function() {
  19700. this.dispatchEvent(ol.events.EventType.CHANGE);
  19701. };
  19702. /**
  19703. * @return {ol.Extent} Extent.
  19704. */
  19705. ol.ImageBase.prototype.getExtent = function() {
  19706. return this.extent;
  19707. };
  19708. /**
  19709. * @abstract
  19710. * @return {HTMLCanvasElement|Image|HTMLVideoElement} Image.
  19711. */
  19712. ol.ImageBase.prototype.getImage = function() {};
  19713. /**
  19714. * @return {number} PixelRatio.
  19715. */
  19716. ol.ImageBase.prototype.getPixelRatio = function() {
  19717. return this.pixelRatio_;
  19718. };
  19719. /**
  19720. * @return {number} Resolution.
  19721. */
  19722. ol.ImageBase.prototype.getResolution = function() {
  19723. return /** @type {number} */ (this.resolution);
  19724. };
  19725. /**
  19726. * @return {ol.ImageState} State.
  19727. */
  19728. ol.ImageBase.prototype.getState = function() {
  19729. return this.state;
  19730. };
  19731. /**
  19732. * Load not yet loaded URI.
  19733. * @abstract
  19734. */
  19735. ol.ImageBase.prototype.load = function() {};
  19736. goog.provide('ol.ImageState');
  19737. /**
  19738. * @enum {number}
  19739. */
  19740. ol.ImageState = {
  19741. IDLE: 0,
  19742. LOADING: 1,
  19743. LOADED: 2,
  19744. ERROR: 3
  19745. };
  19746. goog.provide('ol.ImageCanvas');
  19747. goog.require('ol');
  19748. goog.require('ol.ImageBase');
  19749. goog.require('ol.ImageState');
  19750. /**
  19751. * @constructor
  19752. * @extends {ol.ImageBase}
  19753. * @param {ol.Extent} extent Extent.
  19754. * @param {number} resolution Resolution.
  19755. * @param {number} pixelRatio Pixel ratio.
  19756. * @param {HTMLCanvasElement} canvas Canvas.
  19757. * @param {ol.ImageCanvasLoader=} opt_loader Optional loader function to
  19758. * support asynchronous canvas drawing.
  19759. */
  19760. ol.ImageCanvas = function(extent, resolution, pixelRatio, canvas, opt_loader) {
  19761. /**
  19762. * Optional canvas loader function.
  19763. * @type {?ol.ImageCanvasLoader}
  19764. * @private
  19765. */
  19766. this.loader_ = opt_loader !== undefined ? opt_loader : null;
  19767. var state = opt_loader !== undefined ?
  19768. ol.ImageState.IDLE : ol.ImageState.LOADED;
  19769. ol.ImageBase.call(this, extent, resolution, pixelRatio, state);
  19770. /**
  19771. * @private
  19772. * @type {HTMLCanvasElement}
  19773. */
  19774. this.canvas_ = canvas;
  19775. /**
  19776. * @private
  19777. * @type {Error}
  19778. */
  19779. this.error_ = null;
  19780. };
  19781. ol.inherits(ol.ImageCanvas, ol.ImageBase);
  19782. /**
  19783. * Get any error associated with asynchronous rendering.
  19784. * @return {Error} Any error that occurred during rendering.
  19785. */
  19786. ol.ImageCanvas.prototype.getError = function() {
  19787. return this.error_;
  19788. };
  19789. /**
  19790. * Handle async drawing complete.
  19791. * @param {Error} err Any error during drawing.
  19792. * @private
  19793. */
  19794. ol.ImageCanvas.prototype.handleLoad_ = function(err) {
  19795. if (err) {
  19796. this.error_ = err;
  19797. this.state = ol.ImageState.ERROR;
  19798. } else {
  19799. this.state = ol.ImageState.LOADED;
  19800. }
  19801. this.changed();
  19802. };
  19803. /**
  19804. * @inheritDoc
  19805. */
  19806. ol.ImageCanvas.prototype.load = function() {
  19807. if (this.state == ol.ImageState.IDLE) {
  19808. this.state = ol.ImageState.LOADING;
  19809. this.changed();
  19810. this.loader_(this.handleLoad_.bind(this));
  19811. }
  19812. };
  19813. /**
  19814. * @inheritDoc
  19815. */
  19816. ol.ImageCanvas.prototype.getImage = function() {
  19817. return this.canvas_;
  19818. };
  19819. goog.provide('ol.LayerType');
  19820. /**
  19821. * A layer type used when creating layer renderers.
  19822. * @enum {string}
  19823. */
  19824. ol.LayerType = {
  19825. IMAGE: 'IMAGE',
  19826. TILE: 'TILE',
  19827. VECTOR_TILE: 'VECTOR_TILE',
  19828. VECTOR: 'VECTOR'
  19829. };
  19830. goog.provide('ol.layer.VectorRenderType');
  19831. /**
  19832. * @enum {string}
  19833. * Render mode for vector layers:
  19834. * * `'image'`: Vector layers are rendered as images. Great performance, but
  19835. * point symbols and texts are always rotated with the view and pixels are
  19836. * scaled during zoom animations.
  19837. * * `'vector'`: Vector layers are rendered as vectors. Most accurate rendering
  19838. * even during animations, but slower performance.
  19839. * @api
  19840. */
  19841. ol.layer.VectorRenderType = {
  19842. IMAGE: 'image',
  19843. VECTOR: 'vector'
  19844. };
  19845. goog.provide('ol.render.Event');
  19846. goog.require('ol');
  19847. goog.require('ol.events.Event');
  19848. /**
  19849. * @constructor
  19850. * @extends {ol.events.Event}
  19851. * @implements {oli.render.Event}
  19852. * @param {ol.render.EventType} type Type.
  19853. * @param {ol.render.VectorContext=} opt_vectorContext Vector context.
  19854. * @param {olx.FrameState=} opt_frameState Frame state.
  19855. * @param {?CanvasRenderingContext2D=} opt_context Context.
  19856. * @param {?ol.webgl.Context=} opt_glContext WebGL Context.
  19857. */
  19858. ol.render.Event = function(
  19859. type, opt_vectorContext, opt_frameState, opt_context,
  19860. opt_glContext) {
  19861. ol.events.Event.call(this, type);
  19862. /**
  19863. * For canvas, this is an instance of {@link ol.render.canvas.Immediate}.
  19864. * @type {ol.render.VectorContext|undefined}
  19865. * @api
  19866. */
  19867. this.vectorContext = opt_vectorContext;
  19868. /**
  19869. * An object representing the current render frame state.
  19870. * @type {olx.FrameState|undefined}
  19871. * @api
  19872. */
  19873. this.frameState = opt_frameState;
  19874. /**
  19875. * Canvas context. Only available when a Canvas renderer is used, null
  19876. * otherwise.
  19877. * @type {CanvasRenderingContext2D|null|undefined}
  19878. * @api
  19879. */
  19880. this.context = opt_context;
  19881. /**
  19882. * WebGL context. Only available when a WebGL renderer is used, null
  19883. * otherwise.
  19884. * @type {ol.webgl.Context|null|undefined}
  19885. * @api
  19886. */
  19887. this.glContext = opt_glContext;
  19888. };
  19889. ol.inherits(ol.render.Event, ol.events.Event);
  19890. goog.provide('ol.structs.LRUCache');
  19891. goog.require('ol');
  19892. goog.require('ol.asserts');
  19893. goog.require('ol.events.EventTarget');
  19894. goog.require('ol.events.EventType');
  19895. /**
  19896. * Implements a Least-Recently-Used cache where the keys do not conflict with
  19897. * Object's properties (e.g. 'hasOwnProperty' is not allowed as a key). Expiring
  19898. * items from the cache is the responsibility of the user.
  19899. * @constructor
  19900. * @extends {ol.events.EventTarget}
  19901. * @fires ol.events.Event
  19902. * @struct
  19903. * @template T
  19904. * @param {number=} opt_highWaterMark High water mark.
  19905. */
  19906. ol.structs.LRUCache = function(opt_highWaterMark) {
  19907. ol.events.EventTarget.call(this);
  19908. /**
  19909. * @type {number}
  19910. */
  19911. this.highWaterMark = opt_highWaterMark !== undefined ? opt_highWaterMark : 2048;
  19912. /**
  19913. * @private
  19914. * @type {number}
  19915. */
  19916. this.count_ = 0;
  19917. /**
  19918. * @private
  19919. * @type {!Object.<string, ol.LRUCacheEntry>}
  19920. */
  19921. this.entries_ = {};
  19922. /**
  19923. * @private
  19924. * @type {?ol.LRUCacheEntry}
  19925. */
  19926. this.oldest_ = null;
  19927. /**
  19928. * @private
  19929. * @type {?ol.LRUCacheEntry}
  19930. */
  19931. this.newest_ = null;
  19932. };
  19933. ol.inherits(ol.structs.LRUCache, ol.events.EventTarget);
  19934. /**
  19935. * @return {boolean} Can expire cache.
  19936. */
  19937. ol.structs.LRUCache.prototype.canExpireCache = function() {
  19938. return this.getCount() > this.highWaterMark;
  19939. };
  19940. /**
  19941. * FIXME empty description for jsdoc
  19942. */
  19943. ol.structs.LRUCache.prototype.clear = function() {
  19944. this.count_ = 0;
  19945. this.entries_ = {};
  19946. this.oldest_ = null;
  19947. this.newest_ = null;
  19948. this.dispatchEvent(ol.events.EventType.CLEAR);
  19949. };
  19950. /**
  19951. * @param {string} key Key.
  19952. * @return {boolean} Contains key.
  19953. */
  19954. ol.structs.LRUCache.prototype.containsKey = function(key) {
  19955. return this.entries_.hasOwnProperty(key);
  19956. };
  19957. /**
  19958. * @param {function(this: S, T, string, ol.structs.LRUCache): ?} f The function
  19959. * to call for every entry from the oldest to the newer. This function takes
  19960. * 3 arguments (the entry value, the entry key and the LRUCache object).
  19961. * The return value is ignored.
  19962. * @param {S=} opt_this The object to use as `this` in `f`.
  19963. * @template S
  19964. */
  19965. ol.structs.LRUCache.prototype.forEach = function(f, opt_this) {
  19966. var entry = this.oldest_;
  19967. while (entry) {
  19968. f.call(opt_this, entry.value_, entry.key_, this);
  19969. entry = entry.newer;
  19970. }
  19971. };
  19972. /**
  19973. * @param {string} key Key.
  19974. * @return {T} Value.
  19975. */
  19976. ol.structs.LRUCache.prototype.get = function(key) {
  19977. var entry = this.entries_[key];
  19978. ol.asserts.assert(entry !== undefined,
  19979. 15); // Tried to get a value for a key that does not exist in the cache
  19980. if (entry === this.newest_) {
  19981. return entry.value_;
  19982. } else if (entry === this.oldest_) {
  19983. this.oldest_ = /** @type {ol.LRUCacheEntry} */ (this.oldest_.newer);
  19984. this.oldest_.older = null;
  19985. } else {
  19986. entry.newer.older = entry.older;
  19987. entry.older.newer = entry.newer;
  19988. }
  19989. entry.newer = null;
  19990. entry.older = this.newest_;
  19991. this.newest_.newer = entry;
  19992. this.newest_ = entry;
  19993. return entry.value_;
  19994. };
  19995. /**
  19996. * Remove an entry from the cache.
  19997. * @param {string} key The entry key.
  19998. * @return {T} The removed entry.
  19999. */
  20000. ol.structs.LRUCache.prototype.remove = function(key) {
  20001. var entry = this.entries_[key];
  20002. ol.asserts.assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache
  20003. if (entry === this.newest_) {
  20004. this.newest_ = /** @type {ol.LRUCacheEntry} */ (entry.older);
  20005. if (this.newest_) {
  20006. this.newest_.newer = null;
  20007. }
  20008. } else if (entry === this.oldest_) {
  20009. this.oldest_ = /** @type {ol.LRUCacheEntry} */ (entry.newer);
  20010. if (this.oldest_) {
  20011. this.oldest_.older = null;
  20012. }
  20013. } else {
  20014. entry.newer.older = entry.older;
  20015. entry.older.newer = entry.newer;
  20016. }
  20017. delete this.entries_[key];
  20018. --this.count_;
  20019. return entry.value_;
  20020. };
  20021. /**
  20022. * @return {number} Count.
  20023. */
  20024. ol.structs.LRUCache.prototype.getCount = function() {
  20025. return this.count_;
  20026. };
  20027. /**
  20028. * @return {Array.<string>} Keys.
  20029. */
  20030. ol.structs.LRUCache.prototype.getKeys = function() {
  20031. var keys = new Array(this.count_);
  20032. var i = 0;
  20033. var entry;
  20034. for (entry = this.newest_; entry; entry = entry.older) {
  20035. keys[i++] = entry.key_;
  20036. }
  20037. return keys;
  20038. };
  20039. /**
  20040. * @return {Array.<T>} Values.
  20041. */
  20042. ol.structs.LRUCache.prototype.getValues = function() {
  20043. var values = new Array(this.count_);
  20044. var i = 0;
  20045. var entry;
  20046. for (entry = this.newest_; entry; entry = entry.older) {
  20047. values[i++] = entry.value_;
  20048. }
  20049. return values;
  20050. };
  20051. /**
  20052. * @return {T} Last value.
  20053. */
  20054. ol.structs.LRUCache.prototype.peekLast = function() {
  20055. return this.oldest_.value_;
  20056. };
  20057. /**
  20058. * @return {string} Last key.
  20059. */
  20060. ol.structs.LRUCache.prototype.peekLastKey = function() {
  20061. return this.oldest_.key_;
  20062. };
  20063. /**
  20064. * Get the key of the newest item in the cache. Throws if the cache is empty.
  20065. * @return {string} The newest key.
  20066. */
  20067. ol.structs.LRUCache.prototype.peekFirstKey = function() {
  20068. return this.newest_.key_;
  20069. };
  20070. /**
  20071. * @return {T} value Value.
  20072. */
  20073. ol.structs.LRUCache.prototype.pop = function() {
  20074. var entry = this.oldest_;
  20075. delete this.entries_[entry.key_];
  20076. if (entry.newer) {
  20077. entry.newer.older = null;
  20078. }
  20079. this.oldest_ = /** @type {ol.LRUCacheEntry} */ (entry.newer);
  20080. if (!this.oldest_) {
  20081. this.newest_ = null;
  20082. }
  20083. --this.count_;
  20084. return entry.value_;
  20085. };
  20086. /**
  20087. * @param {string} key Key.
  20088. * @param {T} value Value.
  20089. */
  20090. ol.structs.LRUCache.prototype.replace = function(key, value) {
  20091. this.get(key); // update `newest_`
  20092. this.entries_[key].value_ = value;
  20093. };
  20094. /**
  20095. * @param {string} key Key.
  20096. * @param {T} value Value.
  20097. */
  20098. ol.structs.LRUCache.prototype.set = function(key, value) {
  20099. ol.asserts.assert(!(key in this.entries_),
  20100. 16); // Tried to set a value for a key that is used already
  20101. var entry = /** @type {ol.LRUCacheEntry} */ ({
  20102. key_: key,
  20103. newer: null,
  20104. older: this.newest_,
  20105. value_: value
  20106. });
  20107. if (!this.newest_) {
  20108. this.oldest_ = entry;
  20109. } else {
  20110. this.newest_.newer = entry;
  20111. }
  20112. this.newest_ = entry;
  20113. this.entries_[key] = entry;
  20114. ++this.count_;
  20115. };
  20116. /**
  20117. * Prune the cache.
  20118. */
  20119. ol.structs.LRUCache.prototype.prune = function() {
  20120. while (this.canExpireCache()) {
  20121. this.pop();
  20122. }
  20123. };
  20124. goog.provide('ol.render.canvas');
  20125. goog.require('ol.css');
  20126. goog.require('ol.dom');
  20127. goog.require('ol.obj');
  20128. goog.require('ol.structs.LRUCache');
  20129. goog.require('ol.transform');
  20130. /**
  20131. * @const
  20132. * @type {string}
  20133. */
  20134. ol.render.canvas.defaultFont = '10px sans-serif';
  20135. /**
  20136. * @const
  20137. * @type {ol.Color}
  20138. */
  20139. ol.render.canvas.defaultFillStyle = [0, 0, 0, 1];
  20140. /**
  20141. * @const
  20142. * @type {string}
  20143. */
  20144. ol.render.canvas.defaultLineCap = 'round';
  20145. /**
  20146. * @const
  20147. * @type {Array.<number>}
  20148. */
  20149. ol.render.canvas.defaultLineDash = [];
  20150. /**
  20151. * @const
  20152. * @type {number}
  20153. */
  20154. ol.render.canvas.defaultLineDashOffset = 0;
  20155. /**
  20156. * @const
  20157. * @type {string}
  20158. */
  20159. ol.render.canvas.defaultLineJoin = 'round';
  20160. /**
  20161. * @const
  20162. * @type {number}
  20163. */
  20164. ol.render.canvas.defaultMiterLimit = 10;
  20165. /**
  20166. * @const
  20167. * @type {ol.Color}
  20168. */
  20169. ol.render.canvas.defaultStrokeStyle = [0, 0, 0, 1];
  20170. /**
  20171. * @const
  20172. * @type {string}
  20173. */
  20174. ol.render.canvas.defaultTextAlign = 'center';
  20175. /**
  20176. * @const
  20177. * @type {string}
  20178. */
  20179. ol.render.canvas.defaultTextBaseline = 'middle';
  20180. /**
  20181. * @const
  20182. * @type {Array.<number>}
  20183. */
  20184. ol.render.canvas.defaultPadding = [0, 0, 0, 0];
  20185. /**
  20186. * @const
  20187. * @type {number}
  20188. */
  20189. ol.render.canvas.defaultLineWidth = 1;
  20190. /**
  20191. * @type {ol.structs.LRUCache.<HTMLCanvasElement>}
  20192. */
  20193. ol.render.canvas.labelCache = new ol.structs.LRUCache();
  20194. /**
  20195. * @type {!Object.<string, number>}
  20196. */
  20197. ol.render.canvas.checkedFonts_ = {};
  20198. /**
  20199. * @type {CanvasRenderingContext2D}
  20200. */
  20201. ol.render.canvas.measureContext_ = null;
  20202. /**
  20203. * @type {!Object.<string, number>}
  20204. */
  20205. ol.render.canvas.textHeights_ = {};
  20206. /**
  20207. * Clears the label cache when a font becomes available.
  20208. * @param {string} fontSpec CSS font spec.
  20209. */
  20210. ol.render.canvas.checkFont = (function() {
  20211. var retries = 60;
  20212. var checked = ol.render.canvas.checkedFonts_;
  20213. var labelCache = ol.render.canvas.labelCache;
  20214. var font = '32px monospace';
  20215. var text = 'wmytzilWMYTZIL@#/&?$%10';
  20216. var interval, referenceWidth;
  20217. function isAvailable(fontFamily) {
  20218. var context = ol.render.canvas.getMeasureContext();
  20219. context.font = font;
  20220. referenceWidth = context.measureText(text).width;
  20221. var available = true;
  20222. if (fontFamily != 'monospace') {
  20223. context.font = '32px ' + fontFamily + ',monospace';
  20224. var width = context.measureText(text).width;
  20225. // If width and referenceWidth are the same, then the 'monospace'
  20226. // fallback was used instead of the font we wanted, so the font is not
  20227. // available.
  20228. available = width != referenceWidth;
  20229. }
  20230. return available;
  20231. }
  20232. function check() {
  20233. var done = true;
  20234. for (var font in checked) {
  20235. if (checked[font] < retries) {
  20236. if (isAvailable(font)) {
  20237. checked[font] = retries;
  20238. ol.obj.clear(ol.render.canvas.textHeights_);
  20239. // Make sure that loaded fonts are picked up by Safari
  20240. ol.render.canvas.measureContext_ = null;
  20241. labelCache.clear();
  20242. } else {
  20243. ++checked[font];
  20244. done = false;
  20245. }
  20246. }
  20247. }
  20248. if (done) {
  20249. window.clearInterval(interval);
  20250. interval = undefined;
  20251. }
  20252. }
  20253. return function(fontSpec) {
  20254. var fontFamilies = ol.css.getFontFamilies(fontSpec);
  20255. if (!fontFamilies) {
  20256. return;
  20257. }
  20258. for (var i = 0, ii = fontFamilies.length; i < ii; ++i) {
  20259. var fontFamily = fontFamilies[i];
  20260. if (!(fontFamily in checked)) {
  20261. checked[fontFamily] = retries;
  20262. if (!isAvailable(fontFamily)) {
  20263. checked[fontFamily] = 0;
  20264. if (interval === undefined) {
  20265. interval = window.setInterval(check, 32);
  20266. }
  20267. }
  20268. }
  20269. }
  20270. };
  20271. })();
  20272. /**
  20273. * @return {CanvasRenderingContext2D} Measure context.
  20274. */
  20275. ol.render.canvas.getMeasureContext = function() {
  20276. var context = ol.render.canvas.measureContext_;
  20277. if (!context) {
  20278. context = ol.render.canvas.measureContext_ = ol.dom.createCanvasContext2D(1, 1);
  20279. }
  20280. return context;
  20281. };
  20282. /**
  20283. * @param {string} font Font to use for measuring.
  20284. * @return {ol.Size} Measurement.
  20285. */
  20286. ol.render.canvas.measureTextHeight = (function() {
  20287. var span;
  20288. var heights = ol.render.canvas.textHeights_;
  20289. return function(font) {
  20290. var height = heights[font];
  20291. if (height == undefined) {
  20292. if (!span) {
  20293. span = document.createElement('span');
  20294. span.textContent = 'M';
  20295. span.style.margin = span.style.padding = '0 !important';
  20296. span.style.position = 'absolute !important';
  20297. span.style.left = '-99999px !important';
  20298. }
  20299. span.style.font = font;
  20300. document.body.appendChild(span);
  20301. height = heights[font] = span.offsetHeight;
  20302. document.body.removeChild(span);
  20303. }
  20304. return height;
  20305. };
  20306. })();
  20307. /**
  20308. * @param {string} font Font.
  20309. * @param {string} text Text.
  20310. * @return {number} Width.
  20311. */
  20312. ol.render.canvas.measureTextWidth = function(font, text) {
  20313. var measureContext = ol.render.canvas.getMeasureContext();
  20314. if (font != measureContext.font) {
  20315. measureContext.font = font;
  20316. }
  20317. return measureContext.measureText(text).width;
  20318. };
  20319. /**
  20320. * @param {CanvasRenderingContext2D} context Context.
  20321. * @param {number} rotation Rotation.
  20322. * @param {number} offsetX X offset.
  20323. * @param {number} offsetY Y offset.
  20324. */
  20325. ol.render.canvas.rotateAtOffset = function(context, rotation, offsetX, offsetY) {
  20326. if (rotation !== 0) {
  20327. context.translate(offsetX, offsetY);
  20328. context.rotate(rotation);
  20329. context.translate(-offsetX, -offsetY);
  20330. }
  20331. };
  20332. ol.render.canvas.resetTransform_ = ol.transform.create();
  20333. /**
  20334. * @param {CanvasRenderingContext2D} context Context.
  20335. * @param {ol.Transform|null} transform Transform.
  20336. * @param {number} opacity Opacity.
  20337. * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} image Image.
  20338. * @param {number} originX Origin X.
  20339. * @param {number} originY Origin Y.
  20340. * @param {number} w Width.
  20341. * @param {number} h Height.
  20342. * @param {number} x X.
  20343. * @param {number} y Y.
  20344. * @param {number} scale Scale.
  20345. */
  20346. ol.render.canvas.drawImage = function(context,
  20347. transform, opacity, image, originX, originY, w, h, x, y, scale) {
  20348. var alpha;
  20349. if (opacity != 1) {
  20350. alpha = context.globalAlpha;
  20351. context.globalAlpha = alpha * opacity;
  20352. }
  20353. if (transform) {
  20354. context.setTransform.apply(context, transform);
  20355. }
  20356. context.drawImage(image, originX, originY, w, h, x, y, w * scale, h * scale);
  20357. if (alpha) {
  20358. context.globalAlpha = alpha;
  20359. }
  20360. if (transform) {
  20361. context.setTransform.apply(context, ol.render.canvas.resetTransform_);
  20362. }
  20363. };
  20364. goog.provide('ol.color');
  20365. goog.require('ol.asserts');
  20366. goog.require('ol.math');
  20367. /**
  20368. * This RegExp matches # followed by 3, 4, 6, or 8 hex digits.
  20369. * @const
  20370. * @type {RegExp}
  20371. * @private
  20372. */
  20373. ol.color.HEX_COLOR_RE_ = /^#(?:[0-9a-f]{3,4}){1,2}$/i;
  20374. /**
  20375. * Regular expression for matching potential named color style strings.
  20376. * @const
  20377. * @type {RegExp}
  20378. * @private
  20379. */
  20380. ol.color.NAMED_COLOR_RE_ = /^([a-z]*)$/i;
  20381. /**
  20382. * Return the color as an array. This function maintains a cache of calculated
  20383. * arrays which means the result should not be modified.
  20384. * @param {ol.Color|string} color Color.
  20385. * @return {ol.Color} Color.
  20386. * @api
  20387. */
  20388. ol.color.asArray = function(color) {
  20389. if (Array.isArray(color)) {
  20390. return color;
  20391. } else {
  20392. return ol.color.fromString(/** @type {string} */ (color));
  20393. }
  20394. };
  20395. /**
  20396. * Return the color as an rgba string.
  20397. * @param {ol.Color|string} color Color.
  20398. * @return {string} Rgba string.
  20399. * @api
  20400. */
  20401. ol.color.asString = function(color) {
  20402. if (typeof color === 'string') {
  20403. return color;
  20404. } else {
  20405. return ol.color.toString(color);
  20406. }
  20407. };
  20408. /**
  20409. * Return named color as an rgba string.
  20410. * @param {string} color Named color.
  20411. * @return {string} Rgb string.
  20412. */
  20413. ol.color.fromNamed = function(color) {
  20414. var el = document.createElement('div');
  20415. el.style.color = color;
  20416. document.body.appendChild(el);
  20417. var rgb = getComputedStyle(el).color;
  20418. document.body.removeChild(el);
  20419. return rgb;
  20420. };
  20421. /**
  20422. * @param {string} s String.
  20423. * @return {ol.Color} Color.
  20424. */
  20425. ol.color.fromString = (
  20426. function() {
  20427. // We maintain a small cache of parsed strings. To provide cheap LRU-like
  20428. // semantics, whenever the cache grows too large we simply delete an
  20429. // arbitrary 25% of the entries.
  20430. /**
  20431. * @const
  20432. * @type {number}
  20433. */
  20434. var MAX_CACHE_SIZE = 1024;
  20435. /**
  20436. * @type {Object.<string, ol.Color>}
  20437. */
  20438. var cache = {};
  20439. /**
  20440. * @type {number}
  20441. */
  20442. var cacheSize = 0;
  20443. return (
  20444. /**
  20445. * @param {string} s String.
  20446. * @return {ol.Color} Color.
  20447. */
  20448. function(s) {
  20449. var color;
  20450. if (cache.hasOwnProperty(s)) {
  20451. color = cache[s];
  20452. } else {
  20453. if (cacheSize >= MAX_CACHE_SIZE) {
  20454. var i = 0;
  20455. var key;
  20456. for (key in cache) {
  20457. if ((i++ & 3) === 0) {
  20458. delete cache[key];
  20459. --cacheSize;
  20460. }
  20461. }
  20462. }
  20463. color = ol.color.fromStringInternal_(s);
  20464. cache[s] = color;
  20465. ++cacheSize;
  20466. }
  20467. return color;
  20468. });
  20469. })();
  20470. /**
  20471. * @param {string} s String.
  20472. * @private
  20473. * @return {ol.Color} Color.
  20474. */
  20475. ol.color.fromStringInternal_ = function(s) {
  20476. var r, g, b, a, color, parts;
  20477. if (ol.color.NAMED_COLOR_RE_.exec(s)) {
  20478. s = ol.color.fromNamed(s);
  20479. }
  20480. if (ol.color.HEX_COLOR_RE_.exec(s)) { // hex
  20481. var n = s.length - 1; // number of hex digits
  20482. var d; // number of digits per channel
  20483. if (n <= 4) {
  20484. d = 1;
  20485. } else {
  20486. d = 2;
  20487. }
  20488. var hasAlpha = n === 4 || n === 8;
  20489. r = parseInt(s.substr(1 + 0 * d, d), 16);
  20490. g = parseInt(s.substr(1 + 1 * d, d), 16);
  20491. b = parseInt(s.substr(1 + 2 * d, d), 16);
  20492. if (hasAlpha) {
  20493. a = parseInt(s.substr(1 + 3 * d, d), 16);
  20494. } else {
  20495. a = 255;
  20496. }
  20497. if (d == 1) {
  20498. r = (r << 4) + r;
  20499. g = (g << 4) + g;
  20500. b = (b << 4) + b;
  20501. if (hasAlpha) {
  20502. a = (a << 4) + a;
  20503. }
  20504. }
  20505. color = [r, g, b, a / 255];
  20506. } else if (s.indexOf('rgba(') == 0) { // rgba()
  20507. parts = s.slice(5, -1).split(',').map(Number);
  20508. color = ol.color.normalize(parts);
  20509. } else if (s.indexOf('rgb(') == 0) { // rgb()
  20510. parts = s.slice(4, -1).split(',').map(Number);
  20511. parts.push(1);
  20512. color = ol.color.normalize(parts);
  20513. } else {
  20514. ol.asserts.assert(false, 14); // Invalid color
  20515. }
  20516. return /** @type {ol.Color} */ (color);
  20517. };
  20518. /**
  20519. * @param {ol.Color} color Color.
  20520. * @param {ol.Color=} opt_color Color.
  20521. * @return {ol.Color} Clamped color.
  20522. */
  20523. ol.color.normalize = function(color, opt_color) {
  20524. var result = opt_color || [];
  20525. result[0] = ol.math.clamp((color[0] + 0.5) | 0, 0, 255);
  20526. result[1] = ol.math.clamp((color[1] + 0.5) | 0, 0, 255);
  20527. result[2] = ol.math.clamp((color[2] + 0.5) | 0, 0, 255);
  20528. result[3] = ol.math.clamp(color[3], 0, 1);
  20529. return result;
  20530. };
  20531. /**
  20532. * @param {ol.Color} color Color.
  20533. * @return {string} String.
  20534. */
  20535. ol.color.toString = function(color) {
  20536. var r = color[0];
  20537. if (r != (r | 0)) {
  20538. r = (r + 0.5) | 0;
  20539. }
  20540. var g = color[1];
  20541. if (g != (g | 0)) {
  20542. g = (g + 0.5) | 0;
  20543. }
  20544. var b = color[2];
  20545. if (b != (b | 0)) {
  20546. b = (b + 0.5) | 0;
  20547. }
  20548. var a = color[3] === undefined ? 1 : color[3];
  20549. return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
  20550. };
  20551. goog.provide('ol.colorlike');
  20552. goog.require('ol.color');
  20553. /**
  20554. * @param {ol.Color|ol.ColorLike} color Color.
  20555. * @return {ol.ColorLike} The color as an ol.ColorLike
  20556. * @api
  20557. */
  20558. ol.colorlike.asColorLike = function(color) {
  20559. if (ol.colorlike.isColorLike(color)) {
  20560. return /** @type {string|CanvasPattern|CanvasGradient} */ (color);
  20561. } else {
  20562. return ol.color.asString(/** @type {ol.Color} */ (color));
  20563. }
  20564. };
  20565. /**
  20566. * @param {?} color The value that is potentially an ol.ColorLike
  20567. * @return {boolean} Whether the color is an ol.ColorLike
  20568. */
  20569. ol.colorlike.isColorLike = function(color) {
  20570. return (
  20571. typeof color === 'string' ||
  20572. color instanceof CanvasPattern ||
  20573. color instanceof CanvasGradient
  20574. );
  20575. };
  20576. goog.provide('ol.render.VectorContext');
  20577. /**
  20578. * Context for drawing geometries. A vector context is available on render
  20579. * events and does not need to be constructed directly.
  20580. * @constructor
  20581. * @abstract
  20582. * @struct
  20583. * @api
  20584. */
  20585. ol.render.VectorContext = function() {
  20586. };
  20587. /**
  20588. * Render a geometry with a custom renderer.
  20589. *
  20590. * @param {ol.geom.SimpleGeometry} geometry Geometry.
  20591. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20592. * @param {Function} renderer Renderer.
  20593. */
  20594. ol.render.VectorContext.prototype.drawCustom = function(geometry, feature, renderer) {};
  20595. /**
  20596. * Render a geometry.
  20597. *
  20598. * @param {ol.geom.Geometry} geometry The geometry to render.
  20599. */
  20600. ol.render.VectorContext.prototype.drawGeometry = function(geometry) {};
  20601. /**
  20602. * Set the rendering style.
  20603. *
  20604. * @param {ol.style.Style} style The rendering style.
  20605. */
  20606. ol.render.VectorContext.prototype.setStyle = function(style) {};
  20607. /**
  20608. * @param {ol.geom.Circle} circleGeometry Circle geometry.
  20609. * @param {ol.Feature} feature Feature.
  20610. */
  20611. ol.render.VectorContext.prototype.drawCircle = function(circleGeometry, feature) {};
  20612. /**
  20613. * @param {ol.Feature} feature Feature.
  20614. * @param {ol.style.Style} style Style.
  20615. */
  20616. ol.render.VectorContext.prototype.drawFeature = function(feature, style) {};
  20617. /**
  20618. * @param {ol.geom.GeometryCollection} geometryCollectionGeometry Geometry
  20619. * collection.
  20620. * @param {ol.Feature} feature Feature.
  20621. */
  20622. ol.render.VectorContext.prototype.drawGeometryCollection = function(geometryCollectionGeometry, feature) {};
  20623. /**
  20624. * @param {ol.geom.LineString|ol.render.Feature} lineStringGeometry Line
  20625. * string geometry.
  20626. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20627. */
  20628. ol.render.VectorContext.prototype.drawLineString = function(lineStringGeometry, feature) {};
  20629. /**
  20630. * @param {ol.geom.MultiLineString|ol.render.Feature} multiLineStringGeometry
  20631. * MultiLineString geometry.
  20632. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20633. */
  20634. ol.render.VectorContext.prototype.drawMultiLineString = function(multiLineStringGeometry, feature) {};
  20635. /**
  20636. * @param {ol.geom.MultiPoint|ol.render.Feature} multiPointGeometry MultiPoint
  20637. * geometry.
  20638. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20639. */
  20640. ol.render.VectorContext.prototype.drawMultiPoint = function(multiPointGeometry, feature) {};
  20641. /**
  20642. * @param {ol.geom.MultiPolygon} multiPolygonGeometry MultiPolygon geometry.
  20643. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20644. */
  20645. ol.render.VectorContext.prototype.drawMultiPolygon = function(multiPolygonGeometry, feature) {};
  20646. /**
  20647. * @param {ol.geom.Point|ol.render.Feature} pointGeometry Point geometry.
  20648. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20649. */
  20650. ol.render.VectorContext.prototype.drawPoint = function(pointGeometry, feature) {};
  20651. /**
  20652. * @param {ol.geom.Polygon|ol.render.Feature} polygonGeometry Polygon
  20653. * geometry.
  20654. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20655. */
  20656. ol.render.VectorContext.prototype.drawPolygon = function(polygonGeometry, feature) {};
  20657. /**
  20658. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  20659. * @param {ol.Feature|ol.render.Feature} feature Feature.
  20660. */
  20661. ol.render.VectorContext.prototype.drawText = function(geometry, feature) {};
  20662. /**
  20663. * @param {ol.style.Fill} fillStyle Fill style.
  20664. * @param {ol.style.Stroke} strokeStyle Stroke style.
  20665. */
  20666. ol.render.VectorContext.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {};
  20667. /**
  20668. * @param {ol.style.Image} imageStyle Image style.
  20669. * @param {ol.DeclutterGroup=} opt_declutterGroup Declutter.
  20670. */
  20671. ol.render.VectorContext.prototype.setImageStyle = function(imageStyle, opt_declutterGroup) {};
  20672. /**
  20673. * @param {ol.style.Text} textStyle Text style.
  20674. * @param {ol.DeclutterGroup=} opt_declutterGroup Declutter.
  20675. */
  20676. ol.render.VectorContext.prototype.setTextStyle = function(textStyle, opt_declutterGroup) {};
  20677. // FIXME test, especially polygons with holes and multipolygons
  20678. // FIXME need to handle large thick features (where pixel size matters)
  20679. // FIXME add offset and end to ol.geom.flat.transform.transform2D?
  20680. goog.provide('ol.render.canvas.Immediate');
  20681. goog.require('ol');
  20682. goog.require('ol.array');
  20683. goog.require('ol.colorlike');
  20684. goog.require('ol.extent');
  20685. goog.require('ol.geom.GeometryType');
  20686. goog.require('ol.geom.SimpleGeometry');
  20687. goog.require('ol.geom.flat.transform');
  20688. goog.require('ol.has');
  20689. goog.require('ol.render.VectorContext');
  20690. goog.require('ol.render.canvas');
  20691. goog.require('ol.transform');
  20692. /**
  20693. * @classdesc
  20694. * A concrete subclass of {@link ol.render.VectorContext} that implements
  20695. * direct rendering of features and geometries to an HTML5 Canvas context.
  20696. * Instances of this class are created internally by the library and
  20697. * provided to application code as vectorContext member of the
  20698. * {@link ol.render.Event} object associated with postcompose, precompose and
  20699. * render events emitted by layers and maps.
  20700. *
  20701. * @constructor
  20702. * @extends {ol.render.VectorContext}
  20703. * @param {CanvasRenderingContext2D} context Context.
  20704. * @param {number} pixelRatio Pixel ratio.
  20705. * @param {ol.Extent} extent Extent.
  20706. * @param {ol.Transform} transform Transform.
  20707. * @param {number} viewRotation View rotation.
  20708. * @struct
  20709. */
  20710. ol.render.canvas.Immediate = function(context, pixelRatio, extent, transform, viewRotation) {
  20711. ol.render.VectorContext.call(this);
  20712. /**
  20713. * @private
  20714. * @type {CanvasRenderingContext2D}
  20715. */
  20716. this.context_ = context;
  20717. /**
  20718. * @private
  20719. * @type {number}
  20720. */
  20721. this.pixelRatio_ = pixelRatio;
  20722. /**
  20723. * @private
  20724. * @type {ol.Extent}
  20725. */
  20726. this.extent_ = extent;
  20727. /**
  20728. * @private
  20729. * @type {ol.Transform}
  20730. */
  20731. this.transform_ = transform;
  20732. /**
  20733. * @private
  20734. * @type {number}
  20735. */
  20736. this.viewRotation_ = viewRotation;
  20737. /**
  20738. * @private
  20739. * @type {?ol.CanvasFillState}
  20740. */
  20741. this.contextFillState_ = null;
  20742. /**
  20743. * @private
  20744. * @type {?ol.CanvasStrokeState}
  20745. */
  20746. this.contextStrokeState_ = null;
  20747. /**
  20748. * @private
  20749. * @type {?ol.CanvasTextState}
  20750. */
  20751. this.contextTextState_ = null;
  20752. /**
  20753. * @private
  20754. * @type {?ol.CanvasFillState}
  20755. */
  20756. this.fillState_ = null;
  20757. /**
  20758. * @private
  20759. * @type {?ol.CanvasStrokeState}
  20760. */
  20761. this.strokeState_ = null;
  20762. /**
  20763. * @private
  20764. * @type {HTMLCanvasElement|HTMLVideoElement|Image}
  20765. */
  20766. this.image_ = null;
  20767. /**
  20768. * @private
  20769. * @type {number}
  20770. */
  20771. this.imageAnchorX_ = 0;
  20772. /**
  20773. * @private
  20774. * @type {number}
  20775. */
  20776. this.imageAnchorY_ = 0;
  20777. /**
  20778. * @private
  20779. * @type {number}
  20780. */
  20781. this.imageHeight_ = 0;
  20782. /**
  20783. * @private
  20784. * @type {number}
  20785. */
  20786. this.imageOpacity_ = 0;
  20787. /**
  20788. * @private
  20789. * @type {number}
  20790. */
  20791. this.imageOriginX_ = 0;
  20792. /**
  20793. * @private
  20794. * @type {number}
  20795. */
  20796. this.imageOriginY_ = 0;
  20797. /**
  20798. * @private
  20799. * @type {boolean}
  20800. */
  20801. this.imageRotateWithView_ = false;
  20802. /**
  20803. * @private
  20804. * @type {number}
  20805. */
  20806. this.imageRotation_ = 0;
  20807. /**
  20808. * @private
  20809. * @type {number}
  20810. */
  20811. this.imageScale_ = 0;
  20812. /**
  20813. * @private
  20814. * @type {boolean}
  20815. */
  20816. this.imageSnapToPixel_ = false;
  20817. /**
  20818. * @private
  20819. * @type {number}
  20820. */
  20821. this.imageWidth_ = 0;
  20822. /**
  20823. * @private
  20824. * @type {string}
  20825. */
  20826. this.text_ = '';
  20827. /**
  20828. * @private
  20829. * @type {number}
  20830. */
  20831. this.textOffsetX_ = 0;
  20832. /**
  20833. * @private
  20834. * @type {number}
  20835. */
  20836. this.textOffsetY_ = 0;
  20837. /**
  20838. * @private
  20839. * @type {boolean}
  20840. */
  20841. this.textRotateWithView_ = false;
  20842. /**
  20843. * @private
  20844. * @type {number}
  20845. */
  20846. this.textRotation_ = 0;
  20847. /**
  20848. * @private
  20849. * @type {number}
  20850. */
  20851. this.textScale_ = 0;
  20852. /**
  20853. * @private
  20854. * @type {?ol.CanvasFillState}
  20855. */
  20856. this.textFillState_ = null;
  20857. /**
  20858. * @private
  20859. * @type {?ol.CanvasStrokeState}
  20860. */
  20861. this.textStrokeState_ = null;
  20862. /**
  20863. * @private
  20864. * @type {?ol.CanvasTextState}
  20865. */
  20866. this.textState_ = null;
  20867. /**
  20868. * @private
  20869. * @type {Array.<number>}
  20870. */
  20871. this.pixelCoordinates_ = [];
  20872. /**
  20873. * @private
  20874. * @type {ol.Transform}
  20875. */
  20876. this.tmpLocalTransform_ = ol.transform.create();
  20877. };
  20878. ol.inherits(ol.render.canvas.Immediate, ol.render.VectorContext);
  20879. /**
  20880. * @param {Array.<number>} flatCoordinates Flat coordinates.
  20881. * @param {number} offset Offset.
  20882. * @param {number} end End.
  20883. * @param {number} stride Stride.
  20884. * @private
  20885. */
  20886. ol.render.canvas.Immediate.prototype.drawImages_ = function(flatCoordinates, offset, end, stride) {
  20887. if (!this.image_) {
  20888. return;
  20889. }
  20890. var pixelCoordinates = ol.geom.flat.transform.transform2D(
  20891. flatCoordinates, offset, end, 2, this.transform_,
  20892. this.pixelCoordinates_);
  20893. var context = this.context_;
  20894. var localTransform = this.tmpLocalTransform_;
  20895. var alpha = context.globalAlpha;
  20896. if (this.imageOpacity_ != 1) {
  20897. context.globalAlpha = alpha * this.imageOpacity_;
  20898. }
  20899. var rotation = this.imageRotation_;
  20900. if (this.imageRotateWithView_) {
  20901. rotation += this.viewRotation_;
  20902. }
  20903. var i, ii;
  20904. for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
  20905. var x = pixelCoordinates[i] - this.imageAnchorX_;
  20906. var y = pixelCoordinates[i + 1] - this.imageAnchorY_;
  20907. if (this.imageSnapToPixel_) {
  20908. x = Math.round(x);
  20909. y = Math.round(y);
  20910. }
  20911. if (rotation !== 0 || this.imageScale_ != 1) {
  20912. var centerX = x + this.imageAnchorX_;
  20913. var centerY = y + this.imageAnchorY_;
  20914. ol.transform.compose(localTransform,
  20915. centerX, centerY,
  20916. this.imageScale_, this.imageScale_,
  20917. rotation,
  20918. -centerX, -centerY);
  20919. context.setTransform.apply(context, localTransform);
  20920. }
  20921. context.drawImage(this.image_, this.imageOriginX_, this.imageOriginY_,
  20922. this.imageWidth_, this.imageHeight_, x, y,
  20923. this.imageWidth_, this.imageHeight_);
  20924. }
  20925. if (rotation !== 0 || this.imageScale_ != 1) {
  20926. context.setTransform(1, 0, 0, 1, 0, 0);
  20927. }
  20928. if (this.imageOpacity_ != 1) {
  20929. context.globalAlpha = alpha;
  20930. }
  20931. };
  20932. /**
  20933. * @param {Array.<number>} flatCoordinates Flat coordinates.
  20934. * @param {number} offset Offset.
  20935. * @param {number} end End.
  20936. * @param {number} stride Stride.
  20937. * @private
  20938. */
  20939. ol.render.canvas.Immediate.prototype.drawText_ = function(flatCoordinates, offset, end, stride) {
  20940. if (!this.textState_ || this.text_ === '') {
  20941. return;
  20942. }
  20943. if (this.textFillState_) {
  20944. this.setContextFillState_(this.textFillState_);
  20945. }
  20946. if (this.textStrokeState_) {
  20947. this.setContextStrokeState_(this.textStrokeState_);
  20948. }
  20949. this.setContextTextState_(this.textState_);
  20950. var pixelCoordinates = ol.geom.flat.transform.transform2D(
  20951. flatCoordinates, offset, end, stride, this.transform_,
  20952. this.pixelCoordinates_);
  20953. var context = this.context_;
  20954. var rotation = this.textRotation_;
  20955. if (this.textRotateWithView_) {
  20956. rotation += this.viewRotation_;
  20957. }
  20958. for (; offset < end; offset += stride) {
  20959. var x = pixelCoordinates[offset] + this.textOffsetX_;
  20960. var y = pixelCoordinates[offset + 1] + this.textOffsetY_;
  20961. if (rotation !== 0 || this.textScale_ != 1) {
  20962. var localTransform = ol.transform.compose(this.tmpLocalTransform_,
  20963. x, y,
  20964. this.textScale_, this.textScale_,
  20965. rotation,
  20966. -x, -y);
  20967. context.setTransform.apply(context, localTransform);
  20968. }
  20969. if (this.textStrokeState_) {
  20970. context.strokeText(this.text_, x, y);
  20971. }
  20972. if (this.textFillState_) {
  20973. context.fillText(this.text_, x, y);
  20974. }
  20975. }
  20976. if (rotation !== 0 || this.textScale_ != 1) {
  20977. context.setTransform(1, 0, 0, 1, 0, 0);
  20978. }
  20979. };
  20980. /**
  20981. * @param {Array.<number>} flatCoordinates Flat coordinates.
  20982. * @param {number} offset Offset.
  20983. * @param {number} end End.
  20984. * @param {number} stride Stride.
  20985. * @param {boolean} close Close.
  20986. * @private
  20987. * @return {number} end End.
  20988. */
  20989. ol.render.canvas.Immediate.prototype.moveToLineTo_ = function(flatCoordinates, offset, end, stride, close) {
  20990. var context = this.context_;
  20991. var pixelCoordinates = ol.geom.flat.transform.transform2D(
  20992. flatCoordinates, offset, end, stride, this.transform_,
  20993. this.pixelCoordinates_);
  20994. context.moveTo(pixelCoordinates[0], pixelCoordinates[1]);
  20995. var length = pixelCoordinates.length;
  20996. if (close) {
  20997. length -= 2;
  20998. }
  20999. for (var i = 2; i < length; i += 2) {
  21000. context.lineTo(pixelCoordinates[i], pixelCoordinates[i + 1]);
  21001. }
  21002. if (close) {
  21003. context.closePath();
  21004. }
  21005. return end;
  21006. };
  21007. /**
  21008. * @param {Array.<number>} flatCoordinates Flat coordinates.
  21009. * @param {number} offset Offset.
  21010. * @param {Array.<number>} ends Ends.
  21011. * @param {number} stride Stride.
  21012. * @private
  21013. * @return {number} End.
  21014. */
  21015. ol.render.canvas.Immediate.prototype.drawRings_ = function(flatCoordinates, offset, ends, stride) {
  21016. var i, ii;
  21017. for (i = 0, ii = ends.length; i < ii; ++i) {
  21018. offset = this.moveToLineTo_(
  21019. flatCoordinates, offset, ends[i], stride, true);
  21020. }
  21021. return offset;
  21022. };
  21023. /**
  21024. * Render a circle geometry into the canvas. Rendering is immediate and uses
  21025. * the current fill and stroke styles.
  21026. *
  21027. * @param {ol.geom.Circle} geometry Circle geometry.
  21028. * @override
  21029. * @api
  21030. */
  21031. ol.render.canvas.Immediate.prototype.drawCircle = function(geometry) {
  21032. if (!ol.extent.intersects(this.extent_, geometry.getExtent())) {
  21033. return;
  21034. }
  21035. if (this.fillState_ || this.strokeState_) {
  21036. if (this.fillState_) {
  21037. this.setContextFillState_(this.fillState_);
  21038. }
  21039. if (this.strokeState_) {
  21040. this.setContextStrokeState_(this.strokeState_);
  21041. }
  21042. var pixelCoordinates = ol.geom.SimpleGeometry.transform2D(
  21043. geometry, this.transform_, this.pixelCoordinates_);
  21044. var dx = pixelCoordinates[2] - pixelCoordinates[0];
  21045. var dy = pixelCoordinates[3] - pixelCoordinates[1];
  21046. var radius = Math.sqrt(dx * dx + dy * dy);
  21047. var context = this.context_;
  21048. context.beginPath();
  21049. context.arc(
  21050. pixelCoordinates[0], pixelCoordinates[1], radius, 0, 2 * Math.PI);
  21051. if (this.fillState_) {
  21052. context.fill();
  21053. }
  21054. if (this.strokeState_) {
  21055. context.stroke();
  21056. }
  21057. }
  21058. if (this.text_ !== '') {
  21059. this.drawText_(geometry.getCenter(), 0, 2, 2);
  21060. }
  21061. };
  21062. /**
  21063. * Set the rendering style. Note that since this is an immediate rendering API,
  21064. * any `zIndex` on the provided style will be ignored.
  21065. *
  21066. * @param {ol.style.Style} style The rendering style.
  21067. * @override
  21068. * @api
  21069. */
  21070. ol.render.canvas.Immediate.prototype.setStyle = function(style) {
  21071. this.setFillStrokeStyle(style.getFill(), style.getStroke());
  21072. this.setImageStyle(style.getImage());
  21073. this.setTextStyle(style.getText());
  21074. };
  21075. /**
  21076. * Render a geometry into the canvas. Call
  21077. * {@link ol.render.canvas.Immediate#setStyle} first to set the rendering style.
  21078. *
  21079. * @param {ol.geom.Geometry|ol.render.Feature} geometry The geometry to render.
  21080. * @override
  21081. * @api
  21082. */
  21083. ol.render.canvas.Immediate.prototype.drawGeometry = function(geometry) {
  21084. var type = geometry.getType();
  21085. switch (type) {
  21086. case ol.geom.GeometryType.POINT:
  21087. this.drawPoint(/** @type {ol.geom.Point} */ (geometry));
  21088. break;
  21089. case ol.geom.GeometryType.LINE_STRING:
  21090. this.drawLineString(/** @type {ol.geom.LineString} */ (geometry));
  21091. break;
  21092. case ol.geom.GeometryType.POLYGON:
  21093. this.drawPolygon(/** @type {ol.geom.Polygon} */ (geometry));
  21094. break;
  21095. case ol.geom.GeometryType.MULTI_POINT:
  21096. this.drawMultiPoint(/** @type {ol.geom.MultiPoint} */ (geometry));
  21097. break;
  21098. case ol.geom.GeometryType.MULTI_LINE_STRING:
  21099. this.drawMultiLineString(/** @type {ol.geom.MultiLineString} */ (geometry));
  21100. break;
  21101. case ol.geom.GeometryType.MULTI_POLYGON:
  21102. this.drawMultiPolygon(/** @type {ol.geom.MultiPolygon} */ (geometry));
  21103. break;
  21104. case ol.geom.GeometryType.GEOMETRY_COLLECTION:
  21105. this.drawGeometryCollection(/** @type {ol.geom.GeometryCollection} */ (geometry));
  21106. break;
  21107. case ol.geom.GeometryType.CIRCLE:
  21108. this.drawCircle(/** @type {ol.geom.Circle} */ (geometry));
  21109. break;
  21110. default:
  21111. }
  21112. };
  21113. /**
  21114. * Render a feature into the canvas. Note that any `zIndex` on the provided
  21115. * style will be ignored - features are rendered immediately in the order that
  21116. * this method is called. If you need `zIndex` support, you should be using an
  21117. * {@link ol.layer.Vector} instead.
  21118. *
  21119. * @param {ol.Feature} feature Feature.
  21120. * @param {ol.style.Style} style Style.
  21121. * @override
  21122. * @api
  21123. */
  21124. ol.render.canvas.Immediate.prototype.drawFeature = function(feature, style) {
  21125. var geometry = style.getGeometryFunction()(feature);
  21126. if (!geometry ||
  21127. !ol.extent.intersects(this.extent_, geometry.getExtent())) {
  21128. return;
  21129. }
  21130. this.setStyle(style);
  21131. this.drawGeometry(geometry);
  21132. };
  21133. /**
  21134. * Render a GeometryCollection to the canvas. Rendering is immediate and
  21135. * uses the current styles appropriate for each geometry in the collection.
  21136. *
  21137. * @param {ol.geom.GeometryCollection} geometry Geometry collection.
  21138. * @override
  21139. */
  21140. ol.render.canvas.Immediate.prototype.drawGeometryCollection = function(geometry) {
  21141. var geometries = geometry.getGeometriesArray();
  21142. var i, ii;
  21143. for (i = 0, ii = geometries.length; i < ii; ++i) {
  21144. this.drawGeometry(geometries[i]);
  21145. }
  21146. };
  21147. /**
  21148. * Render a Point geometry into the canvas. Rendering is immediate and uses
  21149. * the current style.
  21150. *
  21151. * @param {ol.geom.Point|ol.render.Feature} geometry Point geometry.
  21152. * @override
  21153. */
  21154. ol.render.canvas.Immediate.prototype.drawPoint = function(geometry) {
  21155. var flatCoordinates = geometry.getFlatCoordinates();
  21156. var stride = geometry.getStride();
  21157. if (this.image_) {
  21158. this.drawImages_(flatCoordinates, 0, flatCoordinates.length, stride);
  21159. }
  21160. if (this.text_ !== '') {
  21161. this.drawText_(flatCoordinates, 0, flatCoordinates.length, stride);
  21162. }
  21163. };
  21164. /**
  21165. * Render a MultiPoint geometry into the canvas. Rendering is immediate and
  21166. * uses the current style.
  21167. *
  21168. * @param {ol.geom.MultiPoint|ol.render.Feature} geometry MultiPoint geometry.
  21169. * @override
  21170. */
  21171. ol.render.canvas.Immediate.prototype.drawMultiPoint = function(geometry) {
  21172. var flatCoordinates = geometry.getFlatCoordinates();
  21173. var stride = geometry.getStride();
  21174. if (this.image_) {
  21175. this.drawImages_(flatCoordinates, 0, flatCoordinates.length, stride);
  21176. }
  21177. if (this.text_ !== '') {
  21178. this.drawText_(flatCoordinates, 0, flatCoordinates.length, stride);
  21179. }
  21180. };
  21181. /**
  21182. * Render a LineString into the canvas. Rendering is immediate and uses
  21183. * the current style.
  21184. *
  21185. * @param {ol.geom.LineString|ol.render.Feature} geometry LineString geometry.
  21186. * @override
  21187. */
  21188. ol.render.canvas.Immediate.prototype.drawLineString = function(geometry) {
  21189. if (!ol.extent.intersects(this.extent_, geometry.getExtent())) {
  21190. return;
  21191. }
  21192. if (this.strokeState_) {
  21193. this.setContextStrokeState_(this.strokeState_);
  21194. var context = this.context_;
  21195. var flatCoordinates = geometry.getFlatCoordinates();
  21196. context.beginPath();
  21197. this.moveToLineTo_(flatCoordinates, 0, flatCoordinates.length,
  21198. geometry.getStride(), false);
  21199. context.stroke();
  21200. }
  21201. if (this.text_ !== '') {
  21202. var flatMidpoint = geometry.getFlatMidpoint();
  21203. this.drawText_(flatMidpoint, 0, 2, 2);
  21204. }
  21205. };
  21206. /**
  21207. * Render a MultiLineString geometry into the canvas. Rendering is immediate
  21208. * and uses the current style.
  21209. *
  21210. * @param {ol.geom.MultiLineString|ol.render.Feature} geometry MultiLineString
  21211. * geometry.
  21212. * @override
  21213. */
  21214. ol.render.canvas.Immediate.prototype.drawMultiLineString = function(geometry) {
  21215. var geometryExtent = geometry.getExtent();
  21216. if (!ol.extent.intersects(this.extent_, geometryExtent)) {
  21217. return;
  21218. }
  21219. if (this.strokeState_) {
  21220. this.setContextStrokeState_(this.strokeState_);
  21221. var context = this.context_;
  21222. var flatCoordinates = geometry.getFlatCoordinates();
  21223. var offset = 0;
  21224. var ends = geometry.getEnds();
  21225. var stride = geometry.getStride();
  21226. context.beginPath();
  21227. var i, ii;
  21228. for (i = 0, ii = ends.length; i < ii; ++i) {
  21229. offset = this.moveToLineTo_(
  21230. flatCoordinates, offset, ends[i], stride, false);
  21231. }
  21232. context.stroke();
  21233. }
  21234. if (this.text_ !== '') {
  21235. var flatMidpoints = geometry.getFlatMidpoints();
  21236. this.drawText_(flatMidpoints, 0, flatMidpoints.length, 2);
  21237. }
  21238. };
  21239. /**
  21240. * Render a Polygon geometry into the canvas. Rendering is immediate and uses
  21241. * the current style.
  21242. *
  21243. * @param {ol.geom.Polygon|ol.render.Feature} geometry Polygon geometry.
  21244. * @override
  21245. */
  21246. ol.render.canvas.Immediate.prototype.drawPolygon = function(geometry) {
  21247. if (!ol.extent.intersects(this.extent_, geometry.getExtent())) {
  21248. return;
  21249. }
  21250. if (this.strokeState_ || this.fillState_) {
  21251. if (this.fillState_) {
  21252. this.setContextFillState_(this.fillState_);
  21253. }
  21254. if (this.strokeState_) {
  21255. this.setContextStrokeState_(this.strokeState_);
  21256. }
  21257. var context = this.context_;
  21258. context.beginPath();
  21259. this.drawRings_(geometry.getOrientedFlatCoordinates(),
  21260. 0, geometry.getEnds(), geometry.getStride());
  21261. if (this.fillState_) {
  21262. context.fill();
  21263. }
  21264. if (this.strokeState_) {
  21265. context.stroke();
  21266. }
  21267. }
  21268. if (this.text_ !== '') {
  21269. var flatInteriorPoint = geometry.getFlatInteriorPoint();
  21270. this.drawText_(flatInteriorPoint, 0, 2, 2);
  21271. }
  21272. };
  21273. /**
  21274. * Render MultiPolygon geometry into the canvas. Rendering is immediate and
  21275. * uses the current style.
  21276. * @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry.
  21277. * @override
  21278. */
  21279. ol.render.canvas.Immediate.prototype.drawMultiPolygon = function(geometry) {
  21280. if (!ol.extent.intersects(this.extent_, geometry.getExtent())) {
  21281. return;
  21282. }
  21283. if (this.strokeState_ || this.fillState_) {
  21284. if (this.fillState_) {
  21285. this.setContextFillState_(this.fillState_);
  21286. }
  21287. if (this.strokeState_) {
  21288. this.setContextStrokeState_(this.strokeState_);
  21289. }
  21290. var context = this.context_;
  21291. var flatCoordinates = geometry.getOrientedFlatCoordinates();
  21292. var offset = 0;
  21293. var endss = geometry.getEndss();
  21294. var stride = geometry.getStride();
  21295. var i, ii;
  21296. context.beginPath();
  21297. for (i = 0, ii = endss.length; i < ii; ++i) {
  21298. var ends = endss[i];
  21299. offset = this.drawRings_(flatCoordinates, offset, ends, stride);
  21300. }
  21301. if (this.fillState_) {
  21302. context.fill();
  21303. }
  21304. if (this.strokeState_) {
  21305. context.stroke();
  21306. }
  21307. }
  21308. if (this.text_ !== '') {
  21309. var flatInteriorPoints = geometry.getFlatInteriorPoints();
  21310. this.drawText_(flatInteriorPoints, 0, flatInteriorPoints.length, 2);
  21311. }
  21312. };
  21313. /**
  21314. * @param {ol.CanvasFillState} fillState Fill state.
  21315. * @private
  21316. */
  21317. ol.render.canvas.Immediate.prototype.setContextFillState_ = function(fillState) {
  21318. var context = this.context_;
  21319. var contextFillState = this.contextFillState_;
  21320. if (!contextFillState) {
  21321. context.fillStyle = fillState.fillStyle;
  21322. this.contextFillState_ = {
  21323. fillStyle: fillState.fillStyle
  21324. };
  21325. } else {
  21326. if (contextFillState.fillStyle != fillState.fillStyle) {
  21327. contextFillState.fillStyle = context.fillStyle = fillState.fillStyle;
  21328. }
  21329. }
  21330. };
  21331. /**
  21332. * @param {ol.CanvasStrokeState} strokeState Stroke state.
  21333. * @private
  21334. */
  21335. ol.render.canvas.Immediate.prototype.setContextStrokeState_ = function(strokeState) {
  21336. var context = this.context_;
  21337. var contextStrokeState = this.contextStrokeState_;
  21338. if (!contextStrokeState) {
  21339. context.lineCap = strokeState.lineCap;
  21340. if (ol.has.CANVAS_LINE_DASH) {
  21341. context.setLineDash(strokeState.lineDash);
  21342. context.lineDashOffset = strokeState.lineDashOffset;
  21343. }
  21344. context.lineJoin = strokeState.lineJoin;
  21345. context.lineWidth = strokeState.lineWidth;
  21346. context.miterLimit = strokeState.miterLimit;
  21347. context.strokeStyle = strokeState.strokeStyle;
  21348. this.contextStrokeState_ = {
  21349. lineCap: strokeState.lineCap,
  21350. lineDash: strokeState.lineDash,
  21351. lineDashOffset: strokeState.lineDashOffset,
  21352. lineJoin: strokeState.lineJoin,
  21353. lineWidth: strokeState.lineWidth,
  21354. miterLimit: strokeState.miterLimit,
  21355. strokeStyle: strokeState.strokeStyle
  21356. };
  21357. } else {
  21358. if (contextStrokeState.lineCap != strokeState.lineCap) {
  21359. contextStrokeState.lineCap = context.lineCap = strokeState.lineCap;
  21360. }
  21361. if (ol.has.CANVAS_LINE_DASH) {
  21362. if (!ol.array.equals(
  21363. contextStrokeState.lineDash, strokeState.lineDash)) {
  21364. context.setLineDash(contextStrokeState.lineDash = strokeState.lineDash);
  21365. }
  21366. if (contextStrokeState.lineDashOffset != strokeState.lineDashOffset) {
  21367. contextStrokeState.lineDashOffset = context.lineDashOffset =
  21368. strokeState.lineDashOffset;
  21369. }
  21370. }
  21371. if (contextStrokeState.lineJoin != strokeState.lineJoin) {
  21372. contextStrokeState.lineJoin = context.lineJoin = strokeState.lineJoin;
  21373. }
  21374. if (contextStrokeState.lineWidth != strokeState.lineWidth) {
  21375. contextStrokeState.lineWidth = context.lineWidth = strokeState.lineWidth;
  21376. }
  21377. if (contextStrokeState.miterLimit != strokeState.miterLimit) {
  21378. contextStrokeState.miterLimit = context.miterLimit =
  21379. strokeState.miterLimit;
  21380. }
  21381. if (contextStrokeState.strokeStyle != strokeState.strokeStyle) {
  21382. contextStrokeState.strokeStyle = context.strokeStyle =
  21383. strokeState.strokeStyle;
  21384. }
  21385. }
  21386. };
  21387. /**
  21388. * @param {ol.CanvasTextState} textState Text state.
  21389. * @private
  21390. */
  21391. ol.render.canvas.Immediate.prototype.setContextTextState_ = function(textState) {
  21392. var context = this.context_;
  21393. var contextTextState = this.contextTextState_;
  21394. var textAlign = textState.textAlign ?
  21395. textState.textAlign : ol.render.canvas.defaultTextAlign;
  21396. if (!contextTextState) {
  21397. context.font = textState.font;
  21398. context.textAlign = textAlign;
  21399. context.textBaseline = textState.textBaseline;
  21400. this.contextTextState_ = {
  21401. font: textState.font,
  21402. textAlign: textAlign,
  21403. textBaseline: textState.textBaseline
  21404. };
  21405. } else {
  21406. if (contextTextState.font != textState.font) {
  21407. contextTextState.font = context.font = textState.font;
  21408. }
  21409. if (contextTextState.textAlign != textAlign) {
  21410. contextTextState.textAlign = textAlign;
  21411. }
  21412. if (contextTextState.textBaseline != textState.textBaseline) {
  21413. contextTextState.textBaseline = context.textBaseline =
  21414. textState.textBaseline;
  21415. }
  21416. }
  21417. };
  21418. /**
  21419. * Set the fill and stroke style for subsequent draw operations. To clear
  21420. * either fill or stroke styles, pass null for the appropriate parameter.
  21421. *
  21422. * @param {ol.style.Fill} fillStyle Fill style.
  21423. * @param {ol.style.Stroke} strokeStyle Stroke style.
  21424. * @override
  21425. */
  21426. ol.render.canvas.Immediate.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
  21427. if (!fillStyle) {
  21428. this.fillState_ = null;
  21429. } else {
  21430. var fillStyleColor = fillStyle.getColor();
  21431. this.fillState_ = {
  21432. fillStyle: ol.colorlike.asColorLike(fillStyleColor ?
  21433. fillStyleColor : ol.render.canvas.defaultFillStyle)
  21434. };
  21435. }
  21436. if (!strokeStyle) {
  21437. this.strokeState_ = null;
  21438. } else {
  21439. var strokeStyleColor = strokeStyle.getColor();
  21440. var strokeStyleLineCap = strokeStyle.getLineCap();
  21441. var strokeStyleLineDash = strokeStyle.getLineDash();
  21442. var strokeStyleLineDashOffset = strokeStyle.getLineDashOffset();
  21443. var strokeStyleLineJoin = strokeStyle.getLineJoin();
  21444. var strokeStyleWidth = strokeStyle.getWidth();
  21445. var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
  21446. this.strokeState_ = {
  21447. lineCap: strokeStyleLineCap !== undefined ?
  21448. strokeStyleLineCap : ol.render.canvas.defaultLineCap,
  21449. lineDash: strokeStyleLineDash ?
  21450. strokeStyleLineDash : ol.render.canvas.defaultLineDash,
  21451. lineDashOffset: strokeStyleLineDashOffset ?
  21452. strokeStyleLineDashOffset : ol.render.canvas.defaultLineDashOffset,
  21453. lineJoin: strokeStyleLineJoin !== undefined ?
  21454. strokeStyleLineJoin : ol.render.canvas.defaultLineJoin,
  21455. lineWidth: this.pixelRatio_ * (strokeStyleWidth !== undefined ?
  21456. strokeStyleWidth : ol.render.canvas.defaultLineWidth),
  21457. miterLimit: strokeStyleMiterLimit !== undefined ?
  21458. strokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit,
  21459. strokeStyle: ol.colorlike.asColorLike(strokeStyleColor ?
  21460. strokeStyleColor : ol.render.canvas.defaultStrokeStyle)
  21461. };
  21462. }
  21463. };
  21464. /**
  21465. * Set the image style for subsequent draw operations. Pass null to remove
  21466. * the image style.
  21467. *
  21468. * @param {ol.style.Image} imageStyle Image style.
  21469. * @override
  21470. */
  21471. ol.render.canvas.Immediate.prototype.setImageStyle = function(imageStyle) {
  21472. if (!imageStyle) {
  21473. this.image_ = null;
  21474. } else {
  21475. var imageAnchor = imageStyle.getAnchor();
  21476. // FIXME pixel ratio
  21477. var imageImage = imageStyle.getImage(1);
  21478. var imageOrigin = imageStyle.getOrigin();
  21479. var imageSize = imageStyle.getSize();
  21480. this.imageAnchorX_ = imageAnchor[0];
  21481. this.imageAnchorY_ = imageAnchor[1];
  21482. this.imageHeight_ = imageSize[1];
  21483. this.image_ = imageImage;
  21484. this.imageOpacity_ = imageStyle.getOpacity();
  21485. this.imageOriginX_ = imageOrigin[0];
  21486. this.imageOriginY_ = imageOrigin[1];
  21487. this.imageRotateWithView_ = imageStyle.getRotateWithView();
  21488. this.imageRotation_ = imageStyle.getRotation();
  21489. this.imageScale_ = imageStyle.getScale() * this.pixelRatio_;
  21490. this.imageSnapToPixel_ = imageStyle.getSnapToPixel();
  21491. this.imageWidth_ = imageSize[0];
  21492. }
  21493. };
  21494. /**
  21495. * Set the text style for subsequent draw operations. Pass null to
  21496. * remove the text style.
  21497. *
  21498. * @param {ol.style.Text} textStyle Text style.
  21499. * @override
  21500. */
  21501. ol.render.canvas.Immediate.prototype.setTextStyle = function(textStyle) {
  21502. if (!textStyle) {
  21503. this.text_ = '';
  21504. } else {
  21505. var textFillStyle = textStyle.getFill();
  21506. if (!textFillStyle) {
  21507. this.textFillState_ = null;
  21508. } else {
  21509. var textFillStyleColor = textFillStyle.getColor();
  21510. this.textFillState_ = {
  21511. fillStyle: ol.colorlike.asColorLike(textFillStyleColor ?
  21512. textFillStyleColor : ol.render.canvas.defaultFillStyle)
  21513. };
  21514. }
  21515. var textStrokeStyle = textStyle.getStroke();
  21516. if (!textStrokeStyle) {
  21517. this.textStrokeState_ = null;
  21518. } else {
  21519. var textStrokeStyleColor = textStrokeStyle.getColor();
  21520. var textStrokeStyleLineCap = textStrokeStyle.getLineCap();
  21521. var textStrokeStyleLineDash = textStrokeStyle.getLineDash();
  21522. var textStrokeStyleLineDashOffset = textStrokeStyle.getLineDashOffset();
  21523. var textStrokeStyleLineJoin = textStrokeStyle.getLineJoin();
  21524. var textStrokeStyleWidth = textStrokeStyle.getWidth();
  21525. var textStrokeStyleMiterLimit = textStrokeStyle.getMiterLimit();
  21526. this.textStrokeState_ = {
  21527. lineCap: textStrokeStyleLineCap !== undefined ?
  21528. textStrokeStyleLineCap : ol.render.canvas.defaultLineCap,
  21529. lineDash: textStrokeStyleLineDash ?
  21530. textStrokeStyleLineDash : ol.render.canvas.defaultLineDash,
  21531. lineDashOffset: textStrokeStyleLineDashOffset ?
  21532. textStrokeStyleLineDashOffset : ol.render.canvas.defaultLineDashOffset,
  21533. lineJoin: textStrokeStyleLineJoin !== undefined ?
  21534. textStrokeStyleLineJoin : ol.render.canvas.defaultLineJoin,
  21535. lineWidth: textStrokeStyleWidth !== undefined ?
  21536. textStrokeStyleWidth : ol.render.canvas.defaultLineWidth,
  21537. miterLimit: textStrokeStyleMiterLimit !== undefined ?
  21538. textStrokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit,
  21539. strokeStyle: ol.colorlike.asColorLike(textStrokeStyleColor ?
  21540. textStrokeStyleColor : ol.render.canvas.defaultStrokeStyle)
  21541. };
  21542. }
  21543. var textFont = textStyle.getFont();
  21544. var textOffsetX = textStyle.getOffsetX();
  21545. var textOffsetY = textStyle.getOffsetY();
  21546. var textRotateWithView = textStyle.getRotateWithView();
  21547. var textRotation = textStyle.getRotation();
  21548. var textScale = textStyle.getScale();
  21549. var textText = textStyle.getText();
  21550. var textTextAlign = textStyle.getTextAlign();
  21551. var textTextBaseline = textStyle.getTextBaseline();
  21552. this.textState_ = {
  21553. font: textFont !== undefined ?
  21554. textFont : ol.render.canvas.defaultFont,
  21555. textAlign: textTextAlign !== undefined ?
  21556. textTextAlign : ol.render.canvas.defaultTextAlign,
  21557. textBaseline: textTextBaseline !== undefined ?
  21558. textTextBaseline : ol.render.canvas.defaultTextBaseline
  21559. };
  21560. this.text_ = textText !== undefined ? textText : '';
  21561. this.textOffsetX_ =
  21562. textOffsetX !== undefined ? (this.pixelRatio_ * textOffsetX) : 0;
  21563. this.textOffsetY_ =
  21564. textOffsetY !== undefined ? (this.pixelRatio_ * textOffsetY) : 0;
  21565. this.textRotateWithView_ = textRotateWithView !== undefined ? textRotateWithView : false;
  21566. this.textRotation_ = textRotation !== undefined ? textRotation : 0;
  21567. this.textScale_ = this.pixelRatio_ * (textScale !== undefined ?
  21568. textScale : 1);
  21569. }
  21570. };
  21571. goog.provide('ol.renderer.Layer');
  21572. goog.require('ol');
  21573. goog.require('ol.ImageState');
  21574. goog.require('ol.Observable');
  21575. goog.require('ol.TileState');
  21576. goog.require('ol.asserts');
  21577. goog.require('ol.events');
  21578. goog.require('ol.events.EventType');
  21579. goog.require('ol.functions');
  21580. goog.require('ol.source.State');
  21581. /**
  21582. * @constructor
  21583. * @extends {ol.Observable}
  21584. * @param {ol.layer.Layer} layer Layer.
  21585. * @struct
  21586. */
  21587. ol.renderer.Layer = function(layer) {
  21588. ol.Observable.call(this);
  21589. /**
  21590. * @private
  21591. * @type {ol.layer.Layer}
  21592. */
  21593. this.layer_ = layer;
  21594. };
  21595. ol.inherits(ol.renderer.Layer, ol.Observable);
  21596. /**
  21597. * @param {ol.Coordinate} coordinate Coordinate.
  21598. * @param {olx.FrameState} frameState Frame state.
  21599. * @param {number} hitTolerance Hit tolerance in pixels.
  21600. * @param {function(this: S, (ol.Feature|ol.render.Feature), ol.layer.Layer): T}
  21601. * callback Feature callback.
  21602. * @param {S} thisArg Value to use as `this` when executing `callback`.
  21603. * @return {T|undefined} Callback result.
  21604. * @template S,T
  21605. */
  21606. ol.renderer.Layer.prototype.forEachFeatureAtCoordinate = ol.nullFunction;
  21607. /**
  21608. * @param {ol.Coordinate} coordinate Coordinate.
  21609. * @param {olx.FrameState} frameState Frame state.
  21610. * @return {boolean} Is there a feature at the given coordinate?
  21611. */
  21612. ol.renderer.Layer.prototype.hasFeatureAtCoordinate = ol.functions.FALSE;
  21613. /**
  21614. * Create a function that adds loaded tiles to the tile lookup.
  21615. * @param {ol.source.Tile} source Tile source.
  21616. * @param {ol.proj.Projection} projection Projection of the tiles.
  21617. * @param {Object.<number, Object.<string, ol.Tile>>} tiles Lookup of loaded
  21618. * tiles by zoom level.
  21619. * @return {function(number, ol.TileRange):boolean} A function that can be
  21620. * called with a zoom level and a tile range to add loaded tiles to the
  21621. * lookup.
  21622. * @protected
  21623. */
  21624. ol.renderer.Layer.prototype.createLoadedTileFinder = function(source, projection, tiles) {
  21625. return (
  21626. /**
  21627. * @param {number} zoom Zoom level.
  21628. * @param {ol.TileRange} tileRange Tile range.
  21629. * @return {boolean} The tile range is fully loaded.
  21630. */
  21631. function(zoom, tileRange) {
  21632. function callback(tile) {
  21633. if (!tiles[zoom]) {
  21634. tiles[zoom] = {};
  21635. }
  21636. tiles[zoom][tile.tileCoord.toString()] = tile;
  21637. }
  21638. return source.forEachLoadedTile(projection, zoom, tileRange, callback);
  21639. });
  21640. };
  21641. /**
  21642. * @return {ol.layer.Layer} Layer.
  21643. */
  21644. ol.renderer.Layer.prototype.getLayer = function() {
  21645. return this.layer_;
  21646. };
  21647. /**
  21648. * Handle changes in image state.
  21649. * @param {ol.events.Event} event Image change event.
  21650. * @private
  21651. */
  21652. ol.renderer.Layer.prototype.handleImageChange_ = function(event) {
  21653. var image = /** @type {ol.Image} */ (event.target);
  21654. if (image.getState() === ol.ImageState.LOADED) {
  21655. this.renderIfReadyAndVisible();
  21656. }
  21657. };
  21658. /**
  21659. * Load the image if not already loaded, and register the image change
  21660. * listener if needed.
  21661. * @param {ol.ImageBase} image Image.
  21662. * @return {boolean} `true` if the image is already loaded, `false`
  21663. * otherwise.
  21664. * @protected
  21665. */
  21666. ol.renderer.Layer.prototype.loadImage = function(image) {
  21667. var imageState = image.getState();
  21668. if (imageState != ol.ImageState.LOADED &&
  21669. imageState != ol.ImageState.ERROR) {
  21670. ol.events.listen(image, ol.events.EventType.CHANGE,
  21671. this.handleImageChange_, this);
  21672. }
  21673. if (imageState == ol.ImageState.IDLE) {
  21674. image.load();
  21675. imageState = image.getState();
  21676. }
  21677. return imageState == ol.ImageState.LOADED;
  21678. };
  21679. /**
  21680. * @protected
  21681. */
  21682. ol.renderer.Layer.prototype.renderIfReadyAndVisible = function() {
  21683. var layer = this.getLayer();
  21684. if (layer.getVisible() && layer.getSourceState() == ol.source.State.READY) {
  21685. this.changed();
  21686. }
  21687. };
  21688. /**
  21689. * @param {olx.FrameState} frameState Frame state.
  21690. * @param {ol.source.Tile} tileSource Tile source.
  21691. * @protected
  21692. */
  21693. ol.renderer.Layer.prototype.scheduleExpireCache = function(frameState, tileSource) {
  21694. if (tileSource.canExpireCache()) {
  21695. /**
  21696. * @param {ol.source.Tile} tileSource Tile source.
  21697. * @param {ol.PluggableMap} map Map.
  21698. * @param {olx.FrameState} frameState Frame state.
  21699. */
  21700. var postRenderFunction = function(tileSource, map, frameState) {
  21701. var tileSourceKey = ol.getUid(tileSource).toString();
  21702. if (tileSourceKey in frameState.usedTiles) {
  21703. tileSource.expireCache(frameState.viewState.projection,
  21704. frameState.usedTiles[tileSourceKey]);
  21705. }
  21706. }.bind(null, tileSource);
  21707. frameState.postRenderFunctions.push(
  21708. /** @type {ol.PostRenderFunction} */ (postRenderFunction)
  21709. );
  21710. }
  21711. };
  21712. /**
  21713. * @param {olx.FrameState} frameState Frame state.
  21714. * @param {ol.source.Source} source Source.
  21715. * @protected
  21716. */
  21717. ol.renderer.Layer.prototype.updateLogos = function(frameState, source) {
  21718. var logo = source.getLogo();
  21719. if (logo !== undefined) {
  21720. if (typeof logo === 'string') {
  21721. frameState.logos[logo] = '';
  21722. } else if (logo) {
  21723. ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
  21724. ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
  21725. frameState.logos[logo.src] = logo.href;
  21726. }
  21727. }
  21728. };
  21729. /**
  21730. * @param {Object.<string, Object.<string, ol.TileRange>>} usedTiles Used tiles.
  21731. * @param {ol.source.Tile} tileSource Tile source.
  21732. * @param {number} z Z.
  21733. * @param {ol.TileRange} tileRange Tile range.
  21734. * @protected
  21735. */
  21736. ol.renderer.Layer.prototype.updateUsedTiles = function(usedTiles, tileSource, z, tileRange) {
  21737. // FIXME should we use tilesToDrawByZ instead?
  21738. var tileSourceKey = ol.getUid(tileSource).toString();
  21739. var zKey = z.toString();
  21740. if (tileSourceKey in usedTiles) {
  21741. if (zKey in usedTiles[tileSourceKey]) {
  21742. usedTiles[tileSourceKey][zKey].extend(tileRange);
  21743. } else {
  21744. usedTiles[tileSourceKey][zKey] = tileRange;
  21745. }
  21746. } else {
  21747. usedTiles[tileSourceKey] = {};
  21748. usedTiles[tileSourceKey][zKey] = tileRange;
  21749. }
  21750. };
  21751. /**
  21752. * Manage tile pyramid.
  21753. * This function performs a number of functions related to the tiles at the
  21754. * current zoom and lower zoom levels:
  21755. * - registers idle tiles in frameState.wantedTiles so that they are not
  21756. * discarded by the tile queue
  21757. * - enqueues missing tiles
  21758. * @param {olx.FrameState} frameState Frame state.
  21759. * @param {ol.source.Tile} tileSource Tile source.
  21760. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
  21761. * @param {number} pixelRatio Pixel ratio.
  21762. * @param {ol.proj.Projection} projection Projection.
  21763. * @param {ol.Extent} extent Extent.
  21764. * @param {number} currentZ Current Z.
  21765. * @param {number} preload Load low resolution tiles up to 'preload' levels.
  21766. * @param {function(this: T, ol.Tile)=} opt_tileCallback Tile callback.
  21767. * @param {T=} opt_this Object to use as `this` in `opt_tileCallback`.
  21768. * @protected
  21769. * @template T
  21770. */
  21771. ol.renderer.Layer.prototype.manageTilePyramid = function(
  21772. frameState, tileSource, tileGrid, pixelRatio, projection, extent,
  21773. currentZ, preload, opt_tileCallback, opt_this) {
  21774. var tileSourceKey = ol.getUid(tileSource).toString();
  21775. if (!(tileSourceKey in frameState.wantedTiles)) {
  21776. frameState.wantedTiles[tileSourceKey] = {};
  21777. }
  21778. var wantedTiles = frameState.wantedTiles[tileSourceKey];
  21779. var tileQueue = frameState.tileQueue;
  21780. var minZoom = tileGrid.getMinZoom();
  21781. var tile, tileRange, tileResolution, x, y, z;
  21782. for (z = minZoom; z <= currentZ; ++z) {
  21783. tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z, tileRange);
  21784. tileResolution = tileGrid.getResolution(z);
  21785. for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
  21786. for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
  21787. if (currentZ - z <= preload) {
  21788. tile = tileSource.getTile(z, x, y, pixelRatio, projection);
  21789. if (tile.getState() == ol.TileState.IDLE) {
  21790. wantedTiles[tile.getKey()] = true;
  21791. if (!tileQueue.isKeyQueued(tile.getKey())) {
  21792. tileQueue.enqueue([tile, tileSourceKey,
  21793. tileGrid.getTileCoordCenter(tile.tileCoord), tileResolution]);
  21794. }
  21795. }
  21796. if (opt_tileCallback !== undefined) {
  21797. opt_tileCallback.call(opt_this, tile);
  21798. }
  21799. } else {
  21800. tileSource.useTile(z, x, y, projection);
  21801. }
  21802. }
  21803. }
  21804. }
  21805. };
  21806. goog.provide('ol.renderer.canvas.Layer');
  21807. goog.require('ol');
  21808. goog.require('ol.extent');
  21809. goog.require('ol.functions');
  21810. goog.require('ol.render.Event');
  21811. goog.require('ol.render.EventType');
  21812. goog.require('ol.render.canvas');
  21813. goog.require('ol.render.canvas.Immediate');
  21814. goog.require('ol.renderer.Layer');
  21815. goog.require('ol.transform');
  21816. /**
  21817. * @constructor
  21818. * @abstract
  21819. * @extends {ol.renderer.Layer}
  21820. * @param {ol.layer.Layer} layer Layer.
  21821. */
  21822. ol.renderer.canvas.Layer = function(layer) {
  21823. ol.renderer.Layer.call(this, layer);
  21824. /**
  21825. * @protected
  21826. * @type {number}
  21827. */
  21828. this.renderedResolution;
  21829. /**
  21830. * @private
  21831. * @type {ol.Transform}
  21832. */
  21833. this.transform_ = ol.transform.create();
  21834. };
  21835. ol.inherits(ol.renderer.canvas.Layer, ol.renderer.Layer);
  21836. /**
  21837. * @param {CanvasRenderingContext2D} context Context.
  21838. * @param {olx.FrameState} frameState Frame state.
  21839. * @param {ol.Extent} extent Clip extent.
  21840. * @protected
  21841. */
  21842. ol.renderer.canvas.Layer.prototype.clip = function(context, frameState, extent) {
  21843. var pixelRatio = frameState.pixelRatio;
  21844. var width = frameState.size[0] * pixelRatio;
  21845. var height = frameState.size[1] * pixelRatio;
  21846. var rotation = frameState.viewState.rotation;
  21847. var topLeft = ol.extent.getTopLeft(/** @type {ol.Extent} */ (extent));
  21848. var topRight = ol.extent.getTopRight(/** @type {ol.Extent} */ (extent));
  21849. var bottomRight = ol.extent.getBottomRight(/** @type {ol.Extent} */ (extent));
  21850. var bottomLeft = ol.extent.getBottomLeft(/** @type {ol.Extent} */ (extent));
  21851. ol.transform.apply(frameState.coordinateToPixelTransform, topLeft);
  21852. ol.transform.apply(frameState.coordinateToPixelTransform, topRight);
  21853. ol.transform.apply(frameState.coordinateToPixelTransform, bottomRight);
  21854. ol.transform.apply(frameState.coordinateToPixelTransform, bottomLeft);
  21855. context.save();
  21856. ol.render.canvas.rotateAtOffset(context, -rotation, width / 2, height / 2);
  21857. context.beginPath();
  21858. context.moveTo(topLeft[0] * pixelRatio, topLeft[1] * pixelRatio);
  21859. context.lineTo(topRight[0] * pixelRatio, topRight[1] * pixelRatio);
  21860. context.lineTo(bottomRight[0] * pixelRatio, bottomRight[1] * pixelRatio);
  21861. context.lineTo(bottomLeft[0] * pixelRatio, bottomLeft[1] * pixelRatio);
  21862. context.clip();
  21863. ol.render.canvas.rotateAtOffset(context, rotation, width / 2, height / 2);
  21864. };
  21865. /**
  21866. * @param {ol.render.EventType} type Event type.
  21867. * @param {CanvasRenderingContext2D} context Context.
  21868. * @param {olx.FrameState} frameState Frame state.
  21869. * @param {ol.Transform=} opt_transform Transform.
  21870. * @private
  21871. */
  21872. ol.renderer.canvas.Layer.prototype.dispatchComposeEvent_ = function(type, context, frameState, opt_transform) {
  21873. var layer = this.getLayer();
  21874. if (layer.hasListener(type)) {
  21875. var width = frameState.size[0] * frameState.pixelRatio;
  21876. var height = frameState.size[1] * frameState.pixelRatio;
  21877. var rotation = frameState.viewState.rotation;
  21878. ol.render.canvas.rotateAtOffset(context, -rotation, width / 2, height / 2);
  21879. var transform = opt_transform !== undefined ?
  21880. opt_transform : this.getTransform(frameState, 0);
  21881. var render = new ol.render.canvas.Immediate(
  21882. context, frameState.pixelRatio, frameState.extent, transform,
  21883. frameState.viewState.rotation);
  21884. var composeEvent = new ol.render.Event(type, render, frameState,
  21885. context, null);
  21886. layer.dispatchEvent(composeEvent);
  21887. ol.render.canvas.rotateAtOffset(context, rotation, width / 2, height / 2);
  21888. }
  21889. };
  21890. /**
  21891. * @param {ol.Coordinate} coordinate Coordinate.
  21892. * @param {olx.FrameState} frameState FrameState.
  21893. * @param {function(this: S, ol.layer.Layer, (Uint8ClampedArray|Uint8Array)): T} callback Layer
  21894. * callback.
  21895. * @param {S} thisArg Value to use as `this` when executing `callback`.
  21896. * @return {T|undefined} Callback result.
  21897. * @template S,T,U
  21898. */
  21899. ol.renderer.canvas.Layer.prototype.forEachLayerAtCoordinate = function(coordinate, frameState, callback, thisArg) {
  21900. var hasFeature = this.forEachFeatureAtCoordinate(
  21901. coordinate, frameState, 0, ol.functions.TRUE, this);
  21902. if (hasFeature) {
  21903. return callback.call(thisArg, this.getLayer(), null);
  21904. } else {
  21905. return undefined;
  21906. }
  21907. };
  21908. /**
  21909. * @param {CanvasRenderingContext2D} context Context.
  21910. * @param {olx.FrameState} frameState Frame state.
  21911. * @param {ol.LayerState} layerState Layer state.
  21912. * @param {ol.Transform=} opt_transform Transform.
  21913. * @protected
  21914. */
  21915. ol.renderer.canvas.Layer.prototype.postCompose = function(context, frameState, layerState, opt_transform) {
  21916. this.dispatchComposeEvent_(ol.render.EventType.POSTCOMPOSE, context,
  21917. frameState, opt_transform);
  21918. };
  21919. /**
  21920. * @param {CanvasRenderingContext2D} context Context.
  21921. * @param {olx.FrameState} frameState Frame state.
  21922. * @param {ol.Transform=} opt_transform Transform.
  21923. * @protected
  21924. */
  21925. ol.renderer.canvas.Layer.prototype.preCompose = function(context, frameState, opt_transform) {
  21926. this.dispatchComposeEvent_(ol.render.EventType.PRECOMPOSE, context,
  21927. frameState, opt_transform);
  21928. };
  21929. /**
  21930. * @param {CanvasRenderingContext2D} context Context.
  21931. * @param {olx.FrameState} frameState Frame state.
  21932. * @param {ol.Transform=} opt_transform Transform.
  21933. * @protected
  21934. */
  21935. ol.renderer.canvas.Layer.prototype.dispatchRenderEvent = function(context, frameState, opt_transform) {
  21936. this.dispatchComposeEvent_(ol.render.EventType.RENDER, context,
  21937. frameState, opt_transform);
  21938. };
  21939. /**
  21940. * @param {olx.FrameState} frameState Frame state.
  21941. * @param {number} offsetX Offset on the x-axis in view coordinates.
  21942. * @protected
  21943. * @return {!ol.Transform} Transform.
  21944. */
  21945. ol.renderer.canvas.Layer.prototype.getTransform = function(frameState, offsetX) {
  21946. var viewState = frameState.viewState;
  21947. var pixelRatio = frameState.pixelRatio;
  21948. var dx1 = pixelRatio * frameState.size[0] / 2;
  21949. var dy1 = pixelRatio * frameState.size[1] / 2;
  21950. var sx = pixelRatio / viewState.resolution;
  21951. var sy = -sx;
  21952. var angle = -viewState.rotation;
  21953. var dx2 = -viewState.center[0] + offsetX;
  21954. var dy2 = -viewState.center[1];
  21955. return ol.transform.compose(this.transform_, dx1, dy1, sx, sy, angle, dx2, dy2);
  21956. };
  21957. /**
  21958. * @abstract
  21959. * @param {olx.FrameState} frameState Frame state.
  21960. * @param {ol.LayerState} layerState Layer state.
  21961. * @param {CanvasRenderingContext2D} context Context.
  21962. */
  21963. ol.renderer.canvas.Layer.prototype.composeFrame = function(frameState, layerState, context) {};
  21964. /**
  21965. * @abstract
  21966. * @param {olx.FrameState} frameState Frame state.
  21967. * @param {ol.LayerState} layerState Layer state.
  21968. * @return {boolean} whether composeFrame should be called.
  21969. */
  21970. ol.renderer.canvas.Layer.prototype.prepareFrame = function(frameState, layerState) {};
  21971. goog.provide('ol.renderer.canvas.IntermediateCanvas');
  21972. goog.require('ol');
  21973. goog.require('ol.coordinate');
  21974. goog.require('ol.dom');
  21975. goog.require('ol.extent');
  21976. goog.require('ol.renderer.canvas.Layer');
  21977. goog.require('ol.transform');
  21978. /**
  21979. * @constructor
  21980. * @abstract
  21981. * @extends {ol.renderer.canvas.Layer}
  21982. * @param {ol.layer.Layer} layer Layer.
  21983. */
  21984. ol.renderer.canvas.IntermediateCanvas = function(layer) {
  21985. ol.renderer.canvas.Layer.call(this, layer);
  21986. /**
  21987. * @protected
  21988. * @type {ol.Transform}
  21989. */
  21990. this.coordinateToCanvasPixelTransform = ol.transform.create();
  21991. /**
  21992. * @private
  21993. * @type {CanvasRenderingContext2D}
  21994. */
  21995. this.hitCanvasContext_ = null;
  21996. };
  21997. ol.inherits(ol.renderer.canvas.IntermediateCanvas, ol.renderer.canvas.Layer);
  21998. /**
  21999. * @inheritDoc
  22000. */
  22001. ol.renderer.canvas.IntermediateCanvas.prototype.composeFrame = function(frameState, layerState, context) {
  22002. this.preCompose(context, frameState);
  22003. var image = this.getImage();
  22004. if (image) {
  22005. // clipped rendering if layer extent is set
  22006. var extent = layerState.extent;
  22007. var clipped = extent !== undefined &&
  22008. !ol.extent.containsExtent(extent, frameState.extent) &&
  22009. ol.extent.intersects(extent, frameState.extent);
  22010. if (clipped) {
  22011. this.clip(context, frameState, /** @type {ol.Extent} */ (extent));
  22012. }
  22013. var imageTransform = this.getImageTransform();
  22014. // for performance reasons, context.save / context.restore is not used
  22015. // to save and restore the transformation matrix and the opacity.
  22016. // see http://jsperf.com/context-save-restore-versus-variable
  22017. var alpha = context.globalAlpha;
  22018. context.globalAlpha = layerState.opacity;
  22019. // for performance reasons, context.setTransform is only used
  22020. // when the view is rotated. see http://jsperf.com/canvas-transform
  22021. var dx = imageTransform[4];
  22022. var dy = imageTransform[5];
  22023. var dw = image.width * imageTransform[0];
  22024. var dh = image.height * imageTransform[3];
  22025. context.drawImage(image, 0, 0, +image.width, +image.height,
  22026. Math.round(dx), Math.round(dy), Math.round(dw), Math.round(dh));
  22027. context.globalAlpha = alpha;
  22028. if (clipped) {
  22029. context.restore();
  22030. }
  22031. }
  22032. this.postCompose(context, frameState, layerState);
  22033. };
  22034. /**
  22035. * @abstract
  22036. * @return {HTMLCanvasElement|HTMLVideoElement|Image} Canvas.
  22037. */
  22038. ol.renderer.canvas.IntermediateCanvas.prototype.getImage = function() {};
  22039. /**
  22040. * @abstract
  22041. * @return {!ol.Transform} Image transform.
  22042. */
  22043. ol.renderer.canvas.IntermediateCanvas.prototype.getImageTransform = function() {};
  22044. /**
  22045. * @inheritDoc
  22046. */
  22047. ol.renderer.canvas.IntermediateCanvas.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
  22048. var layer = this.getLayer();
  22049. var source = layer.getSource();
  22050. var resolution = frameState.viewState.resolution;
  22051. var rotation = frameState.viewState.rotation;
  22052. var skippedFeatureUids = frameState.skippedFeatureUids;
  22053. return source.forEachFeatureAtCoordinate(
  22054. coordinate, resolution, rotation, hitTolerance, skippedFeatureUids,
  22055. /**
  22056. * @param {ol.Feature|ol.render.Feature} feature Feature.
  22057. * @return {?} Callback result.
  22058. */
  22059. function(feature) {
  22060. return callback.call(thisArg, feature, layer);
  22061. });
  22062. };
  22063. /**
  22064. * @inheritDoc
  22065. */
  22066. ol.renderer.canvas.IntermediateCanvas.prototype.forEachLayerAtCoordinate = function(coordinate, frameState, callback, thisArg) {
  22067. if (!this.getImage()) {
  22068. return undefined;
  22069. }
  22070. if (this.getLayer().getSource().forEachFeatureAtCoordinate !== ol.nullFunction) {
  22071. // for ImageCanvas sources use the original hit-detection logic,
  22072. // so that for example also transparent polygons are detected
  22073. return ol.renderer.canvas.Layer.prototype.forEachLayerAtCoordinate.apply(this, arguments);
  22074. } else {
  22075. var pixel = ol.transform.apply(this.coordinateToCanvasPixelTransform, coordinate.slice());
  22076. ol.coordinate.scale(pixel, frameState.viewState.resolution / this.renderedResolution);
  22077. if (!this.hitCanvasContext_) {
  22078. this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);
  22079. }
  22080. this.hitCanvasContext_.clearRect(0, 0, 1, 1);
  22081. this.hitCanvasContext_.drawImage(this.getImage(), pixel[0], pixel[1], 1, 1, 0, 0, 1, 1);
  22082. var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
  22083. if (imageData[3] > 0) {
  22084. return callback.call(thisArg, this.getLayer(), imageData);
  22085. } else {
  22086. return undefined;
  22087. }
  22088. }
  22089. };
  22090. goog.provide('ol.renderer.canvas.ImageLayer');
  22091. goog.require('ol');
  22092. goog.require('ol.ImageCanvas');
  22093. goog.require('ol.LayerType');
  22094. goog.require('ol.ViewHint');
  22095. goog.require('ol.array');
  22096. goog.require('ol.extent');
  22097. goog.require('ol.layer.VectorRenderType');
  22098. goog.require('ol.obj');
  22099. goog.require('ol.plugins');
  22100. goog.require('ol.renderer.Type');
  22101. goog.require('ol.renderer.canvas.IntermediateCanvas');
  22102. goog.require('ol.transform');
  22103. /**
  22104. * @constructor
  22105. * @extends {ol.renderer.canvas.IntermediateCanvas}
  22106. * @param {ol.layer.Image} imageLayer Single image layer.
  22107. * @api
  22108. */
  22109. ol.renderer.canvas.ImageLayer = function(imageLayer) {
  22110. ol.renderer.canvas.IntermediateCanvas.call(this, imageLayer);
  22111. /**
  22112. * @private
  22113. * @type {?ol.ImageBase}
  22114. */
  22115. this.image_ = null;
  22116. /**
  22117. * @private
  22118. * @type {ol.Transform}
  22119. */
  22120. this.imageTransform_ = ol.transform.create();
  22121. /**
  22122. * @type {!Array.<string>}
  22123. */
  22124. this.skippedFeatures_ = [];
  22125. /**
  22126. * @private
  22127. * @type {ol.renderer.canvas.VectorLayer}
  22128. */
  22129. this.vectorRenderer_ = null;
  22130. };
  22131. ol.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.IntermediateCanvas);
  22132. /**
  22133. * Determine if this renderer handles the provided layer.
  22134. * @param {ol.renderer.Type} type The renderer type.
  22135. * @param {ol.layer.Layer} layer The candidate layer.
  22136. * @return {boolean} The renderer can render the layer.
  22137. */
  22138. ol.renderer.canvas.ImageLayer['handles'] = function(type, layer) {
  22139. return type === ol.renderer.Type.CANVAS && (layer.getType() === ol.LayerType.IMAGE ||
  22140. layer.getType() === ol.LayerType.VECTOR &&
  22141. /** @type {ol.layer.Vector} */ (layer).getRenderMode() === ol.layer.VectorRenderType.IMAGE);
  22142. };
  22143. /**
  22144. * Create a layer renderer.
  22145. * @param {ol.renderer.Map} mapRenderer The map renderer.
  22146. * @param {ol.layer.Layer} layer The layer to be rendererd.
  22147. * @return {ol.renderer.canvas.ImageLayer} The layer renderer.
  22148. */
  22149. ol.renderer.canvas.ImageLayer['create'] = function(mapRenderer, layer) {
  22150. var renderer = new ol.renderer.canvas.ImageLayer(/** @type {ol.layer.Image} */ (layer));
  22151. if (layer.getType() === ol.LayerType.VECTOR) {
  22152. var candidates = ol.plugins.getLayerRendererPlugins();
  22153. for (var i = 0, ii = candidates.length; i < ii; ++i) {
  22154. var candidate = /** @type {Object.<string, Function>} */ (candidates[i]);
  22155. if (candidate !== ol.renderer.canvas.ImageLayer && candidate['handles'](ol.renderer.Type.CANVAS, layer)) {
  22156. renderer.setVectorRenderer(candidate['create'](mapRenderer, layer));
  22157. }
  22158. }
  22159. }
  22160. return renderer;
  22161. };
  22162. /**
  22163. * @inheritDoc
  22164. */
  22165. ol.renderer.canvas.ImageLayer.prototype.getImage = function() {
  22166. return !this.image_ ? null : this.image_.getImage();
  22167. };
  22168. /**
  22169. * @inheritDoc
  22170. */
  22171. ol.renderer.canvas.ImageLayer.prototype.getImageTransform = function() {
  22172. return this.imageTransform_;
  22173. };
  22174. /**
  22175. * @inheritDoc
  22176. */
  22177. ol.renderer.canvas.ImageLayer.prototype.prepareFrame = function(frameState, layerState) {
  22178. var pixelRatio = frameState.pixelRatio;
  22179. var size = frameState.size;
  22180. var viewState = frameState.viewState;
  22181. var viewCenter = viewState.center;
  22182. var viewResolution = viewState.resolution;
  22183. var image;
  22184. var imageLayer = /** @type {ol.layer.Image} */ (this.getLayer());
  22185. var imageSource = imageLayer.getSource();
  22186. var hints = frameState.viewHints;
  22187. var renderedExtent = frameState.extent;
  22188. if (layerState.extent !== undefined) {
  22189. renderedExtent = ol.extent.getIntersection(
  22190. renderedExtent, layerState.extent);
  22191. }
  22192. if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING] &&
  22193. !ol.extent.isEmpty(renderedExtent)) {
  22194. var projection = viewState.projection;
  22195. if (!ol.ENABLE_RASTER_REPROJECTION) {
  22196. var sourceProjection = imageSource.getProjection();
  22197. if (sourceProjection) {
  22198. projection = sourceProjection;
  22199. }
  22200. }
  22201. var vectorRenderer = this.vectorRenderer_;
  22202. if (vectorRenderer) {
  22203. var context = vectorRenderer.context;
  22204. var imageFrameState = /** @type {olx.FrameState} */ (ol.obj.assign({}, frameState, {
  22205. size: [
  22206. ol.extent.getWidth(renderedExtent) / viewResolution,
  22207. ol.extent.getHeight(renderedExtent) / viewResolution
  22208. ],
  22209. viewState: /** @type {olx.ViewState} */ (ol.obj.assign({}, frameState.viewState, {
  22210. rotation: 0
  22211. }))
  22212. }));
  22213. var skippedFeatures = Object.keys(imageFrameState.skippedFeatureUids).sort();
  22214. if (vectorRenderer.prepareFrame(imageFrameState, layerState) &&
  22215. (vectorRenderer.replayGroupChanged ||
  22216. !ol.array.equals(skippedFeatures, this.skippedFeatures_))) {
  22217. context.canvas.width = imageFrameState.size[0] * pixelRatio;
  22218. context.canvas.height = imageFrameState.size[1] * pixelRatio;
  22219. vectorRenderer.composeFrame(imageFrameState, layerState, context);
  22220. this.image_ = new ol.ImageCanvas(renderedExtent, viewResolution, pixelRatio, context.canvas);
  22221. this.skippedFeatures_ = skippedFeatures;
  22222. }
  22223. } else {
  22224. image = imageSource.getImage(
  22225. renderedExtent, viewResolution, pixelRatio, projection);
  22226. if (image) {
  22227. var loaded = this.loadImage(image);
  22228. if (loaded) {
  22229. this.image_ = image;
  22230. }
  22231. }
  22232. }
  22233. }
  22234. if (this.image_) {
  22235. image = this.image_;
  22236. var imageExtent = image.getExtent();
  22237. var imageResolution = image.getResolution();
  22238. var imagePixelRatio = image.getPixelRatio();
  22239. var scale = pixelRatio * imageResolution /
  22240. (viewResolution * imagePixelRatio);
  22241. var transform = ol.transform.compose(this.imageTransform_,
  22242. pixelRatio * size[0] / 2, pixelRatio * size[1] / 2,
  22243. scale, scale,
  22244. 0,
  22245. imagePixelRatio * (imageExtent[0] - viewCenter[0]) / imageResolution,
  22246. imagePixelRatio * (viewCenter[1] - imageExtent[3]) / imageResolution);
  22247. ol.transform.compose(this.coordinateToCanvasPixelTransform,
  22248. pixelRatio * size[0] / 2 - transform[4], pixelRatio * size[1] / 2 - transform[5],
  22249. pixelRatio / viewResolution, -pixelRatio / viewResolution,
  22250. 0,
  22251. -viewCenter[0], -viewCenter[1]);
  22252. this.updateLogos(frameState, imageSource);
  22253. this.renderedResolution = imageResolution * pixelRatio / imagePixelRatio;
  22254. }
  22255. return !!this.image_;
  22256. };
  22257. /**
  22258. * @inheritDoc
  22259. */
  22260. ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
  22261. if (this.vectorRenderer_) {
  22262. return this.vectorRenderer_.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg);
  22263. } else {
  22264. return ol.renderer.canvas.IntermediateCanvas.prototype.forEachFeatureAtCoordinate.call(this, coordinate, frameState, hitTolerance, callback, thisArg);
  22265. }
  22266. };
  22267. /**
  22268. * @param {ol.renderer.canvas.VectorLayer} renderer Vector renderer.
  22269. */
  22270. ol.renderer.canvas.ImageLayer.prototype.setVectorRenderer = function(renderer) {
  22271. this.vectorRenderer_ = renderer;
  22272. };
  22273. goog.provide('ol.style.IconImageCache');
  22274. goog.require('ol.color');
  22275. /**
  22276. * Singleton class. Available through {@link ol.style.iconImageCache}.
  22277. * @constructor
  22278. */
  22279. ol.style.IconImageCache = function() {
  22280. /**
  22281. * @type {Object.<string, ol.style.IconImage>}
  22282. * @private
  22283. */
  22284. this.cache_ = {};
  22285. /**
  22286. * @type {number}
  22287. * @private
  22288. */
  22289. this.cacheSize_ = 0;
  22290. /**
  22291. * @type {number}
  22292. * @private
  22293. */
  22294. this.maxCacheSize_ = 32;
  22295. };
  22296. /**
  22297. * @param {string} src Src.
  22298. * @param {?string} crossOrigin Cross origin.
  22299. * @param {ol.Color} color Color.
  22300. * @return {string} Cache key.
  22301. */
  22302. ol.style.IconImageCache.getKey = function(src, crossOrigin, color) {
  22303. var colorString = color ? ol.color.asString(color) : 'null';
  22304. return crossOrigin + ':' + src + ':' + colorString;
  22305. };
  22306. /**
  22307. * FIXME empty description for jsdoc
  22308. */
  22309. ol.style.IconImageCache.prototype.clear = function() {
  22310. this.cache_ = {};
  22311. this.cacheSize_ = 0;
  22312. };
  22313. /**
  22314. * FIXME empty description for jsdoc
  22315. */
  22316. ol.style.IconImageCache.prototype.expire = function() {
  22317. if (this.cacheSize_ > this.maxCacheSize_) {
  22318. var i = 0;
  22319. var key, iconImage;
  22320. for (key in this.cache_) {
  22321. iconImage = this.cache_[key];
  22322. if ((i++ & 3) === 0 && !iconImage.hasListener()) {
  22323. delete this.cache_[key];
  22324. --this.cacheSize_;
  22325. }
  22326. }
  22327. }
  22328. };
  22329. /**
  22330. * @param {string} src Src.
  22331. * @param {?string} crossOrigin Cross origin.
  22332. * @param {ol.Color} color Color.
  22333. * @return {ol.style.IconImage} Icon image.
  22334. */
  22335. ol.style.IconImageCache.prototype.get = function(src, crossOrigin, color) {
  22336. var key = ol.style.IconImageCache.getKey(src, crossOrigin, color);
  22337. return key in this.cache_ ? this.cache_[key] : null;
  22338. };
  22339. /**
  22340. * @param {string} src Src.
  22341. * @param {?string} crossOrigin Cross origin.
  22342. * @param {ol.Color} color Color.
  22343. * @param {ol.style.IconImage} iconImage Icon image.
  22344. */
  22345. ol.style.IconImageCache.prototype.set = function(src, crossOrigin, color, iconImage) {
  22346. var key = ol.style.IconImageCache.getKey(src, crossOrigin, color);
  22347. this.cache_[key] = iconImage;
  22348. ++this.cacheSize_;
  22349. };
  22350. /**
  22351. * Set the cache size of the icon cache. Default is `32`. Change this value when
  22352. * your map uses more than 32 different icon images and you are not caching icon
  22353. * styles on the application level.
  22354. * @param {number} maxCacheSize Cache max size.
  22355. * @api
  22356. */
  22357. ol.style.IconImageCache.prototype.setSize = function(maxCacheSize) {
  22358. this.maxCacheSize_ = maxCacheSize;
  22359. this.expire();
  22360. };
  22361. goog.provide('ol.style');
  22362. goog.require('ol.style.IconImageCache');
  22363. /**
  22364. * The {@link ol.style.IconImageCache} for {@link ol.style.Icon} images.
  22365. * @api
  22366. */
  22367. ol.style.iconImageCache = new ol.style.IconImageCache();
  22368. goog.provide('ol.renderer.Map');
  22369. goog.require('ol');
  22370. goog.require('ol.Disposable');
  22371. goog.require('ol.events');
  22372. goog.require('ol.events.EventType');
  22373. goog.require('ol.extent');
  22374. goog.require('ol.functions');
  22375. goog.require('ol.layer.Layer');
  22376. goog.require('ol.plugins');
  22377. goog.require('ol.style');
  22378. goog.require('ol.transform');
  22379. /**
  22380. * @constructor
  22381. * @abstract
  22382. * @extends {ol.Disposable}
  22383. * @param {Element} container Container.
  22384. * @param {ol.PluggableMap} map Map.
  22385. * @struct
  22386. */
  22387. ol.renderer.Map = function(container, map) {
  22388. ol.Disposable.call(this);
  22389. /**
  22390. * @private
  22391. * @type {ol.PluggableMap}
  22392. */
  22393. this.map_ = map;
  22394. /**
  22395. * @private
  22396. * @type {Object.<string, ol.renderer.Layer>}
  22397. */
  22398. this.layerRenderers_ = {};
  22399. /**
  22400. * @private
  22401. * @type {Object.<string, ol.EventsKey>}
  22402. */
  22403. this.layerRendererListeners_ = {};
  22404. };
  22405. ol.inherits(ol.renderer.Map, ol.Disposable);
  22406. /**
  22407. * @param {olx.FrameState} frameState FrameState.
  22408. * @protected
  22409. */
  22410. ol.renderer.Map.prototype.calculateMatrices2D = function(frameState) {
  22411. var viewState = frameState.viewState;
  22412. var coordinateToPixelTransform = frameState.coordinateToPixelTransform;
  22413. var pixelToCoordinateTransform = frameState.pixelToCoordinateTransform;
  22414. ol.transform.compose(coordinateToPixelTransform,
  22415. frameState.size[0] / 2, frameState.size[1] / 2,
  22416. 1 / viewState.resolution, -1 / viewState.resolution,
  22417. -viewState.rotation,
  22418. -viewState.center[0], -viewState.center[1]);
  22419. ol.transform.invert(
  22420. ol.transform.setFromArray(pixelToCoordinateTransform, coordinateToPixelTransform));
  22421. };
  22422. /**
  22423. * Removes all layer renderers.
  22424. */
  22425. ol.renderer.Map.prototype.removeLayerRenderers = function() {
  22426. for (var key in this.layerRenderers_) {
  22427. this.removeLayerRendererByKey_(key).dispose();
  22428. }
  22429. };
  22430. /**
  22431. * @param {ol.PluggableMap} map Map.
  22432. * @param {olx.FrameState} frameState Frame state.
  22433. * @private
  22434. */
  22435. ol.renderer.Map.expireIconCache_ = function(map, frameState) {
  22436. var cache = ol.style.iconImageCache;
  22437. cache.expire();
  22438. };
  22439. /**
  22440. * @param {ol.Coordinate} coordinate Coordinate.
  22441. * @param {olx.FrameState} frameState FrameState.
  22442. * @param {number} hitTolerance Hit tolerance in pixels.
  22443. * @param {function(this: S, (ol.Feature|ol.render.Feature),
  22444. * ol.layer.Layer): T} callback Feature callback.
  22445. * @param {S} thisArg Value to use as `this` when executing `callback`.
  22446. * @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
  22447. * function, only layers which are visible and for which this function
  22448. * returns `true` will be tested for features. By default, all visible
  22449. * layers will be tested.
  22450. * @param {U} thisArg2 Value to use as `this` when executing `layerFilter`.
  22451. * @return {T|undefined} Callback result.
  22452. * @template S,T,U
  22453. */
  22454. ol.renderer.Map.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg,
  22455. layerFilter, thisArg2) {
  22456. var result;
  22457. var viewState = frameState.viewState;
  22458. var viewResolution = viewState.resolution;
  22459. /**
  22460. * @param {ol.Feature|ol.render.Feature} feature Feature.
  22461. * @param {ol.layer.Layer} layer Layer.
  22462. * @return {?} Callback result.
  22463. */
  22464. function forEachFeatureAtCoordinate(feature, layer) {
  22465. var key = ol.getUid(feature).toString();
  22466. var managed = frameState.layerStates[ol.getUid(layer)].managed;
  22467. if (!(key in frameState.skippedFeatureUids && !managed)) {
  22468. return callback.call(thisArg, feature, managed ? layer : null);
  22469. }
  22470. }
  22471. var projection = viewState.projection;
  22472. var translatedCoordinate = coordinate;
  22473. if (projection.canWrapX()) {
  22474. var projectionExtent = projection.getExtent();
  22475. var worldWidth = ol.extent.getWidth(projectionExtent);
  22476. var x = coordinate[0];
  22477. if (x < projectionExtent[0] || x > projectionExtent[2]) {
  22478. var worldsAway = Math.ceil((projectionExtent[0] - x) / worldWidth);
  22479. translatedCoordinate = [x + worldWidth * worldsAway, coordinate[1]];
  22480. }
  22481. }
  22482. var layerStates = frameState.layerStatesArray;
  22483. var numLayers = layerStates.length;
  22484. var i;
  22485. for (i = numLayers - 1; i >= 0; --i) {
  22486. var layerState = layerStates[i];
  22487. var layer = layerState.layer;
  22488. if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
  22489. layerFilter.call(thisArg2, layer)) {
  22490. var layerRenderer = this.getLayerRenderer(layer);
  22491. if (layer.getSource()) {
  22492. result = layerRenderer.forEachFeatureAtCoordinate(
  22493. layer.getSource().getWrapX() ? translatedCoordinate : coordinate,
  22494. frameState, hitTolerance, forEachFeatureAtCoordinate, thisArg);
  22495. }
  22496. if (result) {
  22497. return result;
  22498. }
  22499. }
  22500. }
  22501. return undefined;
  22502. };
  22503. /**
  22504. * @abstract
  22505. * @param {ol.Pixel} pixel Pixel.
  22506. * @param {olx.FrameState} frameState FrameState.
  22507. * @param {function(this: S, ol.layer.Layer, (Uint8ClampedArray|Uint8Array)): T} callback Layer
  22508. * callback.
  22509. * @param {S} thisArg Value to use as `this` when executing `callback`.
  22510. * @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
  22511. * function, only layers which are visible and for which this function
  22512. * returns `true` will be tested for features. By default, all visible
  22513. * layers will be tested.
  22514. * @param {U} thisArg2 Value to use as `this` when executing `layerFilter`.
  22515. * @return {T|undefined} Callback result.
  22516. * @template S,T,U
  22517. */
  22518. ol.renderer.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg,
  22519. layerFilter, thisArg2) {};
  22520. /**
  22521. * @param {ol.Coordinate} coordinate Coordinate.
  22522. * @param {olx.FrameState} frameState FrameState.
  22523. * @param {number} hitTolerance Hit tolerance in pixels.
  22524. * @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
  22525. * function, only layers which are visible and for which this function
  22526. * returns `true` will be tested for features. By default, all visible
  22527. * layers will be tested.
  22528. * @param {U} thisArg Value to use as `this` when executing `layerFilter`.
  22529. * @return {boolean} Is there a feature at the given coordinate?
  22530. * @template U
  22531. */
  22532. ol.renderer.Map.prototype.hasFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, layerFilter, thisArg) {
  22533. var hasFeature = this.forEachFeatureAtCoordinate(
  22534. coordinate, frameState, hitTolerance, ol.functions.TRUE, this, layerFilter, thisArg);
  22535. return hasFeature !== undefined;
  22536. };
  22537. /**
  22538. * @param {ol.layer.Layer} layer Layer.
  22539. * @protected
  22540. * @return {ol.renderer.Layer} Layer renderer.
  22541. */
  22542. ol.renderer.Map.prototype.getLayerRenderer = function(layer) {
  22543. var layerKey = ol.getUid(layer).toString();
  22544. if (layerKey in this.layerRenderers_) {
  22545. return this.layerRenderers_[layerKey];
  22546. } else {
  22547. var layerRendererPlugins = ol.plugins.getLayerRendererPlugins();
  22548. var renderer;
  22549. var type = this.getType();
  22550. for (var i = 0, ii = layerRendererPlugins.length; i < ii; ++i) {
  22551. var plugin = layerRendererPlugins[i];
  22552. if (plugin['handles'](type, layer)) {
  22553. renderer = plugin['create'](this, layer);
  22554. break;
  22555. }
  22556. }
  22557. if (renderer) {
  22558. this.layerRenderers_[layerKey] = renderer;
  22559. this.layerRendererListeners_[layerKey] = ol.events.listen(renderer,
  22560. ol.events.EventType.CHANGE, this.handleLayerRendererChange_, this);
  22561. } else {
  22562. throw new Error('Unable to create renderer for layer: ' + layer.getType());
  22563. }
  22564. return renderer;
  22565. }
  22566. };
  22567. /**
  22568. * @param {string} layerKey Layer key.
  22569. * @protected
  22570. * @return {ol.renderer.Layer} Layer renderer.
  22571. */
  22572. ol.renderer.Map.prototype.getLayerRendererByKey = function(layerKey) {
  22573. return this.layerRenderers_[layerKey];
  22574. };
  22575. /**
  22576. * @protected
  22577. * @return {Object.<string, ol.renderer.Layer>} Layer renderers.
  22578. */
  22579. ol.renderer.Map.prototype.getLayerRenderers = function() {
  22580. return this.layerRenderers_;
  22581. };
  22582. /**
  22583. * @return {ol.PluggableMap} Map.
  22584. */
  22585. ol.renderer.Map.prototype.getMap = function() {
  22586. return this.map_;
  22587. };
  22588. /**
  22589. * @abstract
  22590. * @return {ol.renderer.Type} Type
  22591. */
  22592. ol.renderer.Map.prototype.getType = function() {};
  22593. /**
  22594. * Handle changes in a layer renderer.
  22595. * @private
  22596. */
  22597. ol.renderer.Map.prototype.handleLayerRendererChange_ = function() {
  22598. this.map_.render();
  22599. };
  22600. /**
  22601. * @param {string} layerKey Layer key.
  22602. * @return {ol.renderer.Layer} Layer renderer.
  22603. * @private
  22604. */
  22605. ol.renderer.Map.prototype.removeLayerRendererByKey_ = function(layerKey) {
  22606. var layerRenderer = this.layerRenderers_[layerKey];
  22607. delete this.layerRenderers_[layerKey];
  22608. ol.events.unlistenByKey(this.layerRendererListeners_[layerKey]);
  22609. delete this.layerRendererListeners_[layerKey];
  22610. return layerRenderer;
  22611. };
  22612. /**
  22613. * Render.
  22614. * @param {?olx.FrameState} frameState Frame state.
  22615. */
  22616. ol.renderer.Map.prototype.renderFrame = ol.nullFunction;
  22617. /**
  22618. * @param {ol.PluggableMap} map Map.
  22619. * @param {olx.FrameState} frameState Frame state.
  22620. * @private
  22621. */
  22622. ol.renderer.Map.prototype.removeUnusedLayerRenderers_ = function(map, frameState) {
  22623. var layerKey;
  22624. for (layerKey in this.layerRenderers_) {
  22625. if (!frameState || !(layerKey in frameState.layerStates)) {
  22626. this.removeLayerRendererByKey_(layerKey).dispose();
  22627. }
  22628. }
  22629. };
  22630. /**
  22631. * @param {olx.FrameState} frameState Frame state.
  22632. * @protected
  22633. */
  22634. ol.renderer.Map.prototype.scheduleExpireIconCache = function(frameState) {
  22635. frameState.postRenderFunctions.push(
  22636. /** @type {ol.PostRenderFunction} */ (ol.renderer.Map.expireIconCache_)
  22637. );
  22638. };
  22639. /**
  22640. * @param {!olx.FrameState} frameState Frame state.
  22641. * @protected
  22642. */
  22643. ol.renderer.Map.prototype.scheduleRemoveUnusedLayerRenderers = function(frameState) {
  22644. var layerKey;
  22645. for (layerKey in this.layerRenderers_) {
  22646. if (!(layerKey in frameState.layerStates)) {
  22647. frameState.postRenderFunctions.push(
  22648. /** @type {ol.PostRenderFunction} */ (this.removeUnusedLayerRenderers_.bind(this))
  22649. );
  22650. return;
  22651. }
  22652. }
  22653. };
  22654. /**
  22655. * @param {ol.LayerState} state1 First layer state.
  22656. * @param {ol.LayerState} state2 Second layer state.
  22657. * @return {number} The zIndex difference.
  22658. */
  22659. ol.renderer.Map.sortByZIndex = function(state1, state2) {
  22660. return state1.zIndex - state2.zIndex;
  22661. };
  22662. // FIXME offset panning
  22663. goog.provide('ol.renderer.canvas.Map');
  22664. goog.require('ol.transform');
  22665. goog.require('ol');
  22666. goog.require('ol.array');
  22667. goog.require('ol.css');
  22668. goog.require('ol.dom');
  22669. goog.require('ol.layer.Layer');
  22670. goog.require('ol.render.Event');
  22671. goog.require('ol.render.EventType');
  22672. goog.require('ol.render.canvas');
  22673. goog.require('ol.render.canvas.Immediate');
  22674. goog.require('ol.renderer.Map');
  22675. goog.require('ol.renderer.Type');
  22676. goog.require('ol.source.State');
  22677. /**
  22678. * @constructor
  22679. * @extends {ol.renderer.Map}
  22680. * @param {Element} container Container.
  22681. * @param {ol.PluggableMap} map Map.
  22682. * @api
  22683. */
  22684. ol.renderer.canvas.Map = function(container, map) {
  22685. ol.renderer.Map.call(this, container, map);
  22686. /**
  22687. * @private
  22688. * @type {CanvasRenderingContext2D}
  22689. */
  22690. this.context_ = ol.dom.createCanvasContext2D();
  22691. /**
  22692. * @private
  22693. * @type {HTMLCanvasElement}
  22694. */
  22695. this.canvas_ = this.context_.canvas;
  22696. this.canvas_.style.width = '100%';
  22697. this.canvas_.style.height = '100%';
  22698. this.canvas_.style.display = 'block';
  22699. this.canvas_.className = ol.css.CLASS_UNSELECTABLE;
  22700. container.insertBefore(this.canvas_, container.childNodes[0] || null);
  22701. /**
  22702. * @private
  22703. * @type {boolean}
  22704. */
  22705. this.renderedVisible_ = true;
  22706. /**
  22707. * @private
  22708. * @type {ol.Transform}
  22709. */
  22710. this.transform_ = ol.transform.create();
  22711. };
  22712. ol.inherits(ol.renderer.canvas.Map, ol.renderer.Map);
  22713. /**
  22714. * Determine if this renderer handles the provided layer.
  22715. * @param {ol.renderer.Type} type The renderer type.
  22716. * @return {boolean} The renderer can render the layer.
  22717. */
  22718. ol.renderer.canvas.Map['handles'] = function(type) {
  22719. return type === ol.renderer.Type.CANVAS;
  22720. };
  22721. /**
  22722. * Create the map renderer.
  22723. * @param {Element} container Container.
  22724. * @param {ol.PluggableMap} map Map.
  22725. * @return {ol.renderer.canvas.Map} The map renderer.
  22726. */
  22727. ol.renderer.canvas.Map['create'] = function(container, map) {
  22728. return new ol.renderer.canvas.Map(container, map);
  22729. };
  22730. /**
  22731. * @param {ol.render.EventType} type Event type.
  22732. * @param {olx.FrameState} frameState Frame state.
  22733. * @private
  22734. */
  22735. ol.renderer.canvas.Map.prototype.dispatchComposeEvent_ = function(type, frameState) {
  22736. var map = this.getMap();
  22737. var context = this.context_;
  22738. if (map.hasListener(type)) {
  22739. var extent = frameState.extent;
  22740. var pixelRatio = frameState.pixelRatio;
  22741. var viewState = frameState.viewState;
  22742. var rotation = viewState.rotation;
  22743. var transform = this.getTransform(frameState);
  22744. var vectorContext = new ol.render.canvas.Immediate(context, pixelRatio,
  22745. extent, transform, rotation);
  22746. var composeEvent = new ol.render.Event(type, vectorContext,
  22747. frameState, context, null);
  22748. map.dispatchEvent(composeEvent);
  22749. }
  22750. };
  22751. /**
  22752. * @param {olx.FrameState} frameState Frame state.
  22753. * @protected
  22754. * @return {!ol.Transform} Transform.
  22755. */
  22756. ol.renderer.canvas.Map.prototype.getTransform = function(frameState) {
  22757. var viewState = frameState.viewState;
  22758. var dx1 = this.canvas_.width / 2;
  22759. var dy1 = this.canvas_.height / 2;
  22760. var sx = frameState.pixelRatio / viewState.resolution;
  22761. var sy = -sx;
  22762. var angle = -viewState.rotation;
  22763. var dx2 = -viewState.center[0];
  22764. var dy2 = -viewState.center[1];
  22765. return ol.transform.compose(this.transform_, dx1, dy1, sx, sy, angle, dx2, dy2);
  22766. };
  22767. /**
  22768. * @inheritDoc
  22769. */
  22770. ol.renderer.canvas.Map.prototype.getType = function() {
  22771. return ol.renderer.Type.CANVAS;
  22772. };
  22773. /**
  22774. * @inheritDoc
  22775. */
  22776. ol.renderer.canvas.Map.prototype.renderFrame = function(frameState) {
  22777. if (!frameState) {
  22778. if (this.renderedVisible_) {
  22779. this.canvas_.style.display = 'none';
  22780. this.renderedVisible_ = false;
  22781. }
  22782. return;
  22783. }
  22784. var context = this.context_;
  22785. var pixelRatio = frameState.pixelRatio;
  22786. var width = Math.round(frameState.size[0] * pixelRatio);
  22787. var height = Math.round(frameState.size[1] * pixelRatio);
  22788. if (this.canvas_.width != width || this.canvas_.height != height) {
  22789. this.canvas_.width = width;
  22790. this.canvas_.height = height;
  22791. } else {
  22792. context.clearRect(0, 0, width, height);
  22793. }
  22794. var rotation = frameState.viewState.rotation;
  22795. this.calculateMatrices2D(frameState);
  22796. this.dispatchComposeEvent_(ol.render.EventType.PRECOMPOSE, frameState);
  22797. var layerStatesArray = frameState.layerStatesArray;
  22798. ol.array.stableSort(layerStatesArray, ol.renderer.Map.sortByZIndex);
  22799. if (rotation) {
  22800. context.save();
  22801. ol.render.canvas.rotateAtOffset(context, rotation, width / 2, height / 2);
  22802. }
  22803. var viewResolution = frameState.viewState.resolution;
  22804. var i, ii, layer, layerRenderer, layerState;
  22805. for (i = 0, ii = layerStatesArray.length; i < ii; ++i) {
  22806. layerState = layerStatesArray[i];
  22807. layer = layerState.layer;
  22808. layerRenderer = /** @type {ol.renderer.canvas.Layer} */ (this.getLayerRenderer(layer));
  22809. if (!ol.layer.Layer.visibleAtResolution(layerState, viewResolution) ||
  22810. layerState.sourceState != ol.source.State.READY) {
  22811. continue;
  22812. }
  22813. if (layerRenderer.prepareFrame(frameState, layerState)) {
  22814. layerRenderer.composeFrame(frameState, layerState, context);
  22815. }
  22816. }
  22817. if (rotation) {
  22818. context.restore();
  22819. }
  22820. this.dispatchComposeEvent_(
  22821. ol.render.EventType.POSTCOMPOSE, frameState);
  22822. if (!this.renderedVisible_) {
  22823. this.canvas_.style.display = '';
  22824. this.renderedVisible_ = true;
  22825. }
  22826. this.scheduleRemoveUnusedLayerRenderers(frameState);
  22827. this.scheduleExpireIconCache(frameState);
  22828. };
  22829. /**
  22830. * @inheritDoc
  22831. */
  22832. ol.renderer.canvas.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg,
  22833. layerFilter, thisArg2) {
  22834. var result;
  22835. var viewState = frameState.viewState;
  22836. var viewResolution = viewState.resolution;
  22837. var layerStates = frameState.layerStatesArray;
  22838. var numLayers = layerStates.length;
  22839. var coordinate = ol.transform.apply(
  22840. frameState.pixelToCoordinateTransform, pixel.slice());
  22841. var i;
  22842. for (i = numLayers - 1; i >= 0; --i) {
  22843. var layerState = layerStates[i];
  22844. var layer = layerState.layer;
  22845. if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
  22846. layerFilter.call(thisArg2, layer)) {
  22847. var layerRenderer = /** @type {ol.renderer.canvas.Layer} */ (this.getLayerRenderer(layer));
  22848. result = layerRenderer.forEachLayerAtCoordinate(
  22849. coordinate, frameState, callback, thisArg);
  22850. if (result) {
  22851. return result;
  22852. }
  22853. }
  22854. }
  22855. return undefined;
  22856. };
  22857. goog.provide('ol.renderer.canvas.TileLayer');
  22858. goog.require('ol');
  22859. goog.require('ol.LayerType');
  22860. goog.require('ol.TileRange');
  22861. goog.require('ol.TileState');
  22862. goog.require('ol.ViewHint');
  22863. goog.require('ol.dom');
  22864. goog.require('ol.extent');
  22865. goog.require('ol.renderer.Type');
  22866. goog.require('ol.renderer.canvas.IntermediateCanvas');
  22867. goog.require('ol.transform');
  22868. /**
  22869. * @constructor
  22870. * @extends {ol.renderer.canvas.IntermediateCanvas}
  22871. * @param {ol.layer.Tile|ol.layer.VectorTile} tileLayer Tile layer.
  22872. * @api
  22873. */
  22874. ol.renderer.canvas.TileLayer = function(tileLayer) {
  22875. ol.renderer.canvas.IntermediateCanvas.call(this, tileLayer);
  22876. /**
  22877. * @protected
  22878. * @type {CanvasRenderingContext2D}
  22879. */
  22880. this.context = this.context === null ? null : ol.dom.createCanvasContext2D();
  22881. /**
  22882. * @private
  22883. * @type {number}
  22884. */
  22885. this.oversampling_;
  22886. /**
  22887. * @private
  22888. * @type {ol.Extent}
  22889. */
  22890. this.renderedExtent_ = null;
  22891. /**
  22892. * @protected
  22893. * @type {number}
  22894. */
  22895. this.renderedRevision;
  22896. /**
  22897. * @protected
  22898. * @type {!Array.<ol.Tile>}
  22899. */
  22900. this.renderedTiles = [];
  22901. /**
  22902. * @protected
  22903. * @type {ol.Extent}
  22904. */
  22905. this.tmpExtent = ol.extent.createEmpty();
  22906. /**
  22907. * @private
  22908. * @type {ol.TileRange}
  22909. */
  22910. this.tmpTileRange_ = new ol.TileRange(0, 0, 0, 0);
  22911. /**
  22912. * @private
  22913. * @type {ol.Transform}
  22914. */
  22915. this.imageTransform_ = ol.transform.create();
  22916. /**
  22917. * @protected
  22918. * @type {number}
  22919. */
  22920. this.zDirection = 0;
  22921. };
  22922. ol.inherits(ol.renderer.canvas.TileLayer, ol.renderer.canvas.IntermediateCanvas);
  22923. /**
  22924. * Determine if this renderer handles the provided layer.
  22925. * @param {ol.renderer.Type} type The renderer type.
  22926. * @param {ol.layer.Layer} layer The candidate layer.
  22927. * @return {boolean} The renderer can render the layer.
  22928. */
  22929. ol.renderer.canvas.TileLayer['handles'] = function(type, layer) {
  22930. return type === ol.renderer.Type.CANVAS && layer.getType() === ol.LayerType.TILE;
  22931. };
  22932. /**
  22933. * Create a layer renderer.
  22934. * @param {ol.renderer.Map} mapRenderer The map renderer.
  22935. * @param {ol.layer.Layer} layer The layer to be rendererd.
  22936. * @return {ol.renderer.canvas.TileLayer} The layer renderer.
  22937. */
  22938. ol.renderer.canvas.TileLayer['create'] = function(mapRenderer, layer) {
  22939. return new ol.renderer.canvas.TileLayer(/** @type {ol.layer.Tile} */ (layer));
  22940. };
  22941. /**
  22942. * @private
  22943. * @param {ol.Tile} tile Tile.
  22944. * @return {boolean} Tile is drawable.
  22945. */
  22946. ol.renderer.canvas.TileLayer.prototype.isDrawableTile_ = function(tile) {
  22947. var tileState = tile.getState();
  22948. var useInterimTilesOnError = this.getLayer().getUseInterimTilesOnError();
  22949. return tileState == ol.TileState.LOADED ||
  22950. tileState == ol.TileState.EMPTY ||
  22951. tileState == ol.TileState.ERROR && !useInterimTilesOnError;
  22952. };
  22953. /**
  22954. * @inheritDoc
  22955. */
  22956. ol.renderer.canvas.TileLayer.prototype.prepareFrame = function(frameState, layerState) {
  22957. var pixelRatio = frameState.pixelRatio;
  22958. var size = frameState.size;
  22959. var viewState = frameState.viewState;
  22960. var projection = viewState.projection;
  22961. var viewResolution = viewState.resolution;
  22962. var viewCenter = viewState.center;
  22963. var tileLayer = this.getLayer();
  22964. var tileSource = /** @type {ol.source.Tile} */ (tileLayer.getSource());
  22965. var sourceRevision = tileSource.getRevision();
  22966. var tileGrid = tileSource.getTileGridForProjection(projection);
  22967. var z = tileGrid.getZForResolution(viewResolution, this.zDirection);
  22968. var tileResolution = tileGrid.getResolution(z);
  22969. var oversampling = Math.round(viewResolution / tileResolution) || 1;
  22970. var extent = frameState.extent;
  22971. if (layerState.extent !== undefined) {
  22972. extent = ol.extent.getIntersection(extent, layerState.extent);
  22973. }
  22974. if (ol.extent.isEmpty(extent)) {
  22975. // Return false to prevent the rendering of the layer.
  22976. return false;
  22977. }
  22978. var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
  22979. var imageExtent = tileGrid.getTileRangeExtent(z, tileRange);
  22980. var tilePixelRatio = tileSource.getTilePixelRatio(pixelRatio);
  22981. /**
  22982. * @type {Object.<number, Object.<string, ol.Tile>>}
  22983. */
  22984. var tilesToDrawByZ = {};
  22985. tilesToDrawByZ[z] = {};
  22986. var findLoadedTiles = this.createLoadedTileFinder(
  22987. tileSource, projection, tilesToDrawByZ);
  22988. var tmpExtent = this.tmpExtent;
  22989. var tmpTileRange = this.tmpTileRange_;
  22990. var newTiles = false;
  22991. var tile, x, y;
  22992. for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
  22993. for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
  22994. tile = tileSource.getTile(z, x, y, pixelRatio, projection);
  22995. if (tile.getState() == ol.TileState.ERROR) {
  22996. if (!tileLayer.getUseInterimTilesOnError()) {
  22997. // When useInterimTilesOnError is false, we consider the error tile as loaded.
  22998. tile.setState(ol.TileState.LOADED);
  22999. } else if (tileLayer.getPreload() > 0) {
  23000. // Preloaded tiles for lower resolutions might have finished loading.
  23001. newTiles = true;
  23002. }
  23003. }
  23004. if (!this.isDrawableTile_(tile)) {
  23005. tile = tile.getInterimTile();
  23006. }
  23007. if (this.isDrawableTile_(tile)) {
  23008. var uid = ol.getUid(this);
  23009. if (tile.getState() == ol.TileState.LOADED) {
  23010. tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
  23011. var inTransition = tile.inTransition(uid);
  23012. if (!newTiles && (inTransition || this.renderedTiles.indexOf(tile) === -1)) {
  23013. newTiles = true;
  23014. }
  23015. }
  23016. if (tile.getAlpha(uid, frameState.time) === 1) {
  23017. // don't look for alt tiles if alpha is 1
  23018. continue;
  23019. }
  23020. }
  23021. var childTileRange = tileGrid.getTileCoordChildTileRange(
  23022. tile.tileCoord, tmpTileRange, tmpExtent);
  23023. var covered = false;
  23024. if (childTileRange) {
  23025. covered = findLoadedTiles(z + 1, childTileRange);
  23026. }
  23027. if (!covered) {
  23028. tileGrid.forEachTileCoordParentTileRange(
  23029. tile.tileCoord, findLoadedTiles, null, tmpTileRange, tmpExtent);
  23030. }
  23031. }
  23032. }
  23033. var renderedResolution = tileResolution * pixelRatio / tilePixelRatio * oversampling;
  23034. var hints = frameState.viewHints;
  23035. var animatingOrInteracting = hints[ol.ViewHint.ANIMATING] || hints[ol.ViewHint.INTERACTING];
  23036. if (!(this.renderedResolution && Date.now() - frameState.time > 16 && animatingOrInteracting) && (
  23037. newTiles ||
  23038. !(this.renderedExtent_ && ol.extent.containsExtent(this.renderedExtent_, extent)) ||
  23039. this.renderedRevision != sourceRevision ||
  23040. oversampling != this.oversampling_ ||
  23041. !animatingOrInteracting && renderedResolution != this.renderedResolution
  23042. )) {
  23043. var context = this.context;
  23044. if (context) {
  23045. var tilePixelSize = tileSource.getTilePixelSize(z, pixelRatio, projection);
  23046. var width = Math.round(tileRange.getWidth() * tilePixelSize[0] / oversampling);
  23047. var height = Math.round(tileRange.getHeight() * tilePixelSize[1] / oversampling);
  23048. var canvas = context.canvas;
  23049. if (canvas.width != width || canvas.height != height) {
  23050. this.oversampling_ = oversampling;
  23051. canvas.width = width;
  23052. canvas.height = height;
  23053. } else {
  23054. if (this.renderedExtent_ && !ol.extent.equals(imageExtent, this.renderedExtent_)) {
  23055. context.clearRect(0, 0, width, height);
  23056. }
  23057. oversampling = this.oversampling_;
  23058. }
  23059. }
  23060. this.renderedTiles.length = 0;
  23061. /** @type {Array.<number>} */
  23062. var zs = Object.keys(tilesToDrawByZ).map(Number);
  23063. zs.sort(function(a, b) {
  23064. if (a === z) {
  23065. return 1;
  23066. } else if (b === z) {
  23067. return -1;
  23068. } else {
  23069. return a > b ? 1 : a < b ? -1 : 0;
  23070. }
  23071. });
  23072. var currentResolution, currentScale, currentTilePixelSize, currentZ, i, ii;
  23073. var tileExtent, tileGutter, tilesToDraw, w, h;
  23074. for (i = 0, ii = zs.length; i < ii; ++i) {
  23075. currentZ = zs[i];
  23076. currentTilePixelSize = tileSource.getTilePixelSize(currentZ, pixelRatio, projection);
  23077. currentResolution = tileGrid.getResolution(currentZ);
  23078. currentScale = currentResolution / tileResolution;
  23079. tileGutter = tilePixelRatio * tileSource.getGutter(projection);
  23080. tilesToDraw = tilesToDrawByZ[currentZ];
  23081. for (var tileCoordKey in tilesToDraw) {
  23082. tile = tilesToDraw[tileCoordKey];
  23083. tileExtent = tileGrid.getTileCoordExtent(tile.getTileCoord(), tmpExtent);
  23084. x = (tileExtent[0] - imageExtent[0]) / tileResolution * tilePixelRatio / oversampling;
  23085. y = (imageExtent[3] - tileExtent[3]) / tileResolution * tilePixelRatio / oversampling;
  23086. w = currentTilePixelSize[0] * currentScale / oversampling;
  23087. h = currentTilePixelSize[1] * currentScale / oversampling;
  23088. this.drawTileImage(tile, frameState, layerState, x, y, w, h, tileGutter, z === currentZ);
  23089. this.renderedTiles.push(tile);
  23090. }
  23091. }
  23092. this.renderedRevision = sourceRevision;
  23093. this.renderedResolution = tileResolution * pixelRatio / tilePixelRatio * oversampling;
  23094. this.renderedExtent_ = imageExtent;
  23095. }
  23096. var scale = this.renderedResolution / viewResolution;
  23097. var transform = ol.transform.compose(this.imageTransform_,
  23098. pixelRatio * size[0] / 2, pixelRatio * size[1] / 2,
  23099. scale, scale,
  23100. 0,
  23101. (this.renderedExtent_[0] - viewCenter[0]) / this.renderedResolution * pixelRatio,
  23102. (viewCenter[1] - this.renderedExtent_[3]) / this.renderedResolution * pixelRatio);
  23103. ol.transform.compose(this.coordinateToCanvasPixelTransform,
  23104. pixelRatio * size[0] / 2 - transform[4], pixelRatio * size[1] / 2 - transform[5],
  23105. pixelRatio / viewResolution, -pixelRatio / viewResolution,
  23106. 0,
  23107. -viewCenter[0], -viewCenter[1]);
  23108. this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
  23109. this.manageTilePyramid(frameState, tileSource, tileGrid, pixelRatio,
  23110. projection, extent, z, tileLayer.getPreload());
  23111. this.scheduleExpireCache(frameState, tileSource);
  23112. this.updateLogos(frameState, tileSource);
  23113. return this.renderedTiles.length > 0;
  23114. };
  23115. /**
  23116. * @param {ol.Tile} tile Tile.
  23117. * @param {olx.FrameState} frameState Frame state.
  23118. * @param {ol.LayerState} layerState Layer state.
  23119. * @param {number} x Left of the tile.
  23120. * @param {number} y Top of the tile.
  23121. * @param {number} w Width of the tile.
  23122. * @param {number} h Height of the tile.
  23123. * @param {number} gutter Tile gutter.
  23124. * @param {boolean} transition Apply an alpha transition.
  23125. */
  23126. ol.renderer.canvas.TileLayer.prototype.drawTileImage = function(tile, frameState, layerState, x, y, w, h, gutter, transition) {
  23127. var image = tile.getImage(this.getLayer());
  23128. if (!image) {
  23129. return;
  23130. }
  23131. var uid = ol.getUid(this);
  23132. var alpha = transition ? tile.getAlpha(uid, frameState.time) : 1;
  23133. if (alpha === 1 && !this.getLayer().getSource().getOpaque(frameState.viewState.projection)) {
  23134. this.context.clearRect(x, y, w, h);
  23135. }
  23136. var alphaChanged = alpha !== this.context.globalAlpha;
  23137. if (alphaChanged) {
  23138. this.context.save();
  23139. this.context.globalAlpha = alpha;
  23140. }
  23141. this.context.drawImage(image, gutter, gutter,
  23142. image.width - 2 * gutter, image.height - 2 * gutter, x, y, w, h);
  23143. if (alphaChanged) {
  23144. this.context.restore();
  23145. }
  23146. if (alpha !== 1) {
  23147. frameState.animate = true;
  23148. } else if (transition) {
  23149. tile.endTransition(uid);
  23150. }
  23151. };
  23152. /**
  23153. * @inheritDoc
  23154. */
  23155. ol.renderer.canvas.TileLayer.prototype.getImage = function() {
  23156. var context = this.context;
  23157. return context ? context.canvas : null;
  23158. };
  23159. /**
  23160. * @function
  23161. * @return {ol.layer.Tile|ol.layer.VectorTile}
  23162. */
  23163. ol.renderer.canvas.TileLayer.prototype.getLayer;
  23164. /**
  23165. * @inheritDoc
  23166. */
  23167. ol.renderer.canvas.TileLayer.prototype.getImageTransform = function() {
  23168. return this.imageTransform_;
  23169. };
  23170. /**
  23171. * @fileoverview
  23172. * @suppress {accessControls, ambiguousFunctionDecl, checkDebuggerStatement, checkRegExp, checkTypes, checkVars, const, constantProperty, deprecated, duplicate, es5Strict, fileoverviewTags, missingProperties, nonStandardJsDocs, strictModuleDepCheck, suspiciousCode, undefinedNames, undefinedVars, unknownDefines, unusedLocalVariables, uselessCode, visibility}
  23173. */
  23174. goog.provide('ol.ext.rbush');
  23175. /** @typedef {function(*)} */
  23176. ol.ext.rbush = function() {};
  23177. (function() {(function (exports) {
  23178. 'use strict';
  23179. var quickselect_1 = quickselect;
  23180. var default_1 = quickselect;
  23181. function quickselect(arr, k, left, right, compare) {
  23182. quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
  23183. }
  23184. function quickselectStep(arr, k, left, right, compare) {
  23185. while (right > left) {
  23186. if (right - left > 600) {
  23187. var n = right - left + 1;
  23188. var m = k - left + 1;
  23189. var z = Math.log(n);
  23190. var s = 0.5 * Math.exp(2 * z / 3);
  23191. var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  23192. var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  23193. var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  23194. quickselectStep(arr, k, newLeft, newRight, compare);
  23195. }
  23196. var t = arr[k];
  23197. var i = left;
  23198. var j = right;
  23199. swap(arr, left, k);
  23200. if (compare(arr[right], t) > 0) swap(arr, left, right);
  23201. while (i < j) {
  23202. swap(arr, i, j);
  23203. i++;
  23204. j--;
  23205. while (compare(arr[i], t) < 0) i++;
  23206. while (compare(arr[j], t) > 0) j--;
  23207. }
  23208. if (compare(arr[left], t) === 0) swap(arr, left, j);
  23209. else {
  23210. j++;
  23211. swap(arr, j, right);
  23212. }
  23213. if (j <= k) left = j + 1;
  23214. if (k <= j) right = j - 1;
  23215. }
  23216. }
  23217. function swap(arr, i, j) {
  23218. var tmp = arr[i];
  23219. arr[i] = arr[j];
  23220. arr[j] = tmp;
  23221. }
  23222. function defaultCompare(a, b) {
  23223. return a < b ? -1 : a > b ? 1 : 0;
  23224. }
  23225. quickselect_1.default = default_1;
  23226. var rbush_1 = rbush;
  23227. function rbush(maxEntries, format) {
  23228. if (!(this instanceof rbush)) return new rbush(maxEntries, format);
  23229. this._maxEntries = Math.max(4, maxEntries || 9);
  23230. this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
  23231. if (format) {
  23232. this._initFormat(format);
  23233. }
  23234. this.clear();
  23235. }
  23236. rbush.prototype = {
  23237. all: function () {
  23238. return this._all(this.data, []);
  23239. },
  23240. search: function (bbox) {
  23241. var node = this.data,
  23242. result = [],
  23243. toBBox = this.toBBox;
  23244. if (!intersects(bbox, node)) return result;
  23245. var nodesToSearch = [],
  23246. i, len, child, childBBox;
  23247. while (node) {
  23248. for (i = 0, len = node.children.length; i < len; i++) {
  23249. child = node.children[i];
  23250. childBBox = node.leaf ? toBBox(child) : child;
  23251. if (intersects(bbox, childBBox)) {
  23252. if (node.leaf) result.push(child);
  23253. else if (contains(bbox, childBBox)) this._all(child, result);
  23254. else nodesToSearch.push(child);
  23255. }
  23256. }
  23257. node = nodesToSearch.pop();
  23258. }
  23259. return result;
  23260. },
  23261. collides: function (bbox) {
  23262. var node = this.data,
  23263. toBBox = this.toBBox;
  23264. if (!intersects(bbox, node)) return false;
  23265. var nodesToSearch = [],
  23266. i, len, child, childBBox;
  23267. while (node) {
  23268. for (i = 0, len = node.children.length; i < len; i++) {
  23269. child = node.children[i];
  23270. childBBox = node.leaf ? toBBox(child) : child;
  23271. if (intersects(bbox, childBBox)) {
  23272. if (node.leaf || contains(bbox, childBBox)) return true;
  23273. nodesToSearch.push(child);
  23274. }
  23275. }
  23276. node = nodesToSearch.pop();
  23277. }
  23278. return false;
  23279. },
  23280. load: function (data) {
  23281. if (!(data && data.length)) return this;
  23282. if (data.length < this._minEntries) {
  23283. for (var i = 0, len = data.length; i < len; i++) {
  23284. this.insert(data[i]);
  23285. }
  23286. return this;
  23287. }
  23288. var node = this._build(data.slice(), 0, data.length - 1, 0);
  23289. if (!this.data.children.length) {
  23290. this.data = node;
  23291. } else if (this.data.height === node.height) {
  23292. this._splitRoot(this.data, node);
  23293. } else {
  23294. if (this.data.height < node.height) {
  23295. var tmpNode = this.data;
  23296. this.data = node;
  23297. node = tmpNode;
  23298. }
  23299. this._insert(node, this.data.height - node.height - 1, true);
  23300. }
  23301. return this;
  23302. },
  23303. insert: function (item) {
  23304. if (item) this._insert(item, this.data.height - 1);
  23305. return this;
  23306. },
  23307. clear: function () {
  23308. this.data = createNode([]);
  23309. return this;
  23310. },
  23311. remove: function (item, equalsFn) {
  23312. if (!item) return this;
  23313. var node = this.data,
  23314. bbox = this.toBBox(item),
  23315. path = [],
  23316. indexes = [],
  23317. i, parent, index, goingUp;
  23318. while (node || path.length) {
  23319. if (!node) {
  23320. node = path.pop();
  23321. parent = path[path.length - 1];
  23322. i = indexes.pop();
  23323. goingUp = true;
  23324. }
  23325. if (node.leaf) {
  23326. index = findItem(item, node.children, equalsFn);
  23327. if (index !== -1) {
  23328. node.children.splice(index, 1);
  23329. path.push(node);
  23330. this._condense(path);
  23331. return this;
  23332. }
  23333. }
  23334. if (!goingUp && !node.leaf && contains(node, bbox)) {
  23335. path.push(node);
  23336. indexes.push(i);
  23337. i = 0;
  23338. parent = node;
  23339. node = node.children[0];
  23340. } else if (parent) {
  23341. i++;
  23342. node = parent.children[i];
  23343. goingUp = false;
  23344. } else node = null;
  23345. }
  23346. return this;
  23347. },
  23348. toBBox: function (item) { return item; },
  23349. compareMinX: compareNodeMinX,
  23350. compareMinY: compareNodeMinY,
  23351. toJSON: function () { return this.data; },
  23352. fromJSON: function (data) {
  23353. this.data = data;
  23354. return this;
  23355. },
  23356. _all: function (node, result) {
  23357. var nodesToSearch = [];
  23358. while (node) {
  23359. if (node.leaf) result.push.apply(result, node.children);
  23360. else nodesToSearch.push.apply(nodesToSearch, node.children);
  23361. node = nodesToSearch.pop();
  23362. }
  23363. return result;
  23364. },
  23365. _build: function (items, left, right, height) {
  23366. var N = right - left + 1,
  23367. M = this._maxEntries,
  23368. node;
  23369. if (N <= M) {
  23370. node = createNode(items.slice(left, right + 1));
  23371. calcBBox(node, this.toBBox);
  23372. return node;
  23373. }
  23374. if (!height) {
  23375. height = Math.ceil(Math.log(N) / Math.log(M));
  23376. M = Math.ceil(N / Math.pow(M, height - 1));
  23377. }
  23378. node = createNode([]);
  23379. node.leaf = false;
  23380. node.height = height;
  23381. var N2 = Math.ceil(N / M),
  23382. N1 = N2 * Math.ceil(Math.sqrt(M)),
  23383. i, j, right2, right3;
  23384. multiSelect(items, left, right, N1, this.compareMinX);
  23385. for (i = left; i <= right; i += N1) {
  23386. right2 = Math.min(i + N1 - 1, right);
  23387. multiSelect(items, i, right2, N2, this.compareMinY);
  23388. for (j = i; j <= right2; j += N2) {
  23389. right3 = Math.min(j + N2 - 1, right2);
  23390. node.children.push(this._build(items, j, right3, height - 1));
  23391. }
  23392. }
  23393. calcBBox(node, this.toBBox);
  23394. return node;
  23395. },
  23396. _chooseSubtree: function (bbox, node, level, path) {
  23397. var i, len, child, targetNode, area, enlargement, minArea, minEnlargement;
  23398. while (true) {
  23399. path.push(node);
  23400. if (node.leaf || path.length - 1 === level) break;
  23401. minArea = minEnlargement = Infinity;
  23402. for (i = 0, len = node.children.length; i < len; i++) {
  23403. child = node.children[i];
  23404. area = bboxArea(child);
  23405. enlargement = enlargedArea(bbox, child) - area;
  23406. if (enlargement < minEnlargement) {
  23407. minEnlargement = enlargement;
  23408. minArea = area < minArea ? area : minArea;
  23409. targetNode = child;
  23410. } else if (enlargement === minEnlargement) {
  23411. if (area < minArea) {
  23412. minArea = area;
  23413. targetNode = child;
  23414. }
  23415. }
  23416. }
  23417. node = targetNode || node.children[0];
  23418. }
  23419. return node;
  23420. },
  23421. _insert: function (item, level, isNode) {
  23422. var toBBox = this.toBBox,
  23423. bbox = isNode ? item : toBBox(item),
  23424. insertPath = [];
  23425. var node = this._chooseSubtree(bbox, this.data, level, insertPath);
  23426. node.children.push(item);
  23427. extend(node, bbox);
  23428. while (level >= 0) {
  23429. if (insertPath[level].children.length > this._maxEntries) {
  23430. this._split(insertPath, level);
  23431. level--;
  23432. } else break;
  23433. }
  23434. this._adjustParentBBoxes(bbox, insertPath, level);
  23435. },
  23436. _split: function (insertPath, level) {
  23437. var node = insertPath[level],
  23438. M = node.children.length,
  23439. m = this._minEntries;
  23440. this._chooseSplitAxis(node, m, M);
  23441. var splitIndex = this._chooseSplitIndex(node, m, M);
  23442. var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
  23443. newNode.height = node.height;
  23444. newNode.leaf = node.leaf;
  23445. calcBBox(node, this.toBBox);
  23446. calcBBox(newNode, this.toBBox);
  23447. if (level) insertPath[level - 1].children.push(newNode);
  23448. else this._splitRoot(node, newNode);
  23449. },
  23450. _splitRoot: function (node, newNode) {
  23451. this.data = createNode([node, newNode]);
  23452. this.data.height = node.height + 1;
  23453. this.data.leaf = false;
  23454. calcBBox(this.data, this.toBBox);
  23455. },
  23456. _chooseSplitIndex: function (node, m, M) {
  23457. var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index;
  23458. minOverlap = minArea = Infinity;
  23459. for (i = m; i <= M - m; i++) {
  23460. bbox1 = distBBox(node, 0, i, this.toBBox);
  23461. bbox2 = distBBox(node, i, M, this.toBBox);
  23462. overlap = intersectionArea(bbox1, bbox2);
  23463. area = bboxArea(bbox1) + bboxArea(bbox2);
  23464. if (overlap < minOverlap) {
  23465. minOverlap = overlap;
  23466. index = i;
  23467. minArea = area < minArea ? area : minArea;
  23468. } else if (overlap === minOverlap) {
  23469. if (area < minArea) {
  23470. minArea = area;
  23471. index = i;
  23472. }
  23473. }
  23474. }
  23475. return index;
  23476. },
  23477. _chooseSplitAxis: function (node, m, M) {
  23478. var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX,
  23479. compareMinY = node.leaf ? this.compareMinY : compareNodeMinY,
  23480. xMargin = this._allDistMargin(node, m, M, compareMinX),
  23481. yMargin = this._allDistMargin(node, m, M, compareMinY);
  23482. if (xMargin < yMargin) node.children.sort(compareMinX);
  23483. },
  23484. _allDistMargin: function (node, m, M, compare) {
  23485. node.children.sort(compare);
  23486. var toBBox = this.toBBox,
  23487. leftBBox = distBBox(node, 0, m, toBBox),
  23488. rightBBox = distBBox(node, M - m, M, toBBox),
  23489. margin = bboxMargin(leftBBox) + bboxMargin(rightBBox),
  23490. i, child;
  23491. for (i = m; i < M - m; i++) {
  23492. child = node.children[i];
  23493. extend(leftBBox, node.leaf ? toBBox(child) : child);
  23494. margin += bboxMargin(leftBBox);
  23495. }
  23496. for (i = M - m - 1; i >= m; i--) {
  23497. child = node.children[i];
  23498. extend(rightBBox, node.leaf ? toBBox(child) : child);
  23499. margin += bboxMargin(rightBBox);
  23500. }
  23501. return margin;
  23502. },
  23503. _adjustParentBBoxes: function (bbox, path, level) {
  23504. for (var i = level; i >= 0; i--) {
  23505. extend(path[i], bbox);
  23506. }
  23507. },
  23508. _condense: function (path) {
  23509. for (var i = path.length - 1, siblings; i >= 0; i--) {
  23510. if (path[i].children.length === 0) {
  23511. if (i > 0) {
  23512. siblings = path[i - 1].children;
  23513. siblings.splice(siblings.indexOf(path[i]), 1);
  23514. } else this.clear();
  23515. } else calcBBox(path[i], this.toBBox);
  23516. }
  23517. },
  23518. _initFormat: function (format) {
  23519. var compareArr = ['return a', ' - b', ';'];
  23520. this.compareMinX = new Function('a', 'b', compareArr.join(format[0]));
  23521. this.compareMinY = new Function('a', 'b', compareArr.join(format[1]));
  23522. this.toBBox = new Function('a',
  23523. 'return {minX: a' + format[0] +
  23524. ', minY: a' + format[1] +
  23525. ', maxX: a' + format[2] +
  23526. ', maxY: a' + format[3] + '};');
  23527. }
  23528. };
  23529. function findItem(item, items, equalsFn) {
  23530. if (!equalsFn) return items.indexOf(item);
  23531. for (var i = 0; i < items.length; i++) {
  23532. if (equalsFn(item, items[i])) return i;
  23533. }
  23534. return -1;
  23535. }
  23536. function calcBBox(node, toBBox) {
  23537. distBBox(node, 0, node.children.length, toBBox, node);
  23538. }
  23539. function distBBox(node, k, p, toBBox, destNode) {
  23540. if (!destNode) destNode = createNode(null);
  23541. destNode.minX = Infinity;
  23542. destNode.minY = Infinity;
  23543. destNode.maxX = -Infinity;
  23544. destNode.maxY = -Infinity;
  23545. for (var i = k, child; i < p; i++) {
  23546. child = node.children[i];
  23547. extend(destNode, node.leaf ? toBBox(child) : child);
  23548. }
  23549. return destNode;
  23550. }
  23551. function extend(a, b) {
  23552. a.minX = Math.min(a.minX, b.minX);
  23553. a.minY = Math.min(a.minY, b.minY);
  23554. a.maxX = Math.max(a.maxX, b.maxX);
  23555. a.maxY = Math.max(a.maxY, b.maxY);
  23556. return a;
  23557. }
  23558. function compareNodeMinX(a, b) { return a.minX - b.minX; }
  23559. function compareNodeMinY(a, b) { return a.minY - b.minY; }
  23560. function bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }
  23561. function bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }
  23562. function enlargedArea(a, b) {
  23563. return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *
  23564. (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
  23565. }
  23566. function intersectionArea(a, b) {
  23567. var minX = Math.max(a.minX, b.minX),
  23568. minY = Math.max(a.minY, b.minY),
  23569. maxX = Math.min(a.maxX, b.maxX),
  23570. maxY = Math.min(a.maxY, b.maxY);
  23571. return Math.max(0, maxX - minX) *
  23572. Math.max(0, maxY - minY);
  23573. }
  23574. function contains(a, b) {
  23575. return a.minX <= b.minX &&
  23576. a.minY <= b.minY &&
  23577. b.maxX <= a.maxX &&
  23578. b.maxY <= a.maxY;
  23579. }
  23580. function intersects(a, b) {
  23581. return b.minX <= a.maxX &&
  23582. b.minY <= a.maxY &&
  23583. b.maxX >= a.minX &&
  23584. b.maxY >= a.minY;
  23585. }
  23586. function createNode(children) {
  23587. return {
  23588. children: children,
  23589. height: 1,
  23590. leaf: true,
  23591. minX: Infinity,
  23592. minY: Infinity,
  23593. maxX: -Infinity,
  23594. maxY: -Infinity
  23595. };
  23596. }
  23597. function multiSelect(arr, left, right, n, compare) {
  23598. var stack = [left, right],
  23599. mid;
  23600. while (stack.length) {
  23601. right = stack.pop();
  23602. left = stack.pop();
  23603. if (right - left <= n) continue;
  23604. mid = left + Math.ceil((right - left) / n / 2) * n;
  23605. quickselect_1(arr, mid, left, right, compare);
  23606. stack.push(left, mid, mid, right);
  23607. }
  23608. }
  23609. exports['default'] = rbush_1;
  23610. }((this.rbush = this.rbush || {})));}).call(ol.ext);
  23611. ol.ext.rbush = ol.ext.rbush.default;
  23612. goog.provide('ol.render.ReplayGroup');
  23613. /**
  23614. * Base class for replay groups.
  23615. * @constructor
  23616. * @abstract
  23617. */
  23618. ol.render.ReplayGroup = function() {};
  23619. /**
  23620. * @abstract
  23621. * @param {number|undefined} zIndex Z index.
  23622. * @param {ol.render.ReplayType} replayType Replay type.
  23623. * @return {ol.render.VectorContext} Replay.
  23624. */
  23625. ol.render.ReplayGroup.prototype.getReplay = function(zIndex, replayType) {};
  23626. /**
  23627. * @abstract
  23628. * @return {boolean} Is empty.
  23629. */
  23630. ol.render.ReplayGroup.prototype.isEmpty = function() {};
  23631. goog.provide('ol.render.ReplayType');
  23632. /**
  23633. * @enum {string}
  23634. */
  23635. ol.render.ReplayType = {
  23636. CIRCLE: 'Circle',
  23637. DEFAULT: 'Default',
  23638. IMAGE: 'Image',
  23639. LINE_STRING: 'LineString',
  23640. POLYGON: 'Polygon',
  23641. TEXT: 'Text'
  23642. };
  23643. goog.provide('ol.geom.flat.length');
  23644. /**
  23645. * @param {Array.<number>} flatCoordinates Flat coordinates.
  23646. * @param {number} offset Offset.
  23647. * @param {number} end End.
  23648. * @param {number} stride Stride.
  23649. * @return {number} Length.
  23650. */
  23651. ol.geom.flat.length.lineString = function(flatCoordinates, offset, end, stride) {
  23652. var x1 = flatCoordinates[offset];
  23653. var y1 = flatCoordinates[offset + 1];
  23654. var length = 0;
  23655. var i;
  23656. for (i = offset + stride; i < end; i += stride) {
  23657. var x2 = flatCoordinates[i];
  23658. var y2 = flatCoordinates[i + 1];
  23659. length += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  23660. x1 = x2;
  23661. y1 = y2;
  23662. }
  23663. return length;
  23664. };
  23665. /**
  23666. * @param {Array.<number>} flatCoordinates Flat coordinates.
  23667. * @param {number} offset Offset.
  23668. * @param {number} end End.
  23669. * @param {number} stride Stride.
  23670. * @return {number} Perimeter.
  23671. */
  23672. ol.geom.flat.length.linearRing = function(flatCoordinates, offset, end, stride) {
  23673. var perimeter =
  23674. ol.geom.flat.length.lineString(flatCoordinates, offset, end, stride);
  23675. var dx = flatCoordinates[end - stride] - flatCoordinates[offset];
  23676. var dy = flatCoordinates[end - stride + 1] - flatCoordinates[offset + 1];
  23677. perimeter += Math.sqrt(dx * dx + dy * dy);
  23678. return perimeter;
  23679. };
  23680. goog.provide('ol.geom.flat.textpath');
  23681. goog.require('ol.math');
  23682. /**
  23683. * @param {Array.<number>} flatCoordinates Path to put text on.
  23684. * @param {number} offset Start offset of the `flatCoordinates`.
  23685. * @param {number} end End offset of the `flatCoordinates`.
  23686. * @param {number} stride Stride.
  23687. * @param {string} text Text to place on the path.
  23688. * @param {function(string):number} measure Measure function returning the
  23689. * width of the character passed as 1st argument.
  23690. * @param {number} startM m along the path where the text starts.
  23691. * @param {number} maxAngle Max angle between adjacent chars in radians.
  23692. * @return {Array.<Array.<*>>} The result array of null if `maxAngle` was
  23693. * exceeded. Entries of the array are x, y, anchorX, angle, chunk.
  23694. */
  23695. ol.geom.flat.textpath.lineString = function(
  23696. flatCoordinates, offset, end, stride, text, measure, startM, maxAngle) {
  23697. var result = [];
  23698. // Keep text upright
  23699. var reverse = flatCoordinates[offset] > flatCoordinates[end - stride];
  23700. var numChars = text.length;
  23701. var x1 = flatCoordinates[offset];
  23702. var y1 = flatCoordinates[offset + 1];
  23703. offset += stride;
  23704. var x2 = flatCoordinates[offset];
  23705. var y2 = flatCoordinates[offset + 1];
  23706. var segmentM = 0;
  23707. var segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
  23708. var chunk = '';
  23709. var chunkLength = 0;
  23710. var data, index, previousAngle;
  23711. for (var i = 0; i < numChars; ++i) {
  23712. index = reverse ? numChars - i - 1 : i;
  23713. var char = text.charAt(index);
  23714. chunk = reverse ? char + chunk : chunk + char;
  23715. var charLength = measure(chunk) - chunkLength;
  23716. chunkLength += charLength;
  23717. var charM = startM + charLength / 2;
  23718. while (offset < end - stride && segmentM + segmentLength < charM) {
  23719. x1 = x2;
  23720. y1 = y2;
  23721. offset += stride;
  23722. x2 = flatCoordinates[offset];
  23723. y2 = flatCoordinates[offset + 1];
  23724. segmentM += segmentLength;
  23725. segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
  23726. }
  23727. var segmentPos = charM - segmentM;
  23728. var angle = Math.atan2(y2 - y1, x2 - x1);
  23729. if (reverse) {
  23730. angle += angle > 0 ? -Math.PI : Math.PI;
  23731. }
  23732. if (previousAngle !== undefined) {
  23733. var delta = angle - previousAngle;
  23734. delta += (delta > Math.PI) ? -2 * Math.PI : (delta < -Math.PI) ? 2 * Math.PI : 0;
  23735. if (Math.abs(delta) > maxAngle) {
  23736. return null;
  23737. }
  23738. }
  23739. var interpolate = segmentPos / segmentLength;
  23740. var x = ol.math.lerp(x1, x2, interpolate);
  23741. var y = ol.math.lerp(y1, y2, interpolate);
  23742. if (previousAngle == angle) {
  23743. if (reverse) {
  23744. data[0] = x;
  23745. data[1] = y;
  23746. data[2] = charLength / 2;
  23747. }
  23748. data[4] = chunk;
  23749. } else {
  23750. chunk = char;
  23751. chunkLength = charLength;
  23752. data = [x, y, charLength / 2, angle, chunk];
  23753. if (reverse) {
  23754. result.unshift(data);
  23755. } else {
  23756. result.push(data);
  23757. }
  23758. previousAngle = angle;
  23759. }
  23760. startM += charLength;
  23761. }
  23762. return result;
  23763. };
  23764. goog.provide('ol.render.canvas.Instruction');
  23765. /**
  23766. * @enum {number}
  23767. */
  23768. ol.render.canvas.Instruction = {
  23769. BEGIN_GEOMETRY: 0,
  23770. BEGIN_PATH: 1,
  23771. CIRCLE: 2,
  23772. CLOSE_PATH: 3,
  23773. CUSTOM: 4,
  23774. DRAW_CHARS: 5,
  23775. DRAW_IMAGE: 6,
  23776. END_GEOMETRY: 7,
  23777. FILL: 8,
  23778. MOVE_TO_LINE_TO: 9,
  23779. SET_FILL_STYLE: 10,
  23780. SET_STROKE_STYLE: 11,
  23781. STROKE: 12
  23782. };
  23783. goog.provide('ol.render.replay');
  23784. goog.require('ol.render.ReplayType');
  23785. /**
  23786. * @const
  23787. * @type {Array.<ol.render.ReplayType>}
  23788. */
  23789. ol.render.replay.ORDER = [
  23790. ol.render.ReplayType.POLYGON,
  23791. ol.render.ReplayType.CIRCLE,
  23792. ol.render.ReplayType.LINE_STRING,
  23793. ol.render.ReplayType.IMAGE,
  23794. ol.render.ReplayType.TEXT,
  23795. ol.render.ReplayType.DEFAULT
  23796. ];
  23797. /**
  23798. * @const
  23799. * @enum {number}
  23800. */
  23801. ol.render.replay.TEXT_ALIGN = {};
  23802. ol.render.replay.TEXT_ALIGN['left'] = 0;
  23803. ol.render.replay.TEXT_ALIGN['end'] = 0;
  23804. ol.render.replay.TEXT_ALIGN['center'] = 0.5;
  23805. ol.render.replay.TEXT_ALIGN['right'] = 1;
  23806. ol.render.replay.TEXT_ALIGN['start'] = 1;
  23807. ol.render.replay.TEXT_ALIGN['top'] = 0;
  23808. ol.render.replay.TEXT_ALIGN['middle'] = 0.5;
  23809. ol.render.replay.TEXT_ALIGN['hanging'] = 0.2;
  23810. ol.render.replay.TEXT_ALIGN['alphabetic'] = 0.8;
  23811. ol.render.replay.TEXT_ALIGN['ideographic'] = 0.8;
  23812. ol.render.replay.TEXT_ALIGN['bottom'] = 1;
  23813. goog.provide('ol.render.canvas.Replay');
  23814. goog.require('ol');
  23815. goog.require('ol.array');
  23816. goog.require('ol.colorlike');
  23817. goog.require('ol.extent');
  23818. goog.require('ol.extent.Relationship');
  23819. goog.require('ol.geom.GeometryType');
  23820. goog.require('ol.geom.flat.inflate');
  23821. goog.require('ol.geom.flat.length');
  23822. goog.require('ol.geom.flat.textpath');
  23823. goog.require('ol.geom.flat.transform');
  23824. goog.require('ol.has');
  23825. goog.require('ol.obj');
  23826. goog.require('ol.render.VectorContext');
  23827. goog.require('ol.render.canvas');
  23828. goog.require('ol.render.canvas.Instruction');
  23829. goog.require('ol.render.replay');
  23830. goog.require('ol.transform');
  23831. /**
  23832. * @constructor
  23833. * @extends {ol.render.VectorContext}
  23834. * @param {number} tolerance Tolerance.
  23835. * @param {ol.Extent} maxExtent Maximum extent.
  23836. * @param {number} resolution Resolution.
  23837. * @param {number} pixelRatio Pixel ratio.
  23838. * @param {boolean} overlaps The replay can have overlapping geometries.
  23839. * @param {?} declutterTree Declutter tree.
  23840. * @struct
  23841. */
  23842. ol.render.canvas.Replay = function(tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
  23843. ol.render.VectorContext.call(this);
  23844. /**
  23845. * @type {?}
  23846. */
  23847. this.declutterTree = declutterTree;
  23848. /**
  23849. * @private
  23850. * @type {ol.Extent}
  23851. */
  23852. this.tmpExtent_ = ol.extent.createEmpty();
  23853. /**
  23854. * @protected
  23855. * @type {number}
  23856. */
  23857. this.tolerance = tolerance;
  23858. /**
  23859. * @protected
  23860. * @const
  23861. * @type {ol.Extent}
  23862. */
  23863. this.maxExtent = maxExtent;
  23864. /**
  23865. * @protected
  23866. * @type {boolean}
  23867. */
  23868. this.overlaps = overlaps;
  23869. /**
  23870. * @protected
  23871. * @type {number}
  23872. */
  23873. this.pixelRatio = pixelRatio;
  23874. /**
  23875. * @protected
  23876. * @type {number}
  23877. */
  23878. this.maxLineWidth = 0;
  23879. /**
  23880. * @protected
  23881. * @const
  23882. * @type {number}
  23883. */
  23884. this.resolution = resolution;
  23885. /**
  23886. * @private
  23887. * @type {ol.Coordinate}
  23888. */
  23889. this.fillOrigin_;
  23890. /**
  23891. * @private
  23892. * @type {Array.<*>}
  23893. */
  23894. this.beginGeometryInstruction1_ = null;
  23895. /**
  23896. * @private
  23897. * @type {Array.<*>}
  23898. */
  23899. this.beginGeometryInstruction2_ = null;
  23900. /**
  23901. * @private
  23902. * @type {ol.Extent}
  23903. */
  23904. this.bufferedMaxExtent_ = null;
  23905. /**
  23906. * @protected
  23907. * @type {Array.<*>}
  23908. */
  23909. this.instructions = [];
  23910. /**
  23911. * @protected
  23912. * @type {Array.<number>}
  23913. */
  23914. this.coordinates = [];
  23915. /**
  23916. * @private
  23917. * @type {Object.<number,ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>>}
  23918. */
  23919. this.coordinateCache_ = {};
  23920. /**
  23921. * @private
  23922. * @type {!ol.Transform}
  23923. */
  23924. this.renderedTransform_ = ol.transform.create();
  23925. /**
  23926. * @protected
  23927. * @type {Array.<*>}
  23928. */
  23929. this.hitDetectionInstructions = [];
  23930. /**
  23931. * @private
  23932. * @type {Array.<number>}
  23933. */
  23934. this.pixelCoordinates_ = null;
  23935. /**
  23936. * @protected
  23937. * @type {ol.CanvasFillStrokeState}
  23938. */
  23939. this.state = /** @type {ol.CanvasFillStrokeState} */ ({});
  23940. /**
  23941. * @private
  23942. * @type {number}
  23943. */
  23944. this.viewRotation_ = 0;
  23945. /**
  23946. * @private
  23947. * @type {!ol.Transform}
  23948. */
  23949. this.tmpLocalTransform_ = ol.transform.create();
  23950. /**
  23951. * @private
  23952. * @type {!ol.Transform}
  23953. */
  23954. this.resetTransform_ = ol.transform.create();
  23955. };
  23956. ol.inherits(ol.render.canvas.Replay, ol.render.VectorContext);
  23957. /**
  23958. * @param {CanvasRenderingContext2D} context Context.
  23959. * @param {ol.Coordinate} p1 1st point of the background box.
  23960. * @param {ol.Coordinate} p2 2nd point of the background box.
  23961. * @param {ol.Coordinate} p3 3rd point of the background box.
  23962. * @param {ol.Coordinate} p4 4th point of the background box.
  23963. * @param {Array.<*>} fillInstruction Fill instruction.
  23964. * @param {Array.<*>} strokeInstruction Stroke instruction.
  23965. */
  23966. ol.render.canvas.Replay.prototype.replayTextBackground_ = function(context, p1, p2, p3, p4,
  23967. fillInstruction, strokeInstruction) {
  23968. context.beginPath();
  23969. context.moveTo.apply(context, p1);
  23970. context.lineTo.apply(context, p2);
  23971. context.lineTo.apply(context, p3);
  23972. context.lineTo.apply(context, p4);
  23973. context.lineTo.apply(context, p1);
  23974. if (fillInstruction) {
  23975. this.fillOrigin_ = /** @type {Array.<number>} */ (fillInstruction[2]);
  23976. this.fill_(context);
  23977. }
  23978. if (strokeInstruction) {
  23979. this.setStrokeStyle_(context, /** @type {Array.<*>} */ (strokeInstruction));
  23980. context.stroke();
  23981. }
  23982. };
  23983. /**
  23984. * @param {CanvasRenderingContext2D} context Context.
  23985. * @param {number} x X.
  23986. * @param {number} y Y.
  23987. * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} image Image.
  23988. * @param {number} anchorX Anchor X.
  23989. * @param {number} anchorY Anchor Y.
  23990. * @param {ol.DeclutterGroup} declutterGroup Declutter group.
  23991. * @param {number} height Height.
  23992. * @param {number} opacity Opacity.
  23993. * @param {number} originX Origin X.
  23994. * @param {number} originY Origin Y.
  23995. * @param {number} rotation Rotation.
  23996. * @param {number} scale Scale.
  23997. * @param {boolean} snapToPixel Snap to pixel.
  23998. * @param {number} width Width.
  23999. * @param {Array.<number>} padding Padding.
  24000. * @param {Array.<*>} fillInstruction Fill instruction.
  24001. * @param {Array.<*>} strokeInstruction Stroke instruction.
  24002. */
  24003. ol.render.canvas.Replay.prototype.replayImage_ = function(context, x, y, image,
  24004. anchorX, anchorY, declutterGroup, height, opacity, originX, originY,
  24005. rotation, scale, snapToPixel, width, padding, fillInstruction, strokeInstruction) {
  24006. var fillStroke = fillInstruction || strokeInstruction;
  24007. var localTransform = this.tmpLocalTransform_;
  24008. anchorX *= scale;
  24009. anchorY *= scale;
  24010. x -= anchorX;
  24011. y -= anchorY;
  24012. if (snapToPixel) {
  24013. x = Math.round(x);
  24014. y = Math.round(y);
  24015. }
  24016. var w = (width + originX > image.width) ? image.width - originX : width;
  24017. var h = (height + originY > image.height) ? image.height - originY : height;
  24018. var box = this.tmpExtent_;
  24019. var boxW = padding[3] + w * scale + padding[1];
  24020. var boxH = padding[0] + h * scale + padding[2];
  24021. var boxX = x - padding[3];
  24022. var boxY = y - padding[0];
  24023. /** @type {ol.Coordinate} */
  24024. var p1;
  24025. /** @type {ol.Coordinate} */
  24026. var p2;
  24027. /** @type {ol.Coordinate} */
  24028. var p3;
  24029. /** @type {ol.Coordinate} */
  24030. var p4;
  24031. if (fillStroke || rotation !== 0) {
  24032. p1 = [boxX, boxY];
  24033. p2 = [boxX + boxW, boxY];
  24034. p3 = [boxX + boxW, boxY + boxH];
  24035. p4 = [boxX, boxY + boxH];
  24036. }
  24037. var transform = null;
  24038. if (rotation !== 0) {
  24039. var centerX = x + anchorX;
  24040. var centerY = y + anchorY;
  24041. transform = ol.transform.compose(localTransform,
  24042. centerX, centerY, 1, 1, rotation, -centerX, -centerY);
  24043. ol.extent.createOrUpdateEmpty(box);
  24044. ol.extent.extendCoordinate(box, ol.transform.apply(localTransform, p1));
  24045. ol.extent.extendCoordinate(box, ol.transform.apply(localTransform, p2));
  24046. ol.extent.extendCoordinate(box, ol.transform.apply(localTransform, p3));
  24047. ol.extent.extendCoordinate(box, ol.transform.apply(localTransform, p4));
  24048. } else {
  24049. ol.extent.createOrUpdate(boxX, boxY, boxX + boxW, boxY + boxH, box);
  24050. }
  24051. var canvas = context.canvas;
  24052. var intersects = box[0] <= canvas.width && box[2] >= 0 && box[1] <= canvas.height && box[3] >= 0;
  24053. if (declutterGroup) {
  24054. if (!intersects && declutterGroup[4] == 1) {
  24055. return;
  24056. }
  24057. ol.extent.extend(declutterGroup, box);
  24058. var declutterArgs = intersects ?
  24059. [context, transform ? transform.slice(0) : null, opacity, image, originX, originY, w, h, x, y, scale] :
  24060. null;
  24061. if (declutterArgs && fillStroke) {
  24062. declutterArgs.push(fillInstruction, strokeInstruction, p1, p2, p3, p4);
  24063. }
  24064. declutterGroup.push(declutterArgs);
  24065. } else if (intersects) {
  24066. if (fillStroke) {
  24067. this.replayTextBackground_(context, p1, p2, p3, p4,
  24068. /** @type {Array.<*>} */ (fillInstruction),
  24069. /** @type {Array.<*>} */ (strokeInstruction));
  24070. }
  24071. ol.render.canvas.drawImage(context, transform, opacity, image, originX, originY, w, h, x, y, scale);
  24072. }
  24073. };
  24074. /**
  24075. * @protected
  24076. * @param {Array.<number>} dashArray Dash array.
  24077. * @return {Array.<number>} Dash array with pixel ratio applied
  24078. */
  24079. ol.render.canvas.Replay.prototype.applyPixelRatio = function(dashArray) {
  24080. var pixelRatio = this.pixelRatio;
  24081. return pixelRatio == 1 ? dashArray : dashArray.map(function(dash) {
  24082. return dash * pixelRatio;
  24083. });
  24084. };
  24085. /**
  24086. * @param {Array.<number>} flatCoordinates Flat coordinates.
  24087. * @param {number} offset Offset.
  24088. * @param {number} end End.
  24089. * @param {number} stride Stride.
  24090. * @param {boolean} closed Last input coordinate equals first.
  24091. * @param {boolean} skipFirst Skip first coordinate.
  24092. * @protected
  24093. * @return {number} My end.
  24094. */
  24095. ol.render.canvas.Replay.prototype.appendFlatCoordinates = function(flatCoordinates, offset, end, stride, closed, skipFirst) {
  24096. var myEnd = this.coordinates.length;
  24097. var extent = this.getBufferedMaxExtent();
  24098. if (skipFirst) {
  24099. offset += stride;
  24100. }
  24101. var lastCoord = [flatCoordinates[offset], flatCoordinates[offset + 1]];
  24102. var nextCoord = [NaN, NaN];
  24103. var skipped = true;
  24104. var i, lastRel, nextRel;
  24105. for (i = offset + stride; i < end; i += stride) {
  24106. nextCoord[0] = flatCoordinates[i];
  24107. nextCoord[1] = flatCoordinates[i + 1];
  24108. nextRel = ol.extent.coordinateRelationship(extent, nextCoord);
  24109. if (nextRel !== lastRel) {
  24110. if (skipped) {
  24111. this.coordinates[myEnd++] = lastCoord[0];
  24112. this.coordinates[myEnd++] = lastCoord[1];
  24113. }
  24114. this.coordinates[myEnd++] = nextCoord[0];
  24115. this.coordinates[myEnd++] = nextCoord[1];
  24116. skipped = false;
  24117. } else if (nextRel === ol.extent.Relationship.INTERSECTING) {
  24118. this.coordinates[myEnd++] = nextCoord[0];
  24119. this.coordinates[myEnd++] = nextCoord[1];
  24120. skipped = false;
  24121. } else {
  24122. skipped = true;
  24123. }
  24124. lastCoord[0] = nextCoord[0];
  24125. lastCoord[1] = nextCoord[1];
  24126. lastRel = nextRel;
  24127. }
  24128. // Last coordinate equals first or only one point to append:
  24129. if ((closed && skipped) || i === offset + stride) {
  24130. this.coordinates[myEnd++] = lastCoord[0];
  24131. this.coordinates[myEnd++] = lastCoord[1];
  24132. }
  24133. return myEnd;
  24134. };
  24135. /**
  24136. * @param {Array.<number>} flatCoordinates Flat coordinates.
  24137. * @param {number} offset Offset.
  24138. * @param {Array.<number>} ends Ends.
  24139. * @param {number} stride Stride.
  24140. * @param {Array.<number>} replayEnds Replay ends.
  24141. * @return {number} Offset.
  24142. */
  24143. ol.render.canvas.Replay.prototype.drawCustomCoordinates_ = function(flatCoordinates, offset, ends, stride, replayEnds) {
  24144. for (var i = 0, ii = ends.length; i < ii; ++i) {
  24145. var end = ends[i];
  24146. var replayEnd = this.appendFlatCoordinates(flatCoordinates, offset, end, stride, false, false);
  24147. replayEnds.push(replayEnd);
  24148. offset = end;
  24149. }
  24150. return offset;
  24151. };
  24152. /**
  24153. * @inheritDoc.
  24154. */
  24155. ol.render.canvas.Replay.prototype.drawCustom = function(geometry, feature, renderer) {
  24156. this.beginGeometry(geometry, feature);
  24157. var type = geometry.getType();
  24158. var stride = geometry.getStride();
  24159. var replayBegin = this.coordinates.length;
  24160. var flatCoordinates, replayEnd, replayEnds, replayEndss;
  24161. var offset;
  24162. if (type == ol.geom.GeometryType.MULTI_POLYGON) {
  24163. geometry = /** @type {ol.geom.MultiPolygon} */ (geometry);
  24164. flatCoordinates = geometry.getOrientedFlatCoordinates();
  24165. replayEndss = [];
  24166. var endss = geometry.getEndss();
  24167. offset = 0;
  24168. for (var i = 0, ii = endss.length; i < ii; ++i) {
  24169. var myEnds = [];
  24170. offset = this.drawCustomCoordinates_(flatCoordinates, offset, endss[i], stride, myEnds);
  24171. replayEndss.push(myEnds);
  24172. }
  24173. this.instructions.push([ol.render.canvas.Instruction.CUSTOM,
  24174. replayBegin, replayEndss, geometry, renderer, ol.geom.flat.inflate.coordinatesss]);
  24175. } else if (type == ol.geom.GeometryType.POLYGON || type == ol.geom.GeometryType.MULTI_LINE_STRING) {
  24176. replayEnds = [];
  24177. flatCoordinates = (type == ol.geom.GeometryType.POLYGON) ?
  24178. /** @type {ol.geom.Polygon} */ (geometry).getOrientedFlatCoordinates() :
  24179. geometry.getFlatCoordinates();
  24180. offset = this.drawCustomCoordinates_(flatCoordinates, 0,
  24181. /** @type {ol.geom.Polygon|ol.geom.MultiLineString} */ (geometry).getEnds(),
  24182. stride, replayEnds);
  24183. this.instructions.push([ol.render.canvas.Instruction.CUSTOM,
  24184. replayBegin, replayEnds, geometry, renderer, ol.geom.flat.inflate.coordinatess]);
  24185. } else if (type == ol.geom.GeometryType.LINE_STRING || type == ol.geom.GeometryType.MULTI_POINT) {
  24186. flatCoordinates = geometry.getFlatCoordinates();
  24187. replayEnd = this.appendFlatCoordinates(
  24188. flatCoordinates, 0, flatCoordinates.length, stride, false, false);
  24189. this.instructions.push([ol.render.canvas.Instruction.CUSTOM,
  24190. replayBegin, replayEnd, geometry, renderer, ol.geom.flat.inflate.coordinates]);
  24191. } else if (type == ol.geom.GeometryType.POINT) {
  24192. flatCoordinates = geometry.getFlatCoordinates();
  24193. this.coordinates.push(flatCoordinates[0], flatCoordinates[1]);
  24194. replayEnd = this.coordinates.length;
  24195. this.instructions.push([ol.render.canvas.Instruction.CUSTOM,
  24196. replayBegin, replayEnd, geometry, renderer]);
  24197. }
  24198. this.endGeometry(geometry, feature);
  24199. };
  24200. /**
  24201. * @protected
  24202. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  24203. * @param {ol.Feature|ol.render.Feature} feature Feature.
  24204. */
  24205. ol.render.canvas.Replay.prototype.beginGeometry = function(geometry, feature) {
  24206. this.beginGeometryInstruction1_ =
  24207. [ol.render.canvas.Instruction.BEGIN_GEOMETRY, feature, 0];
  24208. this.instructions.push(this.beginGeometryInstruction1_);
  24209. this.beginGeometryInstruction2_ =
  24210. [ol.render.canvas.Instruction.BEGIN_GEOMETRY, feature, 0];
  24211. this.hitDetectionInstructions.push(this.beginGeometryInstruction2_);
  24212. };
  24213. /**
  24214. * @private
  24215. * @param {CanvasRenderingContext2D} context Context.
  24216. */
  24217. ol.render.canvas.Replay.prototype.fill_ = function(context) {
  24218. if (this.fillOrigin_) {
  24219. var origin = ol.transform.apply(this.renderedTransform_, this.fillOrigin_.slice());
  24220. context.translate(origin[0], origin[1]);
  24221. context.rotate(this.viewRotation_);
  24222. }
  24223. context.fill();
  24224. if (this.fillOrigin_) {
  24225. context.setTransform.apply(context, ol.render.canvas.resetTransform_);
  24226. }
  24227. };
  24228. /**
  24229. * @private
  24230. * @param {CanvasRenderingContext2D} context Context.
  24231. * @param {Array.<*>} instruction Instruction.
  24232. */
  24233. ol.render.canvas.Replay.prototype.setStrokeStyle_ = function(context, instruction) {
  24234. context.strokeStyle = /** @type {ol.ColorLike} */ (instruction[1]);
  24235. context.lineWidth = /** @type {number} */ (instruction[2]);
  24236. context.lineCap = /** @type {string} */ (instruction[3]);
  24237. context.lineJoin = /** @type {string} */ (instruction[4]);
  24238. context.miterLimit = /** @type {number} */ (instruction[5]);
  24239. if (ol.has.CANVAS_LINE_DASH) {
  24240. context.lineDashOffset = /** @type {number} */ (instruction[7]);
  24241. context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
  24242. }
  24243. };
  24244. /**
  24245. * @param {ol.DeclutterGroup} declutterGroup Declutter group.
  24246. * @param {ol.Feature|ol.render.Feature} feature Feature.
  24247. */
  24248. ol.render.canvas.Replay.prototype.renderDeclutter_ = function(declutterGroup, feature) {
  24249. if (declutterGroup && declutterGroup.length > 5) {
  24250. var groupCount = declutterGroup[4];
  24251. if (groupCount == 1 || groupCount == declutterGroup.length - 5) {
  24252. /** @type {ol.RBushEntry} */
  24253. var box = {
  24254. minX: /** @type {number} */ (declutterGroup[0]),
  24255. minY: /** @type {number} */ (declutterGroup[1]),
  24256. maxX: /** @type {number} */ (declutterGroup[2]),
  24257. maxY: /** @type {number} */ (declutterGroup[3]),
  24258. value: feature
  24259. };
  24260. if (!this.declutterTree.collides(box)) {
  24261. this.declutterTree.insert(box);
  24262. var drawImage = ol.render.canvas.drawImage;
  24263. for (var j = 5, jj = declutterGroup.length; j < jj; ++j) {
  24264. var declutterData = /** @type {Array} */ (declutterGroup[j]);
  24265. if (declutterData) {
  24266. if (declutterData.length > 11) {
  24267. this.replayTextBackground_(declutterData[0],
  24268. declutterData[13], declutterData[14], declutterData[15], declutterData[16],
  24269. declutterData[11], declutterData[12]);
  24270. }
  24271. drawImage.apply(undefined, declutterData);
  24272. }
  24273. }
  24274. }
  24275. declutterGroup.length = 5;
  24276. ol.extent.createOrUpdateEmpty(declutterGroup);
  24277. }
  24278. }
  24279. };
  24280. /**
  24281. * @private
  24282. * @param {CanvasRenderingContext2D} context Context.
  24283. * @param {ol.Transform} transform Transform.
  24284. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  24285. * to skip.
  24286. * @param {Array.<*>} instructions Instructions array.
  24287. * @param {function((ol.Feature|ol.render.Feature)): T|undefined}
  24288. * featureCallback Feature callback.
  24289. * @param {ol.Extent=} opt_hitExtent Only check features that intersect this
  24290. * extent.
  24291. * @return {T|undefined} Callback result.
  24292. * @template T
  24293. */
  24294. ol.render.canvas.Replay.prototype.replay_ = function(
  24295. context, transform, skippedFeaturesHash,
  24296. instructions, featureCallback, opt_hitExtent) {
  24297. /** @type {Array.<number>} */
  24298. var pixelCoordinates;
  24299. if (this.pixelCoordinates_ && ol.array.equals(transform, this.renderedTransform_)) {
  24300. pixelCoordinates = this.pixelCoordinates_;
  24301. } else {
  24302. if (!this.pixelCoordinates_) {
  24303. this.pixelCoordinates_ = [];
  24304. }
  24305. pixelCoordinates = ol.geom.flat.transform.transform2D(
  24306. this.coordinates, 0, this.coordinates.length, 2,
  24307. transform, this.pixelCoordinates_);
  24308. ol.transform.setFromArray(this.renderedTransform_, transform);
  24309. }
  24310. var skipFeatures = !ol.obj.isEmpty(skippedFeaturesHash);
  24311. var i = 0; // instruction index
  24312. var ii = instructions.length; // end of instructions
  24313. var d = 0; // data index
  24314. var dd; // end of per-instruction data
  24315. var anchorX, anchorY, prevX, prevY, roundX, roundY, declutterGroup, image;
  24316. var pendingFill = 0;
  24317. var pendingStroke = 0;
  24318. var lastFillInstruction = null;
  24319. var lastStrokeInstruction = null;
  24320. var coordinateCache = this.coordinateCache_;
  24321. var viewRotation = this.viewRotation_;
  24322. var state = /** @type {olx.render.State} */ ({
  24323. context: context,
  24324. pixelRatio: this.pixelRatio,
  24325. resolution: this.resolution,
  24326. rotation: viewRotation
  24327. });
  24328. // When the batch size gets too big, performance decreases. 200 is a good
  24329. // balance between batch size and number of fill/stroke instructions.
  24330. var batchSize =
  24331. this.instructions != instructions || this.overlaps ? 0 : 200;
  24332. while (i < ii) {
  24333. var instruction = instructions[i];
  24334. var type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]);
  24335. var /** @type {ol.Feature|ol.render.Feature} */ feature, x, y;
  24336. switch (type) {
  24337. case ol.render.canvas.Instruction.BEGIN_GEOMETRY:
  24338. feature = /** @type {ol.Feature|ol.render.Feature} */ (instruction[1]);
  24339. if ((skipFeatures &&
  24340. skippedFeaturesHash[ol.getUid(feature).toString()]) ||
  24341. !feature.getGeometry()) {
  24342. i = /** @type {number} */ (instruction[2]);
  24343. } else if (opt_hitExtent !== undefined && !ol.extent.intersects(
  24344. opt_hitExtent, feature.getGeometry().getExtent())) {
  24345. i = /** @type {number} */ (instruction[2]) + 1;
  24346. } else {
  24347. ++i;
  24348. }
  24349. break;
  24350. case ol.render.canvas.Instruction.BEGIN_PATH:
  24351. if (pendingFill > batchSize) {
  24352. this.fill_(context);
  24353. pendingFill = 0;
  24354. }
  24355. if (pendingStroke > batchSize) {
  24356. context.stroke();
  24357. pendingStroke = 0;
  24358. }
  24359. if (!pendingFill && !pendingStroke) {
  24360. context.beginPath();
  24361. prevX = prevY = NaN;
  24362. }
  24363. ++i;
  24364. break;
  24365. case ol.render.canvas.Instruction.CIRCLE:
  24366. d = /** @type {number} */ (instruction[1]);
  24367. var x1 = pixelCoordinates[d];
  24368. var y1 = pixelCoordinates[d + 1];
  24369. var x2 = pixelCoordinates[d + 2];
  24370. var y2 = pixelCoordinates[d + 3];
  24371. var dx = x2 - x1;
  24372. var dy = y2 - y1;
  24373. var r = Math.sqrt(dx * dx + dy * dy);
  24374. context.moveTo(x1 + r, y1);
  24375. context.arc(x1, y1, r, 0, 2 * Math.PI, true);
  24376. ++i;
  24377. break;
  24378. case ol.render.canvas.Instruction.CLOSE_PATH:
  24379. context.closePath();
  24380. ++i;
  24381. break;
  24382. case ol.render.canvas.Instruction.CUSTOM:
  24383. d = /** @type {number} */ (instruction[1]);
  24384. dd = instruction[2];
  24385. var geometry = /** @type {ol.geom.SimpleGeometry} */ (instruction[3]);
  24386. var renderer = instruction[4];
  24387. var fn = instruction.length == 6 ? instruction[5] : undefined;
  24388. state.geometry = geometry;
  24389. state.feature = feature;
  24390. if (!(i in coordinateCache)) {
  24391. coordinateCache[i] = [];
  24392. }
  24393. var coords = coordinateCache[i];
  24394. if (fn) {
  24395. fn(pixelCoordinates, d, dd, 2, coords);
  24396. } else {
  24397. coords[0] = pixelCoordinates[d];
  24398. coords[1] = pixelCoordinates[d + 1];
  24399. coords.length = 2;
  24400. }
  24401. renderer(coords, state);
  24402. ++i;
  24403. break;
  24404. case ol.render.canvas.Instruction.DRAW_IMAGE:
  24405. d = /** @type {number} */ (instruction[1]);
  24406. dd = /** @type {number} */ (instruction[2]);
  24407. image = /** @type {HTMLCanvasElement|HTMLVideoElement|Image} */
  24408. (instruction[3]);
  24409. // Remaining arguments in DRAW_IMAGE are in alphabetical order
  24410. anchorX = /** @type {number} */ (instruction[4]);
  24411. anchorY = /** @type {number} */ (instruction[5]);
  24412. declutterGroup = featureCallback ? null : /** @type {ol.DeclutterGroup} */ (instruction[6]);
  24413. var height = /** @type {number} */ (instruction[7]);
  24414. var opacity = /** @type {number} */ (instruction[8]);
  24415. var originX = /** @type {number} */ (instruction[9]);
  24416. var originY = /** @type {number} */ (instruction[10]);
  24417. var rotateWithView = /** @type {boolean} */ (instruction[11]);
  24418. var rotation = /** @type {number} */ (instruction[12]);
  24419. var scale = /** @type {number} */ (instruction[13]);
  24420. var snapToPixel = /** @type {boolean} */ (instruction[14]);
  24421. var width = /** @type {number} */ (instruction[15]);
  24422. var padding, backgroundFill, backgroundStroke;
  24423. if (instruction.length > 16) {
  24424. padding = /** @type {Array.<number>} */ (instruction[16]);
  24425. backgroundFill = /** @type {boolean} */ (instruction[17]);
  24426. backgroundStroke = /** @type {boolean} */ (instruction[18]);
  24427. } else {
  24428. padding = ol.render.canvas.defaultPadding;
  24429. backgroundFill = backgroundStroke = false;
  24430. }
  24431. if (rotateWithView) {
  24432. rotation += viewRotation;
  24433. }
  24434. for (; d < dd; d += 2) {
  24435. this.replayImage_(context,
  24436. pixelCoordinates[d], pixelCoordinates[d + 1], image, anchorX, anchorY,
  24437. declutterGroup, height, opacity, originX, originY, rotation, scale,
  24438. snapToPixel, width, padding,
  24439. backgroundFill ? /** @type {Array.<*>} */ (lastFillInstruction) : null,
  24440. backgroundStroke ? /** @type {Array.<*>} */ (lastStrokeInstruction) : null);
  24441. }
  24442. this.renderDeclutter_(declutterGroup, feature);
  24443. ++i;
  24444. break;
  24445. case ol.render.canvas.Instruction.DRAW_CHARS:
  24446. var begin = /** @type {number} */ (instruction[1]);
  24447. var end = /** @type {number} */ (instruction[2]);
  24448. var baseline = /** @type {number} */ (instruction[3]);
  24449. declutterGroup = featureCallback ? null : /** @type {ol.DeclutterGroup} */ (instruction[4]);
  24450. var overflow = /** @type {number} */ (instruction[5]);
  24451. var fillKey = /** @type {string} */ (instruction[6]);
  24452. var maxAngle = /** @type {number} */ (instruction[7]);
  24453. var measure = /** @type {function(string):number} */ (instruction[8]);
  24454. var offsetY = /** @type {number} */ (instruction[9]);
  24455. var strokeKey = /** @type {string} */ (instruction[10]);
  24456. var strokeWidth = /** @type {number} */ (instruction[11]);
  24457. var text = /** @type {string} */ (instruction[12]);
  24458. var textKey = /** @type {string} */ (instruction[13]);
  24459. var textScale = /** @type {number} */ (instruction[14]);
  24460. var pathLength = ol.geom.flat.length.lineString(pixelCoordinates, begin, end, 2);
  24461. var textLength = measure(text);
  24462. if (overflow || textLength <= pathLength) {
  24463. var textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign;
  24464. var startM = (pathLength - textLength) * ol.render.replay.TEXT_ALIGN[textAlign];
  24465. var parts = ol.geom.flat.textpath.lineString(
  24466. pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle);
  24467. if (parts) {
  24468. var c, cc, chars, label, part;
  24469. if (strokeKey) {
  24470. for (c = 0, cc = parts.length; c < cc; ++c) {
  24471. part = parts[c]; // x, y, anchorX, rotation, chunk
  24472. chars = /** @type {string} */ (part[4]);
  24473. label = /** @type {ol.render.canvas.TextReplay} */ (this).getImage(chars, textKey, '', strokeKey);
  24474. anchorX = /** @type {number} */ (part[2]) + strokeWidth;
  24475. anchorY = baseline * label.height + (0.5 - baseline) * 2 * strokeWidth - offsetY;
  24476. this.replayImage_(context,
  24477. /** @type {number} */ (part[0]), /** @type {number} */ (part[1]), label,
  24478. anchorX, anchorY, declutterGroup, label.height, 1, 0, 0,
  24479. /** @type {number} */ (part[3]), textScale, false, label.width,
  24480. ol.render.canvas.defaultPadding, null, null);
  24481. }
  24482. }
  24483. if (fillKey) {
  24484. for (c = 0, cc = parts.length; c < cc; ++c) {
  24485. part = parts[c]; // x, y, anchorX, rotation, chunk
  24486. chars = /** @type {string} */ (part[4]);
  24487. label = /** @type {ol.render.canvas.TextReplay} */ (this).getImage(chars, textKey, fillKey, '');
  24488. anchorX = /** @type {number} */ (part[2]);
  24489. anchorY = baseline * label.height - offsetY;
  24490. this.replayImage_(context,
  24491. /** @type {number} */ (part[0]), /** @type {number} */ (part[1]), label,
  24492. anchorX, anchorY, declutterGroup, label.height, 1, 0, 0,
  24493. /** @type {number} */ (part[3]), textScale, false, label.width,
  24494. ol.render.canvas.defaultPadding, null, null);
  24495. }
  24496. }
  24497. }
  24498. }
  24499. this.renderDeclutter_(declutterGroup, feature);
  24500. ++i;
  24501. break;
  24502. case ol.render.canvas.Instruction.END_GEOMETRY:
  24503. if (featureCallback !== undefined) {
  24504. feature = /** @type {ol.Feature|ol.render.Feature} */ (instruction[1]);
  24505. var result = featureCallback(feature);
  24506. if (result) {
  24507. return result;
  24508. }
  24509. }
  24510. ++i;
  24511. break;
  24512. case ol.render.canvas.Instruction.FILL:
  24513. if (batchSize) {
  24514. pendingFill++;
  24515. } else {
  24516. this.fill_(context);
  24517. }
  24518. ++i;
  24519. break;
  24520. case ol.render.canvas.Instruction.MOVE_TO_LINE_TO:
  24521. d = /** @type {number} */ (instruction[1]);
  24522. dd = /** @type {number} */ (instruction[2]);
  24523. x = pixelCoordinates[d];
  24524. y = pixelCoordinates[d + 1];
  24525. roundX = (x + 0.5) | 0;
  24526. roundY = (y + 0.5) | 0;
  24527. if (roundX !== prevX || roundY !== prevY) {
  24528. context.moveTo(x, y);
  24529. prevX = roundX;
  24530. prevY = roundY;
  24531. }
  24532. for (d += 2; d < dd; d += 2) {
  24533. x = pixelCoordinates[d];
  24534. y = pixelCoordinates[d + 1];
  24535. roundX = (x + 0.5) | 0;
  24536. roundY = (y + 0.5) | 0;
  24537. if (d == dd - 2 || roundX !== prevX || roundY !== prevY) {
  24538. context.lineTo(x, y);
  24539. prevX = roundX;
  24540. prevY = roundY;
  24541. }
  24542. }
  24543. ++i;
  24544. break;
  24545. case ol.render.canvas.Instruction.SET_FILL_STYLE:
  24546. lastFillInstruction = instruction;
  24547. this.fillOrigin_ = instruction[2];
  24548. if (pendingFill) {
  24549. this.fill_(context);
  24550. pendingFill = 0;
  24551. if (pendingStroke) {
  24552. context.stroke();
  24553. pendingStroke = 0;
  24554. }
  24555. }
  24556. context.fillStyle = /** @type {ol.ColorLike} */ (instruction[1]);
  24557. ++i;
  24558. break;
  24559. case ol.render.canvas.Instruction.SET_STROKE_STYLE:
  24560. lastStrokeInstruction = instruction;
  24561. if (pendingStroke) {
  24562. context.stroke();
  24563. pendingStroke = 0;
  24564. }
  24565. this.setStrokeStyle_(context, /** @type {Array.<*>} */ (instruction));
  24566. ++i;
  24567. break;
  24568. case ol.render.canvas.Instruction.STROKE:
  24569. if (batchSize) {
  24570. pendingStroke++;
  24571. } else {
  24572. context.stroke();
  24573. }
  24574. ++i;
  24575. break;
  24576. default:
  24577. ++i; // consume the instruction anyway, to avoid an infinite loop
  24578. break;
  24579. }
  24580. }
  24581. if (pendingFill) {
  24582. this.fill_(context);
  24583. }
  24584. if (pendingStroke) {
  24585. context.stroke();
  24586. }
  24587. return undefined;
  24588. };
  24589. /**
  24590. * @param {CanvasRenderingContext2D} context Context.
  24591. * @param {ol.Transform} transform Transform.
  24592. * @param {number} viewRotation View rotation.
  24593. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  24594. * to skip.
  24595. */
  24596. ol.render.canvas.Replay.prototype.replay = function(
  24597. context, transform, viewRotation, skippedFeaturesHash) {
  24598. this.viewRotation_ = viewRotation;
  24599. this.replay_(context, transform,
  24600. skippedFeaturesHash, this.instructions, undefined, undefined);
  24601. };
  24602. /**
  24603. * @param {CanvasRenderingContext2D} context Context.
  24604. * @param {ol.Transform} transform Transform.
  24605. * @param {number} viewRotation View rotation.
  24606. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  24607. * to skip.
  24608. * @param {function((ol.Feature|ol.render.Feature)): T=} opt_featureCallback
  24609. * Feature callback.
  24610. * @param {ol.Extent=} opt_hitExtent Only check features that intersect this
  24611. * extent.
  24612. * @return {T|undefined} Callback result.
  24613. * @template T
  24614. */
  24615. ol.render.canvas.Replay.prototype.replayHitDetection = function(
  24616. context, transform, viewRotation, skippedFeaturesHash,
  24617. opt_featureCallback, opt_hitExtent) {
  24618. this.viewRotation_ = viewRotation;
  24619. return this.replay_(context, transform, skippedFeaturesHash,
  24620. this.hitDetectionInstructions, opt_featureCallback, opt_hitExtent);
  24621. };
  24622. /**
  24623. * Reverse the hit detection instructions.
  24624. */
  24625. ol.render.canvas.Replay.prototype.reverseHitDetectionInstructions = function() {
  24626. var hitDetectionInstructions = this.hitDetectionInstructions;
  24627. // step 1 - reverse array
  24628. hitDetectionInstructions.reverse();
  24629. // step 2 - reverse instructions within geometry blocks
  24630. var i;
  24631. var n = hitDetectionInstructions.length;
  24632. var instruction;
  24633. var type;
  24634. var begin = -1;
  24635. for (i = 0; i < n; ++i) {
  24636. instruction = hitDetectionInstructions[i];
  24637. type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]);
  24638. if (type == ol.render.canvas.Instruction.END_GEOMETRY) {
  24639. begin = i;
  24640. } else if (type == ol.render.canvas.Instruction.BEGIN_GEOMETRY) {
  24641. instruction[2] = i;
  24642. ol.array.reverseSubArray(this.hitDetectionInstructions, begin, i);
  24643. begin = -1;
  24644. }
  24645. }
  24646. };
  24647. /**
  24648. * @inheritDoc
  24649. */
  24650. ol.render.canvas.Replay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
  24651. var state = this.state;
  24652. if (fillStyle) {
  24653. var fillStyleColor = fillStyle.getColor();
  24654. state.fillStyle = ol.colorlike.asColorLike(fillStyleColor ?
  24655. fillStyleColor : ol.render.canvas.defaultFillStyle);
  24656. } else {
  24657. state.fillStyle = undefined;
  24658. }
  24659. if (strokeStyle) {
  24660. var strokeStyleColor = strokeStyle.getColor();
  24661. state.strokeStyle = ol.colorlike.asColorLike(strokeStyleColor ?
  24662. strokeStyleColor : ol.render.canvas.defaultStrokeStyle);
  24663. var strokeStyleLineCap = strokeStyle.getLineCap();
  24664. state.lineCap = strokeStyleLineCap !== undefined ?
  24665. strokeStyleLineCap : ol.render.canvas.defaultLineCap;
  24666. var strokeStyleLineDash = strokeStyle.getLineDash();
  24667. state.lineDash = strokeStyleLineDash ?
  24668. strokeStyleLineDash.slice() : ol.render.canvas.defaultLineDash;
  24669. var strokeStyleLineDashOffset = strokeStyle.getLineDashOffset();
  24670. state.lineDashOffset = strokeStyleLineDashOffset ?
  24671. strokeStyleLineDashOffset : ol.render.canvas.defaultLineDashOffset;
  24672. var strokeStyleLineJoin = strokeStyle.getLineJoin();
  24673. state.lineJoin = strokeStyleLineJoin !== undefined ?
  24674. strokeStyleLineJoin : ol.render.canvas.defaultLineJoin;
  24675. var strokeStyleWidth = strokeStyle.getWidth();
  24676. state.lineWidth = strokeStyleWidth !== undefined ?
  24677. strokeStyleWidth : ol.render.canvas.defaultLineWidth;
  24678. var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
  24679. state.miterLimit = strokeStyleMiterLimit !== undefined ?
  24680. strokeStyleMiterLimit : ol.render.canvas.defaultMiterLimit;
  24681. if (state.lineWidth > this.maxLineWidth) {
  24682. this.maxLineWidth = state.lineWidth;
  24683. // invalidate the buffered max extent cache
  24684. this.bufferedMaxExtent_ = null;
  24685. }
  24686. } else {
  24687. state.strokeStyle = undefined;
  24688. state.lineCap = undefined;
  24689. state.lineDash = null;
  24690. state.lineDashOffset = undefined;
  24691. state.lineJoin = undefined;
  24692. state.lineWidth = undefined;
  24693. state.miterLimit = undefined;
  24694. }
  24695. };
  24696. /**
  24697. * @param {ol.CanvasFillStrokeState} state State.
  24698. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  24699. */
  24700. ol.render.canvas.Replay.prototype.applyFill = function(state, geometry) {
  24701. var fillStyle = state.fillStyle;
  24702. var fillInstruction = [ol.render.canvas.Instruction.SET_FILL_STYLE, fillStyle];
  24703. if (typeof fillStyle !== 'string') {
  24704. var fillExtent = geometry.getExtent();
  24705. fillInstruction.push([fillExtent[0], fillExtent[3]]);
  24706. }
  24707. this.instructions.push(fillInstruction);
  24708. };
  24709. /**
  24710. * @param {ol.CanvasFillStrokeState} state State.
  24711. */
  24712. ol.render.canvas.Replay.prototype.applyStroke = function(state) {
  24713. this.instructions.push([
  24714. ol.render.canvas.Instruction.SET_STROKE_STYLE,
  24715. state.strokeStyle, state.lineWidth * this.pixelRatio, state.lineCap,
  24716. state.lineJoin, state.miterLimit,
  24717. this.applyPixelRatio(state.lineDash), state.lineDashOffset * this.pixelRatio
  24718. ]);
  24719. };
  24720. /**
  24721. * @param {ol.CanvasFillStrokeState} state State.
  24722. * @param {function(this:ol.render.canvas.Replay, ol.CanvasFillStrokeState, (ol.geom.Geometry|ol.render.Feature))} applyFill Apply fill.
  24723. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  24724. */
  24725. ol.render.canvas.Replay.prototype.updateFillStyle = function(state, applyFill, geometry) {
  24726. var fillStyle = state.fillStyle;
  24727. if (typeof fillStyle !== 'string' || state.currentFillStyle != fillStyle) {
  24728. applyFill.call(this, state, geometry);
  24729. state.currentFillStyle = fillStyle;
  24730. }
  24731. };
  24732. /**
  24733. * @param {ol.CanvasFillStrokeState} state State.
  24734. * @param {function(this:ol.render.canvas.Replay, ol.CanvasFillStrokeState)} applyStroke Apply stroke.
  24735. */
  24736. ol.render.canvas.Replay.prototype.updateStrokeStyle = function(state, applyStroke) {
  24737. var strokeStyle = state.strokeStyle;
  24738. var lineCap = state.lineCap;
  24739. var lineDash = state.lineDash;
  24740. var lineDashOffset = state.lineDashOffset;
  24741. var lineJoin = state.lineJoin;
  24742. var lineWidth = state.lineWidth;
  24743. var miterLimit = state.miterLimit;
  24744. if (state.currentStrokeStyle != strokeStyle ||
  24745. state.currentLineCap != lineCap ||
  24746. (lineDash != state.currentLineDash && !ol.array.equals(state.currentLineDash, lineDash)) ||
  24747. state.currentLineDashOffset != lineDashOffset ||
  24748. state.currentLineJoin != lineJoin ||
  24749. state.currentLineWidth != lineWidth ||
  24750. state.currentMiterLimit != miterLimit) {
  24751. applyStroke.call(this, state);
  24752. state.currentStrokeStyle = strokeStyle;
  24753. state.currentLineCap = lineCap;
  24754. state.currentLineDash = lineDash;
  24755. state.currentLineDashOffset = lineDashOffset;
  24756. state.currentLineJoin = lineJoin;
  24757. state.currentLineWidth = lineWidth;
  24758. state.currentMiterLimit = miterLimit;
  24759. }
  24760. };
  24761. /**
  24762. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  24763. * @param {ol.Feature|ol.render.Feature} feature Feature.
  24764. */
  24765. ol.render.canvas.Replay.prototype.endGeometry = function(geometry, feature) {
  24766. this.beginGeometryInstruction1_[2] = this.instructions.length;
  24767. this.beginGeometryInstruction1_ = null;
  24768. this.beginGeometryInstruction2_[2] = this.hitDetectionInstructions.length;
  24769. this.beginGeometryInstruction2_ = null;
  24770. var endGeometryInstruction =
  24771. [ol.render.canvas.Instruction.END_GEOMETRY, feature];
  24772. this.instructions.push(endGeometryInstruction);
  24773. this.hitDetectionInstructions.push(endGeometryInstruction);
  24774. };
  24775. /**
  24776. * FIXME empty description for jsdoc
  24777. */
  24778. ol.render.canvas.Replay.prototype.finish = ol.nullFunction;
  24779. /**
  24780. * Get the buffered rendering extent. Rendering will be clipped to the extent
  24781. * provided to the constructor. To account for symbolizers that may intersect
  24782. * this extent, we calculate a buffered extent (e.g. based on stroke width).
  24783. * @return {ol.Extent} The buffered rendering extent.
  24784. * @protected
  24785. */
  24786. ol.render.canvas.Replay.prototype.getBufferedMaxExtent = function() {
  24787. if (!this.bufferedMaxExtent_) {
  24788. this.bufferedMaxExtent_ = ol.extent.clone(this.maxExtent);
  24789. if (this.maxLineWidth > 0) {
  24790. var width = this.resolution * (this.maxLineWidth + 1) / 2;
  24791. ol.extent.buffer(this.bufferedMaxExtent_, width, this.bufferedMaxExtent_);
  24792. }
  24793. }
  24794. return this.bufferedMaxExtent_;
  24795. };
  24796. goog.provide('ol.render.canvas.ImageReplay');
  24797. goog.require('ol');
  24798. goog.require('ol.render.canvas.Instruction');
  24799. goog.require('ol.render.canvas.Replay');
  24800. /**
  24801. * @constructor
  24802. * @extends {ol.render.canvas.Replay}
  24803. * @param {number} tolerance Tolerance.
  24804. * @param {ol.Extent} maxExtent Maximum extent.
  24805. * @param {number} resolution Resolution.
  24806. * @param {number} pixelRatio Pixel ratio.
  24807. * @param {boolean} overlaps The replay can have overlapping geometries.
  24808. * @param {?} declutterTree Declutter tree.
  24809. * @struct
  24810. */
  24811. ol.render.canvas.ImageReplay = function(
  24812. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
  24813. ol.render.canvas.Replay.call(this,
  24814. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
  24815. /**
  24816. * @private
  24817. * @type {ol.DeclutterGroup}
  24818. */
  24819. this.declutterGroup_ = null;
  24820. /**
  24821. * @private
  24822. * @type {HTMLCanvasElement|HTMLVideoElement|Image}
  24823. */
  24824. this.hitDetectionImage_ = null;
  24825. /**
  24826. * @private
  24827. * @type {HTMLCanvasElement|HTMLVideoElement|Image}
  24828. */
  24829. this.image_ = null;
  24830. /**
  24831. * @private
  24832. * @type {number|undefined}
  24833. */
  24834. this.anchorX_ = undefined;
  24835. /**
  24836. * @private
  24837. * @type {number|undefined}
  24838. */
  24839. this.anchorY_ = undefined;
  24840. /**
  24841. * @private
  24842. * @type {number|undefined}
  24843. */
  24844. this.height_ = undefined;
  24845. /**
  24846. * @private
  24847. * @type {number|undefined}
  24848. */
  24849. this.opacity_ = undefined;
  24850. /**
  24851. * @private
  24852. * @type {number|undefined}
  24853. */
  24854. this.originX_ = undefined;
  24855. /**
  24856. * @private
  24857. * @type {number|undefined}
  24858. */
  24859. this.originY_ = undefined;
  24860. /**
  24861. * @private
  24862. * @type {boolean|undefined}
  24863. */
  24864. this.rotateWithView_ = undefined;
  24865. /**
  24866. * @private
  24867. * @type {number|undefined}
  24868. */
  24869. this.rotation_ = undefined;
  24870. /**
  24871. * @private
  24872. * @type {number|undefined}
  24873. */
  24874. this.scale_ = undefined;
  24875. /**
  24876. * @private
  24877. * @type {boolean|undefined}
  24878. */
  24879. this.snapToPixel_ = undefined;
  24880. /**
  24881. * @private
  24882. * @type {number|undefined}
  24883. */
  24884. this.width_ = undefined;
  24885. };
  24886. ol.inherits(ol.render.canvas.ImageReplay, ol.render.canvas.Replay);
  24887. /**
  24888. * @param {Array.<number>} flatCoordinates Flat coordinates.
  24889. * @param {number} offset Offset.
  24890. * @param {number} end End.
  24891. * @param {number} stride Stride.
  24892. * @private
  24893. * @return {number} My end.
  24894. */
  24895. ol.render.canvas.ImageReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) {
  24896. return this.appendFlatCoordinates(
  24897. flatCoordinates, offset, end, stride, false, false);
  24898. };
  24899. /**
  24900. * @inheritDoc
  24901. */
  24902. ol.render.canvas.ImageReplay.prototype.drawPoint = function(pointGeometry, feature) {
  24903. if (!this.image_) {
  24904. return;
  24905. }
  24906. this.beginGeometry(pointGeometry, feature);
  24907. var flatCoordinates = pointGeometry.getFlatCoordinates();
  24908. var stride = pointGeometry.getStride();
  24909. var myBegin = this.coordinates.length;
  24910. var myEnd = this.drawCoordinates_(
  24911. flatCoordinates, 0, flatCoordinates.length, stride);
  24912. this.instructions.push([
  24913. ol.render.canvas.Instruction.DRAW_IMAGE, myBegin, myEnd, this.image_,
  24914. // Remaining arguments to DRAW_IMAGE are in alphabetical order
  24915. this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
  24916. this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
  24917. this.scale_ * this.pixelRatio, this.snapToPixel_, this.width_
  24918. ]);
  24919. this.hitDetectionInstructions.push([
  24920. ol.render.canvas.Instruction.DRAW_IMAGE, myBegin, myEnd,
  24921. this.hitDetectionImage_,
  24922. // Remaining arguments to DRAW_IMAGE are in alphabetical order
  24923. this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
  24924. this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
  24925. this.scale_, this.snapToPixel_, this.width_
  24926. ]);
  24927. this.endGeometry(pointGeometry, feature);
  24928. };
  24929. /**
  24930. * @inheritDoc
  24931. */
  24932. ol.render.canvas.ImageReplay.prototype.drawMultiPoint = function(multiPointGeometry, feature) {
  24933. if (!this.image_) {
  24934. return;
  24935. }
  24936. this.beginGeometry(multiPointGeometry, feature);
  24937. var flatCoordinates = multiPointGeometry.getFlatCoordinates();
  24938. var stride = multiPointGeometry.getStride();
  24939. var myBegin = this.coordinates.length;
  24940. var myEnd = this.drawCoordinates_(
  24941. flatCoordinates, 0, flatCoordinates.length, stride);
  24942. this.instructions.push([
  24943. ol.render.canvas.Instruction.DRAW_IMAGE, myBegin, myEnd, this.image_,
  24944. // Remaining arguments to DRAW_IMAGE are in alphabetical order
  24945. this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
  24946. this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
  24947. this.scale_ * this.pixelRatio, this.snapToPixel_, this.width_
  24948. ]);
  24949. this.hitDetectionInstructions.push([
  24950. ol.render.canvas.Instruction.DRAW_IMAGE, myBegin, myEnd,
  24951. this.hitDetectionImage_,
  24952. // Remaining arguments to DRAW_IMAGE are in alphabetical order
  24953. this.anchorX_, this.anchorY_, this.declutterGroup_, this.height_, this.opacity_,
  24954. this.originX_, this.originY_, this.rotateWithView_, this.rotation_,
  24955. this.scale_, this.snapToPixel_, this.width_
  24956. ]);
  24957. this.endGeometry(multiPointGeometry, feature);
  24958. };
  24959. /**
  24960. * @inheritDoc
  24961. */
  24962. ol.render.canvas.ImageReplay.prototype.finish = function() {
  24963. this.reverseHitDetectionInstructions();
  24964. // FIXME this doesn't really protect us against further calls to draw*Geometry
  24965. this.anchorX_ = undefined;
  24966. this.anchorY_ = undefined;
  24967. this.hitDetectionImage_ = null;
  24968. this.image_ = null;
  24969. this.height_ = undefined;
  24970. this.scale_ = undefined;
  24971. this.opacity_ = undefined;
  24972. this.originX_ = undefined;
  24973. this.originY_ = undefined;
  24974. this.rotateWithView_ = undefined;
  24975. this.rotation_ = undefined;
  24976. this.snapToPixel_ = undefined;
  24977. this.width_ = undefined;
  24978. };
  24979. /**
  24980. * @inheritDoc
  24981. */
  24982. ol.render.canvas.ImageReplay.prototype.setImageStyle = function(imageStyle, declutterGroup) {
  24983. var anchor = imageStyle.getAnchor();
  24984. var size = imageStyle.getSize();
  24985. var hitDetectionImage = imageStyle.getHitDetectionImage(1);
  24986. var image = imageStyle.getImage(1);
  24987. var origin = imageStyle.getOrigin();
  24988. this.anchorX_ = anchor[0];
  24989. this.anchorY_ = anchor[1];
  24990. this.declutterGroup_ = /** @type {ol.DeclutterGroup} */ (declutterGroup);
  24991. this.hitDetectionImage_ = hitDetectionImage;
  24992. this.image_ = image;
  24993. this.height_ = size[1];
  24994. this.opacity_ = imageStyle.getOpacity();
  24995. this.originX_ = origin[0];
  24996. this.originY_ = origin[1];
  24997. this.rotateWithView_ = imageStyle.getRotateWithView();
  24998. this.rotation_ = imageStyle.getRotation();
  24999. this.scale_ = imageStyle.getScale();
  25000. this.snapToPixel_ = imageStyle.getSnapToPixel();
  25001. this.width_ = size[0];
  25002. };
  25003. goog.provide('ol.render.canvas.LineStringReplay');
  25004. goog.require('ol');
  25005. goog.require('ol.render.canvas.Instruction');
  25006. goog.require('ol.render.canvas.Replay');
  25007. /**
  25008. * @constructor
  25009. * @extends {ol.render.canvas.Replay}
  25010. * @param {number} tolerance Tolerance.
  25011. * @param {ol.Extent} maxExtent Maximum extent.
  25012. * @param {number} resolution Resolution.
  25013. * @param {number} pixelRatio Pixel ratio.
  25014. * @param {boolean} overlaps The replay can have overlapping geometries.
  25015. * @param {?} declutterTree Declutter tree.
  25016. * @struct
  25017. */
  25018. ol.render.canvas.LineStringReplay = function(
  25019. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
  25020. ol.render.canvas.Replay.call(this,
  25021. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
  25022. };
  25023. ol.inherits(ol.render.canvas.LineStringReplay, ol.render.canvas.Replay);
  25024. /**
  25025. * @param {Array.<number>} flatCoordinates Flat coordinates.
  25026. * @param {number} offset Offset.
  25027. * @param {number} end End.
  25028. * @param {number} stride Stride.
  25029. * @private
  25030. * @return {number} end.
  25031. */
  25032. ol.render.canvas.LineStringReplay.prototype.drawFlatCoordinates_ = function(flatCoordinates, offset, end, stride) {
  25033. var myBegin = this.coordinates.length;
  25034. var myEnd = this.appendFlatCoordinates(
  25035. flatCoordinates, offset, end, stride, false, false);
  25036. var moveToLineToInstruction =
  25037. [ol.render.canvas.Instruction.MOVE_TO_LINE_TO, myBegin, myEnd];
  25038. this.instructions.push(moveToLineToInstruction);
  25039. this.hitDetectionInstructions.push(moveToLineToInstruction);
  25040. return end;
  25041. };
  25042. /**
  25043. * @inheritDoc
  25044. */
  25045. ol.render.canvas.LineStringReplay.prototype.drawLineString = function(lineStringGeometry, feature) {
  25046. var state = this.state;
  25047. var strokeStyle = state.strokeStyle;
  25048. var lineWidth = state.lineWidth;
  25049. if (strokeStyle === undefined || lineWidth === undefined) {
  25050. return;
  25051. }
  25052. this.updateStrokeStyle(state, this.applyStroke);
  25053. this.beginGeometry(lineStringGeometry, feature);
  25054. this.hitDetectionInstructions.push([
  25055. ol.render.canvas.Instruction.SET_STROKE_STYLE,
  25056. state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
  25057. state.miterLimit, state.lineDash, state.lineDashOffset
  25058. ], [
  25059. ol.render.canvas.Instruction.BEGIN_PATH
  25060. ]);
  25061. var flatCoordinates = lineStringGeometry.getFlatCoordinates();
  25062. var stride = lineStringGeometry.getStride();
  25063. this.drawFlatCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
  25064. this.hitDetectionInstructions.push([ol.render.canvas.Instruction.STROKE]);
  25065. this.endGeometry(lineStringGeometry, feature);
  25066. };
  25067. /**
  25068. * @inheritDoc
  25069. */
  25070. ol.render.canvas.LineStringReplay.prototype.drawMultiLineString = function(multiLineStringGeometry, feature) {
  25071. var state = this.state;
  25072. var strokeStyle = state.strokeStyle;
  25073. var lineWidth = state.lineWidth;
  25074. if (strokeStyle === undefined || lineWidth === undefined) {
  25075. return;
  25076. }
  25077. this.updateStrokeStyle(state, this.applyStroke);
  25078. this.beginGeometry(multiLineStringGeometry, feature);
  25079. this.hitDetectionInstructions.push([
  25080. ol.render.canvas.Instruction.SET_STROKE_STYLE,
  25081. state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
  25082. state.miterLimit, state.lineDash, state.lineDashOffset
  25083. ], [
  25084. ol.render.canvas.Instruction.BEGIN_PATH
  25085. ]);
  25086. var ends = multiLineStringGeometry.getEnds();
  25087. var flatCoordinates = multiLineStringGeometry.getFlatCoordinates();
  25088. var stride = multiLineStringGeometry.getStride();
  25089. var offset = 0;
  25090. var i, ii;
  25091. for (i = 0, ii = ends.length; i < ii; ++i) {
  25092. offset = this.drawFlatCoordinates_(
  25093. flatCoordinates, offset, ends[i], stride);
  25094. }
  25095. this.hitDetectionInstructions.push([ol.render.canvas.Instruction.STROKE]);
  25096. this.endGeometry(multiLineStringGeometry, feature);
  25097. };
  25098. /**
  25099. * @inheritDoc
  25100. */
  25101. ol.render.canvas.LineStringReplay.prototype.finish = function() {
  25102. var state = this.state;
  25103. if (state.lastStroke != undefined && state.lastStroke != this.coordinates.length) {
  25104. this.instructions.push([ol.render.canvas.Instruction.STROKE]);
  25105. }
  25106. this.reverseHitDetectionInstructions();
  25107. this.state = null;
  25108. };
  25109. /**
  25110. * @inheritDoc.
  25111. */
  25112. ol.render.canvas.LineStringReplay.prototype.applyStroke = function(state) {
  25113. if (state.lastStroke != undefined && state.lastStroke != this.coordinates.length) {
  25114. this.instructions.push([ol.render.canvas.Instruction.STROKE]);
  25115. state.lastStroke = this.coordinates.length;
  25116. }
  25117. state.lastStroke = 0;
  25118. ol.render.canvas.Replay.prototype.applyStroke.call(this, state);
  25119. this.instructions.push([ol.render.canvas.Instruction.BEGIN_PATH]);
  25120. };
  25121. goog.provide('ol.render.canvas.PolygonReplay');
  25122. goog.require('ol');
  25123. goog.require('ol.color');
  25124. goog.require('ol.geom.flat.simplify');
  25125. goog.require('ol.render.canvas');
  25126. goog.require('ol.render.canvas.Instruction');
  25127. goog.require('ol.render.canvas.Replay');
  25128. /**
  25129. * @constructor
  25130. * @extends {ol.render.canvas.Replay}
  25131. * @param {number} tolerance Tolerance.
  25132. * @param {ol.Extent} maxExtent Maximum extent.
  25133. * @param {number} resolution Resolution.
  25134. * @param {number} pixelRatio Pixel ratio.
  25135. * @param {boolean} overlaps The replay can have overlapping geometries.
  25136. * @param {?} declutterTree Declutter tree.
  25137. * @struct
  25138. */
  25139. ol.render.canvas.PolygonReplay = function(
  25140. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
  25141. ol.render.canvas.Replay.call(this,
  25142. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
  25143. };
  25144. ol.inherits(ol.render.canvas.PolygonReplay, ol.render.canvas.Replay);
  25145. /**
  25146. * @param {Array.<number>} flatCoordinates Flat coordinates.
  25147. * @param {number} offset Offset.
  25148. * @param {Array.<number>} ends Ends.
  25149. * @param {number} stride Stride.
  25150. * @private
  25151. * @return {number} End.
  25152. */
  25153. ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ = function(flatCoordinates, offset, ends, stride) {
  25154. var state = this.state;
  25155. var fill = state.fillStyle !== undefined;
  25156. var stroke = state.strokeStyle != undefined;
  25157. var numEnds = ends.length;
  25158. var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH];
  25159. this.instructions.push(beginPathInstruction);
  25160. this.hitDetectionInstructions.push(beginPathInstruction);
  25161. for (var i = 0; i < numEnds; ++i) {
  25162. var end = ends[i];
  25163. var myBegin = this.coordinates.length;
  25164. var myEnd = this.appendFlatCoordinates(
  25165. flatCoordinates, offset, end, stride, true, !stroke);
  25166. var moveToLineToInstruction =
  25167. [ol.render.canvas.Instruction.MOVE_TO_LINE_TO, myBegin, myEnd];
  25168. this.instructions.push(moveToLineToInstruction);
  25169. this.hitDetectionInstructions.push(moveToLineToInstruction);
  25170. if (stroke) {
  25171. // Performance optimization: only call closePath() when we have a stroke.
  25172. // Otherwise the ring is closed already (see appendFlatCoordinates above).
  25173. var closePathInstruction = [ol.render.canvas.Instruction.CLOSE_PATH];
  25174. this.instructions.push(closePathInstruction);
  25175. this.hitDetectionInstructions.push(closePathInstruction);
  25176. }
  25177. offset = end;
  25178. }
  25179. var fillInstruction = [ol.render.canvas.Instruction.FILL];
  25180. this.hitDetectionInstructions.push(fillInstruction);
  25181. if (fill) {
  25182. this.instructions.push(fillInstruction);
  25183. }
  25184. if (stroke) {
  25185. var strokeInstruction = [ol.render.canvas.Instruction.STROKE];
  25186. this.instructions.push(strokeInstruction);
  25187. this.hitDetectionInstructions.push(strokeInstruction);
  25188. }
  25189. return offset;
  25190. };
  25191. /**
  25192. * @inheritDoc
  25193. */
  25194. ol.render.canvas.PolygonReplay.prototype.drawCircle = function(circleGeometry, feature) {
  25195. var state = this.state;
  25196. var fillStyle = state.fillStyle;
  25197. var strokeStyle = state.strokeStyle;
  25198. if (fillStyle === undefined && strokeStyle === undefined) {
  25199. return;
  25200. }
  25201. this.setFillStrokeStyles_(circleGeometry);
  25202. this.beginGeometry(circleGeometry, feature);
  25203. // always fill the circle for hit detection
  25204. this.hitDetectionInstructions.push([
  25205. ol.render.canvas.Instruction.SET_FILL_STYLE,
  25206. ol.color.asString(ol.render.canvas.defaultFillStyle)
  25207. ]);
  25208. if (state.strokeStyle !== undefined) {
  25209. this.hitDetectionInstructions.push([
  25210. ol.render.canvas.Instruction.SET_STROKE_STYLE,
  25211. state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
  25212. state.miterLimit, state.lineDash, state.lineDashOffset
  25213. ]);
  25214. }
  25215. var flatCoordinates = circleGeometry.getFlatCoordinates();
  25216. var stride = circleGeometry.getStride();
  25217. var myBegin = this.coordinates.length;
  25218. this.appendFlatCoordinates(
  25219. flatCoordinates, 0, flatCoordinates.length, stride, false, false);
  25220. var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH];
  25221. var circleInstruction = [ol.render.canvas.Instruction.CIRCLE, myBegin];
  25222. this.instructions.push(beginPathInstruction, circleInstruction);
  25223. this.hitDetectionInstructions.push(beginPathInstruction, circleInstruction);
  25224. var fillInstruction = [ol.render.canvas.Instruction.FILL];
  25225. this.hitDetectionInstructions.push(fillInstruction);
  25226. if (state.fillStyle !== undefined) {
  25227. this.instructions.push(fillInstruction);
  25228. }
  25229. if (state.strokeStyle !== undefined) {
  25230. var strokeInstruction = [ol.render.canvas.Instruction.STROKE];
  25231. this.instructions.push(strokeInstruction);
  25232. this.hitDetectionInstructions.push(strokeInstruction);
  25233. }
  25234. this.endGeometry(circleGeometry, feature);
  25235. };
  25236. /**
  25237. * @inheritDoc
  25238. */
  25239. ol.render.canvas.PolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) {
  25240. var state = this.state;
  25241. this.setFillStrokeStyles_(polygonGeometry);
  25242. this.beginGeometry(polygonGeometry, feature);
  25243. // always fill the polygon for hit detection
  25244. this.hitDetectionInstructions.push([
  25245. ol.render.canvas.Instruction.SET_FILL_STYLE,
  25246. ol.color.asString(ol.render.canvas.defaultFillStyle)]
  25247. );
  25248. if (state.strokeStyle !== undefined) {
  25249. this.hitDetectionInstructions.push([
  25250. ol.render.canvas.Instruction.SET_STROKE_STYLE,
  25251. state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
  25252. state.miterLimit, state.lineDash, state.lineDashOffset
  25253. ]);
  25254. }
  25255. var ends = polygonGeometry.getEnds();
  25256. var flatCoordinates = polygonGeometry.getOrientedFlatCoordinates();
  25257. var stride = polygonGeometry.getStride();
  25258. this.drawFlatCoordinatess_(flatCoordinates, 0, ends, stride);
  25259. this.endGeometry(polygonGeometry, feature);
  25260. };
  25261. /**
  25262. * @inheritDoc
  25263. */
  25264. ol.render.canvas.PolygonReplay.prototype.drawMultiPolygon = function(multiPolygonGeometry, feature) {
  25265. var state = this.state;
  25266. var fillStyle = state.fillStyle;
  25267. var strokeStyle = state.strokeStyle;
  25268. if (fillStyle === undefined && strokeStyle === undefined) {
  25269. return;
  25270. }
  25271. this.setFillStrokeStyles_(multiPolygonGeometry);
  25272. this.beginGeometry(multiPolygonGeometry, feature);
  25273. // always fill the multi-polygon for hit detection
  25274. this.hitDetectionInstructions.push([
  25275. ol.render.canvas.Instruction.SET_FILL_STYLE,
  25276. ol.color.asString(ol.render.canvas.defaultFillStyle)
  25277. ]);
  25278. if (state.strokeStyle !== undefined) {
  25279. this.hitDetectionInstructions.push([
  25280. ol.render.canvas.Instruction.SET_STROKE_STYLE,
  25281. state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
  25282. state.miterLimit, state.lineDash, state.lineDashOffset
  25283. ]);
  25284. }
  25285. var endss = multiPolygonGeometry.getEndss();
  25286. var flatCoordinates = multiPolygonGeometry.getOrientedFlatCoordinates();
  25287. var stride = multiPolygonGeometry.getStride();
  25288. var offset = 0;
  25289. var i, ii;
  25290. for (i = 0, ii = endss.length; i < ii; ++i) {
  25291. offset = this.drawFlatCoordinatess_(
  25292. flatCoordinates, offset, endss[i], stride);
  25293. }
  25294. this.endGeometry(multiPolygonGeometry, feature);
  25295. };
  25296. /**
  25297. * @inheritDoc
  25298. */
  25299. ol.render.canvas.PolygonReplay.prototype.finish = function() {
  25300. this.reverseHitDetectionInstructions();
  25301. this.state = null;
  25302. // We want to preserve topology when drawing polygons. Polygons are
  25303. // simplified using quantization and point elimination. However, we might
  25304. // have received a mix of quantized and non-quantized geometries, so ensure
  25305. // that all are quantized by quantizing all coordinates in the batch.
  25306. var tolerance = this.tolerance;
  25307. if (tolerance !== 0) {
  25308. var coordinates = this.coordinates;
  25309. var i, ii;
  25310. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  25311. coordinates[i] = ol.geom.flat.simplify.snap(coordinates[i], tolerance);
  25312. }
  25313. }
  25314. };
  25315. /**
  25316. * @private
  25317. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  25318. */
  25319. ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function(geometry) {
  25320. var state = this.state;
  25321. var fillStyle = state.fillStyle;
  25322. if (fillStyle !== undefined) {
  25323. this.updateFillStyle(state, this.applyFill, geometry);
  25324. }
  25325. if (state.strokeStyle !== undefined) {
  25326. this.updateStrokeStyle(state, this.applyStroke);
  25327. }
  25328. };
  25329. goog.provide('ol.geom.flat.straightchunk');
  25330. /**
  25331. * @param {number} maxAngle Maximum acceptable angle delta between segments.
  25332. * @param {Array.<number>} flatCoordinates Flat coordinates.
  25333. * @param {number} offset Offset.
  25334. * @param {number} end End.
  25335. * @param {number} stride Stride.
  25336. * @return {Array.<number>} Start and end of the first suitable chunk of the
  25337. * given `flatCoordinates`.
  25338. */
  25339. ol.geom.flat.straightchunk.lineString = function(maxAngle, flatCoordinates, offset, end, stride) {
  25340. var chunkStart = offset;
  25341. var chunkEnd = offset;
  25342. var chunkM = 0;
  25343. var m = 0;
  25344. var start = offset;
  25345. var acos, i, m12, m23, x1, y1, x12, y12, x23, y23;
  25346. for (i = offset; i < end; i += stride) {
  25347. var x2 = flatCoordinates[i];
  25348. var y2 = flatCoordinates[i + 1];
  25349. if (x1 !== undefined) {
  25350. x23 = x2 - x1;
  25351. y23 = y2 - y1;
  25352. m23 = Math.sqrt(x23 * x23 + y23 * y23);
  25353. if (x12 !== undefined) {
  25354. m += m12;
  25355. acos = Math.acos((x12 * x23 + y12 * y23) / (m12 * m23));
  25356. if (acos > maxAngle) {
  25357. if (m > chunkM) {
  25358. chunkM = m;
  25359. chunkStart = start;
  25360. chunkEnd = i;
  25361. }
  25362. m = 0;
  25363. start = i - stride;
  25364. }
  25365. }
  25366. m12 = m23;
  25367. x12 = x23;
  25368. y12 = y23;
  25369. }
  25370. x1 = x2;
  25371. y1 = y2;
  25372. }
  25373. m += m23;
  25374. return m > chunkM ? [start, i] : [chunkStart, chunkEnd];
  25375. };
  25376. goog.provide('ol.style.TextPlacement');
  25377. /**
  25378. * Text placement. One of `'point'`, `'line'`. Default is `'point'`. Note that
  25379. * `'line'` requires the underlying geometry to be a {@link ol.geom.LineString},
  25380. * {@link ol.geom.Polygon}, {@link ol.geom.MultiLineString} or
  25381. * {@link ol.geom.MultiPolygon}.
  25382. * @enum {string}
  25383. */
  25384. ol.style.TextPlacement = {
  25385. POINT: 'point',
  25386. LINE: 'line'
  25387. };
  25388. goog.provide('ol.render.canvas.TextReplay');
  25389. goog.require('ol');
  25390. goog.require('ol.colorlike');
  25391. goog.require('ol.dom');
  25392. goog.require('ol.extent');
  25393. goog.require('ol.geom.flat.straightchunk');
  25394. goog.require('ol.geom.GeometryType');
  25395. goog.require('ol.has');
  25396. goog.require('ol.render.canvas');
  25397. goog.require('ol.render.canvas.Instruction');
  25398. goog.require('ol.render.canvas.Replay');
  25399. goog.require('ol.render.replay');
  25400. goog.require('ol.style.TextPlacement');
  25401. /**
  25402. * @constructor
  25403. * @extends {ol.render.canvas.Replay}
  25404. * @param {number} tolerance Tolerance.
  25405. * @param {ol.Extent} maxExtent Maximum extent.
  25406. * @param {number} resolution Resolution.
  25407. * @param {number} pixelRatio Pixel ratio.
  25408. * @param {boolean} overlaps The replay can have overlapping geometries.
  25409. * @param {?} declutterTree Declutter tree.
  25410. * @struct
  25411. */
  25412. ol.render.canvas.TextReplay = function(
  25413. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
  25414. ol.render.canvas.Replay.call(this,
  25415. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree);
  25416. /**
  25417. * @private
  25418. * @type {ol.DeclutterGroup}
  25419. */
  25420. this.declutterGroup_;
  25421. /**
  25422. * @private
  25423. * @type {Array.<HTMLCanvasElement>}
  25424. */
  25425. this.labels_ = null;
  25426. /**
  25427. * @private
  25428. * @type {string}
  25429. */
  25430. this.text_ = '';
  25431. /**
  25432. * @private
  25433. * @type {number}
  25434. */
  25435. this.textOffsetX_ = 0;
  25436. /**
  25437. * @private
  25438. * @type {number}
  25439. */
  25440. this.textOffsetY_ = 0;
  25441. /**
  25442. * @private
  25443. * @type {boolean|undefined}
  25444. */
  25445. this.textRotateWithView_ = undefined;
  25446. /**
  25447. * @private
  25448. * @type {number}
  25449. */
  25450. this.textRotation_ = 0;
  25451. /**
  25452. * @private
  25453. * @type {?ol.CanvasFillState}
  25454. */
  25455. this.textFillState_ = null;
  25456. /**
  25457. * @type {Object.<string, ol.CanvasFillState>}
  25458. */
  25459. this.fillStates = {};
  25460. /**
  25461. * @private
  25462. * @type {?ol.CanvasStrokeState}
  25463. */
  25464. this.textStrokeState_ = null;
  25465. /**
  25466. * @type {Object.<string, ol.CanvasStrokeState>}
  25467. */
  25468. this.strokeStates = {};
  25469. /**
  25470. * @private
  25471. * @type {ol.CanvasTextState}
  25472. */
  25473. this.textState_ = /** @type {ol.CanvasTextState} */ ({});
  25474. /**
  25475. * @type {Object.<string, ol.CanvasTextState>}
  25476. */
  25477. this.textStates = {};
  25478. /**
  25479. * @private
  25480. * @type {string}
  25481. */
  25482. this.textKey_ = '';
  25483. /**
  25484. * @private
  25485. * @type {string}
  25486. */
  25487. this.fillKey_ = '';
  25488. /**
  25489. * @private
  25490. * @type {string}
  25491. */
  25492. this.strokeKey_ = '';
  25493. /**
  25494. * @private
  25495. * @type {Object.<string, Object.<string, number>>}
  25496. */
  25497. this.widths_ = {};
  25498. var labelCache = ol.render.canvas.labelCache;
  25499. labelCache.prune();
  25500. };
  25501. ol.inherits(ol.render.canvas.TextReplay, ol.render.canvas.Replay);
  25502. /**
  25503. * @param {string} font Font to use for measuring.
  25504. * @param {Array.<string>} lines Lines to measure.
  25505. * @param {Array.<number>} widths Array will be populated with the widths of
  25506. * each line.
  25507. * @return {number} Width of the whole text.
  25508. */
  25509. ol.render.canvas.TextReplay.measureTextWidths = function(font, lines, widths) {
  25510. var numLines = lines.length;
  25511. var width = 0;
  25512. var currentWidth, i;
  25513. for (i = 0; i < numLines; ++i) {
  25514. currentWidth = ol.render.canvas.measureTextWidth(font, lines[i]);
  25515. width = Math.max(width, currentWidth);
  25516. widths.push(currentWidth);
  25517. }
  25518. return width;
  25519. };
  25520. /**
  25521. * @inheritDoc
  25522. */
  25523. ol.render.canvas.TextReplay.prototype.drawText = function(geometry, feature) {
  25524. var fillState = this.textFillState_;
  25525. var strokeState = this.textStrokeState_;
  25526. var textState = this.textState_;
  25527. if (this.text_ === '' || !textState || (!fillState && !strokeState)) {
  25528. return;
  25529. }
  25530. var begin = this.coordinates.length;
  25531. var geometryType = geometry.getType();
  25532. var flatCoordinates = null;
  25533. var end = 2;
  25534. var stride = 2;
  25535. var i, ii;
  25536. if (textState.placement === ol.style.TextPlacement.LINE) {
  25537. if (!ol.extent.intersects(this.getBufferedMaxExtent(), geometry.getExtent())) {
  25538. return;
  25539. }
  25540. var ends;
  25541. flatCoordinates = geometry.getFlatCoordinates();
  25542. stride = geometry.getStride();
  25543. if (geometryType == ol.geom.GeometryType.LINE_STRING) {
  25544. ends = [flatCoordinates.length];
  25545. } else if (geometryType == ol.geom.GeometryType.MULTI_LINE_STRING) {
  25546. ends = geometry.getEnds();
  25547. } else if (geometryType == ol.geom.GeometryType.POLYGON) {
  25548. ends = geometry.getEnds().slice(0, 1);
  25549. } else if (geometryType == ol.geom.GeometryType.MULTI_POLYGON) {
  25550. var endss = geometry.getEndss();
  25551. ends = [];
  25552. for (i = 0, ii = endss.length; i < ii; ++i) {
  25553. ends.push(endss[i][0]);
  25554. }
  25555. }
  25556. this.beginGeometry(geometry, feature);
  25557. var textAlign = textState.textAlign;
  25558. var flatOffset = 0;
  25559. var flatEnd;
  25560. for (var o = 0, oo = ends.length; o < oo; ++o) {
  25561. if (textAlign == undefined) {
  25562. var range = ol.geom.flat.straightchunk.lineString(
  25563. textState.maxAngle, flatCoordinates, flatOffset, ends[o], stride);
  25564. flatOffset = range[0];
  25565. flatEnd = range[1];
  25566. } else {
  25567. flatEnd = ends[o];
  25568. }
  25569. for (i = flatOffset; i < flatEnd; i += stride) {
  25570. this.coordinates.push(flatCoordinates[i], flatCoordinates[i + 1]);
  25571. }
  25572. end = this.coordinates.length;
  25573. flatOffset = ends[o];
  25574. this.drawChars_(begin, end, this.declutterGroup_);
  25575. begin = end;
  25576. }
  25577. this.endGeometry(geometry, feature);
  25578. } else {
  25579. var label = this.getImage(this.text_, this.textKey_, this.fillKey_, this.strokeKey_);
  25580. var width = label.width / this.pixelRatio;
  25581. switch (geometryType) {
  25582. case ol.geom.GeometryType.POINT:
  25583. case ol.geom.GeometryType.MULTI_POINT:
  25584. flatCoordinates = geometry.getFlatCoordinates();
  25585. end = flatCoordinates.length;
  25586. break;
  25587. case ol.geom.GeometryType.LINE_STRING:
  25588. flatCoordinates = /** @type {ol.geom.LineString} */ (geometry).getFlatMidpoint();
  25589. break;
  25590. case ol.geom.GeometryType.CIRCLE:
  25591. flatCoordinates = /** @type {ol.geom.Circle} */ (geometry).getCenter();
  25592. break;
  25593. case ol.geom.GeometryType.MULTI_LINE_STRING:
  25594. flatCoordinates = /** @type {ol.geom.MultiLineString} */ (geometry).getFlatMidpoints();
  25595. end = flatCoordinates.length;
  25596. break;
  25597. case ol.geom.GeometryType.POLYGON:
  25598. flatCoordinates = /** @type {ol.geom.Polygon} */ (geometry).getFlatInteriorPoint();
  25599. if (!textState.overflow && flatCoordinates[2] / this.resolution < width) {
  25600. return;
  25601. }
  25602. stride = 3;
  25603. break;
  25604. case ol.geom.GeometryType.MULTI_POLYGON:
  25605. var interiorPoints = /** @type {ol.geom.MultiPolygon} */ (geometry).getFlatInteriorPoints();
  25606. flatCoordinates = [];
  25607. for (i = 0, ii = interiorPoints.length; i < ii; i += 3) {
  25608. if (textState.overflow || interiorPoints[i + 2] / this.resolution >= width) {
  25609. flatCoordinates.push(interiorPoints[i], interiorPoints[i + 1]);
  25610. }
  25611. }
  25612. end = flatCoordinates.length;
  25613. if (end == 0) {
  25614. return;
  25615. }
  25616. break;
  25617. default:
  25618. }
  25619. end = this.appendFlatCoordinates(flatCoordinates, 0, end, stride, false, false);
  25620. this.beginGeometry(geometry, feature);
  25621. if (textState.backgroundFill || textState.backgroundStroke) {
  25622. this.setFillStrokeStyle(textState.backgroundFill, textState.backgroundStroke);
  25623. this.updateFillStyle(this.state, this.applyFill, geometry);
  25624. this.updateStrokeStyle(this.state, this.applyStroke);
  25625. }
  25626. this.drawTextImage_(label, begin, end);
  25627. this.endGeometry(geometry, feature);
  25628. }
  25629. };
  25630. /**
  25631. * @param {string} text Text.
  25632. * @param {string} textKey Text style key.
  25633. * @param {string} fillKey Fill style key.
  25634. * @param {string} strokeKey Stroke style key.
  25635. * @return {HTMLCanvasElement} Image.
  25636. */
  25637. ol.render.canvas.TextReplay.prototype.getImage = function(text, textKey, fillKey, strokeKey) {
  25638. var label;
  25639. var key = strokeKey + textKey + text + fillKey + this.pixelRatio;
  25640. var labelCache = ol.render.canvas.labelCache;
  25641. if (!labelCache.containsKey(key)) {
  25642. var strokeState = strokeKey ? this.strokeStates[strokeKey] || this.textStrokeState_ : null;
  25643. var fillState = fillKey ? this.fillStates[fillKey] || this.textFillState_ : null;
  25644. var textState = this.textStates[textKey] || this.textState_;
  25645. var pixelRatio = this.pixelRatio;
  25646. var scale = textState.scale * pixelRatio;
  25647. var align = ol.render.replay.TEXT_ALIGN[textState.textAlign || ol.render.canvas.defaultTextAlign];
  25648. var strokeWidth = strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
  25649. var lines = text.split('\n');
  25650. var numLines = lines.length;
  25651. var widths = [];
  25652. var width = ol.render.canvas.TextReplay.measureTextWidths(textState.font, lines, widths);
  25653. var lineHeight = ol.render.canvas.measureTextHeight(textState.font);
  25654. var height = lineHeight * numLines;
  25655. var renderWidth = (width + strokeWidth);
  25656. var context = ol.dom.createCanvasContext2D(
  25657. Math.ceil(renderWidth * scale),
  25658. Math.ceil((height + strokeWidth) * scale));
  25659. label = context.canvas;
  25660. labelCache.set(key, label);
  25661. if (scale != 1) {
  25662. context.scale(scale, scale);
  25663. }
  25664. context.font = textState.font;
  25665. if (strokeKey) {
  25666. context.strokeStyle = strokeState.strokeStyle;
  25667. context.lineWidth = strokeWidth * (ol.has.SAFARI ? scale : 1);
  25668. context.lineCap = strokeState.lineCap;
  25669. context.lineJoin = strokeState.lineJoin;
  25670. context.miterLimit = strokeState.miterLimit;
  25671. if (ol.has.CANVAS_LINE_DASH && strokeState.lineDash.length) {
  25672. context.setLineDash(strokeState.lineDash);
  25673. context.lineDashOffset = strokeState.lineDashOffset;
  25674. }
  25675. }
  25676. if (fillKey) {
  25677. context.fillStyle = fillState.fillStyle;
  25678. }
  25679. context.textBaseline = 'middle';
  25680. context.textAlign = 'center';
  25681. var leftRight = (0.5 - align);
  25682. var x = align * label.width / scale + leftRight * strokeWidth;
  25683. var i;
  25684. if (strokeKey) {
  25685. for (i = 0; i < numLines; ++i) {
  25686. context.strokeText(lines[i], x + leftRight * widths[i], 0.5 * (strokeWidth + lineHeight) + i * lineHeight);
  25687. }
  25688. }
  25689. if (fillKey) {
  25690. for (i = 0; i < numLines; ++i) {
  25691. context.fillText(lines[i], x + leftRight * widths[i], 0.5 * (strokeWidth + lineHeight) + i * lineHeight);
  25692. }
  25693. }
  25694. }
  25695. return labelCache.get(key);
  25696. };
  25697. /**
  25698. * @private
  25699. * @param {HTMLCanvasElement} label Label.
  25700. * @param {number} begin Begin.
  25701. * @param {number} end End.
  25702. */
  25703. ol.render.canvas.TextReplay.prototype.drawTextImage_ = function(label, begin, end) {
  25704. var textState = this.textState_;
  25705. var strokeState = this.textStrokeState_;
  25706. var pixelRatio = this.pixelRatio;
  25707. var align = ol.render.replay.TEXT_ALIGN[textState.textAlign || ol.render.canvas.defaultTextAlign];
  25708. var baseline = ol.render.replay.TEXT_ALIGN[textState.textBaseline];
  25709. var strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0;
  25710. var anchorX = align * label.width / pixelRatio + 2 * (0.5 - align) * strokeWidth;
  25711. var anchorY = baseline * label.height / pixelRatio + 2 * (0.5 - baseline) * strokeWidth;
  25712. this.instructions.push([ol.render.canvas.Instruction.DRAW_IMAGE, begin, end,
  25713. label, (anchorX - this.textOffsetX_) * pixelRatio, (anchorY - this.textOffsetY_) * pixelRatio,
  25714. this.declutterGroup_, label.height, 1, 0, 0, this.textRotateWithView_, this.textRotation_,
  25715. 1, true, label.width,
  25716. textState.padding == ol.render.canvas.defaultPadding ?
  25717. ol.render.canvas.defaultPadding : textState.padding.map(function(p) {
  25718. return p * pixelRatio;
  25719. }),
  25720. !!textState.backgroundFill, !!textState.backgroundStroke
  25721. ]);
  25722. this.hitDetectionInstructions.push([ol.render.canvas.Instruction.DRAW_IMAGE, begin, end,
  25723. label, (anchorX - this.textOffsetX_) * pixelRatio, (anchorY - this.textOffsetY_) * pixelRatio,
  25724. this.declutterGroup_, label.height, 1, 0, 0, this.textRotateWithView_, this.textRotation_,
  25725. 1 / pixelRatio, true, label.width, textState.padding,
  25726. !!textState.backgroundFill, !!textState.backgroundStroke
  25727. ]);
  25728. };
  25729. /**
  25730. * @private
  25731. * @param {number} begin Begin.
  25732. * @param {number} end End.
  25733. * @param {ol.DeclutterGroup} declutterGroup Declutter group.
  25734. */
  25735. ol.render.canvas.TextReplay.prototype.drawChars_ = function(begin, end, declutterGroup) {
  25736. var strokeState = this.textStrokeState_;
  25737. var textState = this.textState_;
  25738. var fillState = this.textFillState_;
  25739. var strokeKey = this.strokeKey_;
  25740. if (strokeState) {
  25741. if (!(strokeKey in this.strokeStates)) {
  25742. this.strokeStates[strokeKey] = /** @type {ol.CanvasStrokeState} */ ({
  25743. strokeStyle: strokeState.strokeStyle,
  25744. lineCap: strokeState.lineCap,
  25745. lineDashOffset: strokeState.lineDashOffset,
  25746. lineWidth: strokeState.lineWidth,
  25747. lineJoin: strokeState.lineJoin,
  25748. miterLimit: strokeState.miterLimit,
  25749. lineDash: strokeState.lineDash
  25750. });
  25751. }
  25752. }
  25753. var textKey = this.textKey_;
  25754. if (!(this.textKey_ in this.textStates)) {
  25755. this.textStates[this.textKey_] = /** @type {ol.CanvasTextState} */ ({
  25756. font: textState.font,
  25757. textAlign: textState.textAlign || ol.render.canvas.defaultTextAlign,
  25758. scale: textState.scale
  25759. });
  25760. }
  25761. var fillKey = this.fillKey_;
  25762. if (fillState) {
  25763. if (!(fillKey in this.fillStates)) {
  25764. this.fillStates[fillKey] = /** @type {ol.CanvasFillState} */ ({
  25765. fillStyle: fillState.fillStyle
  25766. });
  25767. }
  25768. }
  25769. var pixelRatio = this.pixelRatio;
  25770. var baseline = ol.render.replay.TEXT_ALIGN[textState.textBaseline];
  25771. var offsetY = this.textOffsetY_ * pixelRatio;
  25772. var text = this.text_;
  25773. var font = textState.font;
  25774. var textScale = textState.scale;
  25775. var strokeWidth = strokeState ? strokeState.lineWidth * textScale / 2 : 0;
  25776. var widths = this.widths_[font];
  25777. if (!widths) {
  25778. this.widths_[font] = widths = {};
  25779. }
  25780. this.instructions.push([ol.render.canvas.Instruction.DRAW_CHARS,
  25781. begin, end, baseline, declutterGroup,
  25782. textState.overflow, fillKey, textState.maxAngle,
  25783. function(text) {
  25784. var width = widths[text];
  25785. if (!width) {
  25786. width = widths[text] = ol.render.canvas.measureTextWidth(font, text);
  25787. }
  25788. return width * textScale * pixelRatio;
  25789. },
  25790. offsetY, strokeKey, strokeWidth * pixelRatio, text, textKey, 1
  25791. ]);
  25792. this.hitDetectionInstructions.push([ol.render.canvas.Instruction.DRAW_CHARS,
  25793. begin, end, baseline, declutterGroup,
  25794. textState.overflow, fillKey, textState.maxAngle,
  25795. function(text) {
  25796. var width = widths[text];
  25797. if (!width) {
  25798. width = widths[text] = ol.render.canvas.measureTextWidth(font, text);
  25799. }
  25800. return width * textScale;
  25801. },
  25802. offsetY, strokeKey, strokeWidth, text, textKey, 1 / pixelRatio
  25803. ]);
  25804. };
  25805. /**
  25806. * @inheritDoc
  25807. */
  25808. ol.render.canvas.TextReplay.prototype.setTextStyle = function(textStyle, declutterGroup) {
  25809. var textState, fillState, strokeState;
  25810. if (!textStyle) {
  25811. this.text_ = '';
  25812. } else {
  25813. this.declutterGroup_ = /** @type {ol.DeclutterGroup} */ (declutterGroup);
  25814. var textFillStyle = textStyle.getFill();
  25815. if (!textFillStyle) {
  25816. fillState = this.textFillState_ = null;
  25817. } else {
  25818. fillState = this.textFillState_;
  25819. if (!fillState) {
  25820. fillState = this.textFillState_ = /** @type {ol.CanvasFillState} */ ({});
  25821. }
  25822. fillState.fillStyle = ol.colorlike.asColorLike(
  25823. textFillStyle.getColor() || ol.render.canvas.defaultFillStyle);
  25824. }
  25825. var textStrokeStyle = textStyle.getStroke();
  25826. if (!textStrokeStyle) {
  25827. strokeState = this.textStrokeState_ = null;
  25828. } else {
  25829. strokeState = this.textStrokeState_;
  25830. if (!strokeState) {
  25831. strokeState = this.textStrokeState_ = /** @type {ol.CanvasStrokeState} */ ({});
  25832. }
  25833. var lineDash = textStrokeStyle.getLineDash();
  25834. var lineDashOffset = textStrokeStyle.getLineDashOffset();
  25835. var lineWidth = textStrokeStyle.getWidth();
  25836. var miterLimit = textStrokeStyle.getMiterLimit();
  25837. strokeState.lineCap = textStrokeStyle.getLineCap() || ol.render.canvas.defaultLineCap;
  25838. strokeState.lineDash = lineDash ? lineDash.slice() : ol.render.canvas.defaultLineDash;
  25839. strokeState.lineDashOffset =
  25840. lineDashOffset === undefined ? ol.render.canvas.defaultLineDashOffset : lineDashOffset;
  25841. strokeState.lineJoin = textStrokeStyle.getLineJoin() || ol.render.canvas.defaultLineJoin;
  25842. strokeState.lineWidth =
  25843. lineWidth === undefined ? ol.render.canvas.defaultLineWidth : lineWidth;
  25844. strokeState.miterLimit =
  25845. miterLimit === undefined ? ol.render.canvas.defaultMiterLimit : miterLimit;
  25846. strokeState.strokeStyle = ol.colorlike.asColorLike(
  25847. textStrokeStyle.getColor() || ol.render.canvas.defaultStrokeStyle);
  25848. }
  25849. textState = this.textState_;
  25850. var font = textStyle.getFont() || ol.render.canvas.defaultFont;
  25851. ol.render.canvas.checkFont(font);
  25852. var textScale = textStyle.getScale();
  25853. textState.overflow = textStyle.getOverflow();
  25854. textState.font = font;
  25855. textState.maxAngle = textStyle.getMaxAngle();
  25856. textState.placement = textStyle.getPlacement();
  25857. textState.textAlign = textStyle.getTextAlign();
  25858. textState.textBaseline = textStyle.getTextBaseline() || ol.render.canvas.defaultTextBaseline;
  25859. textState.backgroundFill = textStyle.getBackgroundFill();
  25860. textState.backgroundStroke = textStyle.getBackgroundStroke();
  25861. textState.padding = textStyle.getPadding() || ol.render.canvas.defaultPadding;
  25862. textState.scale = textScale === undefined ? 1 : textScale;
  25863. var textOffsetX = textStyle.getOffsetX();
  25864. var textOffsetY = textStyle.getOffsetY();
  25865. var textRotateWithView = textStyle.getRotateWithView();
  25866. var textRotation = textStyle.getRotation();
  25867. this.text_ = textStyle.getText() || '';
  25868. this.textOffsetX_ = textOffsetX === undefined ? 0 : textOffsetX;
  25869. this.textOffsetY_ = textOffsetY === undefined ? 0 : textOffsetY;
  25870. this.textRotateWithView_ = textRotateWithView === undefined ? false : textRotateWithView;
  25871. this.textRotation_ = textRotation === undefined ? 0 : textRotation;
  25872. this.strokeKey_ = strokeState ?
  25873. (typeof strokeState.strokeStyle == 'string' ? strokeState.strokeStyle : ol.getUid(strokeState.strokeStyle)) +
  25874. strokeState.lineCap + strokeState.lineDashOffset + '|' + strokeState.lineWidth +
  25875. strokeState.lineJoin + strokeState.miterLimit + '[' + strokeState.lineDash.join() + ']' :
  25876. '';
  25877. this.textKey_ = textState.font + textState.scale + (textState.textAlign || '?');
  25878. this.fillKey_ = fillState ?
  25879. (typeof fillState.fillStyle == 'string' ? fillState.fillStyle : ('|' + ol.getUid(fillState.fillStyle))) :
  25880. '';
  25881. }
  25882. };
  25883. goog.provide('ol.render.canvas.ReplayGroup');
  25884. goog.require('ol');
  25885. goog.require('ol.array');
  25886. goog.require('ol.dom');
  25887. goog.require('ol.extent');
  25888. goog.require('ol.geom.flat.transform');
  25889. goog.require('ol.obj');
  25890. goog.require('ol.render.ReplayGroup');
  25891. goog.require('ol.render.ReplayType');
  25892. goog.require('ol.render.canvas.Replay');
  25893. goog.require('ol.render.canvas.ImageReplay');
  25894. goog.require('ol.render.canvas.LineStringReplay');
  25895. goog.require('ol.render.canvas.PolygonReplay');
  25896. goog.require('ol.render.canvas.TextReplay');
  25897. goog.require('ol.render.replay');
  25898. goog.require('ol.transform');
  25899. /**
  25900. * @constructor
  25901. * @extends {ol.render.ReplayGroup}
  25902. * @param {number} tolerance Tolerance.
  25903. * @param {ol.Extent} maxExtent Max extent.
  25904. * @param {number} resolution Resolution.
  25905. * @param {number} pixelRatio Pixel ratio.
  25906. * @param {boolean} overlaps The replay group can have overlapping geometries.
  25907. * @param {?} declutterTree Declutter tree
  25908. * for declutter processing in postrender.
  25909. * @param {number=} opt_renderBuffer Optional rendering buffer.
  25910. * @struct
  25911. */
  25912. ol.render.canvas.ReplayGroup = function(
  25913. tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree, opt_renderBuffer) {
  25914. ol.render.ReplayGroup.call(this);
  25915. /**
  25916. * Declutter tree.
  25917. * @private
  25918. */
  25919. this.declutterTree_ = declutterTree;
  25920. /**
  25921. * @type {ol.DeclutterGroup}
  25922. * @private
  25923. */
  25924. this.declutterGroup_ = null;
  25925. /**
  25926. * @private
  25927. * @type {number}
  25928. */
  25929. this.tolerance_ = tolerance;
  25930. /**
  25931. * @private
  25932. * @type {ol.Extent}
  25933. */
  25934. this.maxExtent_ = maxExtent;
  25935. /**
  25936. * @private
  25937. * @type {boolean}
  25938. */
  25939. this.overlaps_ = overlaps;
  25940. /**
  25941. * @private
  25942. * @type {number}
  25943. */
  25944. this.pixelRatio_ = pixelRatio;
  25945. /**
  25946. * @private
  25947. * @type {number}
  25948. */
  25949. this.resolution_ = resolution;
  25950. /**
  25951. * @private
  25952. * @type {number|undefined}
  25953. */
  25954. this.renderBuffer_ = opt_renderBuffer;
  25955. /**
  25956. * @private
  25957. * @type {!Object.<string,
  25958. * Object.<ol.render.ReplayType, ol.render.canvas.Replay>>}
  25959. */
  25960. this.replaysByZIndex_ = {};
  25961. /**
  25962. * @private
  25963. * @type {CanvasRenderingContext2D}
  25964. */
  25965. this.hitDetectionContext_ = ol.dom.createCanvasContext2D(1, 1);
  25966. /**
  25967. * @private
  25968. * @type {ol.Transform}
  25969. */
  25970. this.hitDetectionTransform_ = ol.transform.create();
  25971. };
  25972. ol.inherits(ol.render.canvas.ReplayGroup, ol.render.ReplayGroup);
  25973. /**
  25974. * This cache is used for storing calculated pixel circles for increasing performance.
  25975. * It is a static property to allow each Replaygroup to access it.
  25976. * @type {Object.<number, Array.<Array.<(boolean|undefined)>>>}
  25977. * @private
  25978. */
  25979. ol.render.canvas.ReplayGroup.circleArrayCache_ = {
  25980. 0: [[true]]
  25981. };
  25982. /**
  25983. * This method fills a row in the array from the given coordinate to the
  25984. * middle with `true`.
  25985. * @param {Array.<Array.<(boolean|undefined)>>} array The array that will be altered.
  25986. * @param {number} x X coordinate.
  25987. * @param {number} y Y coordinate.
  25988. * @private
  25989. */
  25990. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) {
  25991. var i;
  25992. var radius = Math.floor(array.length / 2);
  25993. if (x >= radius) {
  25994. for (i = radius; i < x; i++) {
  25995. array[i][y] = true;
  25996. }
  25997. } else if (x < radius) {
  25998. for (i = x + 1; i < radius; i++) {
  25999. array[i][y] = true;
  26000. }
  26001. }
  26002. };
  26003. /**
  26004. * This methods creates a circle inside a fitting array. Points inside the
  26005. * circle are marked by true, points on the outside are undefined.
  26006. * It uses the midpoint circle algorithm.
  26007. * A cache is used to increase performance.
  26008. * @param {number} radius Radius.
  26009. * @returns {Array.<Array.<(boolean|undefined)>>} An array with marked circle points.
  26010. * @private
  26011. */
  26012. ol.render.canvas.ReplayGroup.getCircleArray_ = function(radius) {
  26013. if (ol.render.canvas.ReplayGroup.circleArrayCache_[radius] !== undefined) {
  26014. return ol.render.canvas.ReplayGroup.circleArrayCache_[radius];
  26015. }
  26016. var arraySize = radius * 2 + 1;
  26017. var arr = new Array(arraySize);
  26018. for (var i = 0; i < arraySize; i++) {
  26019. arr[i] = new Array(arraySize);
  26020. }
  26021. var x = radius;
  26022. var y = 0;
  26023. var error = 0;
  26024. while (x >= y) {
  26025. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + x, radius + y);
  26026. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + y, radius + x);
  26027. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - y, radius + x);
  26028. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - x, radius + y);
  26029. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - x, radius - y);
  26030. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - y, radius - x);
  26031. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + y, radius - x);
  26032. ol.render.canvas.ReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + x, radius - y);
  26033. y++;
  26034. error += 1 + 2 * y;
  26035. if (2 * (error - x) + 1 > 0) {
  26036. x -= 1;
  26037. error += 1 - 2 * x;
  26038. }
  26039. }
  26040. ol.render.canvas.ReplayGroup.circleArrayCache_[radius] = arr;
  26041. return arr;
  26042. };
  26043. /**
  26044. * @param {!Object.<string, Array.<*>>} declutterReplays Declutter replays.
  26045. * @param {CanvasRenderingContext2D} context Context.
  26046. * @param {number} rotation Rotation.
  26047. */
  26048. ol.render.canvas.ReplayGroup.replayDeclutter = function(declutterReplays, context, rotation) {
  26049. var zs = Object.keys(declutterReplays).map(Number).sort(ol.array.numberSafeCompareFunction);
  26050. var skippedFeatureUids = {};
  26051. for (var z = 0, zz = zs.length; z < zz; ++z) {
  26052. var replayData = declutterReplays[zs[z].toString()];
  26053. for (var i = 0, ii = replayData.length; i < ii;) {
  26054. var replay = replayData[i++];
  26055. var transform = replayData[i++];
  26056. replay.replay(context, transform, rotation, skippedFeatureUids);
  26057. }
  26058. }
  26059. };
  26060. /**
  26061. * @param {boolean} group Group with previous replay.
  26062. * @return {ol.DeclutterGroup} Declutter instruction group.
  26063. */
  26064. ol.render.canvas.ReplayGroup.prototype.addDeclutter = function(group) {
  26065. var declutter = null;
  26066. if (this.declutterTree_) {
  26067. if (group) {
  26068. declutter = this.declutterGroup_;
  26069. /** @type {number} */ (declutter[4])++;
  26070. } else {
  26071. declutter = this.declutterGroup_ = ol.extent.createEmpty();
  26072. declutter.push(1);
  26073. }
  26074. }
  26075. return declutter;
  26076. };
  26077. /**
  26078. * @param {CanvasRenderingContext2D} context Context.
  26079. * @param {ol.Transform} transform Transform.
  26080. */
  26081. ol.render.canvas.ReplayGroup.prototype.clip = function(context, transform) {
  26082. var flatClipCoords = this.getClipCoords(transform);
  26083. context.beginPath();
  26084. context.moveTo(flatClipCoords[0], flatClipCoords[1]);
  26085. context.lineTo(flatClipCoords[2], flatClipCoords[3]);
  26086. context.lineTo(flatClipCoords[4], flatClipCoords[5]);
  26087. context.lineTo(flatClipCoords[6], flatClipCoords[7]);
  26088. context.clip();
  26089. };
  26090. /**
  26091. * @param {Array.<ol.render.ReplayType>} replays Replays.
  26092. * @return {boolean} Has replays of the provided types.
  26093. */
  26094. ol.render.canvas.ReplayGroup.prototype.hasReplays = function(replays) {
  26095. for (var zIndex in this.replaysByZIndex_) {
  26096. var candidates = this.replaysByZIndex_[zIndex];
  26097. for (var i = 0, ii = replays.length; i < ii; ++i) {
  26098. if (replays[i] in candidates) {
  26099. return true;
  26100. }
  26101. }
  26102. }
  26103. return false;
  26104. };
  26105. /**
  26106. * FIXME empty description for jsdoc
  26107. */
  26108. ol.render.canvas.ReplayGroup.prototype.finish = function() {
  26109. var zKey;
  26110. for (zKey in this.replaysByZIndex_) {
  26111. var replays = this.replaysByZIndex_[zKey];
  26112. var replayKey;
  26113. for (replayKey in replays) {
  26114. replays[replayKey].finish();
  26115. }
  26116. }
  26117. };
  26118. /**
  26119. * @param {ol.Coordinate} coordinate Coordinate.
  26120. * @param {number} resolution Resolution.
  26121. * @param {number} rotation Rotation.
  26122. * @param {number} hitTolerance Hit tolerance in pixels.
  26123. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  26124. * to skip.
  26125. * @param {function((ol.Feature|ol.render.Feature)): T} callback Feature
  26126. * callback.
  26127. * @param {Object.<string, ol.DeclutterGroup>} declutterReplays Declutter
  26128. * replays.
  26129. * @return {T|undefined} Callback result.
  26130. * @template T
  26131. */
  26132. ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
  26133. coordinate, resolution, rotation, hitTolerance, skippedFeaturesHash, callback, declutterReplays) {
  26134. hitTolerance = Math.round(hitTolerance);
  26135. var contextSize = hitTolerance * 2 + 1;
  26136. var transform = ol.transform.compose(this.hitDetectionTransform_,
  26137. hitTolerance + 0.5, hitTolerance + 0.5,
  26138. 1 / resolution, -1 / resolution,
  26139. -rotation,
  26140. -coordinate[0], -coordinate[1]);
  26141. var context = this.hitDetectionContext_;
  26142. if (context.canvas.width !== contextSize || context.canvas.height !== contextSize) {
  26143. context.canvas.width = contextSize;
  26144. context.canvas.height = contextSize;
  26145. } else {
  26146. context.clearRect(0, 0, contextSize, contextSize);
  26147. }
  26148. /**
  26149. * @type {ol.Extent}
  26150. */
  26151. var hitExtent;
  26152. if (this.renderBuffer_ !== undefined) {
  26153. hitExtent = ol.extent.createEmpty();
  26154. ol.extent.extendCoordinate(hitExtent, coordinate);
  26155. ol.extent.buffer(hitExtent, resolution * (this.renderBuffer_ + hitTolerance), hitExtent);
  26156. }
  26157. var mask = ol.render.canvas.ReplayGroup.getCircleArray_(hitTolerance);
  26158. var declutteredFeatures;
  26159. if (this.declutterTree_) {
  26160. declutteredFeatures = this.declutterTree_.all().map(function(entry) {
  26161. return entry.value;
  26162. });
  26163. }
  26164. var replayType;
  26165. /**
  26166. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26167. * @return {?} Callback result.
  26168. */
  26169. function featureCallback(feature) {
  26170. var imageData = context.getImageData(0, 0, contextSize, contextSize).data;
  26171. for (var i = 0; i < contextSize; i++) {
  26172. for (var j = 0; j < contextSize; j++) {
  26173. if (mask[i][j]) {
  26174. if (imageData[(j * contextSize + i) * 4 + 3] > 0) {
  26175. var result;
  26176. if (!(declutteredFeatures && (replayType == ol.render.ReplayType.IMAGE || replayType == ol.render.ReplayType.TEXT)) ||
  26177. declutteredFeatures.indexOf(feature) !== -1) {
  26178. result = callback(feature);
  26179. }
  26180. if (result) {
  26181. return result;
  26182. } else {
  26183. context.clearRect(0, 0, contextSize, contextSize);
  26184. return undefined;
  26185. }
  26186. }
  26187. }
  26188. }
  26189. }
  26190. }
  26191. /** @type {Array.<number>} */
  26192. var zs = Object.keys(this.replaysByZIndex_).map(Number);
  26193. zs.sort(ol.array.numberSafeCompareFunction);
  26194. var i, j, replays, replay, result;
  26195. for (i = zs.length - 1; i >= 0; --i) {
  26196. var zIndexKey = zs[i].toString();
  26197. replays = this.replaysByZIndex_[zIndexKey];
  26198. for (j = ol.render.replay.ORDER.length - 1; j >= 0; --j) {
  26199. replayType = ol.render.replay.ORDER[j];
  26200. replay = replays[replayType];
  26201. if (replay !== undefined) {
  26202. if (declutterReplays &&
  26203. (replayType == ol.render.ReplayType.IMAGE || replayType == ol.render.ReplayType.TEXT)) {
  26204. var declutter = declutterReplays[zIndexKey];
  26205. if (!declutter) {
  26206. declutterReplays[zIndexKey] = [replay, transform.slice(0)];
  26207. } else {
  26208. declutter.push(replay, transform.slice(0));
  26209. }
  26210. } else {
  26211. result = replay.replayHitDetection(context, transform, rotation,
  26212. skippedFeaturesHash, featureCallback, hitExtent);
  26213. if (result) {
  26214. return result;
  26215. }
  26216. }
  26217. }
  26218. }
  26219. }
  26220. return undefined;
  26221. };
  26222. /**
  26223. * @param {ol.Transform} transform Transform.
  26224. * @return {Array.<number>} Clip coordinates.
  26225. */
  26226. ol.render.canvas.ReplayGroup.prototype.getClipCoords = function(transform) {
  26227. var maxExtent = this.maxExtent_;
  26228. var minX = maxExtent[0];
  26229. var minY = maxExtent[1];
  26230. var maxX = maxExtent[2];
  26231. var maxY = maxExtent[3];
  26232. var flatClipCoords = [minX, minY, minX, maxY, maxX, maxY, maxX, minY];
  26233. ol.geom.flat.transform.transform2D(
  26234. flatClipCoords, 0, 8, 2, transform, flatClipCoords);
  26235. return flatClipCoords;
  26236. };
  26237. /**
  26238. * @inheritDoc
  26239. */
  26240. ol.render.canvas.ReplayGroup.prototype.getReplay = function(zIndex, replayType) {
  26241. var zIndexKey = zIndex !== undefined ? zIndex.toString() : '0';
  26242. var replays = this.replaysByZIndex_[zIndexKey];
  26243. if (replays === undefined) {
  26244. replays = {};
  26245. this.replaysByZIndex_[zIndexKey] = replays;
  26246. }
  26247. var replay = replays[replayType];
  26248. if (replay === undefined) {
  26249. var Constructor = ol.render.canvas.ReplayGroup.BATCH_CONSTRUCTORS_[replayType];
  26250. replay = new Constructor(this.tolerance_, this.maxExtent_,
  26251. this.resolution_, this.pixelRatio_, this.overlaps_, this.declutterTree_);
  26252. replays[replayType] = replay;
  26253. }
  26254. return replay;
  26255. };
  26256. /**
  26257. * @return {Object.<string, Object.<ol.render.ReplayType, ol.render.canvas.Replay>>} Replays.
  26258. */
  26259. ol.render.canvas.ReplayGroup.prototype.getReplays = function() {
  26260. return this.replaysByZIndex_;
  26261. };
  26262. /**
  26263. * @inheritDoc
  26264. */
  26265. ol.render.canvas.ReplayGroup.prototype.isEmpty = function() {
  26266. return ol.obj.isEmpty(this.replaysByZIndex_);
  26267. };
  26268. /**
  26269. * @param {CanvasRenderingContext2D} context Context.
  26270. * @param {ol.Transform} transform Transform.
  26271. * @param {number} viewRotation View rotation.
  26272. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  26273. * to skip.
  26274. * @param {Array.<ol.render.ReplayType>=} opt_replayTypes Ordered replay types
  26275. * to replay. Default is {@link ol.render.replay.ORDER}
  26276. * @param {Object.<string, ol.DeclutterGroup>=} opt_declutterReplays Declutter
  26277. * replays.
  26278. */
  26279. ol.render.canvas.ReplayGroup.prototype.replay = function(context,
  26280. transform, viewRotation, skippedFeaturesHash, opt_replayTypes, opt_declutterReplays) {
  26281. /** @type {Array.<number>} */
  26282. var zs = Object.keys(this.replaysByZIndex_).map(Number);
  26283. zs.sort(ol.array.numberSafeCompareFunction);
  26284. // setup clipping so that the parts of over-simplified geometries are not
  26285. // visible outside the current extent when panning
  26286. context.save();
  26287. this.clip(context, transform);
  26288. var replayTypes = opt_replayTypes ? opt_replayTypes : ol.render.replay.ORDER;
  26289. var i, ii, j, jj, replays, replay;
  26290. for (i = 0, ii = zs.length; i < ii; ++i) {
  26291. var zIndexKey = zs[i].toString();
  26292. replays = this.replaysByZIndex_[zIndexKey];
  26293. for (j = 0, jj = replayTypes.length; j < jj; ++j) {
  26294. var replayType = replayTypes[j];
  26295. replay = replays[replayType];
  26296. if (replay !== undefined) {
  26297. if (opt_declutterReplays &&
  26298. (replayType == ol.render.ReplayType.IMAGE || replayType == ol.render.ReplayType.TEXT)) {
  26299. var declutter = opt_declutterReplays[zIndexKey];
  26300. if (!declutter) {
  26301. opt_declutterReplays[zIndexKey] = [replay, transform.slice(0)];
  26302. } else {
  26303. declutter.push(replay, transform.slice(0));
  26304. }
  26305. } else {
  26306. replay.replay(context, transform, viewRotation, skippedFeaturesHash);
  26307. }
  26308. }
  26309. }
  26310. }
  26311. context.restore();
  26312. };
  26313. /**
  26314. * @const
  26315. * @private
  26316. * @type {Object.<ol.render.ReplayType,
  26317. * function(new: ol.render.canvas.Replay, number, ol.Extent,
  26318. * number, number, boolean, Array.<ol.DeclutterGroup>)>}
  26319. */
  26320. ol.render.canvas.ReplayGroup.BATCH_CONSTRUCTORS_ = {
  26321. 'Circle': ol.render.canvas.PolygonReplay,
  26322. 'Default': ol.render.canvas.Replay,
  26323. 'Image': ol.render.canvas.ImageReplay,
  26324. 'LineString': ol.render.canvas.LineStringReplay,
  26325. 'Polygon': ol.render.canvas.PolygonReplay,
  26326. 'Text': ol.render.canvas.TextReplay
  26327. };
  26328. goog.provide('ol.renderer.vector');
  26329. goog.require('ol');
  26330. goog.require('ol.ImageState');
  26331. goog.require('ol.geom.GeometryType');
  26332. goog.require('ol.render.ReplayType');
  26333. /**
  26334. * @param {ol.Feature|ol.render.Feature} feature1 Feature 1.
  26335. * @param {ol.Feature|ol.render.Feature} feature2 Feature 2.
  26336. * @return {number} Order.
  26337. */
  26338. ol.renderer.vector.defaultOrder = function(feature1, feature2) {
  26339. return ol.getUid(feature1) - ol.getUid(feature2);
  26340. };
  26341. /**
  26342. * @param {number} resolution Resolution.
  26343. * @param {number} pixelRatio Pixel ratio.
  26344. * @return {number} Squared pixel tolerance.
  26345. */
  26346. ol.renderer.vector.getSquaredTolerance = function(resolution, pixelRatio) {
  26347. var tolerance = ol.renderer.vector.getTolerance(resolution, pixelRatio);
  26348. return tolerance * tolerance;
  26349. };
  26350. /**
  26351. * @param {number} resolution Resolution.
  26352. * @param {number} pixelRatio Pixel ratio.
  26353. * @return {number} Pixel tolerance.
  26354. */
  26355. ol.renderer.vector.getTolerance = function(resolution, pixelRatio) {
  26356. return ol.SIMPLIFY_TOLERANCE * resolution / pixelRatio;
  26357. };
  26358. /**
  26359. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26360. * @param {ol.geom.Circle} geometry Geometry.
  26361. * @param {ol.style.Style} style Style.
  26362. * @param {ol.Feature} feature Feature.
  26363. * @private
  26364. */
  26365. ol.renderer.vector.renderCircleGeometry_ = function(replayGroup, geometry, style, feature) {
  26366. var fillStyle = style.getFill();
  26367. var strokeStyle = style.getStroke();
  26368. if (fillStyle || strokeStyle) {
  26369. var circleReplay = replayGroup.getReplay(
  26370. style.getZIndex(), ol.render.ReplayType.CIRCLE);
  26371. circleReplay.setFillStrokeStyle(fillStyle, strokeStyle);
  26372. circleReplay.drawCircle(geometry, feature);
  26373. }
  26374. var textStyle = style.getText();
  26375. if (textStyle) {
  26376. var textReplay = replayGroup.getReplay(
  26377. style.getZIndex(), ol.render.ReplayType.TEXT);
  26378. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
  26379. textReplay.drawText(geometry, feature);
  26380. }
  26381. };
  26382. /**
  26383. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26384. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26385. * @param {ol.style.Style} style Style.
  26386. * @param {number} squaredTolerance Squared tolerance.
  26387. * @param {function(this: T, ol.events.Event)} listener Listener function.
  26388. * @param {T} thisArg Value to use as `this` when executing `listener`.
  26389. * @return {boolean} `true` if style is loading.
  26390. * @template T
  26391. */
  26392. ol.renderer.vector.renderFeature = function(
  26393. replayGroup, feature, style, squaredTolerance, listener, thisArg) {
  26394. var loading = false;
  26395. var imageStyle, imageState;
  26396. imageStyle = style.getImage();
  26397. if (imageStyle) {
  26398. imageState = imageStyle.getImageState();
  26399. if (imageState == ol.ImageState.LOADED ||
  26400. imageState == ol.ImageState.ERROR) {
  26401. imageStyle.unlistenImageChange(listener, thisArg);
  26402. } else {
  26403. if (imageState == ol.ImageState.IDLE) {
  26404. imageStyle.load();
  26405. }
  26406. imageState = imageStyle.getImageState();
  26407. imageStyle.listenImageChange(listener, thisArg);
  26408. loading = true;
  26409. }
  26410. }
  26411. ol.renderer.vector.renderFeature_(replayGroup, feature, style,
  26412. squaredTolerance);
  26413. return loading;
  26414. };
  26415. /**
  26416. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26417. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26418. * @param {ol.style.Style} style Style.
  26419. * @param {number} squaredTolerance Squared tolerance.
  26420. * @private
  26421. */
  26422. ol.renderer.vector.renderFeature_ = function(
  26423. replayGroup, feature, style, squaredTolerance) {
  26424. var geometry = style.getGeometryFunction()(feature);
  26425. if (!geometry) {
  26426. return;
  26427. }
  26428. var simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
  26429. var renderer = style.getRenderer();
  26430. if (renderer) {
  26431. ol.renderer.vector.renderGeometry_(replayGroup, simplifiedGeometry, style, feature);
  26432. } else {
  26433. var geometryRenderer =
  26434. ol.renderer.vector.GEOMETRY_RENDERERS_[simplifiedGeometry.getType()];
  26435. geometryRenderer(replayGroup, simplifiedGeometry, style, feature);
  26436. }
  26437. };
  26438. /**
  26439. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26440. * @param {ol.geom.Geometry} geometry Geometry.
  26441. * @param {ol.style.Style} style Style.
  26442. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26443. * @private
  26444. */
  26445. ol.renderer.vector.renderGeometry_ = function(replayGroup, geometry, style, feature) {
  26446. if (geometry.getType() == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
  26447. var geometries = /** @type {ol.geom.GeometryCollection} */ (geometry).getGeometries();
  26448. for (var i = 0, ii = geometries.length; i < ii; ++i) {
  26449. ol.renderer.vector.renderGeometry_(replayGroup, geometries[i], style, feature);
  26450. }
  26451. return;
  26452. }
  26453. var replay = replayGroup.getReplay(style.getZIndex(), ol.render.ReplayType.DEFAULT);
  26454. replay.drawCustom(/** @type {ol.geom.SimpleGeometry} */ (geometry), feature, style.getRenderer());
  26455. };
  26456. /**
  26457. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26458. * @param {ol.geom.GeometryCollection} geometry Geometry.
  26459. * @param {ol.style.Style} style Style.
  26460. * @param {ol.Feature} feature Feature.
  26461. * @private
  26462. */
  26463. ol.renderer.vector.renderGeometryCollectionGeometry_ = function(replayGroup, geometry, style, feature) {
  26464. var geometries = geometry.getGeometriesArray();
  26465. var i, ii;
  26466. for (i = 0, ii = geometries.length; i < ii; ++i) {
  26467. var geometryRenderer =
  26468. ol.renderer.vector.GEOMETRY_RENDERERS_[geometries[i].getType()];
  26469. geometryRenderer(replayGroup, geometries[i], style, feature);
  26470. }
  26471. };
  26472. /**
  26473. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26474. * @param {ol.geom.LineString|ol.render.Feature} geometry Geometry.
  26475. * @param {ol.style.Style} style Style.
  26476. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26477. * @private
  26478. */
  26479. ol.renderer.vector.renderLineStringGeometry_ = function(replayGroup, geometry, style, feature) {
  26480. var strokeStyle = style.getStroke();
  26481. if (strokeStyle) {
  26482. var lineStringReplay = replayGroup.getReplay(
  26483. style.getZIndex(), ol.render.ReplayType.LINE_STRING);
  26484. lineStringReplay.setFillStrokeStyle(null, strokeStyle);
  26485. lineStringReplay.drawLineString(geometry, feature);
  26486. }
  26487. var textStyle = style.getText();
  26488. if (textStyle) {
  26489. var textReplay = replayGroup.getReplay(
  26490. style.getZIndex(), ol.render.ReplayType.TEXT);
  26491. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
  26492. textReplay.drawText(geometry, feature);
  26493. }
  26494. };
  26495. /**
  26496. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26497. * @param {ol.geom.MultiLineString|ol.render.Feature} geometry Geometry.
  26498. * @param {ol.style.Style} style Style.
  26499. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26500. * @private
  26501. */
  26502. ol.renderer.vector.renderMultiLineStringGeometry_ = function(replayGroup, geometry, style, feature) {
  26503. var strokeStyle = style.getStroke();
  26504. if (strokeStyle) {
  26505. var lineStringReplay = replayGroup.getReplay(
  26506. style.getZIndex(), ol.render.ReplayType.LINE_STRING);
  26507. lineStringReplay.setFillStrokeStyle(null, strokeStyle);
  26508. lineStringReplay.drawMultiLineString(geometry, feature);
  26509. }
  26510. var textStyle = style.getText();
  26511. if (textStyle) {
  26512. var textReplay = replayGroup.getReplay(
  26513. style.getZIndex(), ol.render.ReplayType.TEXT);
  26514. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
  26515. textReplay.drawText(geometry, feature);
  26516. }
  26517. };
  26518. /**
  26519. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26520. * @param {ol.geom.MultiPolygon} geometry Geometry.
  26521. * @param {ol.style.Style} style Style.
  26522. * @param {ol.Feature} feature Feature.
  26523. * @private
  26524. */
  26525. ol.renderer.vector.renderMultiPolygonGeometry_ = function(replayGroup, geometry, style, feature) {
  26526. var fillStyle = style.getFill();
  26527. var strokeStyle = style.getStroke();
  26528. if (strokeStyle || fillStyle) {
  26529. var polygonReplay = replayGroup.getReplay(
  26530. style.getZIndex(), ol.render.ReplayType.POLYGON);
  26531. polygonReplay.setFillStrokeStyle(fillStyle, strokeStyle);
  26532. polygonReplay.drawMultiPolygon(geometry, feature);
  26533. }
  26534. var textStyle = style.getText();
  26535. if (textStyle) {
  26536. var textReplay = replayGroup.getReplay(
  26537. style.getZIndex(), ol.render.ReplayType.TEXT);
  26538. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
  26539. textReplay.drawText(geometry, feature);
  26540. }
  26541. };
  26542. /**
  26543. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26544. * @param {ol.geom.Point|ol.render.Feature} geometry Geometry.
  26545. * @param {ol.style.Style} style Style.
  26546. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26547. * @private
  26548. */
  26549. ol.renderer.vector.renderPointGeometry_ = function(replayGroup, geometry, style, feature) {
  26550. var imageStyle = style.getImage();
  26551. if (imageStyle) {
  26552. if (imageStyle.getImageState() != ol.ImageState.LOADED) {
  26553. return;
  26554. }
  26555. var imageReplay = replayGroup.getReplay(
  26556. style.getZIndex(), ol.render.ReplayType.IMAGE);
  26557. imageReplay.setImageStyle(imageStyle, replayGroup.addDeclutter(false));
  26558. imageReplay.drawPoint(geometry, feature);
  26559. }
  26560. var textStyle = style.getText();
  26561. if (textStyle) {
  26562. var textReplay = replayGroup.getReplay(
  26563. style.getZIndex(), ol.render.ReplayType.TEXT);
  26564. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(!!imageStyle));
  26565. textReplay.drawText(geometry, feature);
  26566. }
  26567. };
  26568. /**
  26569. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26570. * @param {ol.geom.MultiPoint|ol.render.Feature} geometry Geometry.
  26571. * @param {ol.style.Style} style Style.
  26572. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26573. * @private
  26574. */
  26575. ol.renderer.vector.renderMultiPointGeometry_ = function(replayGroup, geometry, style, feature) {
  26576. var imageStyle = style.getImage();
  26577. if (imageStyle) {
  26578. if (imageStyle.getImageState() != ol.ImageState.LOADED) {
  26579. return;
  26580. }
  26581. var imageReplay = replayGroup.getReplay(
  26582. style.getZIndex(), ol.render.ReplayType.IMAGE);
  26583. imageReplay.setImageStyle(imageStyle, replayGroup.addDeclutter(false));
  26584. imageReplay.drawMultiPoint(geometry, feature);
  26585. }
  26586. var textStyle = style.getText();
  26587. if (textStyle) {
  26588. var textReplay = replayGroup.getReplay(
  26589. style.getZIndex(), ol.render.ReplayType.TEXT);
  26590. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(!!imageStyle));
  26591. textReplay.drawText(geometry, feature);
  26592. }
  26593. };
  26594. /**
  26595. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  26596. * @param {ol.geom.Polygon|ol.render.Feature} geometry Geometry.
  26597. * @param {ol.style.Style} style Style.
  26598. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26599. * @private
  26600. */
  26601. ol.renderer.vector.renderPolygonGeometry_ = function(replayGroup, geometry, style, feature) {
  26602. var fillStyle = style.getFill();
  26603. var strokeStyle = style.getStroke();
  26604. if (fillStyle || strokeStyle) {
  26605. var polygonReplay = replayGroup.getReplay(
  26606. style.getZIndex(), ol.render.ReplayType.POLYGON);
  26607. polygonReplay.setFillStrokeStyle(fillStyle, strokeStyle);
  26608. polygonReplay.drawPolygon(geometry, feature);
  26609. }
  26610. var textStyle = style.getText();
  26611. if (textStyle) {
  26612. var textReplay = replayGroup.getReplay(
  26613. style.getZIndex(), ol.render.ReplayType.TEXT);
  26614. textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
  26615. textReplay.drawText(geometry, feature);
  26616. }
  26617. };
  26618. /**
  26619. * @const
  26620. * @private
  26621. * @type {Object.<ol.geom.GeometryType,
  26622. * function(ol.render.ReplayGroup, ol.geom.Geometry,
  26623. * ol.style.Style, Object)>}
  26624. */
  26625. ol.renderer.vector.GEOMETRY_RENDERERS_ = {
  26626. 'Point': ol.renderer.vector.renderPointGeometry_,
  26627. 'LineString': ol.renderer.vector.renderLineStringGeometry_,
  26628. 'Polygon': ol.renderer.vector.renderPolygonGeometry_,
  26629. 'MultiPoint': ol.renderer.vector.renderMultiPointGeometry_,
  26630. 'MultiLineString': ol.renderer.vector.renderMultiLineStringGeometry_,
  26631. 'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_,
  26632. 'GeometryCollection': ol.renderer.vector.renderGeometryCollectionGeometry_,
  26633. 'Circle': ol.renderer.vector.renderCircleGeometry_
  26634. };
  26635. goog.provide('ol.renderer.canvas.VectorLayer');
  26636. goog.require('ol');
  26637. goog.require('ol.LayerType');
  26638. goog.require('ol.ViewHint');
  26639. goog.require('ol.dom');
  26640. goog.require('ol.events');
  26641. goog.require('ol.events.EventType');
  26642. goog.require('ol.ext.rbush');
  26643. goog.require('ol.extent');
  26644. goog.require('ol.render.EventType');
  26645. goog.require('ol.render.canvas');
  26646. goog.require('ol.render.canvas.ReplayGroup');
  26647. goog.require('ol.renderer.Type');
  26648. goog.require('ol.renderer.canvas.Layer');
  26649. goog.require('ol.renderer.vector');
  26650. /**
  26651. * @constructor
  26652. * @extends {ol.renderer.canvas.Layer}
  26653. * @param {ol.layer.Vector} vectorLayer Vector layer.
  26654. * @api
  26655. */
  26656. ol.renderer.canvas.VectorLayer = function(vectorLayer) {
  26657. ol.renderer.canvas.Layer.call(this, vectorLayer);
  26658. /**
  26659. * Declutter tree.
  26660. * @private
  26661. */
  26662. this.declutterTree_ = vectorLayer.getDeclutter() ?
  26663. ol.ext.rbush(9) : null;
  26664. /**
  26665. * @private
  26666. * @type {boolean}
  26667. */
  26668. this.dirty_ = false;
  26669. /**
  26670. * @private
  26671. * @type {number}
  26672. */
  26673. this.renderedRevision_ = -1;
  26674. /**
  26675. * @private
  26676. * @type {number}
  26677. */
  26678. this.renderedResolution_ = NaN;
  26679. /**
  26680. * @private
  26681. * @type {ol.Extent}
  26682. */
  26683. this.renderedExtent_ = ol.extent.createEmpty();
  26684. /**
  26685. * @private
  26686. * @type {function(ol.Feature, ol.Feature): number|null}
  26687. */
  26688. this.renderedRenderOrder_ = null;
  26689. /**
  26690. * @private
  26691. * @type {ol.render.canvas.ReplayGroup}
  26692. */
  26693. this.replayGroup_ = null;
  26694. /**
  26695. * A new replay group had to be created by `prepareFrame()`
  26696. * @type {boolean}
  26697. */
  26698. this.replayGroupChanged = true;
  26699. /**
  26700. * @type {CanvasRenderingContext2D}
  26701. */
  26702. this.context = ol.dom.createCanvasContext2D();
  26703. ol.events.listen(ol.render.canvas.labelCache, ol.events.EventType.CLEAR, this.handleFontsChanged_, this);
  26704. };
  26705. ol.inherits(ol.renderer.canvas.VectorLayer, ol.renderer.canvas.Layer);
  26706. /**
  26707. * Determine if this renderer handles the provided layer.
  26708. * @param {ol.renderer.Type} type The renderer type.
  26709. * @param {ol.layer.Layer} layer The candidate layer.
  26710. * @return {boolean} The renderer can render the layer.
  26711. */
  26712. ol.renderer.canvas.VectorLayer['handles'] = function(type, layer) {
  26713. return type === ol.renderer.Type.CANVAS && layer.getType() === ol.LayerType.VECTOR;
  26714. };
  26715. /**
  26716. * Create a layer renderer.
  26717. * @param {ol.renderer.Map} mapRenderer The map renderer.
  26718. * @param {ol.layer.Layer} layer The layer to be rendererd.
  26719. * @return {ol.renderer.canvas.VectorLayer} The layer renderer.
  26720. */
  26721. ol.renderer.canvas.VectorLayer['create'] = function(mapRenderer, layer) {
  26722. return new ol.renderer.canvas.VectorLayer(/** @type {ol.layer.Vector} */ (layer));
  26723. };
  26724. /**
  26725. * @inheritDoc
  26726. */
  26727. ol.renderer.canvas.VectorLayer.prototype.disposeInternal = function() {
  26728. ol.events.unlisten(ol.render.canvas.labelCache, ol.events.EventType.CLEAR, this.handleFontsChanged_, this);
  26729. ol.renderer.canvas.Layer.prototype.disposeInternal.call(this);
  26730. };
  26731. /**
  26732. * @inheritDoc
  26733. */
  26734. ol.renderer.canvas.VectorLayer.prototype.composeFrame = function(frameState, layerState, context) {
  26735. var extent = frameState.extent;
  26736. var pixelRatio = frameState.pixelRatio;
  26737. var skippedFeatureUids = layerState.managed ?
  26738. frameState.skippedFeatureUids : {};
  26739. var viewState = frameState.viewState;
  26740. var projection = viewState.projection;
  26741. var rotation = viewState.rotation;
  26742. var projectionExtent = projection.getExtent();
  26743. var vectorSource = /** @type {ol.source.Vector} */ (this.getLayer().getSource());
  26744. var transform = this.getTransform(frameState, 0);
  26745. this.preCompose(context, frameState, transform);
  26746. // clipped rendering if layer extent is set
  26747. var clipExtent = layerState.extent;
  26748. var clipped = clipExtent !== undefined;
  26749. if (clipped) {
  26750. this.clip(context, frameState, /** @type {ol.Extent} */ (clipExtent));
  26751. }
  26752. var replayGroup = this.replayGroup_;
  26753. if (replayGroup && !replayGroup.isEmpty()) {
  26754. if (this.declutterTree_) {
  26755. this.declutterTree_.clear();
  26756. }
  26757. var layer = /** @type {ol.layer.Vector} */ (this.getLayer());
  26758. var drawOffsetX = 0;
  26759. var drawOffsetY = 0;
  26760. var replayContext;
  26761. var transparentLayer = layerState.opacity !== 1;
  26762. var hasRenderListeners = layer.hasListener(ol.render.EventType.RENDER);
  26763. if (transparentLayer || hasRenderListeners) {
  26764. var drawWidth = context.canvas.width;
  26765. var drawHeight = context.canvas.height;
  26766. if (rotation) {
  26767. var drawSize = Math.round(Math.sqrt(drawWidth * drawWidth + drawHeight * drawHeight));
  26768. drawOffsetX = (drawSize - drawWidth) / 2;
  26769. drawOffsetY = (drawSize - drawHeight) / 2;
  26770. drawWidth = drawHeight = drawSize;
  26771. }
  26772. // resize and clear
  26773. this.context.canvas.width = drawWidth;
  26774. this.context.canvas.height = drawHeight;
  26775. replayContext = this.context;
  26776. } else {
  26777. replayContext = context;
  26778. }
  26779. var alpha = replayContext.globalAlpha;
  26780. if (!transparentLayer) {
  26781. // for performance reasons, context.save / context.restore is not used
  26782. // to save and restore the transformation matrix and the opacity.
  26783. // see http://jsperf.com/context-save-restore-versus-variable
  26784. replayContext.globalAlpha = layerState.opacity;
  26785. }
  26786. if (replayContext != context) {
  26787. replayContext.translate(drawOffsetX, drawOffsetY);
  26788. }
  26789. var width = frameState.size[0] * pixelRatio;
  26790. var height = frameState.size[1] * pixelRatio;
  26791. ol.render.canvas.rotateAtOffset(replayContext, -rotation,
  26792. width / 2, height / 2);
  26793. replayGroup.replay(replayContext, transform, rotation, skippedFeatureUids);
  26794. if (vectorSource.getWrapX() && projection.canWrapX() &&
  26795. !ol.extent.containsExtent(projectionExtent, extent)) {
  26796. var startX = extent[0];
  26797. var worldWidth = ol.extent.getWidth(projectionExtent);
  26798. var world = 0;
  26799. var offsetX;
  26800. while (startX < projectionExtent[0]) {
  26801. --world;
  26802. offsetX = worldWidth * world;
  26803. transform = this.getTransform(frameState, offsetX);
  26804. replayGroup.replay(replayContext, transform, rotation, skippedFeatureUids);
  26805. startX += worldWidth;
  26806. }
  26807. world = 0;
  26808. startX = extent[2];
  26809. while (startX > projectionExtent[2]) {
  26810. ++world;
  26811. offsetX = worldWidth * world;
  26812. transform = this.getTransform(frameState, offsetX);
  26813. replayGroup.replay(replayContext, transform, rotation, skippedFeatureUids);
  26814. startX -= worldWidth;
  26815. }
  26816. // restore original transform for render and compose events
  26817. transform = this.getTransform(frameState, 0);
  26818. }
  26819. ol.render.canvas.rotateAtOffset(replayContext, rotation,
  26820. width / 2, height / 2);
  26821. if (replayContext != context) {
  26822. if (hasRenderListeners) {
  26823. this.dispatchRenderEvent(replayContext, frameState, transform);
  26824. }
  26825. if (transparentLayer) {
  26826. var mainContextAlpha = context.globalAlpha;
  26827. context.globalAlpha = layerState.opacity;
  26828. context.drawImage(replayContext.canvas, -drawOffsetX, -drawOffsetY);
  26829. context.globalAlpha = mainContextAlpha;
  26830. } else {
  26831. context.drawImage(replayContext.canvas, -drawOffsetX, -drawOffsetY);
  26832. }
  26833. replayContext.translate(-drawOffsetX, -drawOffsetY);
  26834. }
  26835. if (!transparentLayer) {
  26836. replayContext.globalAlpha = alpha;
  26837. }
  26838. }
  26839. if (clipped) {
  26840. context.restore();
  26841. }
  26842. this.postCompose(context, frameState, layerState, transform);
  26843. };
  26844. /**
  26845. * @inheritDoc
  26846. */
  26847. ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
  26848. if (!this.replayGroup_) {
  26849. return undefined;
  26850. } else {
  26851. var resolution = frameState.viewState.resolution;
  26852. var rotation = frameState.viewState.rotation;
  26853. var layer = /** @type {ol.layer.Vector} */ (this.getLayer());
  26854. /** @type {Object.<string, boolean>} */
  26855. var features = {};
  26856. var result = this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution,
  26857. rotation, hitTolerance, {},
  26858. /**
  26859. * @param {ol.Feature|ol.render.Feature} feature Feature.
  26860. * @return {?} Callback result.
  26861. */
  26862. function(feature) {
  26863. var key = ol.getUid(feature).toString();
  26864. if (!(key in features)) {
  26865. features[key] = true;
  26866. return callback.call(thisArg, feature, layer);
  26867. }
  26868. }, null);
  26869. return result;
  26870. }
  26871. };
  26872. /**
  26873. * @param {ol.events.Event} event Event.
  26874. */
  26875. ol.renderer.canvas.VectorLayer.prototype.handleFontsChanged_ = function(event) {
  26876. var layer = this.getLayer();
  26877. if (layer.getVisible() && this.replayGroup_) {
  26878. layer.changed();
  26879. }
  26880. };
  26881. /**
  26882. * Handle changes in image style state.
  26883. * @param {ol.events.Event} event Image style change event.
  26884. * @private
  26885. */
  26886. ol.renderer.canvas.VectorLayer.prototype.handleStyleImageChange_ = function(event) {
  26887. this.renderIfReadyAndVisible();
  26888. };
  26889. /**
  26890. * @inheritDoc
  26891. */
  26892. ol.renderer.canvas.VectorLayer.prototype.prepareFrame = function(frameState, layerState) {
  26893. var vectorLayer = /** @type {ol.layer.Vector} */ (this.getLayer());
  26894. var vectorSource = vectorLayer.getSource();
  26895. this.updateLogos(frameState, vectorSource);
  26896. var animating = frameState.viewHints[ol.ViewHint.ANIMATING];
  26897. var interacting = frameState.viewHints[ol.ViewHint.INTERACTING];
  26898. var updateWhileAnimating = vectorLayer.getUpdateWhileAnimating();
  26899. var updateWhileInteracting = vectorLayer.getUpdateWhileInteracting();
  26900. if (!this.dirty_ && (!updateWhileAnimating && animating) ||
  26901. (!updateWhileInteracting && interacting)) {
  26902. return true;
  26903. }
  26904. var frameStateExtent = frameState.extent;
  26905. var viewState = frameState.viewState;
  26906. var projection = viewState.projection;
  26907. var resolution = viewState.resolution;
  26908. var pixelRatio = frameState.pixelRatio;
  26909. var vectorLayerRevision = vectorLayer.getRevision();
  26910. var vectorLayerRenderBuffer = vectorLayer.getRenderBuffer();
  26911. var vectorLayerRenderOrder = vectorLayer.getRenderOrder();
  26912. if (vectorLayerRenderOrder === undefined) {
  26913. vectorLayerRenderOrder = ol.renderer.vector.defaultOrder;
  26914. }
  26915. var extent = ol.extent.buffer(frameStateExtent,
  26916. vectorLayerRenderBuffer * resolution);
  26917. var projectionExtent = viewState.projection.getExtent();
  26918. if (vectorSource.getWrapX() && viewState.projection.canWrapX() &&
  26919. !ol.extent.containsExtent(projectionExtent, frameState.extent)) {
  26920. // For the replay group, we need an extent that intersects the real world
  26921. // (-180° to +180°). To support geometries in a coordinate range from -540°
  26922. // to +540°, we add at least 1 world width on each side of the projection
  26923. // extent. If the viewport is wider than the world, we need to add half of
  26924. // the viewport width to make sure we cover the whole viewport.
  26925. var worldWidth = ol.extent.getWidth(projectionExtent);
  26926. var buffer = Math.max(ol.extent.getWidth(extent) / 2, worldWidth);
  26927. extent[0] = projectionExtent[0] - buffer;
  26928. extent[2] = projectionExtent[2] + buffer;
  26929. }
  26930. if (!this.dirty_ &&
  26931. this.renderedResolution_ == resolution &&
  26932. this.renderedRevision_ == vectorLayerRevision &&
  26933. this.renderedRenderOrder_ == vectorLayerRenderOrder &&
  26934. ol.extent.containsExtent(this.renderedExtent_, extent)) {
  26935. this.replayGroupChanged = false;
  26936. return true;
  26937. }
  26938. this.replayGroup_ = null;
  26939. this.dirty_ = false;
  26940. var replayGroup = new ol.render.canvas.ReplayGroup(
  26941. ol.renderer.vector.getTolerance(resolution, pixelRatio), extent, resolution,
  26942. pixelRatio, vectorSource.getOverlaps(), this.declutterTree_, vectorLayer.getRenderBuffer());
  26943. vectorSource.loadFeatures(extent, resolution, projection);
  26944. /**
  26945. * @param {ol.Feature} feature Feature.
  26946. * @this {ol.renderer.canvas.VectorLayer}
  26947. */
  26948. var renderFeature = function(feature) {
  26949. var styles;
  26950. var styleFunction = feature.getStyleFunction();
  26951. if (styleFunction) {
  26952. styles = styleFunction.call(feature, resolution);
  26953. } else {
  26954. styleFunction = vectorLayer.getStyleFunction();
  26955. if (styleFunction) {
  26956. styles = styleFunction(feature, resolution);
  26957. }
  26958. }
  26959. if (styles) {
  26960. var dirty = this.renderFeature(
  26961. feature, resolution, pixelRatio, styles, replayGroup);
  26962. this.dirty_ = this.dirty_ || dirty;
  26963. }
  26964. }.bind(this);
  26965. if (vectorLayerRenderOrder) {
  26966. /** @type {Array.<ol.Feature>} */
  26967. var features = [];
  26968. vectorSource.forEachFeatureInExtent(extent,
  26969. /**
  26970. * @param {ol.Feature} feature Feature.
  26971. */
  26972. function(feature) {
  26973. features.push(feature);
  26974. }, this);
  26975. features.sort(vectorLayerRenderOrder);
  26976. for (var i = 0, ii = features.length; i < ii; ++i) {
  26977. renderFeature(features[i]);
  26978. }
  26979. } else {
  26980. vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
  26981. }
  26982. replayGroup.finish();
  26983. this.renderedResolution_ = resolution;
  26984. this.renderedRevision_ = vectorLayerRevision;
  26985. this.renderedRenderOrder_ = vectorLayerRenderOrder;
  26986. this.renderedExtent_ = extent;
  26987. this.replayGroup_ = replayGroup;
  26988. this.replayGroupChanged = true;
  26989. return true;
  26990. };
  26991. /**
  26992. * @param {ol.Feature} feature Feature.
  26993. * @param {number} resolution Resolution.
  26994. * @param {number} pixelRatio Pixel ratio.
  26995. * @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
  26996. * styles.
  26997. * @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
  26998. * @return {boolean} `true` if an image is loading.
  26999. */
  27000. ol.renderer.canvas.VectorLayer.prototype.renderFeature = function(feature, resolution, pixelRatio, styles, replayGroup) {
  27001. if (!styles) {
  27002. return false;
  27003. }
  27004. var loading = false;
  27005. if (Array.isArray(styles)) {
  27006. for (var i = 0, ii = styles.length; i < ii; ++i) {
  27007. loading = ol.renderer.vector.renderFeature(
  27008. replayGroup, feature, styles[i],
  27009. ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
  27010. this.handleStyleImageChange_, this) || loading;
  27011. }
  27012. } else {
  27013. loading = ol.renderer.vector.renderFeature(
  27014. replayGroup, feature, styles,
  27015. ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
  27016. this.handleStyleImageChange_, this);
  27017. }
  27018. return loading;
  27019. };
  27020. goog.provide('ol.layer.VectorTileRenderType');
  27021. /**
  27022. * @enum {string}
  27023. * Render mode for vector tiles:
  27024. * * `'image'`: Vector tiles are rendered as images. Great performance, but
  27025. * point symbols and texts are always rotated with the view and pixels are
  27026. * scaled during zoom animations.
  27027. * * `'hybrid'`: Polygon and line elements are rendered as images, so pixels
  27028. * are scaled during zoom animations. Point symbols and texts are accurately
  27029. * rendered as vectors and can stay upright on rotated views.
  27030. * * `'vector'`: Vector tiles are rendered as vectors. Most accurate rendering
  27031. * even during animations, but slower performance than the other options.
  27032. * @api
  27033. */
  27034. ol.layer.VectorTileRenderType = {
  27035. IMAGE: 'image',
  27036. HYBRID: 'hybrid',
  27037. VECTOR: 'vector'
  27038. };
  27039. goog.provide('ol.renderer.canvas.VectorTileLayer');
  27040. goog.require('ol');
  27041. goog.require('ol.LayerType');
  27042. goog.require('ol.TileState');
  27043. goog.require('ol.dom');
  27044. goog.require('ol.events');
  27045. goog.require('ol.events.EventType');
  27046. goog.require('ol.ext.rbush');
  27047. goog.require('ol.extent');
  27048. goog.require('ol.layer.VectorTileRenderType');
  27049. goog.require('ol.proj');
  27050. goog.require('ol.proj.Units');
  27051. goog.require('ol.render.ReplayType');
  27052. goog.require('ol.render.canvas');
  27053. goog.require('ol.render.canvas.ReplayGroup');
  27054. goog.require('ol.render.replay');
  27055. goog.require('ol.renderer.Type');
  27056. goog.require('ol.renderer.canvas.TileLayer');
  27057. goog.require('ol.renderer.vector');
  27058. goog.require('ol.transform');
  27059. /**
  27060. * @constructor
  27061. * @extends {ol.renderer.canvas.TileLayer}
  27062. * @param {ol.layer.VectorTile} layer VectorTile layer.
  27063. * @api
  27064. */
  27065. ol.renderer.canvas.VectorTileLayer = function(layer) {
  27066. /**
  27067. * @type {CanvasRenderingContext2D}
  27068. */
  27069. this.context = null;
  27070. ol.renderer.canvas.TileLayer.call(this, layer);
  27071. /**
  27072. * Declutter tree.
  27073. * @private
  27074. */
  27075. this.declutterTree_ = layer.getDeclutter() ? ol.ext.rbush(9) : null;
  27076. /**
  27077. * @private
  27078. * @type {boolean}
  27079. */
  27080. this.dirty_ = false;
  27081. /**
  27082. * @private
  27083. * @type {number}
  27084. */
  27085. this.renderedLayerRevision_;
  27086. /**
  27087. * @private
  27088. * @type {ol.Transform}
  27089. */
  27090. this.tmpTransform_ = ol.transform.create();
  27091. // Use lower resolution for pure vector rendering. Closest resolution otherwise.
  27092. this.zDirection =
  27093. layer.getRenderMode() == ol.layer.VectorTileRenderType.VECTOR ? 1 : 0;
  27094. ol.events.listen(ol.render.canvas.labelCache, ol.events.EventType.CLEAR, this.handleFontsChanged_, this);
  27095. };
  27096. ol.inherits(ol.renderer.canvas.VectorTileLayer, ol.renderer.canvas.TileLayer);
  27097. /**
  27098. * Determine if this renderer handles the provided layer.
  27099. * @param {ol.renderer.Type} type The renderer type.
  27100. * @param {ol.layer.Layer} layer The candidate layer.
  27101. * @return {boolean} The renderer can render the layer.
  27102. */
  27103. ol.renderer.canvas.VectorTileLayer['handles'] = function(type, layer) {
  27104. return type === ol.renderer.Type.CANVAS && layer.getType() === ol.LayerType.VECTOR_TILE;
  27105. };
  27106. /**
  27107. * Create a layer renderer.
  27108. * @param {ol.renderer.Map} mapRenderer The map renderer.
  27109. * @param {ol.layer.Layer} layer The layer to be rendererd.
  27110. * @return {ol.renderer.canvas.VectorTileLayer} The layer renderer.
  27111. */
  27112. ol.renderer.canvas.VectorTileLayer['create'] = function(mapRenderer, layer) {
  27113. return new ol.renderer.canvas.VectorTileLayer(/** @type {ol.layer.VectorTile} */ (layer));
  27114. };
  27115. /**
  27116. * @const
  27117. * @type {!Object.<string, Array.<ol.render.ReplayType>>}
  27118. */
  27119. ol.renderer.canvas.VectorTileLayer.IMAGE_REPLAYS = {
  27120. 'image': [ol.render.ReplayType.POLYGON, ol.render.ReplayType.CIRCLE,
  27121. ol.render.ReplayType.LINE_STRING, ol.render.ReplayType.IMAGE, ol.render.ReplayType.TEXT],
  27122. 'hybrid': [ol.render.ReplayType.POLYGON, ol.render.ReplayType.LINE_STRING]
  27123. };
  27124. /**
  27125. * @const
  27126. * @type {!Object.<string, Array.<ol.render.ReplayType>>}
  27127. */
  27128. ol.renderer.canvas.VectorTileLayer.VECTOR_REPLAYS = {
  27129. 'image': [ol.render.ReplayType.DEFAULT],
  27130. 'hybrid': [ol.render.ReplayType.IMAGE, ol.render.ReplayType.TEXT, ol.render.ReplayType.DEFAULT],
  27131. 'vector': ol.render.replay.ORDER
  27132. };
  27133. /**
  27134. * @inheritDoc
  27135. */
  27136. ol.renderer.canvas.VectorTileLayer.prototype.disposeInternal = function() {
  27137. ol.events.unlisten(ol.render.canvas.labelCache, ol.events.EventType.CLEAR, this.handleFontsChanged_, this);
  27138. ol.renderer.canvas.TileLayer.prototype.disposeInternal.call(this);
  27139. };
  27140. /**
  27141. * @inheritDoc
  27142. */
  27143. ol.renderer.canvas.VectorTileLayer.prototype.prepareFrame = function(frameState, layerState) {
  27144. var layer = this.getLayer();
  27145. var layerRevision = layer.getRevision();
  27146. if (this.renderedLayerRevision_ != layerRevision) {
  27147. this.renderedTiles.length = 0;
  27148. var renderMode = layer.getRenderMode();
  27149. if (!this.context && renderMode != ol.layer.VectorTileRenderType.VECTOR) {
  27150. this.context = ol.dom.createCanvasContext2D();
  27151. }
  27152. if (this.context && renderMode == ol.layer.VectorTileRenderType.VECTOR) {
  27153. this.context = null;
  27154. }
  27155. }
  27156. this.renderedLayerRevision_ = layerRevision;
  27157. return ol.renderer.canvas.TileLayer.prototype.prepareFrame.apply(this, arguments);
  27158. };
  27159. /**
  27160. * @param {ol.VectorImageTile} tile Tile.
  27161. * @param {olx.FrameState} frameState Frame state.
  27162. * @private
  27163. */
  27164. ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup_ = function(
  27165. tile, frameState) {
  27166. var layer = this.getLayer();
  27167. var pixelRatio = frameState.pixelRatio;
  27168. var projection = frameState.viewState.projection;
  27169. var revision = layer.getRevision();
  27170. var renderOrder = /** @type {ol.RenderOrderFunction} */
  27171. (layer.getRenderOrder()) || null;
  27172. var replayState = tile.getReplayState(layer);
  27173. if (!replayState.dirty && replayState.renderedRevision == revision &&
  27174. replayState.renderedRenderOrder == renderOrder) {
  27175. return;
  27176. }
  27177. var source = /** @type {ol.source.VectorTile} */ (layer.getSource());
  27178. var sourceTileGrid = source.getTileGrid();
  27179. var tileGrid = source.getTileGridForProjection(projection);
  27180. var resolution = tileGrid.getResolution(tile.tileCoord[0]);
  27181. var tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
  27182. var zIndexKeys = {};
  27183. for (var t = 0, tt = tile.tileKeys.length; t < tt; ++t) {
  27184. var sourceTile = tile.getTile(tile.tileKeys[t]);
  27185. if (sourceTile.getState() == ol.TileState.ERROR) {
  27186. continue;
  27187. }
  27188. var sourceTileCoord = sourceTile.tileCoord;
  27189. var sourceTileExtent = sourceTileGrid.getTileCoordExtent(sourceTileCoord);
  27190. var sharedExtent = ol.extent.getIntersection(tileExtent, sourceTileExtent);
  27191. var bufferedExtent = ol.extent.equals(sourceTileExtent, sharedExtent) ? null :
  27192. ol.extent.buffer(sharedExtent, layer.getRenderBuffer() * resolution);
  27193. var tileProjection = sourceTile.getProjection();
  27194. var reproject = false;
  27195. if (!ol.proj.equivalent(projection, tileProjection)) {
  27196. reproject = true;
  27197. sourceTile.setProjection(projection);
  27198. }
  27199. replayState.dirty = false;
  27200. var replayGroup = new ol.render.canvas.ReplayGroup(0, sharedExtent, resolution,
  27201. pixelRatio, source.getOverlaps(), this.declutterTree_, layer.getRenderBuffer());
  27202. var squaredTolerance = ol.renderer.vector.getSquaredTolerance(
  27203. resolution, pixelRatio);
  27204. /**
  27205. * @param {ol.Feature|ol.render.Feature} feature Feature.
  27206. * @this {ol.renderer.canvas.VectorTileLayer}
  27207. */
  27208. var renderFeature = function(feature) {
  27209. var styles;
  27210. var styleFunction = feature.getStyleFunction();
  27211. if (styleFunction) {
  27212. styles = styleFunction.call(/** @type {ol.Feature} */ (feature), resolution);
  27213. } else {
  27214. styleFunction = layer.getStyleFunction();
  27215. if (styleFunction) {
  27216. styles = styleFunction(feature, resolution);
  27217. }
  27218. }
  27219. if (styles) {
  27220. var dirty = this.renderFeature(feature, squaredTolerance, styles,
  27221. replayGroup);
  27222. this.dirty_ = this.dirty_ || dirty;
  27223. replayState.dirty = replayState.dirty || dirty;
  27224. }
  27225. };
  27226. var features = sourceTile.getFeatures();
  27227. if (renderOrder && renderOrder !== replayState.renderedRenderOrder) {
  27228. features.sort(renderOrder);
  27229. }
  27230. var feature;
  27231. for (var i = 0, ii = features.length; i < ii; ++i) {
  27232. feature = features[i];
  27233. if (reproject) {
  27234. if (tileProjection.getUnits() == ol.proj.Units.TILE_PIXELS) {
  27235. // projected tile extent
  27236. tileProjection.setWorldExtent(sourceTileExtent);
  27237. // tile extent in tile pixel space
  27238. tileProjection.setExtent(sourceTile.getExtent());
  27239. }
  27240. feature.getGeometry().transform(tileProjection, projection);
  27241. }
  27242. if (!bufferedExtent || ol.extent.intersects(bufferedExtent, feature.getGeometry().getExtent())) {
  27243. renderFeature.call(this, feature);
  27244. }
  27245. }
  27246. replayGroup.finish();
  27247. for (var r in replayGroup.getReplays()) {
  27248. zIndexKeys[r] = true;
  27249. }
  27250. sourceTile.setReplayGroup(layer, tile.tileCoord.toString(), replayGroup);
  27251. }
  27252. replayState.renderedRevision = revision;
  27253. replayState.renderedRenderOrder = renderOrder;
  27254. };
  27255. /**
  27256. * @inheritDoc
  27257. */
  27258. ol.renderer.canvas.VectorTileLayer.prototype.drawTileImage = function(
  27259. tile, frameState, layerState, x, y, w, h, gutter, transition) {
  27260. var vectorImageTile = /** @type {ol.VectorImageTile} */ (tile);
  27261. this.createReplayGroup_(vectorImageTile, frameState);
  27262. if (this.context) {
  27263. this.renderTileImage_(vectorImageTile, frameState, layerState);
  27264. ol.renderer.canvas.TileLayer.prototype.drawTileImage.apply(this, arguments);
  27265. }
  27266. };
  27267. /**
  27268. * @inheritDoc
  27269. */
  27270. ol.renderer.canvas.VectorTileLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
  27271. var resolution = frameState.viewState.resolution;
  27272. var rotation = frameState.viewState.rotation;
  27273. hitTolerance = hitTolerance == undefined ? 0 : hitTolerance;
  27274. var layer = this.getLayer();
  27275. /** @type {Object.<string, boolean>} */
  27276. var features = {};
  27277. /** @type {Array.<ol.VectorImageTile>} */
  27278. var renderedTiles = this.renderedTiles;
  27279. var source = /** @type {ol.source.VectorTile} */ (layer.getSource());
  27280. var tileGrid = source.getTileGridForProjection(frameState.viewState.projection);
  27281. var bufferedExtent, found;
  27282. var i, ii, replayGroup;
  27283. var tile, tileCoord, tileExtent;
  27284. for (i = 0, ii = renderedTiles.length; i < ii; ++i) {
  27285. tile = renderedTiles[i];
  27286. tileCoord = tile.wrappedTileCoord;
  27287. tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent);
  27288. bufferedExtent = ol.extent.buffer(tileExtent, hitTolerance * resolution, bufferedExtent);
  27289. if (!ol.extent.containsCoordinate(bufferedExtent, coordinate)) {
  27290. continue;
  27291. }
  27292. for (var t = 0, tt = tile.tileKeys.length; t < tt; ++t) {
  27293. var sourceTile = tile.getTile(tile.tileKeys[t]);
  27294. if (sourceTile.getState() == ol.TileState.ERROR) {
  27295. continue;
  27296. }
  27297. replayGroup = sourceTile.getReplayGroup(layer, tile.tileCoord.toString());
  27298. found = found || replayGroup.forEachFeatureAtCoordinate(
  27299. coordinate, resolution, rotation, hitTolerance, {},
  27300. /**
  27301. * @param {ol.Feature|ol.render.Feature} feature Feature.
  27302. * @return {?} Callback result.
  27303. */
  27304. function(feature) {
  27305. var key = ol.getUid(feature).toString();
  27306. if (!(key in features)) {
  27307. features[key] = true;
  27308. return callback.call(thisArg, feature, layer);
  27309. }
  27310. }, null);
  27311. }
  27312. }
  27313. return found;
  27314. };
  27315. /**
  27316. * @param {ol.VectorTile} tile Tile.
  27317. * @param {olx.FrameState} frameState Frame state.
  27318. * @return {ol.Transform} transform Transform.
  27319. * @private
  27320. */
  27321. ol.renderer.canvas.VectorTileLayer.prototype.getReplayTransform_ = function(tile, frameState) {
  27322. var layer = this.getLayer();
  27323. var source = /** @type {ol.source.VectorTile} */ (layer.getSource());
  27324. var tileGrid = source.getTileGrid();
  27325. var tileCoord = tile.tileCoord;
  27326. var tileResolution = tileGrid.getResolution(tileCoord[0]);
  27327. var viewState = frameState.viewState;
  27328. var pixelRatio = frameState.pixelRatio;
  27329. var renderResolution = viewState.resolution / pixelRatio;
  27330. var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent);
  27331. var center = viewState.center;
  27332. var origin = ol.extent.getTopLeft(tileExtent);
  27333. var size = frameState.size;
  27334. var offsetX = Math.round(pixelRatio * size[0] / 2);
  27335. var offsetY = Math.round(pixelRatio * size[1] / 2);
  27336. return ol.transform.compose(this.tmpTransform_,
  27337. offsetX, offsetY,
  27338. tileResolution / renderResolution, tileResolution / renderResolution,
  27339. viewState.rotation,
  27340. (origin[0] - center[0]) / tileResolution,
  27341. (center[1] - origin[1]) / tileResolution);
  27342. };
  27343. /**
  27344. * @param {ol.events.Event} event Event.
  27345. */
  27346. ol.renderer.canvas.VectorTileLayer.prototype.handleFontsChanged_ = function(event) {
  27347. var layer = this.getLayer();
  27348. if (layer.getVisible() && this.renderedLayerRevision_ !== undefined) {
  27349. layer.changed();
  27350. }
  27351. };
  27352. /**
  27353. * Handle changes in image style state.
  27354. * @param {ol.events.Event} event Image style change event.
  27355. * @private
  27356. */
  27357. ol.renderer.canvas.VectorTileLayer.prototype.handleStyleImageChange_ = function(event) {
  27358. this.renderIfReadyAndVisible();
  27359. };
  27360. /**
  27361. * @inheritDoc
  27362. */
  27363. ol.renderer.canvas.VectorTileLayer.prototype.postCompose = function(context, frameState, layerState) {
  27364. var layer = this.getLayer();
  27365. var declutterReplays = layer.getDeclutter() ? {} : null;
  27366. var source = /** @type {ol.source.VectorTile} */ (layer.getSource());
  27367. var renderMode = layer.getRenderMode();
  27368. var replayTypes = ol.renderer.canvas.VectorTileLayer.VECTOR_REPLAYS[renderMode];
  27369. var pixelRatio = frameState.pixelRatio;
  27370. var rotation = frameState.viewState.rotation;
  27371. var size = frameState.size;
  27372. var offsetX, offsetY;
  27373. if (rotation) {
  27374. offsetX = Math.round(pixelRatio * size[0] / 2);
  27375. offsetY = Math.round(pixelRatio * size[1] / 2);
  27376. ol.render.canvas.rotateAtOffset(context, -rotation, offsetX, offsetY);
  27377. }
  27378. if (declutterReplays) {
  27379. this.declutterTree_.clear();
  27380. }
  27381. var tiles = this.renderedTiles;
  27382. var tileGrid = source.getTileGridForProjection(frameState.viewState.projection);
  27383. var clips = [];
  27384. var zs = [];
  27385. for (var i = tiles.length - 1; i >= 0; --i) {
  27386. var tile = /** @type {ol.VectorImageTile} */ (tiles[i]);
  27387. if (tile.getState() == ol.TileState.ABORT) {
  27388. continue;
  27389. }
  27390. var tileCoord = tile.tileCoord;
  27391. var worldOffset = tileGrid.getTileCoordExtent(tileCoord)[0] -
  27392. tileGrid.getTileCoordExtent(tile.wrappedTileCoord)[0];
  27393. var transform = undefined;
  27394. for (var t = 0, tt = tile.tileKeys.length; t < tt; ++t) {
  27395. var sourceTile = tile.getTile(tile.tileKeys[t]);
  27396. if (sourceTile.getState() == ol.TileState.ERROR) {
  27397. continue;
  27398. }
  27399. var replayGroup = sourceTile.getReplayGroup(layer, tileCoord.toString());
  27400. if (renderMode != ol.layer.VectorTileRenderType.VECTOR && !replayGroup.hasReplays(replayTypes)) {
  27401. continue;
  27402. }
  27403. if (!transform) {
  27404. transform = this.getTransform(frameState, worldOffset);
  27405. }
  27406. var currentZ = sourceTile.tileCoord[0];
  27407. var currentClip = replayGroup.getClipCoords(transform);
  27408. context.save();
  27409. context.globalAlpha = layerState.opacity;
  27410. // Create a clip mask for regions in this low resolution tile that are
  27411. // already filled by a higher resolution tile
  27412. for (var j = 0, jj = clips.length; j < jj; ++j) {
  27413. var clip = clips[j];
  27414. if (currentZ < zs[j]) {
  27415. context.beginPath();
  27416. // counter-clockwise (outer ring) for current tile
  27417. context.moveTo(currentClip[0], currentClip[1]);
  27418. context.lineTo(currentClip[2], currentClip[3]);
  27419. context.lineTo(currentClip[4], currentClip[5]);
  27420. context.lineTo(currentClip[6], currentClip[7]);
  27421. // clockwise (inner ring) for higher resolution tile
  27422. context.moveTo(clip[6], clip[7]);
  27423. context.lineTo(clip[4], clip[5]);
  27424. context.lineTo(clip[2], clip[3]);
  27425. context.lineTo(clip[0], clip[1]);
  27426. context.clip();
  27427. }
  27428. }
  27429. replayGroup.replay(context, transform, rotation, {}, replayTypes, declutterReplays);
  27430. context.restore();
  27431. clips.push(currentClip);
  27432. zs.push(currentZ);
  27433. }
  27434. }
  27435. if (declutterReplays) {
  27436. ol.render.canvas.ReplayGroup.replayDeclutter(declutterReplays, context, rotation);
  27437. }
  27438. if (rotation) {
  27439. ol.render.canvas.rotateAtOffset(context, rotation,
  27440. /** @type {number} */ (offsetX), /** @type {number} */ (offsetY));
  27441. }
  27442. ol.renderer.canvas.TileLayer.prototype.postCompose.apply(this, arguments);
  27443. };
  27444. /**
  27445. * @param {ol.Feature|ol.render.Feature} feature Feature.
  27446. * @param {number} squaredTolerance Squared tolerance.
  27447. * @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
  27448. * styles.
  27449. * @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
  27450. * @return {boolean} `true` if an image is loading.
  27451. */
  27452. ol.renderer.canvas.VectorTileLayer.prototype.renderFeature = function(feature, squaredTolerance, styles, replayGroup) {
  27453. if (!styles) {
  27454. return false;
  27455. }
  27456. var loading = false;
  27457. if (Array.isArray(styles)) {
  27458. for (var i = 0, ii = styles.length; i < ii; ++i) {
  27459. loading = ol.renderer.vector.renderFeature(
  27460. replayGroup, feature, styles[i], squaredTolerance,
  27461. this.handleStyleImageChange_, this) || loading;
  27462. }
  27463. } else {
  27464. loading = ol.renderer.vector.renderFeature(
  27465. replayGroup, feature, styles, squaredTolerance,
  27466. this.handleStyleImageChange_, this);
  27467. }
  27468. return loading;
  27469. };
  27470. /**
  27471. * @param {ol.VectorImageTile} tile Tile.
  27472. * @param {olx.FrameState} frameState Frame state.
  27473. * @param {ol.LayerState} layerState Layer state.
  27474. * @private
  27475. */
  27476. ol.renderer.canvas.VectorTileLayer.prototype.renderTileImage_ = function(
  27477. tile, frameState, layerState) {
  27478. var layer = this.getLayer();
  27479. var replayState = tile.getReplayState(layer);
  27480. var revision = layer.getRevision();
  27481. var replays = ol.renderer.canvas.VectorTileLayer.IMAGE_REPLAYS[layer.getRenderMode()];
  27482. if (replays && replayState.renderedTileRevision !== revision) {
  27483. replayState.renderedTileRevision = revision;
  27484. var tileCoord = tile.wrappedTileCoord;
  27485. var z = tileCoord[0];
  27486. var pixelRatio = frameState.pixelRatio;
  27487. var source = /** @type {ol.source.VectorTile} */ (layer.getSource());
  27488. var tileGrid = source.getTileGridForProjection(frameState.viewState.projection);
  27489. var resolution = tileGrid.getResolution(z);
  27490. var context = tile.getContext(layer);
  27491. var size = source.getTilePixelSize(z, pixelRatio, frameState.viewState.projection);
  27492. context.canvas.width = size[0];
  27493. context.canvas.height = size[1];
  27494. var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
  27495. for (var i = 0, ii = tile.tileKeys.length; i < ii; ++i) {
  27496. var sourceTile = tile.getTile(tile.tileKeys[i]);
  27497. if (sourceTile.getState() == ol.TileState.ERROR) {
  27498. continue;
  27499. }
  27500. var pixelScale = pixelRatio / resolution;
  27501. var transform = ol.transform.reset(this.tmpTransform_);
  27502. ol.transform.scale(transform, pixelScale, -pixelScale);
  27503. ol.transform.translate(transform, -tileExtent[0], -tileExtent[3]);
  27504. var replayGroup = sourceTile.getReplayGroup(layer, tile.tileCoord.toString());
  27505. replayGroup.replay(context, transform, 0, {}, replays);
  27506. }
  27507. }
  27508. };
  27509. goog.provide('ol.CanvasMap');
  27510. goog.require('ol');
  27511. goog.require('ol.PluggableMap');
  27512. goog.require('ol.PluginType');
  27513. goog.require('ol.control');
  27514. goog.require('ol.interaction');
  27515. goog.require('ol.obj');
  27516. goog.require('ol.plugins');
  27517. goog.require('ol.renderer.canvas.ImageLayer');
  27518. goog.require('ol.renderer.canvas.Map');
  27519. goog.require('ol.renderer.canvas.TileLayer');
  27520. goog.require('ol.renderer.canvas.VectorLayer');
  27521. goog.require('ol.renderer.canvas.VectorTileLayer');
  27522. ol.plugins.register(ol.PluginType.MAP_RENDERER, ol.renderer.canvas.Map);
  27523. ol.plugins.registerMultiple(ol.PluginType.LAYER_RENDERER, [
  27524. ol.renderer.canvas.ImageLayer,
  27525. ol.renderer.canvas.TileLayer,
  27526. ol.renderer.canvas.VectorLayer,
  27527. ol.renderer.canvas.VectorTileLayer
  27528. ]);
  27529. /**
  27530. * @classdesc
  27531. * The map is the core component of OpenLayers. For a map to render, a view,
  27532. * one or more layers, and a target container are needed:
  27533. *
  27534. * var map = new ol.CanvasMap({
  27535. * view: new ol.View({
  27536. * center: [0, 0],
  27537. * zoom: 1
  27538. * }),
  27539. * layers: [
  27540. * new ol.layer.Tile({
  27541. * source: new ol.source.OSM()
  27542. * })
  27543. * ],
  27544. * target: 'map'
  27545. * });
  27546. *
  27547. * The above snippet creates a map using a {@link ol.layer.Tile} to display
  27548. * {@link ol.source.OSM} OSM data and render it to a DOM element with the
  27549. * id `map`.
  27550. *
  27551. * The constructor places a viewport container (with CSS class name
  27552. * `ol-viewport`) in the target element (see `getViewport()`), and then two
  27553. * further elements within the viewport: one with CSS class name
  27554. * `ol-overlaycontainer-stopevent` for controls and some overlays, and one with
  27555. * CSS class name `ol-overlaycontainer` for other overlays (see the `stopEvent`
  27556. * option of {@link ol.Overlay} for the difference). The map itself is placed in
  27557. * a further element within the viewport.
  27558. *
  27559. * Layers are stored as a `ol.Collection` in layerGroups. A top-level group is
  27560. * provided by the library. This is what is accessed by `getLayerGroup` and
  27561. * `setLayerGroup`. Layers entered in the options are added to this group, and
  27562. * `addLayer` and `removeLayer` change the layer collection in the group.
  27563. * `getLayers` is a convenience function for `getLayerGroup().getLayers()`.
  27564. * Note that `ol.layer.Group` is a subclass of `ol.layer.Base`, so layers
  27565. * entered in the options or added with `addLayer` can be groups, which can
  27566. * contain further groups, and so on.
  27567. *
  27568. * @constructor
  27569. * @extends {ol.PluggableMap}
  27570. * @param {olx.MapOptions} options Map options.
  27571. * @fires ol.MapBrowserEvent
  27572. * @fires ol.MapEvent
  27573. * @fires ol.render.Event#postcompose
  27574. * @fires ol.render.Event#precompose
  27575. * @api
  27576. */
  27577. ol.CanvasMap = function(options) {
  27578. options = ol.obj.assign({}, options);
  27579. delete options.renderer;
  27580. if (!options.controls) {
  27581. options.controls = ol.control.defaults();
  27582. }
  27583. if (!options.interactions) {
  27584. options.interactions = ol.interaction.defaults();
  27585. }
  27586. ol.PluggableMap.call(this, options);
  27587. };
  27588. ol.inherits(ol.CanvasMap, ol.PluggableMap);
  27589. goog.provide('ol.control.FullScreen');
  27590. goog.require('ol');
  27591. goog.require('ol.control.Control');
  27592. goog.require('ol.css');
  27593. goog.require('ol.dom');
  27594. goog.require('ol.events');
  27595. goog.require('ol.events.EventType');
  27596. /**
  27597. * @classdesc
  27598. * Provides a button that when clicked fills up the full screen with the map.
  27599. * The full screen source element is by default the element containing the map viewport unless
  27600. * overridden by providing the `source` option. In which case, the dom
  27601. * element introduced using this parameter will be displayed in full screen.
  27602. *
  27603. * When in full screen mode, a close button is shown to exit full screen mode.
  27604. * The [Fullscreen API](http://www.w3.org/TR/fullscreen/) is used to
  27605. * toggle the map in full screen mode.
  27606. *
  27607. *
  27608. * @constructor
  27609. * @extends {ol.control.Control}
  27610. * @param {olx.control.FullScreenOptions=} opt_options Options.
  27611. * @api
  27612. */
  27613. ol.control.FullScreen = function(opt_options) {
  27614. var options = opt_options ? opt_options : {};
  27615. /**
  27616. * @private
  27617. * @type {string}
  27618. */
  27619. this.cssClassName_ = options.className !== undefined ? options.className :
  27620. 'ol-full-screen';
  27621. var label = options.label !== undefined ? options.label : '\u2922';
  27622. /**
  27623. * @private
  27624. * @type {Node}
  27625. */
  27626. this.labelNode_ = typeof label === 'string' ?
  27627. document.createTextNode(label) : label;
  27628. var labelActive = options.labelActive !== undefined ? options.labelActive : '\u00d7';
  27629. /**
  27630. * @private
  27631. * @type {Node}
  27632. */
  27633. this.labelActiveNode_ = typeof labelActive === 'string' ?
  27634. document.createTextNode(labelActive) : labelActive;
  27635. var tipLabel = options.tipLabel ? options.tipLabel : 'Toggle full-screen';
  27636. var button = document.createElement('button');
  27637. button.className = this.cssClassName_ + '-' + ol.control.FullScreen.isFullScreen();
  27638. button.setAttribute('type', 'button');
  27639. button.title = tipLabel;
  27640. button.appendChild(this.labelNode_);
  27641. ol.events.listen(button, ol.events.EventType.CLICK,
  27642. this.handleClick_, this);
  27643. var cssClasses = this.cssClassName_ + ' ' + ol.css.CLASS_UNSELECTABLE +
  27644. ' ' + ol.css.CLASS_CONTROL + ' ' +
  27645. (!ol.control.FullScreen.isFullScreenSupported() ? ol.css.CLASS_UNSUPPORTED : '');
  27646. var element = document.createElement('div');
  27647. element.className = cssClasses;
  27648. element.appendChild(button);
  27649. ol.control.Control.call(this, {
  27650. element: element,
  27651. target: options.target
  27652. });
  27653. /**
  27654. * @private
  27655. * @type {boolean}
  27656. */
  27657. this.keys_ = options.keys !== undefined ? options.keys : false;
  27658. /**
  27659. * @private
  27660. * @type {Element|string|undefined}
  27661. */
  27662. this.source_ = options.source;
  27663. };
  27664. ol.inherits(ol.control.FullScreen, ol.control.Control);
  27665. /**
  27666. * @param {Event} event The event to handle
  27667. * @private
  27668. */
  27669. ol.control.FullScreen.prototype.handleClick_ = function(event) {
  27670. event.preventDefault();
  27671. this.handleFullScreen_();
  27672. };
  27673. /**
  27674. * @private
  27675. */
  27676. ol.control.FullScreen.prototype.handleFullScreen_ = function() {
  27677. if (!ol.control.FullScreen.isFullScreenSupported()) {
  27678. return;
  27679. }
  27680. var map = this.getMap();
  27681. if (!map) {
  27682. return;
  27683. }
  27684. if (ol.control.FullScreen.isFullScreen()) {
  27685. ol.control.FullScreen.exitFullScreen();
  27686. } else {
  27687. var element;
  27688. if (this.source_) {
  27689. element = typeof this.source_ === 'string' ?
  27690. document.getElementById(this.source_) :
  27691. this.source_;
  27692. } else {
  27693. element = map.getTargetElement();
  27694. }
  27695. if (this.keys_) {
  27696. ol.control.FullScreen.requestFullScreenWithKeys(element);
  27697. } else {
  27698. ol.control.FullScreen.requestFullScreen(element);
  27699. }
  27700. }
  27701. };
  27702. /**
  27703. * @private
  27704. */
  27705. ol.control.FullScreen.prototype.handleFullScreenChange_ = function() {
  27706. var button = this.element.firstElementChild;
  27707. var map = this.getMap();
  27708. if (ol.control.FullScreen.isFullScreen()) {
  27709. button.className = this.cssClassName_ + '-true';
  27710. ol.dom.replaceNode(this.labelActiveNode_, this.labelNode_);
  27711. } else {
  27712. button.className = this.cssClassName_ + '-false';
  27713. ol.dom.replaceNode(this.labelNode_, this.labelActiveNode_);
  27714. }
  27715. if (map) {
  27716. map.updateSize();
  27717. }
  27718. };
  27719. /**
  27720. * @inheritDoc
  27721. * @api
  27722. */
  27723. ol.control.FullScreen.prototype.setMap = function(map) {
  27724. ol.control.Control.prototype.setMap.call(this, map);
  27725. if (map) {
  27726. this.listenerKeys.push(ol.events.listen(document,
  27727. ol.control.FullScreen.getChangeType_(),
  27728. this.handleFullScreenChange_, this)
  27729. );
  27730. }
  27731. };
  27732. /**
  27733. * @return {boolean} Fullscreen is supported by the current platform.
  27734. */
  27735. ol.control.FullScreen.isFullScreenSupported = function() {
  27736. var body = document.body;
  27737. return !!(
  27738. body.webkitRequestFullscreen ||
  27739. (body.mozRequestFullScreen && document.mozFullScreenEnabled) ||
  27740. (body.msRequestFullscreen && document.msFullscreenEnabled) ||
  27741. (body.requestFullscreen && document.fullscreenEnabled)
  27742. );
  27743. };
  27744. /**
  27745. * @return {boolean} Element is currently in fullscreen.
  27746. */
  27747. ol.control.FullScreen.isFullScreen = function() {
  27748. return !!(
  27749. document.webkitIsFullScreen || document.mozFullScreen ||
  27750. document.msFullscreenElement || document.fullscreenElement
  27751. );
  27752. };
  27753. /**
  27754. * Request to fullscreen an element.
  27755. * @param {Node} element Element to request fullscreen
  27756. */
  27757. ol.control.FullScreen.requestFullScreen = function(element) {
  27758. if (element.requestFullscreen) {
  27759. element.requestFullscreen();
  27760. } else if (element.msRequestFullscreen) {
  27761. element.msRequestFullscreen();
  27762. } else if (element.mozRequestFullScreen) {
  27763. element.mozRequestFullScreen();
  27764. } else if (element.webkitRequestFullscreen) {
  27765. element.webkitRequestFullscreen();
  27766. }
  27767. };
  27768. /**
  27769. * Request to fullscreen an element with keyboard input.
  27770. * @param {Node} element Element to request fullscreen
  27771. */
  27772. ol.control.FullScreen.requestFullScreenWithKeys = function(element) {
  27773. if (element.mozRequestFullScreenWithKeys) {
  27774. element.mozRequestFullScreenWithKeys();
  27775. } else if (element.webkitRequestFullscreen) {
  27776. element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  27777. } else {
  27778. ol.control.FullScreen.requestFullScreen(element);
  27779. }
  27780. };
  27781. /**
  27782. * Exit fullscreen.
  27783. */
  27784. ol.control.FullScreen.exitFullScreen = function() {
  27785. if (document.exitFullscreen) {
  27786. document.exitFullscreen();
  27787. } else if (document.msExitFullscreen) {
  27788. document.msExitFullscreen();
  27789. } else if (document.mozCancelFullScreen) {
  27790. document.mozCancelFullScreen();
  27791. } else if (document.webkitExitFullscreen) {
  27792. document.webkitExitFullscreen();
  27793. }
  27794. };
  27795. /**
  27796. * @return {string} Change type.
  27797. * @private
  27798. */
  27799. ol.control.FullScreen.getChangeType_ = (function() {
  27800. var changeType;
  27801. return function() {
  27802. if (!changeType) {
  27803. var body = document.body;
  27804. if (body.webkitRequestFullscreen) {
  27805. changeType = 'webkitfullscreenchange';
  27806. } else if (body.mozRequestFullScreen) {
  27807. changeType = 'mozfullscreenchange';
  27808. } else if (body.msRequestFullscreen) {
  27809. changeType = 'MSFullscreenChange';
  27810. } else if (body.requestFullscreen) {
  27811. changeType = 'fullscreenchange';
  27812. }
  27813. }
  27814. return changeType;
  27815. };
  27816. })();
  27817. // FIXME should listen on appropriate pane, once it is defined
  27818. goog.provide('ol.control.MousePosition');
  27819. goog.require('ol');
  27820. goog.require('ol.events');
  27821. goog.require('ol.events.EventType');
  27822. goog.require('ol.Object');
  27823. goog.require('ol.control.Control');
  27824. goog.require('ol.proj');
  27825. /**
  27826. * @classdesc
  27827. * A control to show the 2D coordinates of the mouse cursor. By default, these
  27828. * are in the view projection, but can be in any supported projection.
  27829. * By default the control is shown in the top right corner of the map, but this
  27830. * can be changed by using the css selector `.ol-mouse-position`.
  27831. *
  27832. * @constructor
  27833. * @extends {ol.control.Control}
  27834. * @param {olx.control.MousePositionOptions=} opt_options Mouse position
  27835. * options.
  27836. * @api
  27837. */
  27838. ol.control.MousePosition = function(opt_options) {
  27839. var options = opt_options ? opt_options : {};
  27840. var element = document.createElement('DIV');
  27841. element.className = options.className !== undefined ? options.className : 'ol-mouse-position';
  27842. var render = options.render ?
  27843. options.render : ol.control.MousePosition.render;
  27844. ol.control.Control.call(this, {
  27845. element: element,
  27846. render: render,
  27847. target: options.target
  27848. });
  27849. ol.events.listen(this,
  27850. ol.Object.getChangeEventType(ol.control.MousePosition.Property_.PROJECTION),
  27851. this.handleProjectionChanged_, this);
  27852. if (options.coordinateFormat) {
  27853. this.setCoordinateFormat(options.coordinateFormat);
  27854. }
  27855. if (options.projection) {
  27856. this.setProjection(options.projection);
  27857. }
  27858. /**
  27859. * @private
  27860. * @type {string}
  27861. */
  27862. this.undefinedHTML_ = options.undefinedHTML !== undefined ? options.undefinedHTML : '';
  27863. /**
  27864. * @private
  27865. * @type {string}
  27866. */
  27867. this.renderedHTML_ = element.innerHTML;
  27868. /**
  27869. * @private
  27870. * @type {ol.proj.Projection}
  27871. */
  27872. this.mapProjection_ = null;
  27873. /**
  27874. * @private
  27875. * @type {?ol.TransformFunction}
  27876. */
  27877. this.transform_ = null;
  27878. /**
  27879. * @private
  27880. * @type {ol.Pixel}
  27881. */
  27882. this.lastMouseMovePixel_ = null;
  27883. };
  27884. ol.inherits(ol.control.MousePosition, ol.control.Control);
  27885. /**
  27886. * Update the mouseposition element.
  27887. * @param {ol.MapEvent} mapEvent Map event.
  27888. * @this {ol.control.MousePosition}
  27889. * @api
  27890. */
  27891. ol.control.MousePosition.render = function(mapEvent) {
  27892. var frameState = mapEvent.frameState;
  27893. if (!frameState) {
  27894. this.mapProjection_ = null;
  27895. } else {
  27896. if (this.mapProjection_ != frameState.viewState.projection) {
  27897. this.mapProjection_ = frameState.viewState.projection;
  27898. this.transform_ = null;
  27899. }
  27900. }
  27901. this.updateHTML_(this.lastMouseMovePixel_);
  27902. };
  27903. /**
  27904. * @private
  27905. */
  27906. ol.control.MousePosition.prototype.handleProjectionChanged_ = function() {
  27907. this.transform_ = null;
  27908. };
  27909. /**
  27910. * Return the coordinate format type used to render the current position or
  27911. * undefined.
  27912. * @return {ol.CoordinateFormatType|undefined} The format to render the current
  27913. * position in.
  27914. * @observable
  27915. * @api
  27916. */
  27917. ol.control.MousePosition.prototype.getCoordinateFormat = function() {
  27918. return /** @type {ol.CoordinateFormatType|undefined} */ (
  27919. this.get(ol.control.MousePosition.Property_.COORDINATE_FORMAT));
  27920. };
  27921. /**
  27922. * Return the projection that is used to report the mouse position.
  27923. * @return {ol.proj.Projection|undefined} The projection to report mouse
  27924. * position in.
  27925. * @observable
  27926. * @api
  27927. */
  27928. ol.control.MousePosition.prototype.getProjection = function() {
  27929. return /** @type {ol.proj.Projection|undefined} */ (
  27930. this.get(ol.control.MousePosition.Property_.PROJECTION));
  27931. };
  27932. /**
  27933. * @param {Event} event Browser event.
  27934. * @protected
  27935. */
  27936. ol.control.MousePosition.prototype.handleMouseMove = function(event) {
  27937. var map = this.getMap();
  27938. this.lastMouseMovePixel_ = map.getEventPixel(event);
  27939. this.updateHTML_(this.lastMouseMovePixel_);
  27940. };
  27941. /**
  27942. * @param {Event} event Browser event.
  27943. * @protected
  27944. */
  27945. ol.control.MousePosition.prototype.handleMouseOut = function(event) {
  27946. this.updateHTML_(null);
  27947. this.lastMouseMovePixel_ = null;
  27948. };
  27949. /**
  27950. * @inheritDoc
  27951. * @api
  27952. */
  27953. ol.control.MousePosition.prototype.setMap = function(map) {
  27954. ol.control.Control.prototype.setMap.call(this, map);
  27955. if (map) {
  27956. var viewport = map.getViewport();
  27957. this.listenerKeys.push(
  27958. ol.events.listen(viewport, ol.events.EventType.MOUSEMOVE,
  27959. this.handleMouseMove, this),
  27960. ol.events.listen(viewport, ol.events.EventType.MOUSEOUT,
  27961. this.handleMouseOut, this)
  27962. );
  27963. }
  27964. };
  27965. /**
  27966. * Set the coordinate format type used to render the current position.
  27967. * @param {ol.CoordinateFormatType} format The format to render the current
  27968. * position in.
  27969. * @observable
  27970. * @api
  27971. */
  27972. ol.control.MousePosition.prototype.setCoordinateFormat = function(format) {
  27973. this.set(ol.control.MousePosition.Property_.COORDINATE_FORMAT, format);
  27974. };
  27975. /**
  27976. * Set the projection that is used to report the mouse position.
  27977. * @param {ol.ProjectionLike} projection The projection to report mouse
  27978. * position in.
  27979. * @observable
  27980. * @api
  27981. */
  27982. ol.control.MousePosition.prototype.setProjection = function(projection) {
  27983. this.set(ol.control.MousePosition.Property_.PROJECTION, ol.proj.get(projection));
  27984. };
  27985. /**
  27986. * @param {?ol.Pixel} pixel Pixel.
  27987. * @private
  27988. */
  27989. ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
  27990. var html = this.undefinedHTML_;
  27991. if (pixel && this.mapProjection_) {
  27992. if (!this.transform_) {
  27993. var projection = this.getProjection();
  27994. if (projection) {
  27995. this.transform_ = ol.proj.getTransformFromProjections(
  27996. this.mapProjection_, projection);
  27997. } else {
  27998. this.transform_ = ol.proj.identityTransform;
  27999. }
  28000. }
  28001. var map = this.getMap();
  28002. var coordinate = map.getCoordinateFromPixel(pixel);
  28003. if (coordinate) {
  28004. this.transform_(coordinate, coordinate);
  28005. var coordinateFormat = this.getCoordinateFormat();
  28006. if (coordinateFormat) {
  28007. html = coordinateFormat(coordinate);
  28008. } else {
  28009. html = coordinate.toString();
  28010. }
  28011. }
  28012. }
  28013. if (!this.renderedHTML_ || html != this.renderedHTML_) {
  28014. this.element.innerHTML = html;
  28015. this.renderedHTML_ = html;
  28016. }
  28017. };
  28018. /**
  28019. * @enum {string}
  28020. * @private
  28021. */
  28022. ol.control.MousePosition.Property_ = {
  28023. PROJECTION: 'projection',
  28024. COORDINATE_FORMAT: 'coordinateFormat'
  28025. };
  28026. goog.provide('ol.OverlayPositioning');
  28027. /**
  28028. * Overlay position: `'bottom-left'`, `'bottom-center'`, `'bottom-right'`,
  28029. * `'center-left'`, `'center-center'`, `'center-right'`, `'top-left'`,
  28030. * `'top-center'`, `'top-right'`
  28031. * @enum {string}
  28032. */
  28033. ol.OverlayPositioning = {
  28034. BOTTOM_LEFT: 'bottom-left',
  28035. BOTTOM_CENTER: 'bottom-center',
  28036. BOTTOM_RIGHT: 'bottom-right',
  28037. CENTER_LEFT: 'center-left',
  28038. CENTER_CENTER: 'center-center',
  28039. CENTER_RIGHT: 'center-right',
  28040. TOP_LEFT: 'top-left',
  28041. TOP_CENTER: 'top-center',
  28042. TOP_RIGHT: 'top-right'
  28043. };
  28044. goog.provide('ol.Overlay');
  28045. goog.require('ol');
  28046. goog.require('ol.MapEventType');
  28047. goog.require('ol.Object');
  28048. goog.require('ol.OverlayPositioning');
  28049. goog.require('ol.css');
  28050. goog.require('ol.dom');
  28051. goog.require('ol.events');
  28052. goog.require('ol.extent');
  28053. /**
  28054. * @classdesc
  28055. * An element to be displayed over the map and attached to a single map
  28056. * location. Like {@link ol.control.Control}, Overlays are visible widgets.
  28057. * Unlike Controls, they are not in a fixed position on the screen, but are tied
  28058. * to a geographical coordinate, so panning the map will move an Overlay but not
  28059. * a Control.
  28060. *
  28061. * Example:
  28062. *
  28063. * var popup = new ol.Overlay({
  28064. * element: document.getElementById('popup')
  28065. * });
  28066. * popup.setPosition(coordinate);
  28067. * map.addOverlay(popup);
  28068. *
  28069. * @constructor
  28070. * @extends {ol.Object}
  28071. * @param {olx.OverlayOptions} options Overlay options.
  28072. * @api
  28073. */
  28074. ol.Overlay = function(options) {
  28075. ol.Object.call(this);
  28076. /**
  28077. * @protected
  28078. * @type {olx.OverlayOptions}
  28079. */
  28080. this.options = options;
  28081. /**
  28082. * @protected
  28083. * @type {number|string|undefined}
  28084. */
  28085. this.id = options.id;
  28086. /**
  28087. * @protected
  28088. * @type {boolean}
  28089. */
  28090. this.insertFirst = options.insertFirst !== undefined ?
  28091. options.insertFirst : true;
  28092. /**
  28093. * @protected
  28094. * @type {boolean}
  28095. */
  28096. this.stopEvent = options.stopEvent !== undefined ? options.stopEvent : true;
  28097. /**
  28098. * @protected
  28099. * @type {Element}
  28100. */
  28101. this.element = document.createElement('DIV');
  28102. this.element.className = options.className !== undefined ?
  28103. options.className : 'ol-overlay-container ' + ol.css.CLASS_SELECTABLE;
  28104. this.element.style.position = 'absolute';
  28105. /**
  28106. * @protected
  28107. * @type {boolean}
  28108. */
  28109. this.autoPan = options.autoPan !== undefined ? options.autoPan : false;
  28110. /**
  28111. * @protected
  28112. * @type {olx.OverlayPanOptions}
  28113. */
  28114. this.autoPanAnimation = options.autoPanAnimation ||
  28115. /** @type {olx.OverlayPanOptions} */ ({});
  28116. /**
  28117. * @protected
  28118. * @type {number}
  28119. */
  28120. this.autoPanMargin = options.autoPanMargin !== undefined ?
  28121. options.autoPanMargin : 20;
  28122. /**
  28123. * @protected
  28124. * @type {{bottom_: string,
  28125. * left_: string,
  28126. * right_: string,
  28127. * top_: string,
  28128. * visible: boolean}}
  28129. */
  28130. this.rendered = {
  28131. bottom_: '',
  28132. left_: '',
  28133. right_: '',
  28134. top_: '',
  28135. visible: true
  28136. };
  28137. /**
  28138. * @protected
  28139. * @type {?ol.EventsKey}
  28140. */
  28141. this.mapPostrenderListenerKey = null;
  28142. ol.events.listen(
  28143. this, ol.Object.getChangeEventType(ol.Overlay.Property.ELEMENT),
  28144. this.handleElementChanged, this);
  28145. ol.events.listen(
  28146. this, ol.Object.getChangeEventType(ol.Overlay.Property.MAP),
  28147. this.handleMapChanged, this);
  28148. ol.events.listen(
  28149. this, ol.Object.getChangeEventType(ol.Overlay.Property.OFFSET),
  28150. this.handleOffsetChanged, this);
  28151. ol.events.listen(
  28152. this, ol.Object.getChangeEventType(ol.Overlay.Property.POSITION),
  28153. this.handlePositionChanged, this);
  28154. ol.events.listen(
  28155. this, ol.Object.getChangeEventType(ol.Overlay.Property.POSITIONING),
  28156. this.handlePositioningChanged, this);
  28157. if (options.element !== undefined) {
  28158. this.setElement(options.element);
  28159. }
  28160. this.setOffset(options.offset !== undefined ? options.offset : [0, 0]);
  28161. this.setPositioning(options.positioning !== undefined ?
  28162. /** @type {ol.OverlayPositioning} */ (options.positioning) :
  28163. ol.OverlayPositioning.TOP_LEFT);
  28164. if (options.position !== undefined) {
  28165. this.setPosition(options.position);
  28166. }
  28167. };
  28168. ol.inherits(ol.Overlay, ol.Object);
  28169. /**
  28170. * Get the DOM element of this overlay.
  28171. * @return {Element|undefined} The Element containing the overlay.
  28172. * @observable
  28173. * @api
  28174. */
  28175. ol.Overlay.prototype.getElement = function() {
  28176. return /** @type {Element|undefined} */ (
  28177. this.get(ol.Overlay.Property.ELEMENT));
  28178. };
  28179. /**
  28180. * Get the overlay identifier which is set on constructor.
  28181. * @return {number|string|undefined} Id.
  28182. * @api
  28183. */
  28184. ol.Overlay.prototype.getId = function() {
  28185. return this.id;
  28186. };
  28187. /**
  28188. * Get the map associated with this overlay.
  28189. * @return {ol.PluggableMap|undefined} The map that the overlay is part of.
  28190. * @observable
  28191. * @api
  28192. */
  28193. ol.Overlay.prototype.getMap = function() {
  28194. return /** @type {ol.PluggableMap|undefined} */ (
  28195. this.get(ol.Overlay.Property.MAP));
  28196. };
  28197. /**
  28198. * Get the offset of this overlay.
  28199. * @return {Array.<number>} The offset.
  28200. * @observable
  28201. * @api
  28202. */
  28203. ol.Overlay.prototype.getOffset = function() {
  28204. return /** @type {Array.<number>} */ (
  28205. this.get(ol.Overlay.Property.OFFSET));
  28206. };
  28207. /**
  28208. * Get the current position of this overlay.
  28209. * @return {ol.Coordinate|undefined} The spatial point that the overlay is
  28210. * anchored at.
  28211. * @observable
  28212. * @api
  28213. */
  28214. ol.Overlay.prototype.getPosition = function() {
  28215. return /** @type {ol.Coordinate|undefined} */ (
  28216. this.get(ol.Overlay.Property.POSITION));
  28217. };
  28218. /**
  28219. * Get the current positioning of this overlay.
  28220. * @return {ol.OverlayPositioning} How the overlay is positioned
  28221. * relative to its point on the map.
  28222. * @observable
  28223. * @api
  28224. */
  28225. ol.Overlay.prototype.getPositioning = function() {
  28226. return /** @type {ol.OverlayPositioning} */ (
  28227. this.get(ol.Overlay.Property.POSITIONING));
  28228. };
  28229. /**
  28230. * @protected
  28231. */
  28232. ol.Overlay.prototype.handleElementChanged = function() {
  28233. ol.dom.removeChildren(this.element);
  28234. var element = this.getElement();
  28235. if (element) {
  28236. this.element.appendChild(element);
  28237. }
  28238. };
  28239. /**
  28240. * @protected
  28241. */
  28242. ol.Overlay.prototype.handleMapChanged = function() {
  28243. if (this.mapPostrenderListenerKey) {
  28244. ol.dom.removeNode(this.element);
  28245. ol.events.unlistenByKey(this.mapPostrenderListenerKey);
  28246. this.mapPostrenderListenerKey = null;
  28247. }
  28248. var map = this.getMap();
  28249. if (map) {
  28250. this.mapPostrenderListenerKey = ol.events.listen(map,
  28251. ol.MapEventType.POSTRENDER, this.render, this);
  28252. this.updatePixelPosition();
  28253. var container = this.stopEvent ?
  28254. map.getOverlayContainerStopEvent() : map.getOverlayContainer();
  28255. if (this.insertFirst) {
  28256. container.insertBefore(this.element, container.childNodes[0] || null);
  28257. } else {
  28258. container.appendChild(this.element);
  28259. }
  28260. }
  28261. };
  28262. /**
  28263. * @protected
  28264. */
  28265. ol.Overlay.prototype.render = function() {
  28266. this.updatePixelPosition();
  28267. };
  28268. /**
  28269. * @protected
  28270. */
  28271. ol.Overlay.prototype.handleOffsetChanged = function() {
  28272. this.updatePixelPosition();
  28273. };
  28274. /**
  28275. * @protected
  28276. */
  28277. ol.Overlay.prototype.handlePositionChanged = function() {
  28278. this.updatePixelPosition();
  28279. if (this.get(ol.Overlay.Property.POSITION) && this.autoPan) {
  28280. this.panIntoView();
  28281. }
  28282. };
  28283. /**
  28284. * @protected
  28285. */
  28286. ol.Overlay.prototype.handlePositioningChanged = function() {
  28287. this.updatePixelPosition();
  28288. };
  28289. /**
  28290. * Set the DOM element to be associated with this overlay.
  28291. * @param {Element|undefined} element The Element containing the overlay.
  28292. * @observable
  28293. * @api
  28294. */
  28295. ol.Overlay.prototype.setElement = function(element) {
  28296. this.set(ol.Overlay.Property.ELEMENT, element);
  28297. };
  28298. /**
  28299. * Set the map to be associated with this overlay.
  28300. * @param {ol.PluggableMap|undefined} map The map that the overlay is part of.
  28301. * @observable
  28302. * @api
  28303. */
  28304. ol.Overlay.prototype.setMap = function(map) {
  28305. this.set(ol.Overlay.Property.MAP, map);
  28306. };
  28307. /**
  28308. * Set the offset for this overlay.
  28309. * @param {Array.<number>} offset Offset.
  28310. * @observable
  28311. * @api
  28312. */
  28313. ol.Overlay.prototype.setOffset = function(offset) {
  28314. this.set(ol.Overlay.Property.OFFSET, offset);
  28315. };
  28316. /**
  28317. * Set the position for this overlay. If the position is `undefined` the
  28318. * overlay is hidden.
  28319. * @param {ol.Coordinate|undefined} position The spatial point that the overlay
  28320. * is anchored at.
  28321. * @observable
  28322. * @api
  28323. */
  28324. ol.Overlay.prototype.setPosition = function(position) {
  28325. this.set(ol.Overlay.Property.POSITION, position);
  28326. };
  28327. /**
  28328. * Pan the map so that the overlay is entirely visible in the current viewport
  28329. * (if necessary).
  28330. * @protected
  28331. */
  28332. ol.Overlay.prototype.panIntoView = function() {
  28333. var map = this.getMap();
  28334. if (!map || !map.getTargetElement()) {
  28335. return;
  28336. }
  28337. var mapRect = this.getRect(map.getTargetElement(), map.getSize());
  28338. var element = /** @type {!Element} */ (this.getElement());
  28339. var overlayRect = this.getRect(element,
  28340. [ol.dom.outerWidth(element), ol.dom.outerHeight(element)]);
  28341. var margin = this.autoPanMargin;
  28342. if (!ol.extent.containsExtent(mapRect, overlayRect)) {
  28343. // the overlay is not completely inside the viewport, so pan the map
  28344. var offsetLeft = overlayRect[0] - mapRect[0];
  28345. var offsetRight = mapRect[2] - overlayRect[2];
  28346. var offsetTop = overlayRect[1] - mapRect[1];
  28347. var offsetBottom = mapRect[3] - overlayRect[3];
  28348. var delta = [0, 0];
  28349. if (offsetLeft < 0) {
  28350. // move map to the left
  28351. delta[0] = offsetLeft - margin;
  28352. } else if (offsetRight < 0) {
  28353. // move map to the right
  28354. delta[0] = Math.abs(offsetRight) + margin;
  28355. }
  28356. if (offsetTop < 0) {
  28357. // move map up
  28358. delta[1] = offsetTop - margin;
  28359. } else if (offsetBottom < 0) {
  28360. // move map down
  28361. delta[1] = Math.abs(offsetBottom) + margin;
  28362. }
  28363. if (delta[0] !== 0 || delta[1] !== 0) {
  28364. var center = /** @type {ol.Coordinate} */ (map.getView().getCenter());
  28365. var centerPx = map.getPixelFromCoordinate(center);
  28366. var newCenterPx = [
  28367. centerPx[0] + delta[0],
  28368. centerPx[1] + delta[1]
  28369. ];
  28370. map.getView().animate({
  28371. center: map.getCoordinateFromPixel(newCenterPx),
  28372. duration: this.autoPanAnimation.duration,
  28373. easing: this.autoPanAnimation.easing
  28374. });
  28375. }
  28376. }
  28377. };
  28378. /**
  28379. * Get the extent of an element relative to the document
  28380. * @param {Element|undefined} element The element.
  28381. * @param {ol.Size|undefined} size The size of the element.
  28382. * @return {ol.Extent} The extent.
  28383. * @protected
  28384. */
  28385. ol.Overlay.prototype.getRect = function(element, size) {
  28386. var box = element.getBoundingClientRect();
  28387. var offsetX = box.left + window.pageXOffset;
  28388. var offsetY = box.top + window.pageYOffset;
  28389. return [
  28390. offsetX,
  28391. offsetY,
  28392. offsetX + size[0],
  28393. offsetY + size[1]
  28394. ];
  28395. };
  28396. /**
  28397. * Set the positioning for this overlay.
  28398. * @param {ol.OverlayPositioning} positioning how the overlay is
  28399. * positioned relative to its point on the map.
  28400. * @observable
  28401. * @api
  28402. */
  28403. ol.Overlay.prototype.setPositioning = function(positioning) {
  28404. this.set(ol.Overlay.Property.POSITIONING, positioning);
  28405. };
  28406. /**
  28407. * Modify the visibility of the element.
  28408. * @param {boolean} visible Element visibility.
  28409. * @protected
  28410. */
  28411. ol.Overlay.prototype.setVisible = function(visible) {
  28412. if (this.rendered.visible !== visible) {
  28413. this.element.style.display = visible ? '' : 'none';
  28414. this.rendered.visible = visible;
  28415. }
  28416. };
  28417. /**
  28418. * Update pixel position.
  28419. * @protected
  28420. */
  28421. ol.Overlay.prototype.updatePixelPosition = function() {
  28422. var map = this.getMap();
  28423. var position = this.getPosition();
  28424. if (!map || !map.isRendered() || !position) {
  28425. this.setVisible(false);
  28426. return;
  28427. }
  28428. var pixel = map.getPixelFromCoordinate(position);
  28429. var mapSize = map.getSize();
  28430. this.updateRenderedPosition(pixel, mapSize);
  28431. };
  28432. /**
  28433. * @param {ol.Pixel} pixel The pixel location.
  28434. * @param {ol.Size|undefined} mapSize The map size.
  28435. * @protected
  28436. */
  28437. ol.Overlay.prototype.updateRenderedPosition = function(pixel, mapSize) {
  28438. var style = this.element.style;
  28439. var offset = this.getOffset();
  28440. var positioning = this.getPositioning();
  28441. this.setVisible(true);
  28442. var offsetX = offset[0];
  28443. var offsetY = offset[1];
  28444. if (positioning == ol.OverlayPositioning.BOTTOM_RIGHT ||
  28445. positioning == ol.OverlayPositioning.CENTER_RIGHT ||
  28446. positioning == ol.OverlayPositioning.TOP_RIGHT) {
  28447. if (this.rendered.left_ !== '') {
  28448. this.rendered.left_ = style.left = '';
  28449. }
  28450. var right = Math.round(mapSize[0] - pixel[0] - offsetX) + 'px';
  28451. if (this.rendered.right_ != right) {
  28452. this.rendered.right_ = style.right = right;
  28453. }
  28454. } else {
  28455. if (this.rendered.right_ !== '') {
  28456. this.rendered.right_ = style.right = '';
  28457. }
  28458. if (positioning == ol.OverlayPositioning.BOTTOM_CENTER ||
  28459. positioning == ol.OverlayPositioning.CENTER_CENTER ||
  28460. positioning == ol.OverlayPositioning.TOP_CENTER) {
  28461. offsetX -= this.element.offsetWidth / 2;
  28462. }
  28463. var left = Math.round(pixel[0] + offsetX) + 'px';
  28464. if (this.rendered.left_ != left) {
  28465. this.rendered.left_ = style.left = left;
  28466. }
  28467. }
  28468. if (positioning == ol.OverlayPositioning.BOTTOM_LEFT ||
  28469. positioning == ol.OverlayPositioning.BOTTOM_CENTER ||
  28470. positioning == ol.OverlayPositioning.BOTTOM_RIGHT) {
  28471. if (this.rendered.top_ !== '') {
  28472. this.rendered.top_ = style.top = '';
  28473. }
  28474. var bottom = Math.round(mapSize[1] - pixel[1] - offsetY) + 'px';
  28475. if (this.rendered.bottom_ != bottom) {
  28476. this.rendered.bottom_ = style.bottom = bottom;
  28477. }
  28478. } else {
  28479. if (this.rendered.bottom_ !== '') {
  28480. this.rendered.bottom_ = style.bottom = '';
  28481. }
  28482. if (positioning == ol.OverlayPositioning.CENTER_LEFT ||
  28483. positioning == ol.OverlayPositioning.CENTER_CENTER ||
  28484. positioning == ol.OverlayPositioning.CENTER_RIGHT) {
  28485. offsetY -= this.element.offsetHeight / 2;
  28486. }
  28487. var top = Math.round(pixel[1] + offsetY) + 'px';
  28488. if (this.rendered.top_ != top) {
  28489. this.rendered.top_ = style.top = top;
  28490. }
  28491. }
  28492. };
  28493. /**
  28494. * returns the options this Overlay has been created with
  28495. * @public
  28496. * @return {olx.OverlayOptions} overlay options
  28497. */
  28498. ol.Overlay.prototype.getOptions = function() {
  28499. return this.options;
  28500. };
  28501. /**
  28502. * @enum {string}
  28503. * @protected
  28504. */
  28505. ol.Overlay.Property = {
  28506. ELEMENT: 'element',
  28507. MAP: 'map',
  28508. OFFSET: 'offset',
  28509. POSITION: 'position',
  28510. POSITIONING: 'positioning'
  28511. };
  28512. goog.provide('ol.control.OverviewMap');
  28513. goog.require('ol');
  28514. goog.require('ol.Collection');
  28515. goog.require('ol.PluggableMap');
  28516. goog.require('ol.MapEventType');
  28517. goog.require('ol.MapProperty');
  28518. goog.require('ol.Object');
  28519. goog.require('ol.ObjectEventType');
  28520. goog.require('ol.Overlay');
  28521. goog.require('ol.OverlayPositioning');
  28522. goog.require('ol.ViewProperty');
  28523. goog.require('ol.control.Control');
  28524. goog.require('ol.coordinate');
  28525. goog.require('ol.css');
  28526. goog.require('ol.dom');
  28527. goog.require('ol.events');
  28528. goog.require('ol.events.EventType');
  28529. goog.require('ol.extent');
  28530. /**
  28531. * Create a new control with a map acting as an overview map for an other
  28532. * defined map.
  28533. * @constructor
  28534. * @extends {ol.control.Control}
  28535. * @param {olx.control.OverviewMapOptions=} opt_options OverviewMap options.
  28536. * @api
  28537. */
  28538. ol.control.OverviewMap = function(opt_options) {
  28539. var options = opt_options ? opt_options : {};
  28540. /**
  28541. * @type {boolean}
  28542. * @private
  28543. */
  28544. this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true;
  28545. /**
  28546. * @private
  28547. * @type {boolean}
  28548. */
  28549. this.collapsible_ = options.collapsible !== undefined ?
  28550. options.collapsible : true;
  28551. if (!this.collapsible_) {
  28552. this.collapsed_ = false;
  28553. }
  28554. var className = options.className !== undefined ? options.className : 'ol-overviewmap';
  28555. var tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Overview map';
  28556. var collapseLabel = options.collapseLabel !== undefined ? options.collapseLabel : '\u00AB';
  28557. if (typeof collapseLabel === 'string') {
  28558. /**
  28559. * @private
  28560. * @type {Node}
  28561. */
  28562. this.collapseLabel_ = document.createElement('span');
  28563. this.collapseLabel_.textContent = collapseLabel;
  28564. } else {
  28565. this.collapseLabel_ = collapseLabel;
  28566. }
  28567. var label = options.label !== undefined ? options.label : '\u00BB';
  28568. if (typeof label === 'string') {
  28569. /**
  28570. * @private
  28571. * @type {Node}
  28572. */
  28573. this.label_ = document.createElement('span');
  28574. this.label_.textContent = label;
  28575. } else {
  28576. this.label_ = label;
  28577. }
  28578. var activeLabel = (this.collapsible_ && !this.collapsed_) ?
  28579. this.collapseLabel_ : this.label_;
  28580. var button = document.createElement('button');
  28581. button.setAttribute('type', 'button');
  28582. button.title = tipLabel;
  28583. button.appendChild(activeLabel);
  28584. ol.events.listen(button, ol.events.EventType.CLICK,
  28585. this.handleClick_, this);
  28586. /**
  28587. * @type {Element}
  28588. * @private
  28589. */
  28590. this.ovmapDiv_ = document.createElement('DIV');
  28591. this.ovmapDiv_.className = 'ol-overviewmap-map';
  28592. /**
  28593. * @type {ol.PluggableMap}
  28594. * @private
  28595. */
  28596. this.ovmap_ = new ol.PluggableMap({
  28597. controls: new ol.Collection(),
  28598. interactions: new ol.Collection(),
  28599. view: options.view
  28600. });
  28601. var ovmap = this.ovmap_;
  28602. if (options.layers) {
  28603. options.layers.forEach(
  28604. /**
  28605. * @param {ol.layer.Layer} layer Layer.
  28606. */
  28607. function(layer) {
  28608. ovmap.addLayer(layer);
  28609. }, this);
  28610. }
  28611. var box = document.createElement('DIV');
  28612. box.className = 'ol-overviewmap-box';
  28613. box.style.boxSizing = 'border-box';
  28614. /**
  28615. * @type {ol.Overlay}
  28616. * @private
  28617. */
  28618. this.boxOverlay_ = new ol.Overlay({
  28619. position: [0, 0],
  28620. positioning: ol.OverlayPositioning.BOTTOM_LEFT,
  28621. element: box
  28622. });
  28623. this.ovmap_.addOverlay(this.boxOverlay_);
  28624. var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
  28625. ol.css.CLASS_CONTROL +
  28626. (this.collapsed_ && this.collapsible_ ? ' ol-collapsed' : '') +
  28627. (this.collapsible_ ? '' : ' ol-uncollapsible');
  28628. var element = document.createElement('div');
  28629. element.className = cssClasses;
  28630. element.appendChild(this.ovmapDiv_);
  28631. element.appendChild(button);
  28632. var render = options.render ? options.render : ol.control.OverviewMap.render;
  28633. ol.control.Control.call(this, {
  28634. element: element,
  28635. render: render,
  28636. target: options.target
  28637. });
  28638. /* Interactive map */
  28639. var scope = this;
  28640. var overlay = this.boxOverlay_;
  28641. var overlayBox = this.boxOverlay_.getElement();
  28642. /* Functions definition */
  28643. var computeDesiredMousePosition = function(mousePosition) {
  28644. return {
  28645. clientX: mousePosition.clientX - (overlayBox.offsetWidth / 2),
  28646. clientY: mousePosition.clientY + (overlayBox.offsetHeight / 2)
  28647. };
  28648. };
  28649. var move = function(event) {
  28650. var coordinates = ovmap.getEventCoordinate(computeDesiredMousePosition(event));
  28651. overlay.setPosition(coordinates);
  28652. };
  28653. var endMoving = function(event) {
  28654. var coordinates = ovmap.getEventCoordinate(event);
  28655. scope.getMap().getView().setCenter(coordinates);
  28656. window.removeEventListener('mousemove', move);
  28657. window.removeEventListener('mouseup', endMoving);
  28658. };
  28659. /* Binding */
  28660. overlayBox.addEventListener('mousedown', function() {
  28661. window.addEventListener('mousemove', move);
  28662. window.addEventListener('mouseup', endMoving);
  28663. });
  28664. };
  28665. ol.inherits(ol.control.OverviewMap, ol.control.Control);
  28666. /**
  28667. * @inheritDoc
  28668. * @api
  28669. */
  28670. ol.control.OverviewMap.prototype.setMap = function(map) {
  28671. var oldMap = this.getMap();
  28672. if (map === oldMap) {
  28673. return;
  28674. }
  28675. if (oldMap) {
  28676. var oldView = oldMap.getView();
  28677. if (oldView) {
  28678. this.unbindView_(oldView);
  28679. }
  28680. this.ovmap_.setTarget(null);
  28681. }
  28682. ol.control.Control.prototype.setMap.call(this, map);
  28683. if (map) {
  28684. this.ovmap_.setTarget(this.ovmapDiv_);
  28685. this.listenerKeys.push(ol.events.listen(
  28686. map, ol.ObjectEventType.PROPERTYCHANGE,
  28687. this.handleMapPropertyChange_, this));
  28688. // TODO: to really support map switching, this would need to be reworked
  28689. if (this.ovmap_.getLayers().getLength() === 0) {
  28690. this.ovmap_.setLayerGroup(map.getLayerGroup());
  28691. }
  28692. var view = map.getView();
  28693. if (view) {
  28694. this.bindView_(view);
  28695. if (view.isDef()) {
  28696. this.ovmap_.updateSize();
  28697. this.resetExtent_();
  28698. }
  28699. }
  28700. }
  28701. };
  28702. /**
  28703. * Handle map property changes. This only deals with changes to the map's view.
  28704. * @param {ol.Object.Event} event The propertychange event.
  28705. * @private
  28706. */
  28707. ol.control.OverviewMap.prototype.handleMapPropertyChange_ = function(event) {
  28708. if (event.key === ol.MapProperty.VIEW) {
  28709. var oldView = /** @type {ol.View} */ (event.oldValue);
  28710. if (oldView) {
  28711. this.unbindView_(oldView);
  28712. }
  28713. var newView = this.getMap().getView();
  28714. this.bindView_(newView);
  28715. }
  28716. };
  28717. /**
  28718. * Register listeners for view property changes.
  28719. * @param {ol.View} view The view.
  28720. * @private
  28721. */
  28722. ol.control.OverviewMap.prototype.bindView_ = function(view) {
  28723. ol.events.listen(view,
  28724. ol.Object.getChangeEventType(ol.ViewProperty.ROTATION),
  28725. this.handleRotationChanged_, this);
  28726. };
  28727. /**
  28728. * Unregister listeners for view property changes.
  28729. * @param {ol.View} view The view.
  28730. * @private
  28731. */
  28732. ol.control.OverviewMap.prototype.unbindView_ = function(view) {
  28733. ol.events.unlisten(view,
  28734. ol.Object.getChangeEventType(ol.ViewProperty.ROTATION),
  28735. this.handleRotationChanged_, this);
  28736. };
  28737. /**
  28738. * Handle rotation changes to the main map.
  28739. * TODO: This should rotate the extent rectrangle instead of the
  28740. * overview map's view.
  28741. * @private
  28742. */
  28743. ol.control.OverviewMap.prototype.handleRotationChanged_ = function() {
  28744. this.ovmap_.getView().setRotation(this.getMap().getView().getRotation());
  28745. };
  28746. /**
  28747. * Update the overview map element.
  28748. * @param {ol.MapEvent} mapEvent Map event.
  28749. * @this {ol.control.OverviewMap}
  28750. * @api
  28751. */
  28752. ol.control.OverviewMap.render = function(mapEvent) {
  28753. this.validateExtent_();
  28754. this.updateBox_();
  28755. };
  28756. /**
  28757. * Reset the overview map extent if the box size (width or
  28758. * height) is less than the size of the overview map size times minRatio
  28759. * or is greater than the size of the overview size times maxRatio.
  28760. *
  28761. * If the map extent was not reset, the box size can fits in the defined
  28762. * ratio sizes. This method then checks if is contained inside the overview
  28763. * map current extent. If not, recenter the overview map to the current
  28764. * main map center location.
  28765. * @private
  28766. */
  28767. ol.control.OverviewMap.prototype.validateExtent_ = function() {
  28768. var map = this.getMap();
  28769. var ovmap = this.ovmap_;
  28770. if (!map.isRendered() || !ovmap.isRendered()) {
  28771. return;
  28772. }
  28773. var mapSize = /** @type {ol.Size} */ (map.getSize());
  28774. var view = map.getView();
  28775. var extent = view.calculateExtent(mapSize);
  28776. var ovmapSize = /** @type {ol.Size} */ (ovmap.getSize());
  28777. var ovview = ovmap.getView();
  28778. var ovextent = ovview.calculateExtent(ovmapSize);
  28779. var topLeftPixel =
  28780. ovmap.getPixelFromCoordinate(ol.extent.getTopLeft(extent));
  28781. var bottomRightPixel =
  28782. ovmap.getPixelFromCoordinate(ol.extent.getBottomRight(extent));
  28783. var boxWidth = Math.abs(topLeftPixel[0] - bottomRightPixel[0]);
  28784. var boxHeight = Math.abs(topLeftPixel[1] - bottomRightPixel[1]);
  28785. var ovmapWidth = ovmapSize[0];
  28786. var ovmapHeight = ovmapSize[1];
  28787. if (boxWidth < ovmapWidth * ol.OVERVIEWMAP_MIN_RATIO ||
  28788. boxHeight < ovmapHeight * ol.OVERVIEWMAP_MIN_RATIO ||
  28789. boxWidth > ovmapWidth * ol.OVERVIEWMAP_MAX_RATIO ||
  28790. boxHeight > ovmapHeight * ol.OVERVIEWMAP_MAX_RATIO) {
  28791. this.resetExtent_();
  28792. } else if (!ol.extent.containsExtent(ovextent, extent)) {
  28793. this.recenter_();
  28794. }
  28795. };
  28796. /**
  28797. * Reset the overview map extent to half calculated min and max ratio times
  28798. * the extent of the main map.
  28799. * @private
  28800. */
  28801. ol.control.OverviewMap.prototype.resetExtent_ = function() {
  28802. if (ol.OVERVIEWMAP_MAX_RATIO === 0 || ol.OVERVIEWMAP_MIN_RATIO === 0) {
  28803. return;
  28804. }
  28805. var map = this.getMap();
  28806. var ovmap = this.ovmap_;
  28807. var mapSize = /** @type {ol.Size} */ (map.getSize());
  28808. var view = map.getView();
  28809. var extent = view.calculateExtent(mapSize);
  28810. var ovview = ovmap.getView();
  28811. // get how many times the current map overview could hold different
  28812. // box sizes using the min and max ratio, pick the step in the middle used
  28813. // to calculate the extent from the main map to set it to the overview map,
  28814. var steps = Math.log(
  28815. ol.OVERVIEWMAP_MAX_RATIO / ol.OVERVIEWMAP_MIN_RATIO) / Math.LN2;
  28816. var ratio = 1 / (Math.pow(2, steps / 2) * ol.OVERVIEWMAP_MIN_RATIO);
  28817. ol.extent.scaleFromCenter(extent, ratio);
  28818. ovview.fit(extent);
  28819. };
  28820. /**
  28821. * Set the center of the overview map to the map center without changing its
  28822. * resolution.
  28823. * @private
  28824. */
  28825. ol.control.OverviewMap.prototype.recenter_ = function() {
  28826. var map = this.getMap();
  28827. var ovmap = this.ovmap_;
  28828. var view = map.getView();
  28829. var ovview = ovmap.getView();
  28830. ovview.setCenter(view.getCenter());
  28831. };
  28832. /**
  28833. * Update the box using the main map extent
  28834. * @private
  28835. */
  28836. ol.control.OverviewMap.prototype.updateBox_ = function() {
  28837. var map = this.getMap();
  28838. var ovmap = this.ovmap_;
  28839. if (!map.isRendered() || !ovmap.isRendered()) {
  28840. return;
  28841. }
  28842. var mapSize = /** @type {ol.Size} */ (map.getSize());
  28843. var view = map.getView();
  28844. var ovview = ovmap.getView();
  28845. var rotation = view.getRotation();
  28846. var overlay = this.boxOverlay_;
  28847. var box = this.boxOverlay_.getElement();
  28848. var extent = view.calculateExtent(mapSize);
  28849. var ovresolution = ovview.getResolution();
  28850. var bottomLeft = ol.extent.getBottomLeft(extent);
  28851. var topRight = ol.extent.getTopRight(extent);
  28852. // set position using bottom left coordinates
  28853. var rotateBottomLeft = this.calculateCoordinateRotate_(rotation, bottomLeft);
  28854. overlay.setPosition(rotateBottomLeft);
  28855. // set box size calculated from map extent size and overview map resolution
  28856. if (box) {
  28857. box.style.width = Math.abs((bottomLeft[0] - topRight[0]) / ovresolution) + 'px';
  28858. box.style.height = Math.abs((topRight[1] - bottomLeft[1]) / ovresolution) + 'px';
  28859. }
  28860. };
  28861. /**
  28862. * @param {number} rotation Target rotation.
  28863. * @param {ol.Coordinate} coordinate Coordinate.
  28864. * @return {ol.Coordinate|undefined} Coordinate for rotation and center anchor.
  28865. * @private
  28866. */
  28867. ol.control.OverviewMap.prototype.calculateCoordinateRotate_ = function(
  28868. rotation, coordinate) {
  28869. var coordinateRotate;
  28870. var map = this.getMap();
  28871. var view = map.getView();
  28872. var currentCenter = view.getCenter();
  28873. if (currentCenter) {
  28874. coordinateRotate = [
  28875. coordinate[0] - currentCenter[0],
  28876. coordinate[1] - currentCenter[1]
  28877. ];
  28878. ol.coordinate.rotate(coordinateRotate, rotation);
  28879. ol.coordinate.add(coordinateRotate, currentCenter);
  28880. }
  28881. return coordinateRotate;
  28882. };
  28883. /**
  28884. * @param {Event} event The event to handle
  28885. * @private
  28886. */
  28887. ol.control.OverviewMap.prototype.handleClick_ = function(event) {
  28888. event.preventDefault();
  28889. this.handleToggle_();
  28890. };
  28891. /**
  28892. * @private
  28893. */
  28894. ol.control.OverviewMap.prototype.handleToggle_ = function() {
  28895. this.element.classList.toggle('ol-collapsed');
  28896. if (this.collapsed_) {
  28897. ol.dom.replaceNode(this.collapseLabel_, this.label_);
  28898. } else {
  28899. ol.dom.replaceNode(this.label_, this.collapseLabel_);
  28900. }
  28901. this.collapsed_ = !this.collapsed_;
  28902. // manage overview map if it had not been rendered before and control
  28903. // is expanded
  28904. var ovmap = this.ovmap_;
  28905. if (!this.collapsed_ && !ovmap.isRendered()) {
  28906. ovmap.updateSize();
  28907. this.resetExtent_();
  28908. ol.events.listenOnce(ovmap, ol.MapEventType.POSTRENDER,
  28909. function(event) {
  28910. this.updateBox_();
  28911. },
  28912. this);
  28913. }
  28914. };
  28915. /**
  28916. * Return `true` if the overview map is collapsible, `false` otherwise.
  28917. * @return {boolean} True if the widget is collapsible.
  28918. * @api
  28919. */
  28920. ol.control.OverviewMap.prototype.getCollapsible = function() {
  28921. return this.collapsible_;
  28922. };
  28923. /**
  28924. * Set whether the overview map should be collapsible.
  28925. * @param {boolean} collapsible True if the widget is collapsible.
  28926. * @api
  28927. */
  28928. ol.control.OverviewMap.prototype.setCollapsible = function(collapsible) {
  28929. if (this.collapsible_ === collapsible) {
  28930. return;
  28931. }
  28932. this.collapsible_ = collapsible;
  28933. this.element.classList.toggle('ol-uncollapsible');
  28934. if (!collapsible && this.collapsed_) {
  28935. this.handleToggle_();
  28936. }
  28937. };
  28938. /**
  28939. * Collapse or expand the overview map according to the passed parameter. Will
  28940. * not do anything if the overview map isn't collapsible or if the current
  28941. * collapsed state is already the one requested.
  28942. * @param {boolean} collapsed True if the widget is collapsed.
  28943. * @api
  28944. */
  28945. ol.control.OverviewMap.prototype.setCollapsed = function(collapsed) {
  28946. if (!this.collapsible_ || this.collapsed_ === collapsed) {
  28947. return;
  28948. }
  28949. this.handleToggle_();
  28950. };
  28951. /**
  28952. * Determine if the overview map is collapsed.
  28953. * @return {boolean} The overview map is collapsed.
  28954. * @api
  28955. */
  28956. ol.control.OverviewMap.prototype.getCollapsed = function() {
  28957. return this.collapsed_;
  28958. };
  28959. /**
  28960. * Return the overview map.
  28961. * @return {ol.PluggableMap} Overview map.
  28962. * @api
  28963. */
  28964. ol.control.OverviewMap.prototype.getOverviewMap = function() {
  28965. return this.ovmap_;
  28966. };
  28967. goog.provide('ol.control.ScaleLineUnits');
  28968. /**
  28969. * Units for the scale line. Supported values are `'degrees'`, `'imperial'`,
  28970. * `'nautical'`, `'metric'`, `'us'`.
  28971. * @enum {string}
  28972. */
  28973. ol.control.ScaleLineUnits = {
  28974. DEGREES: 'degrees',
  28975. IMPERIAL: 'imperial',
  28976. NAUTICAL: 'nautical',
  28977. METRIC: 'metric',
  28978. US: 'us'
  28979. };
  28980. goog.provide('ol.control.ScaleLine');
  28981. goog.require('ol');
  28982. goog.require('ol.Object');
  28983. goog.require('ol.asserts');
  28984. goog.require('ol.control.Control');
  28985. goog.require('ol.control.ScaleLineUnits');
  28986. goog.require('ol.css');
  28987. goog.require('ol.events');
  28988. goog.require('ol.proj');
  28989. goog.require('ol.proj.Units');
  28990. /**
  28991. * @classdesc
  28992. * A control displaying rough y-axis distances, calculated for the center of the
  28993. * viewport. For conformal projections (e.g. EPSG:3857, the default view
  28994. * projection in OpenLayers), the scale is valid for all directions.
  28995. * No scale line will be shown when the y-axis distance of a pixel at the
  28996. * viewport center cannot be calculated in the view projection.
  28997. * By default the scale line will show in the bottom left portion of the map,
  28998. * but this can be changed by using the css selector `.ol-scale-line`.
  28999. *
  29000. * @constructor
  29001. * @extends {ol.control.Control}
  29002. * @param {olx.control.ScaleLineOptions=} opt_options Scale line options.
  29003. * @api
  29004. */
  29005. ol.control.ScaleLine = function(opt_options) {
  29006. var options = opt_options ? opt_options : {};
  29007. var className = options.className !== undefined ? options.className : 'ol-scale-line';
  29008. /**
  29009. * @private
  29010. * @type {Element}
  29011. */
  29012. this.innerElement_ = document.createElement('DIV');
  29013. this.innerElement_.className = className + '-inner';
  29014. /**
  29015. * @private
  29016. * @type {Element}
  29017. */
  29018. this.element_ = document.createElement('DIV');
  29019. this.element_.className = className + ' ' + ol.css.CLASS_UNSELECTABLE;
  29020. this.element_.appendChild(this.innerElement_);
  29021. /**
  29022. * @private
  29023. * @type {?olx.ViewState}
  29024. */
  29025. this.viewState_ = null;
  29026. /**
  29027. * @private
  29028. * @type {number}
  29029. */
  29030. this.minWidth_ = options.minWidth !== undefined ? options.minWidth : 64;
  29031. /**
  29032. * @private
  29033. * @type {boolean}
  29034. */
  29035. this.renderedVisible_ = false;
  29036. /**
  29037. * @private
  29038. * @type {number|undefined}
  29039. */
  29040. this.renderedWidth_ = undefined;
  29041. /**
  29042. * @private
  29043. * @type {string}
  29044. */
  29045. this.renderedHTML_ = '';
  29046. var render = options.render ? options.render : ol.control.ScaleLine.render;
  29047. ol.control.Control.call(this, {
  29048. element: this.element_,
  29049. render: render,
  29050. target: options.target
  29051. });
  29052. ol.events.listen(
  29053. this, ol.Object.getChangeEventType(ol.control.ScaleLine.Property_.UNITS),
  29054. this.handleUnitsChanged_, this);
  29055. this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
  29056. ol.control.ScaleLineUnits.METRIC);
  29057. };
  29058. ol.inherits(ol.control.ScaleLine, ol.control.Control);
  29059. /**
  29060. * @const
  29061. * @type {Array.<number>}
  29062. */
  29063. ol.control.ScaleLine.LEADING_DIGITS = [1, 2, 5];
  29064. /**
  29065. * Return the units to use in the scale line.
  29066. * @return {ol.control.ScaleLineUnits|undefined} The units to use in the scale
  29067. * line.
  29068. * @observable
  29069. * @api
  29070. */
  29071. ol.control.ScaleLine.prototype.getUnits = function() {
  29072. return /** @type {ol.control.ScaleLineUnits|undefined} */ (
  29073. this.get(ol.control.ScaleLine.Property_.UNITS));
  29074. };
  29075. /**
  29076. * Update the scale line element.
  29077. * @param {ol.MapEvent} mapEvent Map event.
  29078. * @this {ol.control.ScaleLine}
  29079. * @api
  29080. */
  29081. ol.control.ScaleLine.render = function(mapEvent) {
  29082. var frameState = mapEvent.frameState;
  29083. if (!frameState) {
  29084. this.viewState_ = null;
  29085. } else {
  29086. this.viewState_ = frameState.viewState;
  29087. }
  29088. this.updateElement_();
  29089. };
  29090. /**
  29091. * @private
  29092. */
  29093. ol.control.ScaleLine.prototype.handleUnitsChanged_ = function() {
  29094. this.updateElement_();
  29095. };
  29096. /**
  29097. * Set the units to use in the scale line.
  29098. * @param {ol.control.ScaleLineUnits} units The units to use in the scale line.
  29099. * @observable
  29100. * @api
  29101. */
  29102. ol.control.ScaleLine.prototype.setUnits = function(units) {
  29103. this.set(ol.control.ScaleLine.Property_.UNITS, units);
  29104. };
  29105. /**
  29106. * @private
  29107. */
  29108. ol.control.ScaleLine.prototype.updateElement_ = function() {
  29109. var viewState = this.viewState_;
  29110. if (!viewState) {
  29111. if (this.renderedVisible_) {
  29112. this.element_.style.display = 'none';
  29113. this.renderedVisible_ = false;
  29114. }
  29115. return;
  29116. }
  29117. var center = viewState.center;
  29118. var projection = viewState.projection;
  29119. var units = this.getUnits();
  29120. var pointResolutionUnits = units == ol.control.ScaleLineUnits.DEGREES ?
  29121. ol.proj.Units.DEGREES :
  29122. ol.proj.Units.METERS;
  29123. var pointResolution =
  29124. ol.proj.getPointResolution(projection, viewState.resolution, center, pointResolutionUnits);
  29125. if (units != ol.control.ScaleLineUnits.DEGREES) {
  29126. pointResolution *= projection.getMetersPerUnit();
  29127. }
  29128. var nominalCount = this.minWidth_ * pointResolution;
  29129. var suffix = '';
  29130. if (units == ol.control.ScaleLineUnits.DEGREES) {
  29131. var metersPerDegree = ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES];
  29132. if (projection.getUnits() == ol.proj.Units.DEGREES) {
  29133. nominalCount *= metersPerDegree;
  29134. } else {
  29135. pointResolution /= metersPerDegree;
  29136. }
  29137. if (nominalCount < metersPerDegree / 60) {
  29138. suffix = '\u2033'; // seconds
  29139. pointResolution *= 3600;
  29140. } else if (nominalCount < metersPerDegree) {
  29141. suffix = '\u2032'; // minutes
  29142. pointResolution *= 60;
  29143. } else {
  29144. suffix = '\u00b0'; // degrees
  29145. }
  29146. } else if (units == ol.control.ScaleLineUnits.IMPERIAL) {
  29147. if (nominalCount < 0.9144) {
  29148. suffix = 'in';
  29149. pointResolution /= 0.0254;
  29150. } else if (nominalCount < 1609.344) {
  29151. suffix = 'ft';
  29152. pointResolution /= 0.3048;
  29153. } else {
  29154. suffix = 'mi';
  29155. pointResolution /= 1609.344;
  29156. }
  29157. } else if (units == ol.control.ScaleLineUnits.NAUTICAL) {
  29158. pointResolution /= 1852;
  29159. suffix = 'nm';
  29160. } else if (units == ol.control.ScaleLineUnits.METRIC) {
  29161. if (nominalCount < 0.001) {
  29162. suffix = 'μm';
  29163. pointResolution *= 1000000;
  29164. } else if (nominalCount < 1) {
  29165. suffix = 'mm';
  29166. pointResolution *= 1000;
  29167. } else if (nominalCount < 1000) {
  29168. suffix = 'm';
  29169. } else {
  29170. suffix = 'km';
  29171. pointResolution /= 1000;
  29172. }
  29173. } else if (units == ol.control.ScaleLineUnits.US) {
  29174. if (nominalCount < 0.9144) {
  29175. suffix = 'in';
  29176. pointResolution *= 39.37;
  29177. } else if (nominalCount < 1609.344) {
  29178. suffix = 'ft';
  29179. pointResolution /= 0.30480061;
  29180. } else {
  29181. suffix = 'mi';
  29182. pointResolution /= 1609.3472;
  29183. }
  29184. } else {
  29185. ol.asserts.assert(false, 33); // Invalid units
  29186. }
  29187. var i = 3 * Math.floor(
  29188. Math.log(this.minWidth_ * pointResolution) / Math.log(10));
  29189. var count, width;
  29190. while (true) {
  29191. count = ol.control.ScaleLine.LEADING_DIGITS[((i % 3) + 3) % 3] *
  29192. Math.pow(10, Math.floor(i / 3));
  29193. width = Math.round(count / pointResolution);
  29194. if (isNaN(width)) {
  29195. this.element_.style.display = 'none';
  29196. this.renderedVisible_ = false;
  29197. return;
  29198. } else if (width >= this.minWidth_) {
  29199. break;
  29200. }
  29201. ++i;
  29202. }
  29203. var html = count + ' ' + suffix;
  29204. if (this.renderedHTML_ != html) {
  29205. this.innerElement_.innerHTML = html;
  29206. this.renderedHTML_ = html;
  29207. }
  29208. if (this.renderedWidth_ != width) {
  29209. this.innerElement_.style.width = width + 'px';
  29210. this.renderedWidth_ = width;
  29211. }
  29212. if (!this.renderedVisible_) {
  29213. this.element_.style.display = '';
  29214. this.renderedVisible_ = true;
  29215. }
  29216. };
  29217. /**
  29218. * @enum {string}
  29219. * @private
  29220. */
  29221. ol.control.ScaleLine.Property_ = {
  29222. UNITS: 'units'
  29223. };
  29224. // FIXME should possibly show tooltip when dragging?
  29225. goog.provide('ol.control.ZoomSlider');
  29226. goog.require('ol');
  29227. goog.require('ol.ViewHint');
  29228. goog.require('ol.control.Control');
  29229. goog.require('ol.css');
  29230. goog.require('ol.easing');
  29231. goog.require('ol.events');
  29232. goog.require('ol.events.Event');
  29233. goog.require('ol.events.EventType');
  29234. goog.require('ol.math');
  29235. goog.require('ol.pointer.EventType');
  29236. goog.require('ol.pointer.PointerEventHandler');
  29237. /**
  29238. * @classdesc
  29239. * A slider type of control for zooming.
  29240. *
  29241. * Example:
  29242. *
  29243. * map.addControl(new ol.control.ZoomSlider());
  29244. *
  29245. * @constructor
  29246. * @extends {ol.control.Control}
  29247. * @param {olx.control.ZoomSliderOptions=} opt_options Zoom slider options.
  29248. * @api
  29249. */
  29250. ol.control.ZoomSlider = function(opt_options) {
  29251. var options = opt_options ? opt_options : {};
  29252. /**
  29253. * Will hold the current resolution of the view.
  29254. *
  29255. * @type {number|undefined}
  29256. * @private
  29257. */
  29258. this.currentResolution_ = undefined;
  29259. /**
  29260. * The direction of the slider. Will be determined from actual display of the
  29261. * container and defaults to ol.control.ZoomSlider.Direction_.VERTICAL.
  29262. *
  29263. * @type {ol.control.ZoomSlider.Direction_}
  29264. * @private
  29265. */
  29266. this.direction_ = ol.control.ZoomSlider.Direction_.VERTICAL;
  29267. /**
  29268. * @type {boolean}
  29269. * @private
  29270. */
  29271. this.dragging_;
  29272. /**
  29273. * @type {number}
  29274. * @private
  29275. */
  29276. this.heightLimit_ = 0;
  29277. /**
  29278. * @type {number}
  29279. * @private
  29280. */
  29281. this.widthLimit_ = 0;
  29282. /**
  29283. * @type {number|undefined}
  29284. * @private
  29285. */
  29286. this.previousX_;
  29287. /**
  29288. * @type {number|undefined}
  29289. * @private
  29290. */
  29291. this.previousY_;
  29292. /**
  29293. * The calculated thumb size (border box plus margins). Set when initSlider_
  29294. * is called.
  29295. * @type {ol.Size}
  29296. * @private
  29297. */
  29298. this.thumbSize_ = null;
  29299. /**
  29300. * Whether the slider is initialized.
  29301. * @type {boolean}
  29302. * @private
  29303. */
  29304. this.sliderInitialized_ = false;
  29305. /**
  29306. * @type {number}
  29307. * @private
  29308. */
  29309. this.duration_ = options.duration !== undefined ? options.duration : 200;
  29310. var className = options.className !== undefined ? options.className : 'ol-zoomslider';
  29311. var thumbElement = document.createElement('button');
  29312. thumbElement.setAttribute('type', 'button');
  29313. thumbElement.className = className + '-thumb ' + ol.css.CLASS_UNSELECTABLE;
  29314. var containerElement = document.createElement('div');
  29315. containerElement.className = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' + ol.css.CLASS_CONTROL;
  29316. containerElement.appendChild(thumbElement);
  29317. /**
  29318. * @type {ol.pointer.PointerEventHandler}
  29319. * @private
  29320. */
  29321. this.dragger_ = new ol.pointer.PointerEventHandler(containerElement);
  29322. ol.events.listen(this.dragger_, ol.pointer.EventType.POINTERDOWN,
  29323. this.handleDraggerStart_, this);
  29324. ol.events.listen(this.dragger_, ol.pointer.EventType.POINTERMOVE,
  29325. this.handleDraggerDrag_, this);
  29326. ol.events.listen(this.dragger_, ol.pointer.EventType.POINTERUP,
  29327. this.handleDraggerEnd_, this);
  29328. ol.events.listen(containerElement, ol.events.EventType.CLICK,
  29329. this.handleContainerClick_, this);
  29330. ol.events.listen(thumbElement, ol.events.EventType.CLICK,
  29331. ol.events.Event.stopPropagation);
  29332. var render = options.render ? options.render : ol.control.ZoomSlider.render;
  29333. ol.control.Control.call(this, {
  29334. element: containerElement,
  29335. render: render
  29336. });
  29337. };
  29338. ol.inherits(ol.control.ZoomSlider, ol.control.Control);
  29339. /**
  29340. * @inheritDoc
  29341. */
  29342. ol.control.ZoomSlider.prototype.disposeInternal = function() {
  29343. this.dragger_.dispose();
  29344. ol.control.Control.prototype.disposeInternal.call(this);
  29345. };
  29346. /**
  29347. * The enum for available directions.
  29348. *
  29349. * @enum {number}
  29350. * @private
  29351. */
  29352. ol.control.ZoomSlider.Direction_ = {
  29353. VERTICAL: 0,
  29354. HORIZONTAL: 1
  29355. };
  29356. /**
  29357. * @inheritDoc
  29358. */
  29359. ol.control.ZoomSlider.prototype.setMap = function(map) {
  29360. ol.control.Control.prototype.setMap.call(this, map);
  29361. if (map) {
  29362. map.render();
  29363. }
  29364. };
  29365. /**
  29366. * Initializes the slider element. This will determine and set this controls
  29367. * direction_ and also constrain the dragging of the thumb to always be within
  29368. * the bounds of the container.
  29369. *
  29370. * @private
  29371. */
  29372. ol.control.ZoomSlider.prototype.initSlider_ = function() {
  29373. var container = this.element;
  29374. var containerSize = {
  29375. width: container.offsetWidth, height: container.offsetHeight
  29376. };
  29377. var thumb = container.firstElementChild;
  29378. var computedStyle = getComputedStyle(thumb);
  29379. var thumbWidth = thumb.offsetWidth +
  29380. parseFloat(computedStyle['marginRight']) +
  29381. parseFloat(computedStyle['marginLeft']);
  29382. var thumbHeight = thumb.offsetHeight +
  29383. parseFloat(computedStyle['marginTop']) +
  29384. parseFloat(computedStyle['marginBottom']);
  29385. this.thumbSize_ = [thumbWidth, thumbHeight];
  29386. if (containerSize.width > containerSize.height) {
  29387. this.direction_ = ol.control.ZoomSlider.Direction_.HORIZONTAL;
  29388. this.widthLimit_ = containerSize.width - thumbWidth;
  29389. } else {
  29390. this.direction_ = ol.control.ZoomSlider.Direction_.VERTICAL;
  29391. this.heightLimit_ = containerSize.height - thumbHeight;
  29392. }
  29393. this.sliderInitialized_ = true;
  29394. };
  29395. /**
  29396. * Update the zoomslider element.
  29397. * @param {ol.MapEvent} mapEvent Map event.
  29398. * @this {ol.control.ZoomSlider}
  29399. * @api
  29400. */
  29401. ol.control.ZoomSlider.render = function(mapEvent) {
  29402. if (!mapEvent.frameState) {
  29403. return;
  29404. }
  29405. if (!this.sliderInitialized_) {
  29406. this.initSlider_();
  29407. }
  29408. var res = mapEvent.frameState.viewState.resolution;
  29409. if (res !== this.currentResolution_) {
  29410. this.currentResolution_ = res;
  29411. this.setThumbPosition_(res);
  29412. }
  29413. };
  29414. /**
  29415. * @param {Event} event The browser event to handle.
  29416. * @private
  29417. */
  29418. ol.control.ZoomSlider.prototype.handleContainerClick_ = function(event) {
  29419. var view = this.getMap().getView();
  29420. var relativePosition = this.getRelativePosition_(
  29421. event.offsetX - this.thumbSize_[0] / 2,
  29422. event.offsetY - this.thumbSize_[1] / 2);
  29423. var resolution = this.getResolutionForPosition_(relativePosition);
  29424. view.animate({
  29425. resolution: view.constrainResolution(resolution),
  29426. duration: this.duration_,
  29427. easing: ol.easing.easeOut
  29428. });
  29429. };
  29430. /**
  29431. * Handle dragger start events.
  29432. * @param {ol.pointer.PointerEvent} event The drag event.
  29433. * @private
  29434. */
  29435. ol.control.ZoomSlider.prototype.handleDraggerStart_ = function(event) {
  29436. if (!this.dragging_ && event.originalEvent.target === this.element.firstElementChild) {
  29437. this.getMap().getView().setHint(ol.ViewHint.INTERACTING, 1);
  29438. this.previousX_ = event.clientX;
  29439. this.previousY_ = event.clientY;
  29440. this.dragging_ = true;
  29441. }
  29442. };
  29443. /**
  29444. * Handle dragger drag events.
  29445. *
  29446. * @param {ol.pointer.PointerEvent|Event} event The drag event.
  29447. * @private
  29448. */
  29449. ol.control.ZoomSlider.prototype.handleDraggerDrag_ = function(event) {
  29450. if (this.dragging_) {
  29451. var element = this.element.firstElementChild;
  29452. var deltaX = event.clientX - this.previousX_ + parseInt(element.style.left, 10);
  29453. var deltaY = event.clientY - this.previousY_ + parseInt(element.style.top, 10);
  29454. var relativePosition = this.getRelativePosition_(deltaX, deltaY);
  29455. this.currentResolution_ = this.getResolutionForPosition_(relativePosition);
  29456. this.getMap().getView().setResolution(this.currentResolution_);
  29457. this.setThumbPosition_(this.currentResolution_);
  29458. this.previousX_ = event.clientX;
  29459. this.previousY_ = event.clientY;
  29460. }
  29461. };
  29462. /**
  29463. * Handle dragger end events.
  29464. * @param {ol.pointer.PointerEvent|Event} event The drag event.
  29465. * @private
  29466. */
  29467. ol.control.ZoomSlider.prototype.handleDraggerEnd_ = function(event) {
  29468. if (this.dragging_) {
  29469. var view = this.getMap().getView();
  29470. view.setHint(ol.ViewHint.INTERACTING, -1);
  29471. view.animate({
  29472. resolution: view.constrainResolution(this.currentResolution_),
  29473. duration: this.duration_,
  29474. easing: ol.easing.easeOut
  29475. });
  29476. this.dragging_ = false;
  29477. this.previousX_ = undefined;
  29478. this.previousY_ = undefined;
  29479. }
  29480. };
  29481. /**
  29482. * Positions the thumb inside its container according to the given resolution.
  29483. *
  29484. * @param {number} res The res.
  29485. * @private
  29486. */
  29487. ol.control.ZoomSlider.prototype.setThumbPosition_ = function(res) {
  29488. var position = this.getPositionForResolution_(res);
  29489. var thumb = this.element.firstElementChild;
  29490. if (this.direction_ == ol.control.ZoomSlider.Direction_.HORIZONTAL) {
  29491. thumb.style.left = this.widthLimit_ * position + 'px';
  29492. } else {
  29493. thumb.style.top = this.heightLimit_ * position + 'px';
  29494. }
  29495. };
  29496. /**
  29497. * Calculates the relative position of the thumb given x and y offsets. The
  29498. * relative position scales from 0 to 1. The x and y offsets are assumed to be
  29499. * in pixel units within the dragger limits.
  29500. *
  29501. * @param {number} x Pixel position relative to the left of the slider.
  29502. * @param {number} y Pixel position relative to the top of the slider.
  29503. * @return {number} The relative position of the thumb.
  29504. * @private
  29505. */
  29506. ol.control.ZoomSlider.prototype.getRelativePosition_ = function(x, y) {
  29507. var amount;
  29508. if (this.direction_ === ol.control.ZoomSlider.Direction_.HORIZONTAL) {
  29509. amount = x / this.widthLimit_;
  29510. } else {
  29511. amount = y / this.heightLimit_;
  29512. }
  29513. return ol.math.clamp(amount, 0, 1);
  29514. };
  29515. /**
  29516. * Calculates the corresponding resolution of the thumb given its relative
  29517. * position (where 0 is the minimum and 1 is the maximum).
  29518. *
  29519. * @param {number} position The relative position of the thumb.
  29520. * @return {number} The corresponding resolution.
  29521. * @private
  29522. */
  29523. ol.control.ZoomSlider.prototype.getResolutionForPosition_ = function(position) {
  29524. var fn = this.getMap().getView().getResolutionForValueFunction();
  29525. return fn(1 - position);
  29526. };
  29527. /**
  29528. * Determines the relative position of the slider for the given resolution. A
  29529. * relative position of 0 corresponds to the minimum view resolution. A
  29530. * relative position of 1 corresponds to the maximum view resolution.
  29531. *
  29532. * @param {number} res The resolution.
  29533. * @return {number} The relative position value (between 0 and 1).
  29534. * @private
  29535. */
  29536. ol.control.ZoomSlider.prototype.getPositionForResolution_ = function(res) {
  29537. var fn = this.getMap().getView().getValueForResolutionFunction();
  29538. return 1 - fn(res);
  29539. };
  29540. goog.provide('ol.control.ZoomToExtent');
  29541. goog.require('ol');
  29542. goog.require('ol.events');
  29543. goog.require('ol.events.EventType');
  29544. goog.require('ol.control.Control');
  29545. goog.require('ol.css');
  29546. /**
  29547. * @classdesc
  29548. * A button control which, when pressed, changes the map view to a specific
  29549. * extent. To style this control use the css selector `.ol-zoom-extent`.
  29550. *
  29551. * @constructor
  29552. * @extends {ol.control.Control}
  29553. * @param {olx.control.ZoomToExtentOptions=} opt_options Options.
  29554. * @api
  29555. */
  29556. ol.control.ZoomToExtent = function(opt_options) {
  29557. var options = opt_options ? opt_options : {};
  29558. /**
  29559. * @type {ol.Extent}
  29560. * @protected
  29561. */
  29562. this.extent = options.extent ? options.extent : null;
  29563. var className = options.className !== undefined ? options.className :
  29564. 'ol-zoom-extent';
  29565. var label = options.label !== undefined ? options.label : 'E';
  29566. var tipLabel = options.tipLabel !== undefined ?
  29567. options.tipLabel : 'Fit to extent';
  29568. var button = document.createElement('button');
  29569. button.setAttribute('type', 'button');
  29570. button.title = tipLabel;
  29571. button.appendChild(
  29572. typeof label === 'string' ? document.createTextNode(label) : label
  29573. );
  29574. ol.events.listen(button, ol.events.EventType.CLICK,
  29575. this.handleClick_, this);
  29576. var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
  29577. ol.css.CLASS_CONTROL;
  29578. var element = document.createElement('div');
  29579. element.className = cssClasses;
  29580. element.appendChild(button);
  29581. ol.control.Control.call(this, {
  29582. element: element,
  29583. target: options.target
  29584. });
  29585. };
  29586. ol.inherits(ol.control.ZoomToExtent, ol.control.Control);
  29587. /**
  29588. * @param {Event} event The event to handle
  29589. * @private
  29590. */
  29591. ol.control.ZoomToExtent.prototype.handleClick_ = function(event) {
  29592. event.preventDefault();
  29593. this.handleZoomToExtent();
  29594. };
  29595. /**
  29596. * @protected
  29597. */
  29598. ol.control.ZoomToExtent.prototype.handleZoomToExtent = function() {
  29599. var map = this.getMap();
  29600. var view = map.getView();
  29601. var extent = !this.extent ? view.getProjection().getExtent() : this.extent;
  29602. view.fit(extent);
  29603. };
  29604. goog.provide('ol.DeviceOrientation');
  29605. goog.require('ol.events');
  29606. goog.require('ol');
  29607. goog.require('ol.Object');
  29608. goog.require('ol.has');
  29609. goog.require('ol.math');
  29610. /**
  29611. * @classdesc
  29612. * The ol.DeviceOrientation class provides access to information from
  29613. * DeviceOrientation events. See the [HTML 5 DeviceOrientation Specification](
  29614. * http://www.w3.org/TR/orientation-event/) for more details.
  29615. *
  29616. * Many new computers, and especially mobile phones
  29617. * and tablets, provide hardware support for device orientation. Web
  29618. * developers targeting mobile devices will be especially interested in this
  29619. * class.
  29620. *
  29621. * Device orientation data are relative to a common starting point. For mobile
  29622. * devices, the starting point is to lay your phone face up on a table with the
  29623. * top of the phone pointing north. This represents the zero state. All
  29624. * angles are then relative to this state. For computers, it is the same except
  29625. * the screen is open at 90 degrees.
  29626. *
  29627. * Device orientation is reported as three angles - `alpha`, `beta`, and
  29628. * `gamma` - relative to the starting position along the three planar axes X, Y
  29629. * and Z. The X axis runs from the left edge to the right edge through the
  29630. * middle of the device. Similarly, the Y axis runs from the bottom to the top
  29631. * of the device through the middle. The Z axis runs from the back to the front
  29632. * through the middle. In the starting position, the X axis points to the
  29633. * right, the Y axis points away from you and the Z axis points straight up
  29634. * from the device lying flat.
  29635. *
  29636. * The three angles representing the device orientation are relative to the
  29637. * three axes. `alpha` indicates how much the device has been rotated around the
  29638. * Z axis, which is commonly interpreted as the compass heading (see note
  29639. * below). `beta` indicates how much the device has been rotated around the X
  29640. * axis, or how much it is tilted from front to back. `gamma` indicates how
  29641. * much the device has been rotated around the Y axis, or how much it is tilted
  29642. * from left to right.
  29643. *
  29644. * For most browsers, the `alpha` value returns the compass heading so if the
  29645. * device points north, it will be 0. With Safari on iOS, the 0 value of
  29646. * `alpha` is calculated from when device orientation was first requested.
  29647. * ol.DeviceOrientation provides the `heading` property which normalizes this
  29648. * behavior across all browsers for you.
  29649. *
  29650. * It is important to note that the HTML 5 DeviceOrientation specification
  29651. * indicates that `alpha`, `beta` and `gamma` are in degrees while the
  29652. * equivalent properties in ol.DeviceOrientation are in radians for consistency
  29653. * with all other uses of angles throughout OpenLayers.
  29654. *
  29655. * To get notified of device orientation changes, register a listener for the
  29656. * generic `change` event on your `ol.DeviceOrientation` instance.
  29657. *
  29658. * @see {@link http://www.w3.org/TR/orientation-event/}
  29659. *
  29660. * @deprecated This class is deprecated and will removed in the next major release.
  29661. *
  29662. * @constructor
  29663. * @extends {ol.Object}
  29664. * @param {olx.DeviceOrientationOptions=} opt_options Options.
  29665. * @api
  29666. */
  29667. ol.DeviceOrientation = function(opt_options) {
  29668. ol.Object.call(this);
  29669. var options = opt_options ? opt_options : {};
  29670. /**
  29671. * @private
  29672. * @type {?ol.EventsKey}
  29673. */
  29674. this.listenerKey_ = null;
  29675. ol.events.listen(this,
  29676. ol.Object.getChangeEventType(ol.DeviceOrientation.Property_.TRACKING),
  29677. this.handleTrackingChanged_, this);
  29678. this.setTracking(options.tracking !== undefined ? options.tracking : false);
  29679. };
  29680. ol.inherits(ol.DeviceOrientation, ol.Object);
  29681. /**
  29682. * @inheritDoc
  29683. */
  29684. ol.DeviceOrientation.prototype.disposeInternal = function() {
  29685. this.setTracking(false);
  29686. ol.Object.prototype.disposeInternal.call(this);
  29687. };
  29688. /**
  29689. * @private
  29690. * @param {Event} originalEvent Event.
  29691. */
  29692. ol.DeviceOrientation.prototype.orientationChange_ = function(originalEvent) {
  29693. var event = /** @type {DeviceOrientationEvent} */ (originalEvent);
  29694. if (event.alpha !== null) {
  29695. var alpha = ol.math.toRadians(event.alpha);
  29696. this.set(ol.DeviceOrientation.Property_.ALPHA, alpha);
  29697. // event.absolute is undefined in iOS.
  29698. if (typeof event.absolute === 'boolean' && event.absolute) {
  29699. this.set(ol.DeviceOrientation.Property_.HEADING, alpha);
  29700. } else if (typeof event.webkitCompassHeading === 'number' &&
  29701. event.webkitCompassAccuracy != -1) {
  29702. var heading = ol.math.toRadians(event.webkitCompassHeading);
  29703. this.set(ol.DeviceOrientation.Property_.HEADING, heading);
  29704. }
  29705. }
  29706. if (event.beta !== null) {
  29707. this.set(ol.DeviceOrientation.Property_.BETA,
  29708. ol.math.toRadians(event.beta));
  29709. }
  29710. if (event.gamma !== null) {
  29711. this.set(ol.DeviceOrientation.Property_.GAMMA,
  29712. ol.math.toRadians(event.gamma));
  29713. }
  29714. this.changed();
  29715. };
  29716. /**
  29717. * Rotation around the device z-axis (in radians).
  29718. * @return {number|undefined} The euler angle in radians of the device from the
  29719. * standard Z axis.
  29720. * @observable
  29721. * @api
  29722. */
  29723. ol.DeviceOrientation.prototype.getAlpha = function() {
  29724. return /** @type {number|undefined} */ (
  29725. this.get(ol.DeviceOrientation.Property_.ALPHA));
  29726. };
  29727. /**
  29728. * Rotation around the device x-axis (in radians).
  29729. * @return {number|undefined} The euler angle in radians of the device from the
  29730. * planar X axis.
  29731. * @observable
  29732. * @api
  29733. */
  29734. ol.DeviceOrientation.prototype.getBeta = function() {
  29735. return /** @type {number|undefined} */ (
  29736. this.get(ol.DeviceOrientation.Property_.BETA));
  29737. };
  29738. /**
  29739. * Rotation around the device y-axis (in radians).
  29740. * @return {number|undefined} The euler angle in radians of the device from the
  29741. * planar Y axis.
  29742. * @observable
  29743. * @api
  29744. */
  29745. ol.DeviceOrientation.prototype.getGamma = function() {
  29746. return /** @type {number|undefined} */ (
  29747. this.get(ol.DeviceOrientation.Property_.GAMMA));
  29748. };
  29749. /**
  29750. * The heading of the device relative to north (in radians).
  29751. * @return {number|undefined} The heading of the device relative to north, in
  29752. * radians, normalizing for different browser behavior.
  29753. * @observable
  29754. * @api
  29755. */
  29756. ol.DeviceOrientation.prototype.getHeading = function() {
  29757. return /** @type {number|undefined} */ (
  29758. this.get(ol.DeviceOrientation.Property_.HEADING));
  29759. };
  29760. /**
  29761. * Determine if orientation is being tracked.
  29762. * @return {boolean} Changes in device orientation are being tracked.
  29763. * @observable
  29764. * @api
  29765. */
  29766. ol.DeviceOrientation.prototype.getTracking = function() {
  29767. return /** @type {boolean} */ (
  29768. this.get(ol.DeviceOrientation.Property_.TRACKING));
  29769. };
  29770. /**
  29771. * @private
  29772. */
  29773. ol.DeviceOrientation.prototype.handleTrackingChanged_ = function() {
  29774. if (ol.has.DEVICE_ORIENTATION) {
  29775. var tracking = this.getTracking();
  29776. if (tracking && !this.listenerKey_) {
  29777. this.listenerKey_ = ol.events.listen(window, 'deviceorientation',
  29778. this.orientationChange_, this);
  29779. } else if (!tracking && this.listenerKey_ !== null) {
  29780. ol.events.unlistenByKey(this.listenerKey_);
  29781. this.listenerKey_ = null;
  29782. }
  29783. }
  29784. };
  29785. /**
  29786. * Enable or disable tracking of device orientation events.
  29787. * @param {boolean} tracking The status of tracking changes to alpha, beta and
  29788. * gamma. If true, changes are tracked and reported immediately.
  29789. * @observable
  29790. * @api
  29791. */
  29792. ol.DeviceOrientation.prototype.setTracking = function(tracking) {
  29793. this.set(ol.DeviceOrientation.Property_.TRACKING, tracking);
  29794. };
  29795. /**
  29796. * @enum {string}
  29797. * @private
  29798. */
  29799. ol.DeviceOrientation.Property_ = {
  29800. ALPHA: 'alpha',
  29801. BETA: 'beta',
  29802. GAMMA: 'gamma',
  29803. HEADING: 'heading',
  29804. TRACKING: 'tracking'
  29805. };
  29806. goog.provide('ol.style.Image');
  29807. /**
  29808. * @classdesc
  29809. * A base class used for creating subclasses and not instantiated in
  29810. * apps. Base class for {@link ol.style.Icon}, {@link ol.style.Circle} and
  29811. * {@link ol.style.RegularShape}.
  29812. *
  29813. * @constructor
  29814. * @abstract
  29815. * @param {ol.StyleImageOptions} options Options.
  29816. * @api
  29817. */
  29818. ol.style.Image = function(options) {
  29819. /**
  29820. * @private
  29821. * @type {number}
  29822. */
  29823. this.opacity_ = options.opacity;
  29824. /**
  29825. * @private
  29826. * @type {boolean}
  29827. */
  29828. this.rotateWithView_ = options.rotateWithView;
  29829. /**
  29830. * @private
  29831. * @type {number}
  29832. */
  29833. this.rotation_ = options.rotation;
  29834. /**
  29835. * @private
  29836. * @type {number}
  29837. */
  29838. this.scale_ = options.scale;
  29839. /**
  29840. * @private
  29841. * @type {boolean}
  29842. */
  29843. this.snapToPixel_ = options.snapToPixel;
  29844. };
  29845. /**
  29846. * Get the symbolizer opacity.
  29847. * @return {number} Opacity.
  29848. * @api
  29849. */
  29850. ol.style.Image.prototype.getOpacity = function() {
  29851. return this.opacity_;
  29852. };
  29853. /**
  29854. * Determine whether the symbolizer rotates with the map.
  29855. * @return {boolean} Rotate with map.
  29856. * @api
  29857. */
  29858. ol.style.Image.prototype.getRotateWithView = function() {
  29859. return this.rotateWithView_;
  29860. };
  29861. /**
  29862. * Get the symoblizer rotation.
  29863. * @return {number} Rotation.
  29864. * @api
  29865. */
  29866. ol.style.Image.prototype.getRotation = function() {
  29867. return this.rotation_;
  29868. };
  29869. /**
  29870. * Get the symbolizer scale.
  29871. * @return {number} Scale.
  29872. * @api
  29873. */
  29874. ol.style.Image.prototype.getScale = function() {
  29875. return this.scale_;
  29876. };
  29877. /**
  29878. * Determine whether the symbolizer should be snapped to a pixel.
  29879. * @return {boolean} The symbolizer should snap to a pixel.
  29880. * @api
  29881. */
  29882. ol.style.Image.prototype.getSnapToPixel = function() {
  29883. return this.snapToPixel_;
  29884. };
  29885. /**
  29886. * Get the anchor point in pixels. The anchor determines the center point for the
  29887. * symbolizer.
  29888. * @abstract
  29889. * @return {Array.<number>} Anchor.
  29890. */
  29891. ol.style.Image.prototype.getAnchor = function() {};
  29892. /**
  29893. * Get the image element for the symbolizer.
  29894. * @abstract
  29895. * @param {number} pixelRatio Pixel ratio.
  29896. * @return {HTMLCanvasElement|HTMLVideoElement|Image} Image element.
  29897. */
  29898. ol.style.Image.prototype.getImage = function(pixelRatio) {};
  29899. /**
  29900. * @abstract
  29901. * @param {number} pixelRatio Pixel ratio.
  29902. * @return {HTMLCanvasElement|HTMLVideoElement|Image} Image element.
  29903. */
  29904. ol.style.Image.prototype.getHitDetectionImage = function(pixelRatio) {};
  29905. /**
  29906. * @abstract
  29907. * @return {ol.ImageState} Image state.
  29908. */
  29909. ol.style.Image.prototype.getImageState = function() {};
  29910. /**
  29911. * @abstract
  29912. * @return {ol.Size} Image size.
  29913. */
  29914. ol.style.Image.prototype.getImageSize = function() {};
  29915. /**
  29916. * @abstract
  29917. * @return {ol.Size} Size of the hit-detection image.
  29918. */
  29919. ol.style.Image.prototype.getHitDetectionImageSize = function() {};
  29920. /**
  29921. * Get the origin of the symbolizer.
  29922. * @abstract
  29923. * @return {Array.<number>} Origin.
  29924. */
  29925. ol.style.Image.prototype.getOrigin = function() {};
  29926. /**
  29927. * Get the size of the symbolizer (in pixels).
  29928. * @abstract
  29929. * @return {ol.Size} Size.
  29930. */
  29931. ol.style.Image.prototype.getSize = function() {};
  29932. /**
  29933. * Set the opacity.
  29934. *
  29935. * @param {number} opacity Opacity.
  29936. * @api
  29937. */
  29938. ol.style.Image.prototype.setOpacity = function(opacity) {
  29939. this.opacity_ = opacity;
  29940. };
  29941. /**
  29942. * Set whether to rotate the style with the view.
  29943. *
  29944. * @param {boolean} rotateWithView Rotate with map.
  29945. */
  29946. ol.style.Image.prototype.setRotateWithView = function(rotateWithView) {
  29947. this.rotateWithView_ = rotateWithView;
  29948. };
  29949. /**
  29950. * Set the rotation.
  29951. *
  29952. * @param {number} rotation Rotation.
  29953. * @api
  29954. */
  29955. ol.style.Image.prototype.setRotation = function(rotation) {
  29956. this.rotation_ = rotation;
  29957. };
  29958. /**
  29959. * Set the scale.
  29960. *
  29961. * @param {number} scale Scale.
  29962. * @api
  29963. */
  29964. ol.style.Image.prototype.setScale = function(scale) {
  29965. this.scale_ = scale;
  29966. };
  29967. /**
  29968. * Set whether to snap the image to the closest pixel.
  29969. *
  29970. * @param {boolean} snapToPixel Snap to pixel?
  29971. */
  29972. ol.style.Image.prototype.setSnapToPixel = function(snapToPixel) {
  29973. this.snapToPixel_ = snapToPixel;
  29974. };
  29975. /**
  29976. * @abstract
  29977. * @param {function(this: T, ol.events.Event)} listener Listener function.
  29978. * @param {T} thisArg Value to use as `this` when executing `listener`.
  29979. * @return {ol.EventsKey|undefined} Listener key.
  29980. * @template T
  29981. */
  29982. ol.style.Image.prototype.listenImageChange = function(listener, thisArg) {};
  29983. /**
  29984. * Load not yet loaded URI.
  29985. * @abstract
  29986. */
  29987. ol.style.Image.prototype.load = function() {};
  29988. /**
  29989. * @abstract
  29990. * @param {function(this: T, ol.events.Event)} listener Listener function.
  29991. * @param {T} thisArg Value to use as `this` when executing `listener`.
  29992. * @template T
  29993. */
  29994. ol.style.Image.prototype.unlistenImageChange = function(listener, thisArg) {};
  29995. goog.provide('ol.style.RegularShape');
  29996. goog.require('ol');
  29997. goog.require('ol.colorlike');
  29998. goog.require('ol.dom');
  29999. goog.require('ol.has');
  30000. goog.require('ol.ImageState');
  30001. goog.require('ol.render.canvas');
  30002. goog.require('ol.style.Image');
  30003. /**
  30004. * @classdesc
  30005. * Set regular shape style for vector features. The resulting shape will be
  30006. * a regular polygon when `radius` is provided, or a star when `radius1` and
  30007. * `radius2` are provided.
  30008. *
  30009. * @constructor
  30010. * @param {olx.style.RegularShapeOptions} options Options.
  30011. * @extends {ol.style.Image}
  30012. * @api
  30013. */
  30014. ol.style.RegularShape = function(options) {
  30015. /**
  30016. * @private
  30017. * @type {Array.<string>}
  30018. */
  30019. this.checksums_ = null;
  30020. /**
  30021. * @private
  30022. * @type {HTMLCanvasElement}
  30023. */
  30024. this.canvas_ = null;
  30025. /**
  30026. * @private
  30027. * @type {HTMLCanvasElement}
  30028. */
  30029. this.hitDetectionCanvas_ = null;
  30030. /**
  30031. * @private
  30032. * @type {ol.style.Fill}
  30033. */
  30034. this.fill_ = options.fill !== undefined ? options.fill : null;
  30035. /**
  30036. * @private
  30037. * @type {Array.<number>}
  30038. */
  30039. this.origin_ = [0, 0];
  30040. /**
  30041. * @private
  30042. * @type {number}
  30043. */
  30044. this.points_ = options.points;
  30045. /**
  30046. * @protected
  30047. * @type {number}
  30048. */
  30049. this.radius_ = /** @type {number} */ (options.radius !== undefined ?
  30050. options.radius : options.radius1);
  30051. /**
  30052. * @private
  30053. * @type {number|undefined}
  30054. */
  30055. this.radius2_ = options.radius2;
  30056. /**
  30057. * @private
  30058. * @type {number}
  30059. */
  30060. this.angle_ = options.angle !== undefined ? options.angle : 0;
  30061. /**
  30062. * @private
  30063. * @type {ol.style.Stroke}
  30064. */
  30065. this.stroke_ = options.stroke !== undefined ? options.stroke : null;
  30066. /**
  30067. * @private
  30068. * @type {Array.<number>}
  30069. */
  30070. this.anchor_ = null;
  30071. /**
  30072. * @private
  30073. * @type {ol.Size}
  30074. */
  30075. this.size_ = null;
  30076. /**
  30077. * @private
  30078. * @type {ol.Size}
  30079. */
  30080. this.imageSize_ = null;
  30081. /**
  30082. * @private
  30083. * @type {ol.Size}
  30084. */
  30085. this.hitDetectionImageSize_ = null;
  30086. /**
  30087. * @protected
  30088. * @type {ol.style.AtlasManager|undefined}
  30089. */
  30090. this.atlasManager_ = options.atlasManager;
  30091. this.render_(this.atlasManager_);
  30092. /**
  30093. * @type {boolean}
  30094. */
  30095. var snapToPixel = options.snapToPixel !== undefined ?
  30096. options.snapToPixel : true;
  30097. /**
  30098. * @type {boolean}
  30099. */
  30100. var rotateWithView = options.rotateWithView !== undefined ?
  30101. options.rotateWithView : false;
  30102. ol.style.Image.call(this, {
  30103. opacity: 1,
  30104. rotateWithView: rotateWithView,
  30105. rotation: options.rotation !== undefined ? options.rotation : 0,
  30106. scale: 1,
  30107. snapToPixel: snapToPixel
  30108. });
  30109. };
  30110. ol.inherits(ol.style.RegularShape, ol.style.Image);
  30111. /**
  30112. * Clones the style. If an atlasmanager was provided to the original style it will be used in the cloned style, too.
  30113. * @return {ol.style.RegularShape} The cloned style.
  30114. * @api
  30115. */
  30116. ol.style.RegularShape.prototype.clone = function() {
  30117. var style = new ol.style.RegularShape({
  30118. fill: this.getFill() ? this.getFill().clone() : undefined,
  30119. points: this.getPoints(),
  30120. radius: this.getRadius(),
  30121. radius2: this.getRadius2(),
  30122. angle: this.getAngle(),
  30123. snapToPixel: this.getSnapToPixel(),
  30124. stroke: this.getStroke() ? this.getStroke().clone() : undefined,
  30125. rotation: this.getRotation(),
  30126. rotateWithView: this.getRotateWithView(),
  30127. atlasManager: this.atlasManager_
  30128. });
  30129. style.setOpacity(this.getOpacity());
  30130. style.setScale(this.getScale());
  30131. return style;
  30132. };
  30133. /**
  30134. * @inheritDoc
  30135. * @api
  30136. */
  30137. ol.style.RegularShape.prototype.getAnchor = function() {
  30138. return this.anchor_;
  30139. };
  30140. /**
  30141. * Get the angle used in generating the shape.
  30142. * @return {number} Shape's rotation in radians.
  30143. * @api
  30144. */
  30145. ol.style.RegularShape.prototype.getAngle = function() {
  30146. return this.angle_;
  30147. };
  30148. /**
  30149. * Get the fill style for the shape.
  30150. * @return {ol.style.Fill} Fill style.
  30151. * @api
  30152. */
  30153. ol.style.RegularShape.prototype.getFill = function() {
  30154. return this.fill_;
  30155. };
  30156. /**
  30157. * @inheritDoc
  30158. */
  30159. ol.style.RegularShape.prototype.getHitDetectionImage = function(pixelRatio) {
  30160. return this.hitDetectionCanvas_;
  30161. };
  30162. /**
  30163. * @inheritDoc
  30164. * @api
  30165. */
  30166. ol.style.RegularShape.prototype.getImage = function(pixelRatio) {
  30167. return this.canvas_;
  30168. };
  30169. /**
  30170. * @inheritDoc
  30171. */
  30172. ol.style.RegularShape.prototype.getImageSize = function() {
  30173. return this.imageSize_;
  30174. };
  30175. /**
  30176. * @inheritDoc
  30177. */
  30178. ol.style.RegularShape.prototype.getHitDetectionImageSize = function() {
  30179. return this.hitDetectionImageSize_;
  30180. };
  30181. /**
  30182. * @inheritDoc
  30183. */
  30184. ol.style.RegularShape.prototype.getImageState = function() {
  30185. return ol.ImageState.LOADED;
  30186. };
  30187. /**
  30188. * @inheritDoc
  30189. * @api
  30190. */
  30191. ol.style.RegularShape.prototype.getOrigin = function() {
  30192. return this.origin_;
  30193. };
  30194. /**
  30195. * Get the number of points for generating the shape.
  30196. * @return {number} Number of points for stars and regular polygons.
  30197. * @api
  30198. */
  30199. ol.style.RegularShape.prototype.getPoints = function() {
  30200. return this.points_;
  30201. };
  30202. /**
  30203. * Get the (primary) radius for the shape.
  30204. * @return {number} Radius.
  30205. * @api
  30206. */
  30207. ol.style.RegularShape.prototype.getRadius = function() {
  30208. return this.radius_;
  30209. };
  30210. /**
  30211. * Get the secondary radius for the shape.
  30212. * @return {number|undefined} Radius2.
  30213. * @api
  30214. */
  30215. ol.style.RegularShape.prototype.getRadius2 = function() {
  30216. return this.radius2_;
  30217. };
  30218. /**
  30219. * @inheritDoc
  30220. * @api
  30221. */
  30222. ol.style.RegularShape.prototype.getSize = function() {
  30223. return this.size_;
  30224. };
  30225. /**
  30226. * Get the stroke style for the shape.
  30227. * @return {ol.style.Stroke} Stroke style.
  30228. * @api
  30229. */
  30230. ol.style.RegularShape.prototype.getStroke = function() {
  30231. return this.stroke_;
  30232. };
  30233. /**
  30234. * @inheritDoc
  30235. */
  30236. ol.style.RegularShape.prototype.listenImageChange = function(listener, thisArg) {};
  30237. /**
  30238. * @inheritDoc
  30239. */
  30240. ol.style.RegularShape.prototype.load = function() {};
  30241. /**
  30242. * @inheritDoc
  30243. */
  30244. ol.style.RegularShape.prototype.unlistenImageChange = function(listener, thisArg) {};
  30245. /**
  30246. * @protected
  30247. * @param {ol.style.AtlasManager|undefined} atlasManager An atlas manager.
  30248. */
  30249. ol.style.RegularShape.prototype.render_ = function(atlasManager) {
  30250. var imageSize;
  30251. var lineCap = '';
  30252. var lineJoin = '';
  30253. var miterLimit = 0;
  30254. var lineDash = null;
  30255. var lineDashOffset = 0;
  30256. var strokeStyle;
  30257. var strokeWidth = 0;
  30258. if (this.stroke_) {
  30259. strokeStyle = this.stroke_.getColor();
  30260. if (strokeStyle === null) {
  30261. strokeStyle = ol.render.canvas.defaultStrokeStyle;
  30262. }
  30263. strokeStyle = ol.colorlike.asColorLike(strokeStyle);
  30264. strokeWidth = this.stroke_.getWidth();
  30265. if (strokeWidth === undefined) {
  30266. strokeWidth = ol.render.canvas.defaultLineWidth;
  30267. }
  30268. lineDash = this.stroke_.getLineDash();
  30269. lineDashOffset = this.stroke_.getLineDashOffset();
  30270. if (!ol.has.CANVAS_LINE_DASH) {
  30271. lineDash = null;
  30272. lineDashOffset = 0;
  30273. }
  30274. lineJoin = this.stroke_.getLineJoin();
  30275. if (lineJoin === undefined) {
  30276. lineJoin = ol.render.canvas.defaultLineJoin;
  30277. }
  30278. lineCap = this.stroke_.getLineCap();
  30279. if (lineCap === undefined) {
  30280. lineCap = ol.render.canvas.defaultLineCap;
  30281. }
  30282. miterLimit = this.stroke_.getMiterLimit();
  30283. if (miterLimit === undefined) {
  30284. miterLimit = ol.render.canvas.defaultMiterLimit;
  30285. }
  30286. }
  30287. var size = 2 * (this.radius_ + strokeWidth) + 1;
  30288. /** @type {ol.RegularShapeRenderOptions} */
  30289. var renderOptions = {
  30290. strokeStyle: strokeStyle,
  30291. strokeWidth: strokeWidth,
  30292. size: size,
  30293. lineCap: lineCap,
  30294. lineDash: lineDash,
  30295. lineDashOffset: lineDashOffset,
  30296. lineJoin: lineJoin,
  30297. miterLimit: miterLimit
  30298. };
  30299. if (atlasManager === undefined) {
  30300. // no atlas manager is used, create a new canvas
  30301. var context = ol.dom.createCanvasContext2D(size, size);
  30302. this.canvas_ = context.canvas;
  30303. // canvas.width and height are rounded to the closest integer
  30304. size = this.canvas_.width;
  30305. imageSize = size;
  30306. this.draw_(renderOptions, context, 0, 0);
  30307. this.createHitDetectionCanvas_(renderOptions);
  30308. } else {
  30309. // an atlas manager is used, add the symbol to an atlas
  30310. size = Math.round(size);
  30311. var hasCustomHitDetectionImage = !this.fill_;
  30312. var renderHitDetectionCallback;
  30313. if (hasCustomHitDetectionImage) {
  30314. // render the hit-detection image into a separate atlas image
  30315. renderHitDetectionCallback =
  30316. this.drawHitDetectionCanvas_.bind(this, renderOptions);
  30317. }
  30318. var id = this.getChecksum();
  30319. var info = atlasManager.add(
  30320. id, size, size, this.draw_.bind(this, renderOptions),
  30321. renderHitDetectionCallback);
  30322. this.canvas_ = info.image;
  30323. this.origin_ = [info.offsetX, info.offsetY];
  30324. imageSize = info.image.width;
  30325. if (hasCustomHitDetectionImage) {
  30326. this.hitDetectionCanvas_ = info.hitImage;
  30327. this.hitDetectionImageSize_ =
  30328. [info.hitImage.width, info.hitImage.height];
  30329. } else {
  30330. this.hitDetectionCanvas_ = this.canvas_;
  30331. this.hitDetectionImageSize_ = [imageSize, imageSize];
  30332. }
  30333. }
  30334. this.anchor_ = [size / 2, size / 2];
  30335. this.size_ = [size, size];
  30336. this.imageSize_ = [imageSize, imageSize];
  30337. };
  30338. /**
  30339. * @private
  30340. * @param {ol.RegularShapeRenderOptions} renderOptions Render options.
  30341. * @param {CanvasRenderingContext2D} context The rendering context.
  30342. * @param {number} x The origin for the symbol (x).
  30343. * @param {number} y The origin for the symbol (y).
  30344. */
  30345. ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) {
  30346. var i, angle0, radiusC;
  30347. // reset transform
  30348. context.setTransform(1, 0, 0, 1, 0, 0);
  30349. // then move to (x, y)
  30350. context.translate(x, y);
  30351. context.beginPath();
  30352. var points = this.points_;
  30353. if (points === Infinity) {
  30354. context.arc(
  30355. renderOptions.size / 2, renderOptions.size / 2,
  30356. this.radius_, 0, 2 * Math.PI, true);
  30357. } else {
  30358. var radius2 = (this.radius2_ !== undefined) ? this.radius2_
  30359. : this.radius_;
  30360. if (radius2 !== this.radius_) {
  30361. points = 2 * points;
  30362. }
  30363. for (i = 0; i <= points; i++) {
  30364. angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_;
  30365. radiusC = i % 2 === 0 ? this.radius_ : radius2;
  30366. context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0),
  30367. renderOptions.size / 2 + radiusC * Math.sin(angle0));
  30368. }
  30369. }
  30370. if (this.fill_) {
  30371. var color = this.fill_.getColor();
  30372. if (color === null) {
  30373. color = ol.render.canvas.defaultFillStyle;
  30374. }
  30375. context.fillStyle = ol.colorlike.asColorLike(color);
  30376. context.fill();
  30377. }
  30378. if (this.stroke_) {
  30379. context.strokeStyle = renderOptions.strokeStyle;
  30380. context.lineWidth = renderOptions.strokeWidth;
  30381. if (renderOptions.lineDash) {
  30382. context.setLineDash(renderOptions.lineDash);
  30383. context.lineDashOffset = renderOptions.lineDashOffset;
  30384. }
  30385. context.lineCap = renderOptions.lineCap;
  30386. context.lineJoin = renderOptions.lineJoin;
  30387. context.miterLimit = renderOptions.miterLimit;
  30388. context.stroke();
  30389. }
  30390. context.closePath();
  30391. };
  30392. /**
  30393. * @private
  30394. * @param {ol.RegularShapeRenderOptions} renderOptions Render options.
  30395. */
  30396. ol.style.RegularShape.prototype.createHitDetectionCanvas_ = function(renderOptions) {
  30397. this.hitDetectionImageSize_ = [renderOptions.size, renderOptions.size];
  30398. if (this.fill_) {
  30399. this.hitDetectionCanvas_ = this.canvas_;
  30400. return;
  30401. }
  30402. // if no fill style is set, create an extra hit-detection image with a
  30403. // default fill style
  30404. var context = ol.dom.createCanvasContext2D(renderOptions.size, renderOptions.size);
  30405. this.hitDetectionCanvas_ = context.canvas;
  30406. this.drawHitDetectionCanvas_(renderOptions, context, 0, 0);
  30407. };
  30408. /**
  30409. * @private
  30410. * @param {ol.RegularShapeRenderOptions} renderOptions Render options.
  30411. * @param {CanvasRenderingContext2D} context The context.
  30412. * @param {number} x The origin for the symbol (x).
  30413. * @param {number} y The origin for the symbol (y).
  30414. */
  30415. ol.style.RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions, context, x, y) {
  30416. // reset transform
  30417. context.setTransform(1, 0, 0, 1, 0, 0);
  30418. // then move to (x, y)
  30419. context.translate(x, y);
  30420. context.beginPath();
  30421. var points = this.points_;
  30422. if (points === Infinity) {
  30423. context.arc(
  30424. renderOptions.size / 2, renderOptions.size / 2,
  30425. this.radius_, 0, 2 * Math.PI, true);
  30426. } else {
  30427. var radius2 = (this.radius2_ !== undefined) ? this.radius2_
  30428. : this.radius_;
  30429. if (radius2 !== this.radius_) {
  30430. points = 2 * points;
  30431. }
  30432. var i, radiusC, angle0;
  30433. for (i = 0; i <= points; i++) {
  30434. angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_;
  30435. radiusC = i % 2 === 0 ? this.radius_ : radius2;
  30436. context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0),
  30437. renderOptions.size / 2 + radiusC * Math.sin(angle0));
  30438. }
  30439. }
  30440. context.fillStyle = ol.render.canvas.defaultFillStyle;
  30441. context.fill();
  30442. if (this.stroke_) {
  30443. context.strokeStyle = renderOptions.strokeStyle;
  30444. context.lineWidth = renderOptions.strokeWidth;
  30445. if (renderOptions.lineDash) {
  30446. context.setLineDash(renderOptions.lineDash);
  30447. context.lineDashOffset = renderOptions.lineDashOffset;
  30448. }
  30449. context.stroke();
  30450. }
  30451. context.closePath();
  30452. };
  30453. /**
  30454. * @return {string} The checksum.
  30455. */
  30456. ol.style.RegularShape.prototype.getChecksum = function() {
  30457. var strokeChecksum = this.stroke_ ?
  30458. this.stroke_.getChecksum() : '-';
  30459. var fillChecksum = this.fill_ ?
  30460. this.fill_.getChecksum() : '-';
  30461. var recalculate = !this.checksums_ ||
  30462. (strokeChecksum != this.checksums_[1] ||
  30463. fillChecksum != this.checksums_[2] ||
  30464. this.radius_ != this.checksums_[3] ||
  30465. this.radius2_ != this.checksums_[4] ||
  30466. this.angle_ != this.checksums_[5] ||
  30467. this.points_ != this.checksums_[6]);
  30468. if (recalculate) {
  30469. var checksum = 'r' + strokeChecksum + fillChecksum +
  30470. (this.radius_ !== undefined ? this.radius_.toString() : '-') +
  30471. (this.radius2_ !== undefined ? this.radius2_.toString() : '-') +
  30472. (this.angle_ !== undefined ? this.angle_.toString() : '-') +
  30473. (this.points_ !== undefined ? this.points_.toString() : '-');
  30474. this.checksums_ = [checksum, strokeChecksum, fillChecksum,
  30475. this.radius_, this.radius2_, this.angle_, this.points_];
  30476. }
  30477. return this.checksums_[0];
  30478. };
  30479. goog.provide('ol.style.Circle');
  30480. goog.require('ol');
  30481. goog.require('ol.style.RegularShape');
  30482. /**
  30483. * @classdesc
  30484. * Set circle style for vector features.
  30485. *
  30486. * @constructor
  30487. * @param {olx.style.CircleOptions=} opt_options Options.
  30488. * @extends {ol.style.RegularShape}
  30489. * @api
  30490. */
  30491. ol.style.Circle = function(opt_options) {
  30492. var options = opt_options || {};
  30493. ol.style.RegularShape.call(this, {
  30494. points: Infinity,
  30495. fill: options.fill,
  30496. radius: options.radius,
  30497. snapToPixel: options.snapToPixel,
  30498. stroke: options.stroke,
  30499. atlasManager: options.atlasManager
  30500. });
  30501. };
  30502. ol.inherits(ol.style.Circle, ol.style.RegularShape);
  30503. /**
  30504. * Clones the style. If an atlasmanager was provided to the original style it will be used in the cloned style, too.
  30505. * @return {ol.style.Circle} The cloned style.
  30506. * @override
  30507. * @api
  30508. */
  30509. ol.style.Circle.prototype.clone = function() {
  30510. var style = new ol.style.Circle({
  30511. fill: this.getFill() ? this.getFill().clone() : undefined,
  30512. stroke: this.getStroke() ? this.getStroke().clone() : undefined,
  30513. radius: this.getRadius(),
  30514. snapToPixel: this.getSnapToPixel(),
  30515. atlasManager: this.atlasManager_
  30516. });
  30517. style.setOpacity(this.getOpacity());
  30518. style.setScale(this.getScale());
  30519. return style;
  30520. };
  30521. /**
  30522. * Set the circle radius.
  30523. *
  30524. * @param {number} radius Circle radius.
  30525. * @api
  30526. */
  30527. ol.style.Circle.prototype.setRadius = function(radius) {
  30528. this.radius_ = radius;
  30529. this.render_(this.atlasManager_);
  30530. };
  30531. goog.provide('ol.style.Fill');
  30532. goog.require('ol');
  30533. goog.require('ol.color');
  30534. /**
  30535. * @classdesc
  30536. * Set fill style for vector features.
  30537. *
  30538. * @constructor
  30539. * @param {olx.style.FillOptions=} opt_options Options.
  30540. * @api
  30541. */
  30542. ol.style.Fill = function(opt_options) {
  30543. var options = opt_options || {};
  30544. /**
  30545. * @private
  30546. * @type {ol.Color|ol.ColorLike}
  30547. */
  30548. this.color_ = options.color !== undefined ? options.color : null;
  30549. /**
  30550. * @private
  30551. * @type {string|undefined}
  30552. */
  30553. this.checksum_ = undefined;
  30554. };
  30555. /**
  30556. * Clones the style. The color is not cloned if it is an {@link ol.ColorLike}.
  30557. * @return {ol.style.Fill} The cloned style.
  30558. * @api
  30559. */
  30560. ol.style.Fill.prototype.clone = function() {
  30561. var color = this.getColor();
  30562. return new ol.style.Fill({
  30563. color: (color && color.slice) ? color.slice() : color || undefined
  30564. });
  30565. };
  30566. /**
  30567. * Get the fill color.
  30568. * @return {ol.Color|ol.ColorLike} Color.
  30569. * @api
  30570. */
  30571. ol.style.Fill.prototype.getColor = function() {
  30572. return this.color_;
  30573. };
  30574. /**
  30575. * Set the color.
  30576. *
  30577. * @param {ol.Color|ol.ColorLike} color Color.
  30578. * @api
  30579. */
  30580. ol.style.Fill.prototype.setColor = function(color) {
  30581. this.color_ = color;
  30582. this.checksum_ = undefined;
  30583. };
  30584. /**
  30585. * @return {string} The checksum.
  30586. */
  30587. ol.style.Fill.prototype.getChecksum = function() {
  30588. if (this.checksum_ === undefined) {
  30589. if (
  30590. this.color_ instanceof CanvasPattern ||
  30591. this.color_ instanceof CanvasGradient
  30592. ) {
  30593. this.checksum_ = ol.getUid(this.color_).toString();
  30594. } else {
  30595. this.checksum_ = 'f' + (this.color_ ?
  30596. ol.color.asString(this.color_) : '-');
  30597. }
  30598. }
  30599. return this.checksum_;
  30600. };
  30601. goog.provide('ol.style.Stroke');
  30602. goog.require('ol');
  30603. /**
  30604. * @classdesc
  30605. * Set stroke style for vector features.
  30606. * Note that the defaults given are the Canvas defaults, which will be used if
  30607. * option is not defined. The `get` functions return whatever was entered in
  30608. * the options; they will not return the default.
  30609. *
  30610. * @constructor
  30611. * @param {olx.style.StrokeOptions=} opt_options Options.
  30612. * @api
  30613. */
  30614. ol.style.Stroke = function(opt_options) {
  30615. var options = opt_options || {};
  30616. /**
  30617. * @private
  30618. * @type {ol.Color|ol.ColorLike}
  30619. */
  30620. this.color_ = options.color !== undefined ? options.color : null;
  30621. /**
  30622. * @private
  30623. * @type {string|undefined}
  30624. */
  30625. this.lineCap_ = options.lineCap;
  30626. /**
  30627. * @private
  30628. * @type {Array.<number>}
  30629. */
  30630. this.lineDash_ = options.lineDash !== undefined ? options.lineDash : null;
  30631. /**
  30632. * @private
  30633. * @type {number|undefined}
  30634. */
  30635. this.lineDashOffset_ = options.lineDashOffset;
  30636. /**
  30637. * @private
  30638. * @type {string|undefined}
  30639. */
  30640. this.lineJoin_ = options.lineJoin;
  30641. /**
  30642. * @private
  30643. * @type {number|undefined}
  30644. */
  30645. this.miterLimit_ = options.miterLimit;
  30646. /**
  30647. * @private
  30648. * @type {number|undefined}
  30649. */
  30650. this.width_ = options.width;
  30651. /**
  30652. * @private
  30653. * @type {string|undefined}
  30654. */
  30655. this.checksum_ = undefined;
  30656. };
  30657. /**
  30658. * Clones the style.
  30659. * @return {ol.style.Stroke} The cloned style.
  30660. * @api
  30661. */
  30662. ol.style.Stroke.prototype.clone = function() {
  30663. var color = this.getColor();
  30664. return new ol.style.Stroke({
  30665. color: (color && color.slice) ? color.slice() : color || undefined,
  30666. lineCap: this.getLineCap(),
  30667. lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined,
  30668. lineDashOffset: this.getLineDashOffset(),
  30669. lineJoin: this.getLineJoin(),
  30670. miterLimit: this.getMiterLimit(),
  30671. width: this.getWidth()
  30672. });
  30673. };
  30674. /**
  30675. * Get the stroke color.
  30676. * @return {ol.Color|ol.ColorLike} Color.
  30677. * @api
  30678. */
  30679. ol.style.Stroke.prototype.getColor = function() {
  30680. return this.color_;
  30681. };
  30682. /**
  30683. * Get the line cap type for the stroke.
  30684. * @return {string|undefined} Line cap.
  30685. * @api
  30686. */
  30687. ol.style.Stroke.prototype.getLineCap = function() {
  30688. return this.lineCap_;
  30689. };
  30690. /**
  30691. * Get the line dash style for the stroke.
  30692. * @return {Array.<number>} Line dash.
  30693. * @api
  30694. */
  30695. ol.style.Stroke.prototype.getLineDash = function() {
  30696. return this.lineDash_;
  30697. };
  30698. /**
  30699. * Get the line dash offset for the stroke.
  30700. * @return {number|undefined} Line dash offset.
  30701. * @api
  30702. */
  30703. ol.style.Stroke.prototype.getLineDashOffset = function() {
  30704. return this.lineDashOffset_;
  30705. };
  30706. /**
  30707. * Get the line join type for the stroke.
  30708. * @return {string|undefined} Line join.
  30709. * @api
  30710. */
  30711. ol.style.Stroke.prototype.getLineJoin = function() {
  30712. return this.lineJoin_;
  30713. };
  30714. /**
  30715. * Get the miter limit for the stroke.
  30716. * @return {number|undefined} Miter limit.
  30717. * @api
  30718. */
  30719. ol.style.Stroke.prototype.getMiterLimit = function() {
  30720. return this.miterLimit_;
  30721. };
  30722. /**
  30723. * Get the stroke width.
  30724. * @return {number|undefined} Width.
  30725. * @api
  30726. */
  30727. ol.style.Stroke.prototype.getWidth = function() {
  30728. return this.width_;
  30729. };
  30730. /**
  30731. * Set the color.
  30732. *
  30733. * @param {ol.Color|ol.ColorLike} color Color.
  30734. * @api
  30735. */
  30736. ol.style.Stroke.prototype.setColor = function(color) {
  30737. this.color_ = color;
  30738. this.checksum_ = undefined;
  30739. };
  30740. /**
  30741. * Set the line cap.
  30742. *
  30743. * @param {string|undefined} lineCap Line cap.
  30744. * @api
  30745. */
  30746. ol.style.Stroke.prototype.setLineCap = function(lineCap) {
  30747. this.lineCap_ = lineCap;
  30748. this.checksum_ = undefined;
  30749. };
  30750. /**
  30751. * Set the line dash.
  30752. *
  30753. * Please note that Internet Explorer 10 and lower [do not support][mdn] the
  30754. * `setLineDash` method on the `CanvasRenderingContext2D` and therefore this
  30755. * property will have no visual effect in these browsers.
  30756. *
  30757. * [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility
  30758. *
  30759. * @param {Array.<number>} lineDash Line dash.
  30760. * @api
  30761. */
  30762. ol.style.Stroke.prototype.setLineDash = function(lineDash) {
  30763. this.lineDash_ = lineDash;
  30764. this.checksum_ = undefined;
  30765. };
  30766. /**
  30767. * Set the line dash offset.
  30768. *
  30769. * @param {number|undefined} lineDashOffset Line dash offset.
  30770. * @api
  30771. */
  30772. ol.style.Stroke.prototype.setLineDashOffset = function(lineDashOffset) {
  30773. this.lineDashOffset_ = lineDashOffset;
  30774. this.checksum_ = undefined;
  30775. };
  30776. /**
  30777. * Set the line join.
  30778. *
  30779. * @param {string|undefined} lineJoin Line join.
  30780. * @api
  30781. */
  30782. ol.style.Stroke.prototype.setLineJoin = function(lineJoin) {
  30783. this.lineJoin_ = lineJoin;
  30784. this.checksum_ = undefined;
  30785. };
  30786. /**
  30787. * Set the miter limit.
  30788. *
  30789. * @param {number|undefined} miterLimit Miter limit.
  30790. * @api
  30791. */
  30792. ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) {
  30793. this.miterLimit_ = miterLimit;
  30794. this.checksum_ = undefined;
  30795. };
  30796. /**
  30797. * Set the width.
  30798. *
  30799. * @param {number|undefined} width Width.
  30800. * @api
  30801. */
  30802. ol.style.Stroke.prototype.setWidth = function(width) {
  30803. this.width_ = width;
  30804. this.checksum_ = undefined;
  30805. };
  30806. /**
  30807. * @return {string} The checksum.
  30808. */
  30809. ol.style.Stroke.prototype.getChecksum = function() {
  30810. if (this.checksum_ === undefined) {
  30811. this.checksum_ = 's';
  30812. if (this.color_) {
  30813. if (typeof this.color_ === 'string') {
  30814. this.checksum_ += this.color_;
  30815. } else {
  30816. this.checksum_ += ol.getUid(this.color_).toString();
  30817. }
  30818. } else {
  30819. this.checksum_ += '-';
  30820. }
  30821. this.checksum_ += ',' +
  30822. (this.lineCap_ !== undefined ?
  30823. this.lineCap_.toString() : '-') + ',' +
  30824. (this.lineDash_ ?
  30825. this.lineDash_.toString() : '-') + ',' +
  30826. (this.lineDashOffset_ !== undefined ?
  30827. this.lineDashOffset_ : '-') + ',' +
  30828. (this.lineJoin_ !== undefined ?
  30829. this.lineJoin_ : '-') + ',' +
  30830. (this.miterLimit_ !== undefined ?
  30831. this.miterLimit_.toString() : '-') + ',' +
  30832. (this.width_ !== undefined ?
  30833. this.width_.toString() : '-');
  30834. }
  30835. return this.checksum_;
  30836. };
  30837. goog.provide('ol.style.Style');
  30838. goog.require('ol.asserts');
  30839. goog.require('ol.geom.GeometryType');
  30840. goog.require('ol.style.Circle');
  30841. goog.require('ol.style.Fill');
  30842. goog.require('ol.style.Stroke');
  30843. /**
  30844. * @classdesc
  30845. * Container for vector feature rendering styles. Any changes made to the style
  30846. * or its children through `set*()` methods will not take effect until the
  30847. * feature or layer that uses the style is re-rendered.
  30848. *
  30849. * @constructor
  30850. * @struct
  30851. * @param {olx.style.StyleOptions=} opt_options Style options.
  30852. * @api
  30853. */
  30854. ol.style.Style = function(opt_options) {
  30855. var options = opt_options || {};
  30856. /**
  30857. * @private
  30858. * @type {string|ol.geom.Geometry|ol.StyleGeometryFunction}
  30859. */
  30860. this.geometry_ = null;
  30861. /**
  30862. * @private
  30863. * @type {!ol.StyleGeometryFunction}
  30864. */
  30865. this.geometryFunction_ = ol.style.Style.defaultGeometryFunction;
  30866. if (options.geometry !== undefined) {
  30867. this.setGeometry(options.geometry);
  30868. }
  30869. /**
  30870. * @private
  30871. * @type {ol.style.Fill}
  30872. */
  30873. this.fill_ = options.fill !== undefined ? options.fill : null;
  30874. /**
  30875. * @private
  30876. * @type {ol.style.Image}
  30877. */
  30878. this.image_ = options.image !== undefined ? options.image : null;
  30879. /**
  30880. * @private
  30881. * @type {ol.StyleRenderFunction|null}
  30882. */
  30883. this.renderer_ = options.renderer !== undefined ? options.renderer : null;
  30884. /**
  30885. * @private
  30886. * @type {ol.style.Stroke}
  30887. */
  30888. this.stroke_ = options.stroke !== undefined ? options.stroke : null;
  30889. /**
  30890. * @private
  30891. * @type {ol.style.Text}
  30892. */
  30893. this.text_ = options.text !== undefined ? options.text : null;
  30894. /**
  30895. * @private
  30896. * @type {number|undefined}
  30897. */
  30898. this.zIndex_ = options.zIndex;
  30899. };
  30900. /**
  30901. * Clones the style.
  30902. * @return {ol.style.Style} The cloned style.
  30903. * @api
  30904. */
  30905. ol.style.Style.prototype.clone = function() {
  30906. var geometry = this.getGeometry();
  30907. if (geometry && geometry.clone) {
  30908. geometry = geometry.clone();
  30909. }
  30910. return new ol.style.Style({
  30911. geometry: geometry,
  30912. fill: this.getFill() ? this.getFill().clone() : undefined,
  30913. image: this.getImage() ? this.getImage().clone() : undefined,
  30914. stroke: this.getStroke() ? this.getStroke().clone() : undefined,
  30915. text: this.getText() ? this.getText().clone() : undefined,
  30916. zIndex: this.getZIndex()
  30917. });
  30918. };
  30919. /**
  30920. * Get the custom renderer function that was configured with
  30921. * {@link #setRenderer} or the `renderer` constructor option.
  30922. * @return {ol.StyleRenderFunction|null} Custom renderer function.
  30923. * @api
  30924. */
  30925. ol.style.Style.prototype.getRenderer = function() {
  30926. return this.renderer_;
  30927. };
  30928. /**
  30929. * Sets a custom renderer function for this style. When set, `fill`, `stroke`
  30930. * and `image` options of the style will be ignored.
  30931. * @param {ol.StyleRenderFunction|null} renderer Custom renderer function.
  30932. * @api
  30933. */
  30934. ol.style.Style.prototype.setRenderer = function(renderer) {
  30935. this.renderer_ = renderer;
  30936. };
  30937. /**
  30938. * Get the geometry to be rendered.
  30939. * @return {string|ol.geom.Geometry|ol.StyleGeometryFunction}
  30940. * Feature property or geometry or function that returns the geometry that will
  30941. * be rendered with this style.
  30942. * @api
  30943. */
  30944. ol.style.Style.prototype.getGeometry = function() {
  30945. return this.geometry_;
  30946. };
  30947. /**
  30948. * Get the function used to generate a geometry for rendering.
  30949. * @return {!ol.StyleGeometryFunction} Function that is called with a feature
  30950. * and returns the geometry to render instead of the feature's geometry.
  30951. * @api
  30952. */
  30953. ol.style.Style.prototype.getGeometryFunction = function() {
  30954. return this.geometryFunction_;
  30955. };
  30956. /**
  30957. * Get the fill style.
  30958. * @return {ol.style.Fill} Fill style.
  30959. * @api
  30960. */
  30961. ol.style.Style.prototype.getFill = function() {
  30962. return this.fill_;
  30963. };
  30964. /**
  30965. * Set the fill style.
  30966. * @param {ol.style.Fill} fill Fill style.
  30967. * @api
  30968. */
  30969. ol.style.Style.prototype.setFill = function(fill) {
  30970. this.fill_ = fill;
  30971. };
  30972. /**
  30973. * Get the image style.
  30974. * @return {ol.style.Image} Image style.
  30975. * @api
  30976. */
  30977. ol.style.Style.prototype.getImage = function() {
  30978. return this.image_;
  30979. };
  30980. /**
  30981. * Set the image style.
  30982. * @param {ol.style.Image} image Image style.
  30983. * @api
  30984. */
  30985. ol.style.Style.prototype.setImage = function(image) {
  30986. this.image_ = image;
  30987. };
  30988. /**
  30989. * Get the stroke style.
  30990. * @return {ol.style.Stroke} Stroke style.
  30991. * @api
  30992. */
  30993. ol.style.Style.prototype.getStroke = function() {
  30994. return this.stroke_;
  30995. };
  30996. /**
  30997. * Set the stroke style.
  30998. * @param {ol.style.Stroke} stroke Stroke style.
  30999. * @api
  31000. */
  31001. ol.style.Style.prototype.setStroke = function(stroke) {
  31002. this.stroke_ = stroke;
  31003. };
  31004. /**
  31005. * Get the text style.
  31006. * @return {ol.style.Text} Text style.
  31007. * @api
  31008. */
  31009. ol.style.Style.prototype.getText = function() {
  31010. return this.text_;
  31011. };
  31012. /**
  31013. * Set the text style.
  31014. * @param {ol.style.Text} text Text style.
  31015. * @api
  31016. */
  31017. ol.style.Style.prototype.setText = function(text) {
  31018. this.text_ = text;
  31019. };
  31020. /**
  31021. * Get the z-index for the style.
  31022. * @return {number|undefined} ZIndex.
  31023. * @api
  31024. */
  31025. ol.style.Style.prototype.getZIndex = function() {
  31026. return this.zIndex_;
  31027. };
  31028. /**
  31029. * Set a geometry that is rendered instead of the feature's geometry.
  31030. *
  31031. * @param {string|ol.geom.Geometry|ol.StyleGeometryFunction} geometry
  31032. * Feature property or geometry or function returning a geometry to render
  31033. * for this style.
  31034. * @api
  31035. */
  31036. ol.style.Style.prototype.setGeometry = function(geometry) {
  31037. if (typeof geometry === 'function') {
  31038. this.geometryFunction_ = geometry;
  31039. } else if (typeof geometry === 'string') {
  31040. this.geometryFunction_ = function(feature) {
  31041. return /** @type {ol.geom.Geometry} */ (feature.get(geometry));
  31042. };
  31043. } else if (!geometry) {
  31044. this.geometryFunction_ = ol.style.Style.defaultGeometryFunction;
  31045. } else if (geometry !== undefined) {
  31046. this.geometryFunction_ = function() {
  31047. return /** @type {ol.geom.Geometry} */ (geometry);
  31048. };
  31049. }
  31050. this.geometry_ = geometry;
  31051. };
  31052. /**
  31053. * Set the z-index.
  31054. *
  31055. * @param {number|undefined} zIndex ZIndex.
  31056. * @api
  31057. */
  31058. ol.style.Style.prototype.setZIndex = function(zIndex) {
  31059. this.zIndex_ = zIndex;
  31060. };
  31061. /**
  31062. * Convert the provided object into a style function. Functions passed through
  31063. * unchanged. Arrays of ol.style.Style or single style objects wrapped in a
  31064. * new style function.
  31065. * @param {ol.StyleFunction|Array.<ol.style.Style>|ol.style.Style} obj
  31066. * A style function, a single style, or an array of styles.
  31067. * @return {ol.StyleFunction} A style function.
  31068. */
  31069. ol.style.Style.createFunction = function(obj) {
  31070. var styleFunction;
  31071. if (typeof obj === 'function') {
  31072. styleFunction = obj;
  31073. } else {
  31074. /**
  31075. * @type {Array.<ol.style.Style>}
  31076. */
  31077. var styles;
  31078. if (Array.isArray(obj)) {
  31079. styles = obj;
  31080. } else {
  31081. ol.asserts.assert(obj instanceof ol.style.Style,
  31082. 41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
  31083. styles = [obj];
  31084. }
  31085. styleFunction = function() {
  31086. return styles;
  31087. };
  31088. }
  31089. return styleFunction;
  31090. };
  31091. /**
  31092. * @type {Array.<ol.style.Style>}
  31093. * @private
  31094. */
  31095. ol.style.Style.default_ = null;
  31096. /**
  31097. * @param {ol.Feature|ol.render.Feature} feature Feature.
  31098. * @param {number} resolution Resolution.
  31099. * @return {Array.<ol.style.Style>} Style.
  31100. */
  31101. ol.style.Style.defaultFunction = function(feature, resolution) {
  31102. // We don't use an immediately-invoked function
  31103. // and a closure so we don't get an error at script evaluation time in
  31104. // browsers that do not support Canvas. (ol.style.Circle does
  31105. // canvas.getContext('2d') at construction time, which will cause an.error
  31106. // in such browsers.)
  31107. if (!ol.style.Style.default_) {
  31108. var fill = new ol.style.Fill({
  31109. color: 'rgba(255,255,255,0.4)'
  31110. });
  31111. var stroke = new ol.style.Stroke({
  31112. color: '#3399CC',
  31113. width: 1.25
  31114. });
  31115. ol.style.Style.default_ = [
  31116. new ol.style.Style({
  31117. image: new ol.style.Circle({
  31118. fill: fill,
  31119. stroke: stroke,
  31120. radius: 5
  31121. }),
  31122. fill: fill,
  31123. stroke: stroke
  31124. })
  31125. ];
  31126. }
  31127. return ol.style.Style.default_;
  31128. };
  31129. /**
  31130. * Default styles for editing features.
  31131. * @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles
  31132. */
  31133. ol.style.Style.createDefaultEditing = function() {
  31134. /** @type {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} */
  31135. var styles = {};
  31136. var white = [255, 255, 255, 1];
  31137. var blue = [0, 153, 255, 1];
  31138. var width = 3;
  31139. styles[ol.geom.GeometryType.POLYGON] = [
  31140. new ol.style.Style({
  31141. fill: new ol.style.Fill({
  31142. color: [255, 255, 255, 0.5]
  31143. })
  31144. })
  31145. ];
  31146. styles[ol.geom.GeometryType.MULTI_POLYGON] =
  31147. styles[ol.geom.GeometryType.POLYGON];
  31148. styles[ol.geom.GeometryType.LINE_STRING] = [
  31149. new ol.style.Style({
  31150. stroke: new ol.style.Stroke({
  31151. color: white,
  31152. width: width + 2
  31153. })
  31154. }),
  31155. new ol.style.Style({
  31156. stroke: new ol.style.Stroke({
  31157. color: blue,
  31158. width: width
  31159. })
  31160. })
  31161. ];
  31162. styles[ol.geom.GeometryType.MULTI_LINE_STRING] =
  31163. styles[ol.geom.GeometryType.LINE_STRING];
  31164. styles[ol.geom.GeometryType.CIRCLE] =
  31165. styles[ol.geom.GeometryType.POLYGON].concat(
  31166. styles[ol.geom.GeometryType.LINE_STRING]
  31167. );
  31168. styles[ol.geom.GeometryType.POINT] = [
  31169. new ol.style.Style({
  31170. image: new ol.style.Circle({
  31171. radius: width * 2,
  31172. fill: new ol.style.Fill({
  31173. color: blue
  31174. }),
  31175. stroke: new ol.style.Stroke({
  31176. color: white,
  31177. width: width / 2
  31178. })
  31179. }),
  31180. zIndex: Infinity
  31181. })
  31182. ];
  31183. styles[ol.geom.GeometryType.MULTI_POINT] =
  31184. styles[ol.geom.GeometryType.POINT];
  31185. styles[ol.geom.GeometryType.GEOMETRY_COLLECTION] =
  31186. styles[ol.geom.GeometryType.POLYGON].concat(
  31187. styles[ol.geom.GeometryType.LINE_STRING],
  31188. styles[ol.geom.GeometryType.POINT]
  31189. );
  31190. return styles;
  31191. };
  31192. /**
  31193. * Function that is called with a feature and returns its default geometry.
  31194. * @param {ol.Feature|ol.render.Feature} feature Feature to get the geometry
  31195. * for.
  31196. * @return {ol.geom.Geometry|ol.render.Feature|undefined} Geometry to render.
  31197. */
  31198. ol.style.Style.defaultGeometryFunction = function(feature) {
  31199. return feature.getGeometry();
  31200. };
  31201. goog.provide('ol.Feature');
  31202. goog.require('ol.asserts');
  31203. goog.require('ol.events');
  31204. goog.require('ol.events.EventType');
  31205. goog.require('ol');
  31206. goog.require('ol.Object');
  31207. goog.require('ol.geom.Geometry');
  31208. goog.require('ol.style.Style');
  31209. /**
  31210. * @classdesc
  31211. * A vector object for geographic features with a geometry and other
  31212. * attribute properties, similar to the features in vector file formats like
  31213. * GeoJSON.
  31214. *
  31215. * Features can be styled individually with `setStyle`; otherwise they use the
  31216. * style of their vector layer.
  31217. *
  31218. * Note that attribute properties are set as {@link ol.Object} properties on
  31219. * the feature object, so they are observable, and have get/set accessors.
  31220. *
  31221. * Typically, a feature has a single geometry property. You can set the
  31222. * geometry using the `setGeometry` method and get it with `getGeometry`.
  31223. * It is possible to store more than one geometry on a feature using attribute
  31224. * properties. By default, the geometry used for rendering is identified by
  31225. * the property name `geometry`. If you want to use another geometry property
  31226. * for rendering, use the `setGeometryName` method to change the attribute
  31227. * property associated with the geometry for the feature. For example:
  31228. *
  31229. * ```js
  31230. * var feature = new ol.Feature({
  31231. * geometry: new ol.geom.Polygon(polyCoords),
  31232. * labelPoint: new ol.geom.Point(labelCoords),
  31233. * name: 'My Polygon'
  31234. * });
  31235. *
  31236. * // get the polygon geometry
  31237. * var poly = feature.getGeometry();
  31238. *
  31239. * // Render the feature as a point using the coordinates from labelPoint
  31240. * feature.setGeometryName('labelPoint');
  31241. *
  31242. * // get the point geometry
  31243. * var point = feature.getGeometry();
  31244. * ```
  31245. *
  31246. * @constructor
  31247. * @extends {ol.Object}
  31248. * @param {ol.geom.Geometry|Object.<string, *>=} opt_geometryOrProperties
  31249. * You may pass a Geometry object directly, or an object literal
  31250. * containing properties. If you pass an object literal, you may
  31251. * include a Geometry associated with a `geometry` key.
  31252. * @api
  31253. */
  31254. ol.Feature = function(opt_geometryOrProperties) {
  31255. ol.Object.call(this);
  31256. /**
  31257. * @private
  31258. * @type {number|string|undefined}
  31259. */
  31260. this.id_ = undefined;
  31261. /**
  31262. * @type {string}
  31263. * @private
  31264. */
  31265. this.geometryName_ = 'geometry';
  31266. /**
  31267. * User provided style.
  31268. * @private
  31269. * @type {ol.style.Style|Array.<ol.style.Style>|
  31270. * ol.FeatureStyleFunction}
  31271. */
  31272. this.style_ = null;
  31273. /**
  31274. * @private
  31275. * @type {ol.FeatureStyleFunction|undefined}
  31276. */
  31277. this.styleFunction_ = undefined;
  31278. /**
  31279. * @private
  31280. * @type {?ol.EventsKey}
  31281. */
  31282. this.geometryChangeKey_ = null;
  31283. ol.events.listen(
  31284. this, ol.Object.getChangeEventType(this.geometryName_),
  31285. this.handleGeometryChanged_, this);
  31286. if (opt_geometryOrProperties !== undefined) {
  31287. if (opt_geometryOrProperties instanceof ol.geom.Geometry ||
  31288. !opt_geometryOrProperties) {
  31289. var geometry = opt_geometryOrProperties;
  31290. this.setGeometry(geometry);
  31291. } else {
  31292. /** @type {Object.<string, *>} */
  31293. var properties = opt_geometryOrProperties;
  31294. this.setProperties(properties);
  31295. }
  31296. }
  31297. };
  31298. ol.inherits(ol.Feature, ol.Object);
  31299. /**
  31300. * Clone this feature. If the original feature has a geometry it
  31301. * is also cloned. The feature id is not set in the clone.
  31302. * @return {ol.Feature} The clone.
  31303. * @api
  31304. */
  31305. ol.Feature.prototype.clone = function() {
  31306. var clone = new ol.Feature(this.getProperties());
  31307. clone.setGeometryName(this.getGeometryName());
  31308. var geometry = this.getGeometry();
  31309. if (geometry) {
  31310. clone.setGeometry(geometry.clone());
  31311. }
  31312. var style = this.getStyle();
  31313. if (style) {
  31314. clone.setStyle(style);
  31315. }
  31316. return clone;
  31317. };
  31318. /**
  31319. * Get the feature's default geometry. A feature may have any number of named
  31320. * geometries. The "default" geometry (the one that is rendered by default) is
  31321. * set when calling {@link ol.Feature#setGeometry}.
  31322. * @return {ol.geom.Geometry|undefined} The default geometry for the feature.
  31323. * @api
  31324. * @observable
  31325. */
  31326. ol.Feature.prototype.getGeometry = function() {
  31327. return /** @type {ol.geom.Geometry|undefined} */ (
  31328. this.get(this.geometryName_));
  31329. };
  31330. /**
  31331. * Get the feature identifier. This is a stable identifier for the feature and
  31332. * is either set when reading data from a remote source or set explicitly by
  31333. * calling {@link ol.Feature#setId}.
  31334. * @return {number|string|undefined} Id.
  31335. * @api
  31336. */
  31337. ol.Feature.prototype.getId = function() {
  31338. return this.id_;
  31339. };
  31340. /**
  31341. * Get the name of the feature's default geometry. By default, the default
  31342. * geometry is named `geometry`.
  31343. * @return {string} Get the property name associated with the default geometry
  31344. * for this feature.
  31345. * @api
  31346. */
  31347. ol.Feature.prototype.getGeometryName = function() {
  31348. return this.geometryName_;
  31349. };
  31350. /**
  31351. * Get the feature's style. Will return what was provided to the
  31352. * {@link ol.Feature#setStyle} method.
  31353. * @return {ol.style.Style|Array.<ol.style.Style>|
  31354. * ol.FeatureStyleFunction|ol.StyleFunction} The feature style.
  31355. * @api
  31356. */
  31357. ol.Feature.prototype.getStyle = function() {
  31358. return this.style_;
  31359. };
  31360. /**
  31361. * Get the feature's style function.
  31362. * @return {ol.FeatureStyleFunction|undefined} Return a function
  31363. * representing the current style of this feature.
  31364. * @api
  31365. */
  31366. ol.Feature.prototype.getStyleFunction = function() {
  31367. return this.styleFunction_;
  31368. };
  31369. /**
  31370. * @private
  31371. */
  31372. ol.Feature.prototype.handleGeometryChange_ = function() {
  31373. this.changed();
  31374. };
  31375. /**
  31376. * @private
  31377. */
  31378. ol.Feature.prototype.handleGeometryChanged_ = function() {
  31379. if (this.geometryChangeKey_) {
  31380. ol.events.unlistenByKey(this.geometryChangeKey_);
  31381. this.geometryChangeKey_ = null;
  31382. }
  31383. var geometry = this.getGeometry();
  31384. if (geometry) {
  31385. this.geometryChangeKey_ = ol.events.listen(geometry,
  31386. ol.events.EventType.CHANGE, this.handleGeometryChange_, this);
  31387. }
  31388. this.changed();
  31389. };
  31390. /**
  31391. * Set the default geometry for the feature. This will update the property
  31392. * with the name returned by {@link ol.Feature#getGeometryName}.
  31393. * @param {ol.geom.Geometry|undefined} geometry The new geometry.
  31394. * @api
  31395. * @observable
  31396. */
  31397. ol.Feature.prototype.setGeometry = function(geometry) {
  31398. this.set(this.geometryName_, geometry);
  31399. };
  31400. /**
  31401. * Set the style for the feature. This can be a single style object, an array
  31402. * of styles, or a function that takes a resolution and returns an array of
  31403. * styles. If it is `null` the feature has no style (a `null` style).
  31404. * @param {ol.style.Style|Array.<ol.style.Style>|
  31405. * ol.FeatureStyleFunction|ol.StyleFunction} style Style for this feature.
  31406. * @api
  31407. * @fires ol.events.Event#event:change
  31408. */
  31409. ol.Feature.prototype.setStyle = function(style) {
  31410. this.style_ = style;
  31411. this.styleFunction_ = !style ?
  31412. undefined : ol.Feature.createStyleFunction(style);
  31413. this.changed();
  31414. };
  31415. /**
  31416. * Set the feature id. The feature id is considered stable and may be used when
  31417. * requesting features or comparing identifiers returned from a remote source.
  31418. * The feature id can be used with the {@link ol.source.Vector#getFeatureById}
  31419. * method.
  31420. * @param {number|string|undefined} id The feature id.
  31421. * @api
  31422. * @fires ol.events.Event#event:change
  31423. */
  31424. ol.Feature.prototype.setId = function(id) {
  31425. this.id_ = id;
  31426. this.changed();
  31427. };
  31428. /**
  31429. * Set the property name to be used when getting the feature's default geometry.
  31430. * When calling {@link ol.Feature#getGeometry}, the value of the property with
  31431. * this name will be returned.
  31432. * @param {string} name The property name of the default geometry.
  31433. * @api
  31434. */
  31435. ol.Feature.prototype.setGeometryName = function(name) {
  31436. ol.events.unlisten(
  31437. this, ol.Object.getChangeEventType(this.geometryName_),
  31438. this.handleGeometryChanged_, this);
  31439. this.geometryName_ = name;
  31440. ol.events.listen(
  31441. this, ol.Object.getChangeEventType(this.geometryName_),
  31442. this.handleGeometryChanged_, this);
  31443. this.handleGeometryChanged_();
  31444. };
  31445. /**
  31446. * Convert the provided object into a feature style function. Functions passed
  31447. * through unchanged. Arrays of ol.style.Style or single style objects wrapped
  31448. * in a new feature style function.
  31449. * @param {ol.FeatureStyleFunction|!Array.<ol.style.Style>|!ol.style.Style} obj
  31450. * A feature style function, a single style, or an array of styles.
  31451. * @return {ol.FeatureStyleFunction} A style function.
  31452. */
  31453. ol.Feature.createStyleFunction = function(obj) {
  31454. var styleFunction;
  31455. if (typeof obj === 'function') {
  31456. if (obj.length == 2) {
  31457. styleFunction = function(resolution) {
  31458. return /** @type {ol.StyleFunction} */ (obj)(this, resolution);
  31459. };
  31460. } else {
  31461. styleFunction = obj;
  31462. }
  31463. } else {
  31464. /**
  31465. * @type {Array.<ol.style.Style>}
  31466. */
  31467. var styles;
  31468. if (Array.isArray(obj)) {
  31469. styles = obj;
  31470. } else {
  31471. ol.asserts.assert(obj instanceof ol.style.Style,
  31472. 41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
  31473. styles = [obj];
  31474. }
  31475. styleFunction = function() {
  31476. return styles;
  31477. };
  31478. }
  31479. return styleFunction;
  31480. };
  31481. goog.provide('ol.format.FormatType');
  31482. /**
  31483. * @enum {string}
  31484. */
  31485. ol.format.FormatType = {
  31486. ARRAY_BUFFER: 'arraybuffer',
  31487. JSON: 'json',
  31488. TEXT: 'text',
  31489. XML: 'xml'
  31490. };
  31491. goog.provide('ol.xml');
  31492. goog.require('ol.array');
  31493. /**
  31494. * This document should be used when creating nodes for XML serializations. This
  31495. * document is also used by {@link ol.xml.createElementNS} and
  31496. * {@link ol.xml.setAttributeNS}
  31497. * @const
  31498. * @type {Document}
  31499. */
  31500. ol.xml.DOCUMENT = document.implementation.createDocument('', '', null);
  31501. /**
  31502. * @param {string} namespaceURI Namespace URI.
  31503. * @param {string} qualifiedName Qualified name.
  31504. * @return {Node} Node.
  31505. */
  31506. ol.xml.createElementNS = function(namespaceURI, qualifiedName) {
  31507. return ol.xml.DOCUMENT.createElementNS(namespaceURI, qualifiedName);
  31508. };
  31509. /**
  31510. * Recursively grab all text content of child nodes into a single string.
  31511. * @param {Node} node Node.
  31512. * @param {boolean} normalizeWhitespace Normalize whitespace: remove all line
  31513. * breaks.
  31514. * @return {string} All text content.
  31515. * @api
  31516. */
  31517. ol.xml.getAllTextContent = function(node, normalizeWhitespace) {
  31518. return ol.xml.getAllTextContent_(node, normalizeWhitespace, []).join('');
  31519. };
  31520. /**
  31521. * Recursively grab all text content of child nodes into a single string.
  31522. * @param {Node} node Node.
  31523. * @param {boolean} normalizeWhitespace Normalize whitespace: remove all line
  31524. * breaks.
  31525. * @param {Array.<string>} accumulator Accumulator.
  31526. * @private
  31527. * @return {Array.<string>} Accumulator.
  31528. */
  31529. ol.xml.getAllTextContent_ = function(node, normalizeWhitespace, accumulator) {
  31530. if (node.nodeType == Node.CDATA_SECTION_NODE ||
  31531. node.nodeType == Node.TEXT_NODE) {
  31532. if (normalizeWhitespace) {
  31533. accumulator.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, ''));
  31534. } else {
  31535. accumulator.push(node.nodeValue);
  31536. }
  31537. } else {
  31538. var n;
  31539. for (n = node.firstChild; n; n = n.nextSibling) {
  31540. ol.xml.getAllTextContent_(n, normalizeWhitespace, accumulator);
  31541. }
  31542. }
  31543. return accumulator;
  31544. };
  31545. /**
  31546. * @param {?} value Value.
  31547. * @return {boolean} Is document.
  31548. */
  31549. ol.xml.isDocument = function(value) {
  31550. return value instanceof Document;
  31551. };
  31552. /**
  31553. * @param {?} value Value.
  31554. * @return {boolean} Is node.
  31555. */
  31556. ol.xml.isNode = function(value) {
  31557. return value instanceof Node;
  31558. };
  31559. /**
  31560. * @param {Node} node Node.
  31561. * @param {?string} namespaceURI Namespace URI.
  31562. * @param {string} name Attribute name.
  31563. * @return {string} Value
  31564. */
  31565. ol.xml.getAttributeNS = function(node, namespaceURI, name) {
  31566. return node.getAttributeNS(namespaceURI, name) || '';
  31567. };
  31568. /**
  31569. * @param {Node} node Node.
  31570. * @param {?string} namespaceURI Namespace URI.
  31571. * @param {string} name Attribute name.
  31572. * @param {string|number} value Value.
  31573. */
  31574. ol.xml.setAttributeNS = function(node, namespaceURI, name, value) {
  31575. node.setAttributeNS(namespaceURI, name, value);
  31576. };
  31577. /**
  31578. * Parse an XML string to an XML Document.
  31579. * @param {string} xml XML.
  31580. * @return {Document} Document.
  31581. * @api
  31582. */
  31583. ol.xml.parse = function(xml) {
  31584. return new DOMParser().parseFromString(xml, 'application/xml');
  31585. };
  31586. /**
  31587. * Make an array extender function for extending the array at the top of the
  31588. * object stack.
  31589. * @param {function(this: T, Node, Array.<*>): (Array.<*>|undefined)}
  31590. * valueReader Value reader.
  31591. * @param {T=} opt_this The object to use as `this` in `valueReader`.
  31592. * @return {ol.XmlParser} Parser.
  31593. * @template T
  31594. */
  31595. ol.xml.makeArrayExtender = function(valueReader, opt_this) {
  31596. return (
  31597. /**
  31598. * @param {Node} node Node.
  31599. * @param {Array.<*>} objectStack Object stack.
  31600. */
  31601. function(node, objectStack) {
  31602. var value = valueReader.call(opt_this, node, objectStack);
  31603. if (value !== undefined) {
  31604. var array = /** @type {Array.<*>} */
  31605. (objectStack[objectStack.length - 1]);
  31606. ol.array.extend(array, value);
  31607. }
  31608. });
  31609. };
  31610. /**
  31611. * Make an array pusher function for pushing to the array at the top of the
  31612. * object stack.
  31613. * @param {function(this: T, Node, Array.<*>): *} valueReader Value reader.
  31614. * @param {T=} opt_this The object to use as `this` in `valueReader`.
  31615. * @return {ol.XmlParser} Parser.
  31616. * @template T
  31617. */
  31618. ol.xml.makeArrayPusher = function(valueReader, opt_this) {
  31619. return (
  31620. /**
  31621. * @param {Node} node Node.
  31622. * @param {Array.<*>} objectStack Object stack.
  31623. */
  31624. function(node, objectStack) {
  31625. var value = valueReader.call(opt_this !== undefined ? opt_this : this,
  31626. node, objectStack);
  31627. if (value !== undefined) {
  31628. var array = objectStack[objectStack.length - 1];
  31629. array.push(value);
  31630. }
  31631. });
  31632. };
  31633. /**
  31634. * Make an object stack replacer function for replacing the object at the
  31635. * top of the stack.
  31636. * @param {function(this: T, Node, Array.<*>): *} valueReader Value reader.
  31637. * @param {T=} opt_this The object to use as `this` in `valueReader`.
  31638. * @return {ol.XmlParser} Parser.
  31639. * @template T
  31640. */
  31641. ol.xml.makeReplacer = function(valueReader, opt_this) {
  31642. return (
  31643. /**
  31644. * @param {Node} node Node.
  31645. * @param {Array.<*>} objectStack Object stack.
  31646. */
  31647. function(node, objectStack) {
  31648. var value = valueReader.call(opt_this !== undefined ? opt_this : this,
  31649. node, objectStack);
  31650. if (value !== undefined) {
  31651. objectStack[objectStack.length - 1] = value;
  31652. }
  31653. });
  31654. };
  31655. /**
  31656. * Make an object property pusher function for adding a property to the
  31657. * object at the top of the stack.
  31658. * @param {function(this: T, Node, Array.<*>): *} valueReader Value reader.
  31659. * @param {string=} opt_property Property.
  31660. * @param {T=} opt_this The object to use as `this` in `valueReader`.
  31661. * @return {ol.XmlParser} Parser.
  31662. * @template T
  31663. */
  31664. ol.xml.makeObjectPropertyPusher = function(valueReader, opt_property, opt_this) {
  31665. return (
  31666. /**
  31667. * @param {Node} node Node.
  31668. * @param {Array.<*>} objectStack Object stack.
  31669. */
  31670. function(node, objectStack) {
  31671. var value = valueReader.call(opt_this !== undefined ? opt_this : this,
  31672. node, objectStack);
  31673. if (value !== undefined) {
  31674. var object = /** @type {Object} */
  31675. (objectStack[objectStack.length - 1]);
  31676. var property = opt_property !== undefined ?
  31677. opt_property : node.localName;
  31678. var array;
  31679. if (property in object) {
  31680. array = object[property];
  31681. } else {
  31682. array = object[property] = [];
  31683. }
  31684. array.push(value);
  31685. }
  31686. });
  31687. };
  31688. /**
  31689. * Make an object property setter function.
  31690. * @param {function(this: T, Node, Array.<*>): *} valueReader Value reader.
  31691. * @param {string=} opt_property Property.
  31692. * @param {T=} opt_this The object to use as `this` in `valueReader`.
  31693. * @return {ol.XmlParser} Parser.
  31694. * @template T
  31695. */
  31696. ol.xml.makeObjectPropertySetter = function(valueReader, opt_property, opt_this) {
  31697. return (
  31698. /**
  31699. * @param {Node} node Node.
  31700. * @param {Array.<*>} objectStack Object stack.
  31701. */
  31702. function(node, objectStack) {
  31703. var value = valueReader.call(opt_this !== undefined ? opt_this : this,
  31704. node, objectStack);
  31705. if (value !== undefined) {
  31706. var object = /** @type {Object} */
  31707. (objectStack[objectStack.length - 1]);
  31708. var property = opt_property !== undefined ?
  31709. opt_property : node.localName;
  31710. object[property] = value;
  31711. }
  31712. });
  31713. };
  31714. /**
  31715. * Create a serializer that appends nodes written by its `nodeWriter` to its
  31716. * designated parent. The parent is the `node` of the
  31717. * {@link ol.XmlNodeStackItem} at the top of the `objectStack`.
  31718. * @param {function(this: T, Node, V, Array.<*>)}
  31719. * nodeWriter Node writer.
  31720. * @param {T=} opt_this The object to use as `this` in `nodeWriter`.
  31721. * @return {ol.XmlSerializer} Serializer.
  31722. * @template T, V
  31723. */
  31724. ol.xml.makeChildAppender = function(nodeWriter, opt_this) {
  31725. return function(node, value, objectStack) {
  31726. nodeWriter.call(opt_this !== undefined ? opt_this : this,
  31727. node, value, objectStack);
  31728. var parent = objectStack[objectStack.length - 1];
  31729. var parentNode = parent.node;
  31730. parentNode.appendChild(node);
  31731. };
  31732. };
  31733. /**
  31734. * Create a serializer that calls the provided `nodeWriter` from
  31735. * {@link ol.xml.serialize}. This can be used by the parent writer to have the
  31736. * 'nodeWriter' called with an array of values when the `nodeWriter` was
  31737. * designed to serialize a single item. An example would be a LineString
  31738. * geometry writer, which could be reused for writing MultiLineString
  31739. * geometries.
  31740. * @param {function(this: T, Node, V, Array.<*>)}
  31741. * nodeWriter Node writer.
  31742. * @param {T=} opt_this The object to use as `this` in `nodeWriter`.
  31743. * @return {ol.XmlSerializer} Serializer.
  31744. * @template T, V
  31745. */
  31746. ol.xml.makeArraySerializer = function(nodeWriter, opt_this) {
  31747. var serializersNS, nodeFactory;
  31748. return function(node, value, objectStack) {
  31749. if (serializersNS === undefined) {
  31750. serializersNS = {};
  31751. var serializers = {};
  31752. serializers[node.localName] = nodeWriter;
  31753. serializersNS[node.namespaceURI] = serializers;
  31754. nodeFactory = ol.xml.makeSimpleNodeFactory(node.localName);
  31755. }
  31756. ol.xml.serialize(serializersNS, nodeFactory, value, objectStack);
  31757. };
  31758. };
  31759. /**
  31760. * Create a node factory which can use the `opt_keys` passed to
  31761. * {@link ol.xml.serialize} or {@link ol.xml.pushSerializeAndPop} as node names,
  31762. * or a fixed node name. The namespace of the created nodes can either be fixed,
  31763. * or the parent namespace will be used.
  31764. * @param {string=} opt_nodeName Fixed node name which will be used for all
  31765. * created nodes. If not provided, the 3rd argument to the resulting node
  31766. * factory needs to be provided and will be the nodeName.
  31767. * @param {string=} opt_namespaceURI Fixed namespace URI which will be used for
  31768. * all created nodes. If not provided, the namespace of the parent node will
  31769. * be used.
  31770. * @return {function(*, Array.<*>, string=): (Node|undefined)} Node factory.
  31771. */
  31772. ol.xml.makeSimpleNodeFactory = function(opt_nodeName, opt_namespaceURI) {
  31773. var fixedNodeName = opt_nodeName;
  31774. return (
  31775. /**
  31776. * @param {*} value Value.
  31777. * @param {Array.<*>} objectStack Object stack.
  31778. * @param {string=} opt_nodeName Node name.
  31779. * @return {Node} Node.
  31780. */
  31781. function(value, objectStack, opt_nodeName) {
  31782. var context = objectStack[objectStack.length - 1];
  31783. var node = context.node;
  31784. var nodeName = fixedNodeName;
  31785. if (nodeName === undefined) {
  31786. nodeName = opt_nodeName;
  31787. }
  31788. var namespaceURI = opt_namespaceURI;
  31789. if (opt_namespaceURI === undefined) {
  31790. namespaceURI = node.namespaceURI;
  31791. }
  31792. return ol.xml.createElementNS(namespaceURI, /** @type {string} */ (nodeName));
  31793. }
  31794. );
  31795. };
  31796. /**
  31797. * A node factory that creates a node using the parent's `namespaceURI` and the
  31798. * `nodeName` passed by {@link ol.xml.serialize} or
  31799. * {@link ol.xml.pushSerializeAndPop} to the node factory.
  31800. * @const
  31801. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  31802. */
  31803. ol.xml.OBJECT_PROPERTY_NODE_FACTORY = ol.xml.makeSimpleNodeFactory();
  31804. /**
  31805. * Create an array of `values` to be used with {@link ol.xml.serialize} or
  31806. * {@link ol.xml.pushSerializeAndPop}, where `orderedKeys` has to be provided as
  31807. * `opt_key` argument.
  31808. * @param {Object.<string, V>} object Key-value pairs for the sequence. Keys can
  31809. * be a subset of the `orderedKeys`.
  31810. * @param {Array.<string>} orderedKeys Keys in the order of the sequence.
  31811. * @return {Array.<V>} Values in the order of the sequence. The resulting array
  31812. * has the same length as the `orderedKeys` array. Values that are not
  31813. * present in `object` will be `undefined` in the resulting array.
  31814. * @template V
  31815. */
  31816. ol.xml.makeSequence = function(object, orderedKeys) {
  31817. var length = orderedKeys.length;
  31818. var sequence = new Array(length);
  31819. for (var i = 0; i < length; ++i) {
  31820. sequence[i] = object[orderedKeys[i]];
  31821. }
  31822. return sequence;
  31823. };
  31824. /**
  31825. * Create a namespaced structure, using the same values for each namespace.
  31826. * This can be used as a starting point for versioned parsers, when only a few
  31827. * values are version specific.
  31828. * @param {Array.<string>} namespaceURIs Namespace URIs.
  31829. * @param {T} structure Structure.
  31830. * @param {Object.<string, T>=} opt_structureNS Namespaced structure to add to.
  31831. * @return {Object.<string, T>} Namespaced structure.
  31832. * @template T
  31833. */
  31834. ol.xml.makeStructureNS = function(namespaceURIs, structure, opt_structureNS) {
  31835. /**
  31836. * @type {Object.<string, *>}
  31837. */
  31838. var structureNS = opt_structureNS !== undefined ? opt_structureNS : {};
  31839. var i, ii;
  31840. for (i = 0, ii = namespaceURIs.length; i < ii; ++i) {
  31841. structureNS[namespaceURIs[i]] = structure;
  31842. }
  31843. return structureNS;
  31844. };
  31845. /**
  31846. * Parse a node using the parsers and object stack.
  31847. * @param {Object.<string, Object.<string, ol.XmlParser>>} parsersNS
  31848. * Parsers by namespace.
  31849. * @param {Node} node Node.
  31850. * @param {Array.<*>} objectStack Object stack.
  31851. * @param {*=} opt_this The object to use as `this`.
  31852. */
  31853. ol.xml.parseNode = function(parsersNS, node, objectStack, opt_this) {
  31854. var n;
  31855. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  31856. var parsers = parsersNS[n.namespaceURI];
  31857. if (parsers !== undefined) {
  31858. var parser = parsers[n.localName];
  31859. if (parser !== undefined) {
  31860. parser.call(opt_this, n, objectStack);
  31861. }
  31862. }
  31863. }
  31864. };
  31865. /**
  31866. * Push an object on top of the stack, parse and return the popped object.
  31867. * @param {T} object Object.
  31868. * @param {Object.<string, Object.<string, ol.XmlParser>>} parsersNS
  31869. * Parsers by namespace.
  31870. * @param {Node} node Node.
  31871. * @param {Array.<*>} objectStack Object stack.
  31872. * @param {*=} opt_this The object to use as `this`.
  31873. * @return {T} Object.
  31874. * @template T
  31875. */
  31876. ol.xml.pushParseAndPop = function(
  31877. object, parsersNS, node, objectStack, opt_this) {
  31878. objectStack.push(object);
  31879. ol.xml.parseNode(parsersNS, node, objectStack, opt_this);
  31880. return objectStack.pop();
  31881. };
  31882. /**
  31883. * Walk through an array of `values` and call a serializer for each value.
  31884. * @param {Object.<string, Object.<string, ol.XmlSerializer>>} serializersNS
  31885. * Namespaced serializers.
  31886. * @param {function(this: T, *, Array.<*>, (string|undefined)): (Node|undefined)} nodeFactory
  31887. * Node factory. The `nodeFactory` creates the node whose namespace and name
  31888. * will be used to choose a node writer from `serializersNS`. This
  31889. * separation allows us to decide what kind of node to create, depending on
  31890. * the value we want to serialize. An example for this would be different
  31891. * geometry writers based on the geometry type.
  31892. * @param {Array.<*>} values Values to serialize. An example would be an array
  31893. * of {@link ol.Feature} instances.
  31894. * @param {Array.<*>} objectStack Node stack.
  31895. * @param {Array.<string>=} opt_keys Keys of the `values`. Will be passed to the
  31896. * `nodeFactory`. This is used for serializing object literals where the
  31897. * node name relates to the property key. The array length of `opt_keys` has
  31898. * to match the length of `values`. For serializing a sequence, `opt_keys`
  31899. * determines the order of the sequence.
  31900. * @param {T=} opt_this The object to use as `this` for the node factory and
  31901. * serializers.
  31902. * @template T
  31903. */
  31904. ol.xml.serialize = function(
  31905. serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this) {
  31906. var length = (opt_keys !== undefined ? opt_keys : values).length;
  31907. var value, node;
  31908. for (var i = 0; i < length; ++i) {
  31909. value = values[i];
  31910. if (value !== undefined) {
  31911. node = nodeFactory.call(opt_this, value, objectStack,
  31912. opt_keys !== undefined ? opt_keys[i] : undefined);
  31913. if (node !== undefined) {
  31914. serializersNS[node.namespaceURI][node.localName]
  31915. .call(opt_this, node, value, objectStack);
  31916. }
  31917. }
  31918. }
  31919. };
  31920. /**
  31921. * @param {O} object Object.
  31922. * @param {Object.<string, Object.<string, ol.XmlSerializer>>} serializersNS
  31923. * Namespaced serializers.
  31924. * @param {function(this: T, *, Array.<*>, (string|undefined)): (Node|undefined)} nodeFactory
  31925. * Node factory. The `nodeFactory` creates the node whose namespace and name
  31926. * will be used to choose a node writer from `serializersNS`. This
  31927. * separation allows us to decide what kind of node to create, depending on
  31928. * the value we want to serialize. An example for this would be different
  31929. * geometry writers based on the geometry type.
  31930. * @param {Array.<*>} values Values to serialize. An example would be an array
  31931. * of {@link ol.Feature} instances.
  31932. * @param {Array.<*>} objectStack Node stack.
  31933. * @param {Array.<string>=} opt_keys Keys of the `values`. Will be passed to the
  31934. * `nodeFactory`. This is used for serializing object literals where the
  31935. * node name relates to the property key. The array length of `opt_keys` has
  31936. * to match the length of `values`. For serializing a sequence, `opt_keys`
  31937. * determines the order of the sequence.
  31938. * @param {T=} opt_this The object to use as `this` for the node factory and
  31939. * serializers.
  31940. * @return {O|undefined} Object.
  31941. * @template O, T
  31942. */
  31943. ol.xml.pushSerializeAndPop = function(object,
  31944. serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this) {
  31945. objectStack.push(object);
  31946. ol.xml.serialize(
  31947. serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this);
  31948. return objectStack.pop();
  31949. };
  31950. goog.provide('ol.featureloader');
  31951. goog.require('ol');
  31952. goog.require('ol.format.FormatType');
  31953. goog.require('ol.xml');
  31954. /**
  31955. * @param {string|ol.FeatureUrlFunction} url Feature URL service.
  31956. * @param {ol.format.Feature} format Feature format.
  31957. * @param {function(this:ol.VectorTile, Array.<ol.Feature>, ol.proj.Projection, ol.Extent)|function(this:ol.source.Vector, Array.<ol.Feature>)} success
  31958. * Function called with the loaded features and optionally with the data
  31959. * projection. Called with the vector tile or source as `this`.
  31960. * @param {function(this:ol.VectorTile)|function(this:ol.source.Vector)} failure
  31961. * Function called when loading failed. Called with the vector tile or
  31962. * source as `this`.
  31963. * @return {ol.FeatureLoader} The feature loader.
  31964. */
  31965. ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
  31966. return (
  31967. /**
  31968. * @param {ol.Extent} extent Extent.
  31969. * @param {number} resolution Resolution.
  31970. * @param {ol.proj.Projection} projection Projection.
  31971. * @this {ol.source.Vector|ol.VectorTile}
  31972. */
  31973. function(extent, resolution, projection) {
  31974. var xhr = new XMLHttpRequest();
  31975. xhr.open('GET',
  31976. typeof url === 'function' ? url(extent, resolution, projection) : url,
  31977. true);
  31978. if (format.getType() == ol.format.FormatType.ARRAY_BUFFER) {
  31979. xhr.responseType = 'arraybuffer';
  31980. }
  31981. /**
  31982. * @param {Event} event Event.
  31983. * @private
  31984. */
  31985. xhr.onload = function(event) {
  31986. // status will be 0 for file:// urls
  31987. if (!xhr.status || xhr.status >= 200 && xhr.status < 300) {
  31988. var type = format.getType();
  31989. /** @type {Document|Node|Object|string|undefined} */
  31990. var source;
  31991. if (type == ol.format.FormatType.JSON ||
  31992. type == ol.format.FormatType.TEXT) {
  31993. source = xhr.responseText;
  31994. } else if (type == ol.format.FormatType.XML) {
  31995. source = xhr.responseXML;
  31996. if (!source) {
  31997. source = ol.xml.parse(xhr.responseText);
  31998. }
  31999. } else if (type == ol.format.FormatType.ARRAY_BUFFER) {
  32000. source = /** @type {ArrayBuffer} */ (xhr.response);
  32001. }
  32002. if (source) {
  32003. success.call(this, format.readFeatures(source,
  32004. {featureProjection: projection}),
  32005. format.readProjection(source), format.getLastExtent());
  32006. } else {
  32007. failure.call(this);
  32008. }
  32009. } else {
  32010. failure.call(this);
  32011. }
  32012. }.bind(this);
  32013. /**
  32014. * @private
  32015. */
  32016. xhr.onerror = function() {
  32017. failure.call(this);
  32018. }.bind(this);
  32019. xhr.send();
  32020. });
  32021. };
  32022. /**
  32023. * Create an XHR feature loader for a `url` and `format`. The feature loader
  32024. * loads features (with XHR), parses the features, and adds them to the
  32025. * vector source.
  32026. * @param {string|ol.FeatureUrlFunction} url Feature URL service.
  32027. * @param {ol.format.Feature} format Feature format.
  32028. * @return {ol.FeatureLoader} The feature loader.
  32029. * @api
  32030. */
  32031. ol.featureloader.xhr = function(url, format) {
  32032. return ol.featureloader.loadFeaturesXhr(url, format,
  32033. /**
  32034. * @param {Array.<ol.Feature>} features The loaded features.
  32035. * @param {ol.proj.Projection} dataProjection Data projection.
  32036. * @this {ol.source.Vector}
  32037. */
  32038. function(features, dataProjection) {
  32039. this.addFeatures(features);
  32040. }, /* FIXME handle error */ ol.nullFunction);
  32041. };
  32042. goog.provide('ol.format.Feature');
  32043. goog.require('ol.geom.Geometry');
  32044. goog.require('ol.obj');
  32045. goog.require('ol.proj');
  32046. /**
  32047. * @classdesc
  32048. * Abstract base class; normally only used for creating subclasses and not
  32049. * instantiated in apps.
  32050. * Base class for feature formats.
  32051. * {ol.format.Feature} subclasses provide the ability to decode and encode
  32052. * {@link ol.Feature} objects from a variety of commonly used geospatial
  32053. * file formats. See the documentation for each format for more details.
  32054. *
  32055. * @constructor
  32056. * @abstract
  32057. * @api
  32058. */
  32059. ol.format.Feature = function() {
  32060. /**
  32061. * @protected
  32062. * @type {ol.proj.Projection}
  32063. */
  32064. this.defaultDataProjection = null;
  32065. /**
  32066. * @protected
  32067. * @type {ol.proj.Projection}
  32068. */
  32069. this.defaultFeatureProjection = null;
  32070. };
  32071. /**
  32072. * Adds the data projection to the read options.
  32073. * @param {Document|Node|Object|string} source Source.
  32074. * @param {olx.format.ReadOptions=} opt_options Options.
  32075. * @return {olx.format.ReadOptions|undefined} Options.
  32076. * @protected
  32077. */
  32078. ol.format.Feature.prototype.getReadOptions = function(source, opt_options) {
  32079. var options;
  32080. if (opt_options) {
  32081. options = {
  32082. dataProjection: opt_options.dataProjection ?
  32083. opt_options.dataProjection : this.readProjection(source),
  32084. featureProjection: opt_options.featureProjection
  32085. };
  32086. }
  32087. return this.adaptOptions(options);
  32088. };
  32089. /**
  32090. * Sets the `defaultDataProjection` on the options, if no `dataProjection`
  32091. * is set.
  32092. * @param {olx.format.WriteOptions|olx.format.ReadOptions|undefined} options
  32093. * Options.
  32094. * @protected
  32095. * @return {olx.format.WriteOptions|olx.format.ReadOptions|undefined}
  32096. * Updated options.
  32097. */
  32098. ol.format.Feature.prototype.adaptOptions = function(options) {
  32099. return ol.obj.assign({
  32100. dataProjection: this.defaultDataProjection,
  32101. featureProjection: this.defaultFeatureProjection
  32102. }, options);
  32103. };
  32104. /**
  32105. * Get the extent from the source of the last {@link readFeatures} call.
  32106. * @return {ol.Extent} Tile extent.
  32107. */
  32108. ol.format.Feature.prototype.getLastExtent = function() {
  32109. return null;
  32110. };
  32111. /**
  32112. * @abstract
  32113. * @return {ol.format.FormatType} Format.
  32114. */
  32115. ol.format.Feature.prototype.getType = function() {};
  32116. /**
  32117. * Read a single feature from a source.
  32118. *
  32119. * @abstract
  32120. * @param {Document|Node|Object|string} source Source.
  32121. * @param {olx.format.ReadOptions=} opt_options Read options.
  32122. * @return {ol.Feature} Feature.
  32123. */
  32124. ol.format.Feature.prototype.readFeature = function(source, opt_options) {};
  32125. /**
  32126. * Read all features from a source.
  32127. *
  32128. * @abstract
  32129. * @param {Document|Node|ArrayBuffer|Object|string} source Source.
  32130. * @param {olx.format.ReadOptions=} opt_options Read options.
  32131. * @return {Array.<ol.Feature>} Features.
  32132. */
  32133. ol.format.Feature.prototype.readFeatures = function(source, opt_options) {};
  32134. /**
  32135. * Read a single geometry from a source.
  32136. *
  32137. * @abstract
  32138. * @param {Document|Node|Object|string} source Source.
  32139. * @param {olx.format.ReadOptions=} opt_options Read options.
  32140. * @return {ol.geom.Geometry} Geometry.
  32141. */
  32142. ol.format.Feature.prototype.readGeometry = function(source, opt_options) {};
  32143. /**
  32144. * Read the projection from a source.
  32145. *
  32146. * @abstract
  32147. * @param {Document|Node|Object|string} source Source.
  32148. * @return {ol.proj.Projection} Projection.
  32149. */
  32150. ol.format.Feature.prototype.readProjection = function(source) {};
  32151. /**
  32152. * Encode a feature in this format.
  32153. *
  32154. * @abstract
  32155. * @param {ol.Feature} feature Feature.
  32156. * @param {olx.format.WriteOptions=} opt_options Write options.
  32157. * @return {string} Result.
  32158. */
  32159. ol.format.Feature.prototype.writeFeature = function(feature, opt_options) {};
  32160. /**
  32161. * Encode an array of features in this format.
  32162. *
  32163. * @abstract
  32164. * @param {Array.<ol.Feature>} features Features.
  32165. * @param {olx.format.WriteOptions=} opt_options Write options.
  32166. * @return {string} Result.
  32167. */
  32168. ol.format.Feature.prototype.writeFeatures = function(features, opt_options) {};
  32169. /**
  32170. * Write a single geometry in this format.
  32171. *
  32172. * @abstract
  32173. * @param {ol.geom.Geometry} geometry Geometry.
  32174. * @param {olx.format.WriteOptions=} opt_options Write options.
  32175. * @return {string} Result.
  32176. */
  32177. ol.format.Feature.prototype.writeGeometry = function(geometry, opt_options) {};
  32178. /**
  32179. * @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
  32180. * @param {boolean} write Set to true for writing, false for reading.
  32181. * @param {(olx.format.WriteOptions|olx.format.ReadOptions)=} opt_options
  32182. * Options.
  32183. * @return {ol.geom.Geometry|ol.Extent} Transformed geometry.
  32184. * @protected
  32185. */
  32186. ol.format.Feature.transformWithOptions = function(
  32187. geometry, write, opt_options) {
  32188. var featureProjection = opt_options ?
  32189. ol.proj.get(opt_options.featureProjection) : null;
  32190. var dataProjection = opt_options ?
  32191. ol.proj.get(opt_options.dataProjection) : null;
  32192. /**
  32193. * @type {ol.geom.Geometry|ol.Extent}
  32194. */
  32195. var transformed;
  32196. if (featureProjection && dataProjection &&
  32197. !ol.proj.equivalent(featureProjection, dataProjection)) {
  32198. if (geometry instanceof ol.geom.Geometry) {
  32199. transformed = (write ? geometry.clone() : geometry).transform(
  32200. write ? featureProjection : dataProjection,
  32201. write ? dataProjection : featureProjection);
  32202. } else {
  32203. // FIXME this is necessary because ol.format.GML treats extents
  32204. // as geometries
  32205. transformed = ol.proj.transformExtent(
  32206. geometry,
  32207. dataProjection,
  32208. featureProjection);
  32209. }
  32210. } else {
  32211. transformed = geometry;
  32212. }
  32213. if (write && opt_options && opt_options.decimals !== undefined) {
  32214. var power = Math.pow(10, opt_options.decimals);
  32215. // if decimals option on write, round each coordinate appropriately
  32216. /**
  32217. * @param {Array.<number>} coordinates Coordinates.
  32218. * @return {Array.<number>} Transformed coordinates.
  32219. */
  32220. var transform = function(coordinates) {
  32221. for (var i = 0, ii = coordinates.length; i < ii; ++i) {
  32222. coordinates[i] = Math.round(coordinates[i] * power) / power;
  32223. }
  32224. return coordinates;
  32225. };
  32226. if (transformed === geometry) {
  32227. transformed = transformed.clone();
  32228. }
  32229. transformed.applyTransform(transform);
  32230. }
  32231. return transformed;
  32232. };
  32233. goog.provide('ol.format.JSONFeature');
  32234. goog.require('ol');
  32235. goog.require('ol.format.Feature');
  32236. goog.require('ol.format.FormatType');
  32237. /**
  32238. * @classdesc
  32239. * Abstract base class; normally only used for creating subclasses and not
  32240. * instantiated in apps.
  32241. * Base class for JSON feature formats.
  32242. *
  32243. * @constructor
  32244. * @abstract
  32245. * @extends {ol.format.Feature}
  32246. */
  32247. ol.format.JSONFeature = function() {
  32248. ol.format.Feature.call(this);
  32249. };
  32250. ol.inherits(ol.format.JSONFeature, ol.format.Feature);
  32251. /**
  32252. * @param {Document|Node|Object|string} source Source.
  32253. * @private
  32254. * @return {Object} Object.
  32255. */
  32256. ol.format.JSONFeature.prototype.getObject_ = function(source) {
  32257. if (typeof source === 'string') {
  32258. var object = JSON.parse(source);
  32259. return object ? /** @type {Object} */ (object) : null;
  32260. } else if (source !== null) {
  32261. return source;
  32262. } else {
  32263. return null;
  32264. }
  32265. };
  32266. /**
  32267. * @inheritDoc
  32268. */
  32269. ol.format.JSONFeature.prototype.getType = function() {
  32270. return ol.format.FormatType.JSON;
  32271. };
  32272. /**
  32273. * @inheritDoc
  32274. */
  32275. ol.format.JSONFeature.prototype.readFeature = function(source, opt_options) {
  32276. return this.readFeatureFromObject(
  32277. this.getObject_(source), this.getReadOptions(source, opt_options));
  32278. };
  32279. /**
  32280. * @inheritDoc
  32281. */
  32282. ol.format.JSONFeature.prototype.readFeatures = function(source, opt_options) {
  32283. return this.readFeaturesFromObject(
  32284. this.getObject_(source), this.getReadOptions(source, opt_options));
  32285. };
  32286. /**
  32287. * @abstract
  32288. * @param {Object} object Object.
  32289. * @param {olx.format.ReadOptions=} opt_options Read options.
  32290. * @protected
  32291. * @return {ol.Feature} Feature.
  32292. */
  32293. ol.format.JSONFeature.prototype.readFeatureFromObject = function(object, opt_options) {};
  32294. /**
  32295. * @abstract
  32296. * @param {Object} object Object.
  32297. * @param {olx.format.ReadOptions=} opt_options Read options.
  32298. * @protected
  32299. * @return {Array.<ol.Feature>} Features.
  32300. */
  32301. ol.format.JSONFeature.prototype.readFeaturesFromObject = function(object, opt_options) {};
  32302. /**
  32303. * @inheritDoc
  32304. */
  32305. ol.format.JSONFeature.prototype.readGeometry = function(source, opt_options) {
  32306. return this.readGeometryFromObject(
  32307. this.getObject_(source), this.getReadOptions(source, opt_options));
  32308. };
  32309. /**
  32310. * @abstract
  32311. * @param {Object} object Object.
  32312. * @param {olx.format.ReadOptions=} opt_options Read options.
  32313. * @protected
  32314. * @return {ol.geom.Geometry} Geometry.
  32315. */
  32316. ol.format.JSONFeature.prototype.readGeometryFromObject = function(object, opt_options) {};
  32317. /**
  32318. * @inheritDoc
  32319. */
  32320. ol.format.JSONFeature.prototype.readProjection = function(source) {
  32321. return this.readProjectionFromObject(this.getObject_(source));
  32322. };
  32323. /**
  32324. * @abstract
  32325. * @param {Object} object Object.
  32326. * @protected
  32327. * @return {ol.proj.Projection} Projection.
  32328. */
  32329. ol.format.JSONFeature.prototype.readProjectionFromObject = function(object) {};
  32330. /**
  32331. * @inheritDoc
  32332. */
  32333. ol.format.JSONFeature.prototype.writeFeature = function(feature, opt_options) {
  32334. return JSON.stringify(this.writeFeatureObject(feature, opt_options));
  32335. };
  32336. /**
  32337. * @abstract
  32338. * @param {ol.Feature} feature Feature.
  32339. * @param {olx.format.WriteOptions=} opt_options Write options.
  32340. * @return {Object} Object.
  32341. */
  32342. ol.format.JSONFeature.prototype.writeFeatureObject = function(feature, opt_options) {};
  32343. /**
  32344. * @inheritDoc
  32345. */
  32346. ol.format.JSONFeature.prototype.writeFeatures = function(features, opt_options) {
  32347. return JSON.stringify(this.writeFeaturesObject(features, opt_options));
  32348. };
  32349. /**
  32350. * @abstract
  32351. * @param {Array.<ol.Feature>} features Features.
  32352. * @param {olx.format.WriteOptions=} opt_options Write options.
  32353. * @return {Object} Object.
  32354. */
  32355. ol.format.JSONFeature.prototype.writeFeaturesObject = function(features, opt_options) {};
  32356. /**
  32357. * @inheritDoc
  32358. */
  32359. ol.format.JSONFeature.prototype.writeGeometry = function(geometry, opt_options) {
  32360. return JSON.stringify(this.writeGeometryObject(geometry, opt_options));
  32361. };
  32362. /**
  32363. * @abstract
  32364. * @param {ol.geom.Geometry} geometry Geometry.
  32365. * @param {olx.format.WriteOptions=} opt_options Write options.
  32366. * @return {Object} Object.
  32367. */
  32368. ol.format.JSONFeature.prototype.writeGeometryObject = function(geometry, opt_options) {};
  32369. goog.provide('ol.geom.flat.interpolate');
  32370. goog.require('ol.array');
  32371. goog.require('ol.math');
  32372. /**
  32373. * @param {Array.<number>} flatCoordinates Flat coordinates.
  32374. * @param {number} offset Offset.
  32375. * @param {number} end End.
  32376. * @param {number} stride Stride.
  32377. * @param {number} fraction Fraction.
  32378. * @param {Array.<number>=} opt_dest Destination.
  32379. * @return {Array.<number>} Destination.
  32380. */
  32381. ol.geom.flat.interpolate.lineString = function(flatCoordinates, offset, end, stride, fraction, opt_dest) {
  32382. var pointX = NaN;
  32383. var pointY = NaN;
  32384. var n = (end - offset) / stride;
  32385. if (n === 1) {
  32386. pointX = flatCoordinates[offset];
  32387. pointY = flatCoordinates[offset + 1];
  32388. } else if (n == 2) {
  32389. pointX = (1 - fraction) * flatCoordinates[offset] +
  32390. fraction * flatCoordinates[offset + stride];
  32391. pointY = (1 - fraction) * flatCoordinates[offset + 1] +
  32392. fraction * flatCoordinates[offset + stride + 1];
  32393. } else if (n !== 0) {
  32394. var x1 = flatCoordinates[offset];
  32395. var y1 = flatCoordinates[offset + 1];
  32396. var length = 0;
  32397. var cumulativeLengths = [0];
  32398. var i;
  32399. for (i = offset + stride; i < end; i += stride) {
  32400. var x2 = flatCoordinates[i];
  32401. var y2 = flatCoordinates[i + 1];
  32402. length += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  32403. cumulativeLengths.push(length);
  32404. x1 = x2;
  32405. y1 = y2;
  32406. }
  32407. var target = fraction * length;
  32408. var index = ol.array.binarySearch(cumulativeLengths, target);
  32409. if (index < 0) {
  32410. var t = (target - cumulativeLengths[-index - 2]) /
  32411. (cumulativeLengths[-index - 1] - cumulativeLengths[-index - 2]);
  32412. var o = offset + (-index - 2) * stride;
  32413. pointX = ol.math.lerp(
  32414. flatCoordinates[o], flatCoordinates[o + stride], t);
  32415. pointY = ol.math.lerp(
  32416. flatCoordinates[o + 1], flatCoordinates[o + stride + 1], t);
  32417. } else {
  32418. pointX = flatCoordinates[offset + index * stride];
  32419. pointY = flatCoordinates[offset + index * stride + 1];
  32420. }
  32421. }
  32422. if (opt_dest) {
  32423. opt_dest[0] = pointX;
  32424. opt_dest[1] = pointY;
  32425. return opt_dest;
  32426. } else {
  32427. return [pointX, pointY];
  32428. }
  32429. };
  32430. /**
  32431. * @param {Array.<number>} flatCoordinates Flat coordinates.
  32432. * @param {number} offset Offset.
  32433. * @param {number} end End.
  32434. * @param {number} stride Stride.
  32435. * @param {number} m M.
  32436. * @param {boolean} extrapolate Extrapolate.
  32437. * @return {ol.Coordinate} Coordinate.
  32438. */
  32439. ol.geom.flat.interpolate.lineStringCoordinateAtM = function(flatCoordinates, offset, end, stride, m, extrapolate) {
  32440. if (end == offset) {
  32441. return null;
  32442. }
  32443. var coordinate;
  32444. if (m < flatCoordinates[offset + stride - 1]) {
  32445. if (extrapolate) {
  32446. coordinate = flatCoordinates.slice(offset, offset + stride);
  32447. coordinate[stride - 1] = m;
  32448. return coordinate;
  32449. } else {
  32450. return null;
  32451. }
  32452. } else if (flatCoordinates[end - 1] < m) {
  32453. if (extrapolate) {
  32454. coordinate = flatCoordinates.slice(end - stride, end);
  32455. coordinate[stride - 1] = m;
  32456. return coordinate;
  32457. } else {
  32458. return null;
  32459. }
  32460. }
  32461. // FIXME use O(1) search
  32462. if (m == flatCoordinates[offset + stride - 1]) {
  32463. return flatCoordinates.slice(offset, offset + stride);
  32464. }
  32465. var lo = offset / stride;
  32466. var hi = end / stride;
  32467. while (lo < hi) {
  32468. var mid = (lo + hi) >> 1;
  32469. if (m < flatCoordinates[(mid + 1) * stride - 1]) {
  32470. hi = mid;
  32471. } else {
  32472. lo = mid + 1;
  32473. }
  32474. }
  32475. var m0 = flatCoordinates[lo * stride - 1];
  32476. if (m == m0) {
  32477. return flatCoordinates.slice((lo - 1) * stride, (lo - 1) * stride + stride);
  32478. }
  32479. var m1 = flatCoordinates[(lo + 1) * stride - 1];
  32480. var t = (m - m0) / (m1 - m0);
  32481. coordinate = [];
  32482. var i;
  32483. for (i = 0; i < stride - 1; ++i) {
  32484. coordinate.push(ol.math.lerp(flatCoordinates[(lo - 1) * stride + i],
  32485. flatCoordinates[lo * stride + i], t));
  32486. }
  32487. coordinate.push(m);
  32488. return coordinate;
  32489. };
  32490. /**
  32491. * @param {Array.<number>} flatCoordinates Flat coordinates.
  32492. * @param {number} offset Offset.
  32493. * @param {Array.<number>} ends Ends.
  32494. * @param {number} stride Stride.
  32495. * @param {number} m M.
  32496. * @param {boolean} extrapolate Extrapolate.
  32497. * @param {boolean} interpolate Interpolate.
  32498. * @return {ol.Coordinate} Coordinate.
  32499. */
  32500. ol.geom.flat.interpolate.lineStringsCoordinateAtM = function(
  32501. flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
  32502. if (interpolate) {
  32503. return ol.geom.flat.interpolate.lineStringCoordinateAtM(
  32504. flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
  32505. }
  32506. var coordinate;
  32507. if (m < flatCoordinates[stride - 1]) {
  32508. if (extrapolate) {
  32509. coordinate = flatCoordinates.slice(0, stride);
  32510. coordinate[stride - 1] = m;
  32511. return coordinate;
  32512. } else {
  32513. return null;
  32514. }
  32515. }
  32516. if (flatCoordinates[flatCoordinates.length - 1] < m) {
  32517. if (extrapolate) {
  32518. coordinate = flatCoordinates.slice(flatCoordinates.length - stride);
  32519. coordinate[stride - 1] = m;
  32520. return coordinate;
  32521. } else {
  32522. return null;
  32523. }
  32524. }
  32525. var i, ii;
  32526. for (i = 0, ii = ends.length; i < ii; ++i) {
  32527. var end = ends[i];
  32528. if (offset == end) {
  32529. continue;
  32530. }
  32531. if (m < flatCoordinates[offset + stride - 1]) {
  32532. return null;
  32533. } else if (m <= flatCoordinates[end - 1]) {
  32534. return ol.geom.flat.interpolate.lineStringCoordinateAtM(
  32535. flatCoordinates, offset, end, stride, m, false);
  32536. }
  32537. offset = end;
  32538. }
  32539. return null;
  32540. };
  32541. goog.provide('ol.geom.LineString');
  32542. goog.require('ol');
  32543. goog.require('ol.array');
  32544. goog.require('ol.extent');
  32545. goog.require('ol.geom.GeometryLayout');
  32546. goog.require('ol.geom.GeometryType');
  32547. goog.require('ol.geom.SimpleGeometry');
  32548. goog.require('ol.geom.flat.closest');
  32549. goog.require('ol.geom.flat.deflate');
  32550. goog.require('ol.geom.flat.inflate');
  32551. goog.require('ol.geom.flat.interpolate');
  32552. goog.require('ol.geom.flat.intersectsextent');
  32553. goog.require('ol.geom.flat.length');
  32554. goog.require('ol.geom.flat.segments');
  32555. goog.require('ol.geom.flat.simplify');
  32556. /**
  32557. * @classdesc
  32558. * Linestring geometry.
  32559. *
  32560. * @constructor
  32561. * @extends {ol.geom.SimpleGeometry}
  32562. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  32563. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  32564. * @api
  32565. */
  32566. ol.geom.LineString = function(coordinates, opt_layout) {
  32567. ol.geom.SimpleGeometry.call(this);
  32568. /**
  32569. * @private
  32570. * @type {ol.Coordinate}
  32571. */
  32572. this.flatMidpoint_ = null;
  32573. /**
  32574. * @private
  32575. * @type {number}
  32576. */
  32577. this.flatMidpointRevision_ = -1;
  32578. /**
  32579. * @private
  32580. * @type {number}
  32581. */
  32582. this.maxDelta_ = -1;
  32583. /**
  32584. * @private
  32585. * @type {number}
  32586. */
  32587. this.maxDeltaRevision_ = -1;
  32588. this.setCoordinates(coordinates, opt_layout);
  32589. };
  32590. ol.inherits(ol.geom.LineString, ol.geom.SimpleGeometry);
  32591. /**
  32592. * Append the passed coordinate to the coordinates of the linestring.
  32593. * @param {ol.Coordinate} coordinate Coordinate.
  32594. * @api
  32595. */
  32596. ol.geom.LineString.prototype.appendCoordinate = function(coordinate) {
  32597. if (!this.flatCoordinates) {
  32598. this.flatCoordinates = coordinate.slice();
  32599. } else {
  32600. ol.array.extend(this.flatCoordinates, coordinate);
  32601. }
  32602. this.changed();
  32603. };
  32604. /**
  32605. * Make a complete copy of the geometry.
  32606. * @return {!ol.geom.LineString} Clone.
  32607. * @override
  32608. * @api
  32609. */
  32610. ol.geom.LineString.prototype.clone = function() {
  32611. var lineString = new ol.geom.LineString(null);
  32612. lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
  32613. return lineString;
  32614. };
  32615. /**
  32616. * @inheritDoc
  32617. */
  32618. ol.geom.LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  32619. if (minSquaredDistance <
  32620. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  32621. return minSquaredDistance;
  32622. }
  32623. if (this.maxDeltaRevision_ != this.getRevision()) {
  32624. this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getMaxSquaredDelta(
  32625. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
  32626. this.maxDeltaRevision_ = this.getRevision();
  32627. }
  32628. return ol.geom.flat.closest.getClosestPoint(
  32629. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  32630. this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
  32631. };
  32632. /**
  32633. * Iterate over each segment, calling the provided callback.
  32634. * If the callback returns a truthy value the function returns that
  32635. * value immediately. Otherwise the function returns `false`.
  32636. *
  32637. * @param {function(this: S, ol.Coordinate, ol.Coordinate): T} callback Function
  32638. * called for each segment.
  32639. * @param {S=} opt_this The object to be used as the value of 'this'
  32640. * within callback.
  32641. * @return {T|boolean} Value.
  32642. * @template T,S
  32643. * @api
  32644. */
  32645. ol.geom.LineString.prototype.forEachSegment = function(callback, opt_this) {
  32646. return ol.geom.flat.segments.forEach(this.flatCoordinates, 0,
  32647. this.flatCoordinates.length, this.stride, callback, opt_this);
  32648. };
  32649. /**
  32650. * Returns the coordinate at `m` using linear interpolation, or `null` if no
  32651. * such coordinate exists.
  32652. *
  32653. * `opt_extrapolate` controls extrapolation beyond the range of Ms in the
  32654. * MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
  32655. * M will return the first coordinate and Ms greater than the last M will
  32656. * return the last coordinate.
  32657. *
  32658. * @param {number} m M.
  32659. * @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
  32660. * @return {ol.Coordinate} Coordinate.
  32661. * @api
  32662. */
  32663. ol.geom.LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) {
  32664. if (this.layout != ol.geom.GeometryLayout.XYM &&
  32665. this.layout != ol.geom.GeometryLayout.XYZM) {
  32666. return null;
  32667. }
  32668. var extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
  32669. return ol.geom.flat.interpolate.lineStringCoordinateAtM(this.flatCoordinates, 0,
  32670. this.flatCoordinates.length, this.stride, m, extrapolate);
  32671. };
  32672. /**
  32673. * Return the coordinates of the linestring.
  32674. * @return {Array.<ol.Coordinate>} Coordinates.
  32675. * @override
  32676. * @api
  32677. */
  32678. ol.geom.LineString.prototype.getCoordinates = function() {
  32679. return ol.geom.flat.inflate.coordinates(
  32680. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
  32681. };
  32682. /**
  32683. * Return the coordinate at the provided fraction along the linestring.
  32684. * The `fraction` is a number between 0 and 1, where 0 is the start of the
  32685. * linestring and 1 is the end.
  32686. * @param {number} fraction Fraction.
  32687. * @param {ol.Coordinate=} opt_dest Optional coordinate whose values will
  32688. * be modified. If not provided, a new coordinate will be returned.
  32689. * @return {ol.Coordinate} Coordinate of the interpolated point.
  32690. * @api
  32691. */
  32692. ol.geom.LineString.prototype.getCoordinateAt = function(fraction, opt_dest) {
  32693. return ol.geom.flat.interpolate.lineString(
  32694. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  32695. fraction, opt_dest);
  32696. };
  32697. /**
  32698. * Return the length of the linestring on projected plane.
  32699. * @return {number} Length (on projected plane).
  32700. * @api
  32701. */
  32702. ol.geom.LineString.prototype.getLength = function() {
  32703. return ol.geom.flat.length.lineString(
  32704. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
  32705. };
  32706. /**
  32707. * @return {Array.<number>} Flat midpoint.
  32708. */
  32709. ol.geom.LineString.prototype.getFlatMidpoint = function() {
  32710. if (this.flatMidpointRevision_ != this.getRevision()) {
  32711. this.flatMidpoint_ = this.getCoordinateAt(0.5, this.flatMidpoint_);
  32712. this.flatMidpointRevision_ = this.getRevision();
  32713. }
  32714. return this.flatMidpoint_;
  32715. };
  32716. /**
  32717. * @inheritDoc
  32718. */
  32719. ol.geom.LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
  32720. var simplifiedFlatCoordinates = [];
  32721. simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker(
  32722. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  32723. squaredTolerance, simplifiedFlatCoordinates, 0);
  32724. var simplifiedLineString = new ol.geom.LineString(null);
  32725. simplifiedLineString.setFlatCoordinates(
  32726. ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates);
  32727. return simplifiedLineString;
  32728. };
  32729. /**
  32730. * @inheritDoc
  32731. * @api
  32732. */
  32733. ol.geom.LineString.prototype.getType = function() {
  32734. return ol.geom.GeometryType.LINE_STRING;
  32735. };
  32736. /**
  32737. * @inheritDoc
  32738. * @api
  32739. */
  32740. ol.geom.LineString.prototype.intersectsExtent = function(extent) {
  32741. return ol.geom.flat.intersectsextent.lineString(
  32742. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
  32743. extent);
  32744. };
  32745. /**
  32746. * Set the coordinates of the linestring.
  32747. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  32748. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  32749. * @override
  32750. * @api
  32751. */
  32752. ol.geom.LineString.prototype.setCoordinates = function(coordinates, opt_layout) {
  32753. if (!coordinates) {
  32754. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null);
  32755. } else {
  32756. this.setLayout(opt_layout, coordinates, 1);
  32757. if (!this.flatCoordinates) {
  32758. this.flatCoordinates = [];
  32759. }
  32760. this.flatCoordinates.length = ol.geom.flat.deflate.coordinates(
  32761. this.flatCoordinates, 0, coordinates, this.stride);
  32762. this.changed();
  32763. }
  32764. };
  32765. /**
  32766. * @param {ol.geom.GeometryLayout} layout Layout.
  32767. * @param {Array.<number>} flatCoordinates Flat coordinates.
  32768. */
  32769. ol.geom.LineString.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
  32770. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  32771. this.changed();
  32772. };
  32773. goog.provide('ol.geom.MultiLineString');
  32774. goog.require('ol');
  32775. goog.require('ol.array');
  32776. goog.require('ol.extent');
  32777. goog.require('ol.geom.GeometryLayout');
  32778. goog.require('ol.geom.GeometryType');
  32779. goog.require('ol.geom.LineString');
  32780. goog.require('ol.geom.SimpleGeometry');
  32781. goog.require('ol.geom.flat.closest');
  32782. goog.require('ol.geom.flat.deflate');
  32783. goog.require('ol.geom.flat.inflate');
  32784. goog.require('ol.geom.flat.interpolate');
  32785. goog.require('ol.geom.flat.intersectsextent');
  32786. goog.require('ol.geom.flat.simplify');
  32787. /**
  32788. * @classdesc
  32789. * Multi-linestring geometry.
  32790. *
  32791. * @constructor
  32792. * @extends {ol.geom.SimpleGeometry}
  32793. * @param {Array.<Array.<ol.Coordinate>>} coordinates Coordinates.
  32794. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  32795. * @api
  32796. */
  32797. ol.geom.MultiLineString = function(coordinates, opt_layout) {
  32798. ol.geom.SimpleGeometry.call(this);
  32799. /**
  32800. * @type {Array.<number>}
  32801. * @private
  32802. */
  32803. this.ends_ = [];
  32804. /**
  32805. * @private
  32806. * @type {number}
  32807. */
  32808. this.maxDelta_ = -1;
  32809. /**
  32810. * @private
  32811. * @type {number}
  32812. */
  32813. this.maxDeltaRevision_ = -1;
  32814. this.setCoordinates(coordinates, opt_layout);
  32815. };
  32816. ol.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
  32817. /**
  32818. * Append the passed linestring to the multilinestring.
  32819. * @param {ol.geom.LineString} lineString LineString.
  32820. * @api
  32821. */
  32822. ol.geom.MultiLineString.prototype.appendLineString = function(lineString) {
  32823. if (!this.flatCoordinates) {
  32824. this.flatCoordinates = lineString.getFlatCoordinates().slice();
  32825. } else {
  32826. ol.array.extend(
  32827. this.flatCoordinates, lineString.getFlatCoordinates().slice());
  32828. }
  32829. this.ends_.push(this.flatCoordinates.length);
  32830. this.changed();
  32831. };
  32832. /**
  32833. * Make a complete copy of the geometry.
  32834. * @return {!ol.geom.MultiLineString} Clone.
  32835. * @override
  32836. * @api
  32837. */
  32838. ol.geom.MultiLineString.prototype.clone = function() {
  32839. var multiLineString = new ol.geom.MultiLineString(null);
  32840. multiLineString.setFlatCoordinates(
  32841. this.layout, this.flatCoordinates.slice(), this.ends_.slice());
  32842. return multiLineString;
  32843. };
  32844. /**
  32845. * @inheritDoc
  32846. */
  32847. ol.geom.MultiLineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  32848. if (minSquaredDistance <
  32849. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  32850. return minSquaredDistance;
  32851. }
  32852. if (this.maxDeltaRevision_ != this.getRevision()) {
  32853. this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getsMaxSquaredDelta(
  32854. this.flatCoordinates, 0, this.ends_, this.stride, 0));
  32855. this.maxDeltaRevision_ = this.getRevision();
  32856. }
  32857. return ol.geom.flat.closest.getsClosestPoint(
  32858. this.flatCoordinates, 0, this.ends_, this.stride,
  32859. this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
  32860. };
  32861. /**
  32862. * Returns the coordinate at `m` using linear interpolation, or `null` if no
  32863. * such coordinate exists.
  32864. *
  32865. * `opt_extrapolate` controls extrapolation beyond the range of Ms in the
  32866. * MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
  32867. * M will return the first coordinate and Ms greater than the last M will
  32868. * return the last coordinate.
  32869. *
  32870. * `opt_interpolate` controls interpolation between consecutive LineStrings
  32871. * within the MultiLineString. If `opt_interpolate` is `true` the coordinates
  32872. * will be linearly interpolated between the last coordinate of one LineString
  32873. * and the first coordinate of the next LineString. If `opt_interpolate` is
  32874. * `false` then the function will return `null` for Ms falling between
  32875. * LineStrings.
  32876. *
  32877. * @param {number} m M.
  32878. * @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
  32879. * @param {boolean=} opt_interpolate Interpolate. Default is `false`.
  32880. * @return {ol.Coordinate} Coordinate.
  32881. * @api
  32882. */
  32883. ol.geom.MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_interpolate) {
  32884. if ((this.layout != ol.geom.GeometryLayout.XYM &&
  32885. this.layout != ol.geom.GeometryLayout.XYZM) ||
  32886. this.flatCoordinates.length === 0) {
  32887. return null;
  32888. }
  32889. var extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
  32890. var interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
  32891. return ol.geom.flat.interpolate.lineStringsCoordinateAtM(this.flatCoordinates, 0,
  32892. this.ends_, this.stride, m, extrapolate, interpolate);
  32893. };
  32894. /**
  32895. * Return the coordinates of the multilinestring.
  32896. * @return {Array.<Array.<ol.Coordinate>>} Coordinates.
  32897. * @override
  32898. * @api
  32899. */
  32900. ol.geom.MultiLineString.prototype.getCoordinates = function() {
  32901. return ol.geom.flat.inflate.coordinatess(
  32902. this.flatCoordinates, 0, this.ends_, this.stride);
  32903. };
  32904. /**
  32905. * @return {Array.<number>} Ends.
  32906. */
  32907. ol.geom.MultiLineString.prototype.getEnds = function() {
  32908. return this.ends_;
  32909. };
  32910. /**
  32911. * Return the linestring at the specified index.
  32912. * @param {number} index Index.
  32913. * @return {ol.geom.LineString} LineString.
  32914. * @api
  32915. */
  32916. ol.geom.MultiLineString.prototype.getLineString = function(index) {
  32917. if (index < 0 || this.ends_.length <= index) {
  32918. return null;
  32919. }
  32920. var lineString = new ol.geom.LineString(null);
  32921. lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
  32922. index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
  32923. return lineString;
  32924. };
  32925. /**
  32926. * Return the linestrings of this multilinestring.
  32927. * @return {Array.<ol.geom.LineString>} LineStrings.
  32928. * @api
  32929. */
  32930. ol.geom.MultiLineString.prototype.getLineStrings = function() {
  32931. var flatCoordinates = this.flatCoordinates;
  32932. var ends = this.ends_;
  32933. var layout = this.layout;
  32934. /** @type {Array.<ol.geom.LineString>} */
  32935. var lineStrings = [];
  32936. var offset = 0;
  32937. var i, ii;
  32938. for (i = 0, ii = ends.length; i < ii; ++i) {
  32939. var end = ends[i];
  32940. var lineString = new ol.geom.LineString(null);
  32941. lineString.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
  32942. lineStrings.push(lineString);
  32943. offset = end;
  32944. }
  32945. return lineStrings;
  32946. };
  32947. /**
  32948. * @return {Array.<number>} Flat midpoints.
  32949. */
  32950. ol.geom.MultiLineString.prototype.getFlatMidpoints = function() {
  32951. var midpoints = [];
  32952. var flatCoordinates = this.flatCoordinates;
  32953. var offset = 0;
  32954. var ends = this.ends_;
  32955. var stride = this.stride;
  32956. var i, ii;
  32957. for (i = 0, ii = ends.length; i < ii; ++i) {
  32958. var end = ends[i];
  32959. var midpoint = ol.geom.flat.interpolate.lineString(
  32960. flatCoordinates, offset, end, stride, 0.5);
  32961. ol.array.extend(midpoints, midpoint);
  32962. offset = end;
  32963. }
  32964. return midpoints;
  32965. };
  32966. /**
  32967. * @inheritDoc
  32968. */
  32969. ol.geom.MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
  32970. var simplifiedFlatCoordinates = [];
  32971. var simplifiedEnds = [];
  32972. simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeuckers(
  32973. this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
  32974. simplifiedFlatCoordinates, 0, simplifiedEnds);
  32975. var simplifiedMultiLineString = new ol.geom.MultiLineString(null);
  32976. simplifiedMultiLineString.setFlatCoordinates(
  32977. ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEnds);
  32978. return simplifiedMultiLineString;
  32979. };
  32980. /**
  32981. * @inheritDoc
  32982. * @api
  32983. */
  32984. ol.geom.MultiLineString.prototype.getType = function() {
  32985. return ol.geom.GeometryType.MULTI_LINE_STRING;
  32986. };
  32987. /**
  32988. * @inheritDoc
  32989. * @api
  32990. */
  32991. ol.geom.MultiLineString.prototype.intersectsExtent = function(extent) {
  32992. return ol.geom.flat.intersectsextent.lineStrings(
  32993. this.flatCoordinates, 0, this.ends_, this.stride, extent);
  32994. };
  32995. /**
  32996. * Set the coordinates of the multilinestring.
  32997. * @param {Array.<Array.<ol.Coordinate>>} coordinates Coordinates.
  32998. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  32999. * @override
  33000. * @api
  33001. */
  33002. ol.geom.MultiLineString.prototype.setCoordinates = function(coordinates, opt_layout) {
  33003. if (!coordinates) {
  33004. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null, this.ends_);
  33005. } else {
  33006. this.setLayout(opt_layout, coordinates, 2);
  33007. if (!this.flatCoordinates) {
  33008. this.flatCoordinates = [];
  33009. }
  33010. var ends = ol.geom.flat.deflate.coordinatess(
  33011. this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
  33012. this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
  33013. this.changed();
  33014. }
  33015. };
  33016. /**
  33017. * @param {ol.geom.GeometryLayout} layout Layout.
  33018. * @param {Array.<number>} flatCoordinates Flat coordinates.
  33019. * @param {Array.<number>} ends Ends.
  33020. */
  33021. ol.geom.MultiLineString.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
  33022. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  33023. this.ends_ = ends;
  33024. this.changed();
  33025. };
  33026. /**
  33027. * @param {Array.<ol.geom.LineString>} lineStrings LineStrings.
  33028. */
  33029. ol.geom.MultiLineString.prototype.setLineStrings = function(lineStrings) {
  33030. var layout = this.getLayout();
  33031. var flatCoordinates = [];
  33032. var ends = [];
  33033. var i, ii;
  33034. for (i = 0, ii = lineStrings.length; i < ii; ++i) {
  33035. var lineString = lineStrings[i];
  33036. if (i === 0) {
  33037. layout = lineString.getLayout();
  33038. }
  33039. ol.array.extend(flatCoordinates, lineString.getFlatCoordinates());
  33040. ends.push(flatCoordinates.length);
  33041. }
  33042. this.setFlatCoordinates(layout, flatCoordinates, ends);
  33043. };
  33044. goog.provide('ol.geom.MultiPoint');
  33045. goog.require('ol');
  33046. goog.require('ol.array');
  33047. goog.require('ol.extent');
  33048. goog.require('ol.geom.GeometryLayout');
  33049. goog.require('ol.geom.GeometryType');
  33050. goog.require('ol.geom.Point');
  33051. goog.require('ol.geom.SimpleGeometry');
  33052. goog.require('ol.geom.flat.deflate');
  33053. goog.require('ol.geom.flat.inflate');
  33054. goog.require('ol.math');
  33055. /**
  33056. * @classdesc
  33057. * Multi-point geometry.
  33058. *
  33059. * @constructor
  33060. * @extends {ol.geom.SimpleGeometry}
  33061. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  33062. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  33063. * @api
  33064. */
  33065. ol.geom.MultiPoint = function(coordinates, opt_layout) {
  33066. ol.geom.SimpleGeometry.call(this);
  33067. this.setCoordinates(coordinates, opt_layout);
  33068. };
  33069. ol.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry);
  33070. /**
  33071. * Append the passed point to this multipoint.
  33072. * @param {ol.geom.Point} point Point.
  33073. * @api
  33074. */
  33075. ol.geom.MultiPoint.prototype.appendPoint = function(point) {
  33076. if (!this.flatCoordinates) {
  33077. this.flatCoordinates = point.getFlatCoordinates().slice();
  33078. } else {
  33079. ol.array.extend(this.flatCoordinates, point.getFlatCoordinates());
  33080. }
  33081. this.changed();
  33082. };
  33083. /**
  33084. * Make a complete copy of the geometry.
  33085. * @return {!ol.geom.MultiPoint} Clone.
  33086. * @override
  33087. * @api
  33088. */
  33089. ol.geom.MultiPoint.prototype.clone = function() {
  33090. var multiPoint = new ol.geom.MultiPoint(null);
  33091. multiPoint.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
  33092. return multiPoint;
  33093. };
  33094. /**
  33095. * @inheritDoc
  33096. */
  33097. ol.geom.MultiPoint.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  33098. if (minSquaredDistance <
  33099. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  33100. return minSquaredDistance;
  33101. }
  33102. var flatCoordinates = this.flatCoordinates;
  33103. var stride = this.stride;
  33104. var i, ii, j;
  33105. for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
  33106. var squaredDistance = ol.math.squaredDistance(
  33107. x, y, flatCoordinates[i], flatCoordinates[i + 1]);
  33108. if (squaredDistance < minSquaredDistance) {
  33109. minSquaredDistance = squaredDistance;
  33110. for (j = 0; j < stride; ++j) {
  33111. closestPoint[j] = flatCoordinates[i + j];
  33112. }
  33113. closestPoint.length = stride;
  33114. }
  33115. }
  33116. return minSquaredDistance;
  33117. };
  33118. /**
  33119. * Return the coordinates of the multipoint.
  33120. * @return {Array.<ol.Coordinate>} Coordinates.
  33121. * @override
  33122. * @api
  33123. */
  33124. ol.geom.MultiPoint.prototype.getCoordinates = function() {
  33125. return ol.geom.flat.inflate.coordinates(
  33126. this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
  33127. };
  33128. /**
  33129. * Return the point at the specified index.
  33130. * @param {number} index Index.
  33131. * @return {ol.geom.Point} Point.
  33132. * @api
  33133. */
  33134. ol.geom.MultiPoint.prototype.getPoint = function(index) {
  33135. var n = !this.flatCoordinates ?
  33136. 0 : this.flatCoordinates.length / this.stride;
  33137. if (index < 0 || n <= index) {
  33138. return null;
  33139. }
  33140. var point = new ol.geom.Point(null);
  33141. point.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
  33142. index * this.stride, (index + 1) * this.stride));
  33143. return point;
  33144. };
  33145. /**
  33146. * Return the points of this multipoint.
  33147. * @return {Array.<ol.geom.Point>} Points.
  33148. * @api
  33149. */
  33150. ol.geom.MultiPoint.prototype.getPoints = function() {
  33151. var flatCoordinates = this.flatCoordinates;
  33152. var layout = this.layout;
  33153. var stride = this.stride;
  33154. /** @type {Array.<ol.geom.Point>} */
  33155. var points = [];
  33156. var i, ii;
  33157. for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
  33158. var point = new ol.geom.Point(null);
  33159. point.setFlatCoordinates(layout, flatCoordinates.slice(i, i + stride));
  33160. points.push(point);
  33161. }
  33162. return points;
  33163. };
  33164. /**
  33165. * @inheritDoc
  33166. * @api
  33167. */
  33168. ol.geom.MultiPoint.prototype.getType = function() {
  33169. return ol.geom.GeometryType.MULTI_POINT;
  33170. };
  33171. /**
  33172. * @inheritDoc
  33173. * @api
  33174. */
  33175. ol.geom.MultiPoint.prototype.intersectsExtent = function(extent) {
  33176. var flatCoordinates = this.flatCoordinates;
  33177. var stride = this.stride;
  33178. var i, ii, x, y;
  33179. for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
  33180. x = flatCoordinates[i];
  33181. y = flatCoordinates[i + 1];
  33182. if (ol.extent.containsXY(extent, x, y)) {
  33183. return true;
  33184. }
  33185. }
  33186. return false;
  33187. };
  33188. /**
  33189. * Set the coordinates of the multipoint.
  33190. * @param {Array.<ol.Coordinate>} coordinates Coordinates.
  33191. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  33192. * @override
  33193. * @api
  33194. */
  33195. ol.geom.MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) {
  33196. if (!coordinates) {
  33197. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null);
  33198. } else {
  33199. this.setLayout(opt_layout, coordinates, 1);
  33200. if (!this.flatCoordinates) {
  33201. this.flatCoordinates = [];
  33202. }
  33203. this.flatCoordinates.length = ol.geom.flat.deflate.coordinates(
  33204. this.flatCoordinates, 0, coordinates, this.stride);
  33205. this.changed();
  33206. }
  33207. };
  33208. /**
  33209. * @param {ol.geom.GeometryLayout} layout Layout.
  33210. * @param {Array.<number>} flatCoordinates Flat coordinates.
  33211. */
  33212. ol.geom.MultiPoint.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
  33213. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  33214. this.changed();
  33215. };
  33216. goog.provide('ol.geom.flat.center');
  33217. goog.require('ol.extent');
  33218. /**
  33219. * @param {Array.<number>} flatCoordinates Flat coordinates.
  33220. * @param {number} offset Offset.
  33221. * @param {Array.<Array.<number>>} endss Endss.
  33222. * @param {number} stride Stride.
  33223. * @return {Array.<number>} Flat centers.
  33224. */
  33225. ol.geom.flat.center.linearRingss = function(flatCoordinates, offset, endss, stride) {
  33226. var flatCenters = [];
  33227. var i, ii;
  33228. var extent = ol.extent.createEmpty();
  33229. for (i = 0, ii = endss.length; i < ii; ++i) {
  33230. var ends = endss[i];
  33231. extent = ol.extent.createOrUpdateFromFlatCoordinates(
  33232. flatCoordinates, offset, ends[0], stride);
  33233. flatCenters.push((extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2);
  33234. offset = ends[ends.length - 1];
  33235. }
  33236. return flatCenters;
  33237. };
  33238. goog.provide('ol.geom.MultiPolygon');
  33239. goog.require('ol');
  33240. goog.require('ol.array');
  33241. goog.require('ol.extent');
  33242. goog.require('ol.geom.GeometryLayout');
  33243. goog.require('ol.geom.GeometryType');
  33244. goog.require('ol.geom.MultiPoint');
  33245. goog.require('ol.geom.Polygon');
  33246. goog.require('ol.geom.SimpleGeometry');
  33247. goog.require('ol.geom.flat.area');
  33248. goog.require('ol.geom.flat.center');
  33249. goog.require('ol.geom.flat.closest');
  33250. goog.require('ol.geom.flat.contains');
  33251. goog.require('ol.geom.flat.deflate');
  33252. goog.require('ol.geom.flat.inflate');
  33253. goog.require('ol.geom.flat.interiorpoint');
  33254. goog.require('ol.geom.flat.intersectsextent');
  33255. goog.require('ol.geom.flat.orient');
  33256. goog.require('ol.geom.flat.simplify');
  33257. /**
  33258. * @classdesc
  33259. * Multi-polygon geometry.
  33260. *
  33261. * @constructor
  33262. * @extends {ol.geom.SimpleGeometry}
  33263. * @param {Array.<Array.<Array.<ol.Coordinate>>>} coordinates Coordinates.
  33264. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  33265. * @api
  33266. */
  33267. ol.geom.MultiPolygon = function(coordinates, opt_layout) {
  33268. ol.geom.SimpleGeometry.call(this);
  33269. /**
  33270. * @type {Array.<Array.<number>>}
  33271. * @private
  33272. */
  33273. this.endss_ = [];
  33274. /**
  33275. * @private
  33276. * @type {number}
  33277. */
  33278. this.flatInteriorPointsRevision_ = -1;
  33279. /**
  33280. * @private
  33281. * @type {Array.<number>}
  33282. */
  33283. this.flatInteriorPoints_ = null;
  33284. /**
  33285. * @private
  33286. * @type {number}
  33287. */
  33288. this.maxDelta_ = -1;
  33289. /**
  33290. * @private
  33291. * @type {number}
  33292. */
  33293. this.maxDeltaRevision_ = -1;
  33294. /**
  33295. * @private
  33296. * @type {number}
  33297. */
  33298. this.orientedRevision_ = -1;
  33299. /**
  33300. * @private
  33301. * @type {Array.<number>}
  33302. */
  33303. this.orientedFlatCoordinates_ = null;
  33304. this.setCoordinates(coordinates, opt_layout);
  33305. };
  33306. ol.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry);
  33307. /**
  33308. * Append the passed polygon to this multipolygon.
  33309. * @param {ol.geom.Polygon} polygon Polygon.
  33310. * @api
  33311. */
  33312. ol.geom.MultiPolygon.prototype.appendPolygon = function(polygon) {
  33313. /** @type {Array.<number>} */
  33314. var ends;
  33315. if (!this.flatCoordinates) {
  33316. this.flatCoordinates = polygon.getFlatCoordinates().slice();
  33317. ends = polygon.getEnds().slice();
  33318. this.endss_.push();
  33319. } else {
  33320. var offset = this.flatCoordinates.length;
  33321. ol.array.extend(this.flatCoordinates, polygon.getFlatCoordinates());
  33322. ends = polygon.getEnds().slice();
  33323. var i, ii;
  33324. for (i = 0, ii = ends.length; i < ii; ++i) {
  33325. ends[i] += offset;
  33326. }
  33327. }
  33328. this.endss_.push(ends);
  33329. this.changed();
  33330. };
  33331. /**
  33332. * Make a complete copy of the geometry.
  33333. * @return {!ol.geom.MultiPolygon} Clone.
  33334. * @override
  33335. * @api
  33336. */
  33337. ol.geom.MultiPolygon.prototype.clone = function() {
  33338. var multiPolygon = new ol.geom.MultiPolygon(null);
  33339. var len = this.endss_.length;
  33340. var newEndss = new Array(len);
  33341. for (var i = 0; i < len; ++i) {
  33342. newEndss[i] = this.endss_[i].slice();
  33343. }
  33344. multiPolygon.setFlatCoordinates(
  33345. this.layout, this.flatCoordinates.slice(), newEndss);
  33346. return multiPolygon;
  33347. };
  33348. /**
  33349. * @inheritDoc
  33350. */
  33351. ol.geom.MultiPolygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  33352. if (minSquaredDistance <
  33353. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  33354. return minSquaredDistance;
  33355. }
  33356. if (this.maxDeltaRevision_ != this.getRevision()) {
  33357. this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getssMaxSquaredDelta(
  33358. this.flatCoordinates, 0, this.endss_, this.stride, 0));
  33359. this.maxDeltaRevision_ = this.getRevision();
  33360. }
  33361. return ol.geom.flat.closest.getssClosestPoint(
  33362. this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
  33363. this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
  33364. };
  33365. /**
  33366. * @inheritDoc
  33367. */
  33368. ol.geom.MultiPolygon.prototype.containsXY = function(x, y) {
  33369. return ol.geom.flat.contains.linearRingssContainsXY(
  33370. this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
  33371. };
  33372. /**
  33373. * Return the area of the multipolygon on projected plane.
  33374. * @return {number} Area (on projected plane).
  33375. * @api
  33376. */
  33377. ol.geom.MultiPolygon.prototype.getArea = function() {
  33378. return ol.geom.flat.area.linearRingss(
  33379. this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
  33380. };
  33381. /**
  33382. * Get the coordinate array for this geometry. This array has the structure
  33383. * of a GeoJSON coordinate array for multi-polygons.
  33384. *
  33385. * @param {boolean=} opt_right Orient coordinates according to the right-hand
  33386. * rule (counter-clockwise for exterior and clockwise for interior rings).
  33387. * If `false`, coordinates will be oriented according to the left-hand rule
  33388. * (clockwise for exterior and counter-clockwise for interior rings).
  33389. * By default, coordinate orientation will depend on how the geometry was
  33390. * constructed.
  33391. * @return {Array.<Array.<Array.<ol.Coordinate>>>} Coordinates.
  33392. * @override
  33393. * @api
  33394. */
  33395. ol.geom.MultiPolygon.prototype.getCoordinates = function(opt_right) {
  33396. var flatCoordinates;
  33397. if (opt_right !== undefined) {
  33398. flatCoordinates = this.getOrientedFlatCoordinates().slice();
  33399. ol.geom.flat.orient.orientLinearRingss(
  33400. flatCoordinates, 0, this.endss_, this.stride, opt_right);
  33401. } else {
  33402. flatCoordinates = this.flatCoordinates;
  33403. }
  33404. return ol.geom.flat.inflate.coordinatesss(
  33405. flatCoordinates, 0, this.endss_, this.stride);
  33406. };
  33407. /**
  33408. * @return {Array.<Array.<number>>} Endss.
  33409. */
  33410. ol.geom.MultiPolygon.prototype.getEndss = function() {
  33411. return this.endss_;
  33412. };
  33413. /**
  33414. * @return {Array.<number>} Flat interior points.
  33415. */
  33416. ol.geom.MultiPolygon.prototype.getFlatInteriorPoints = function() {
  33417. if (this.flatInteriorPointsRevision_ != this.getRevision()) {
  33418. var flatCenters = ol.geom.flat.center.linearRingss(
  33419. this.flatCoordinates, 0, this.endss_, this.stride);
  33420. this.flatInteriorPoints_ = ol.geom.flat.interiorpoint.linearRingss(
  33421. this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
  33422. flatCenters);
  33423. this.flatInteriorPointsRevision_ = this.getRevision();
  33424. }
  33425. return this.flatInteriorPoints_;
  33426. };
  33427. /**
  33428. * Return the interior points as {@link ol.geom.MultiPoint multipoint}.
  33429. * @return {ol.geom.MultiPoint} Interior points as XYM coordinates, where M is
  33430. * the length of the horizontal intersection that the point belongs to.
  33431. * @api
  33432. */
  33433. ol.geom.MultiPolygon.prototype.getInteriorPoints = function() {
  33434. var interiorPoints = new ol.geom.MultiPoint(null);
  33435. interiorPoints.setFlatCoordinates(ol.geom.GeometryLayout.XYM,
  33436. this.getFlatInteriorPoints().slice());
  33437. return interiorPoints;
  33438. };
  33439. /**
  33440. * @return {Array.<number>} Oriented flat coordinates.
  33441. */
  33442. ol.geom.MultiPolygon.prototype.getOrientedFlatCoordinates = function() {
  33443. if (this.orientedRevision_ != this.getRevision()) {
  33444. var flatCoordinates = this.flatCoordinates;
  33445. if (ol.geom.flat.orient.linearRingssAreOriented(
  33446. flatCoordinates, 0, this.endss_, this.stride)) {
  33447. this.orientedFlatCoordinates_ = flatCoordinates;
  33448. } else {
  33449. this.orientedFlatCoordinates_ = flatCoordinates.slice();
  33450. this.orientedFlatCoordinates_.length =
  33451. ol.geom.flat.orient.orientLinearRingss(
  33452. this.orientedFlatCoordinates_, 0, this.endss_, this.stride);
  33453. }
  33454. this.orientedRevision_ = this.getRevision();
  33455. }
  33456. return this.orientedFlatCoordinates_;
  33457. };
  33458. /**
  33459. * @inheritDoc
  33460. */
  33461. ol.geom.MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
  33462. var simplifiedFlatCoordinates = [];
  33463. var simplifiedEndss = [];
  33464. simplifiedFlatCoordinates.length = ol.geom.flat.simplify.quantizess(
  33465. this.flatCoordinates, 0, this.endss_, this.stride,
  33466. Math.sqrt(squaredTolerance),
  33467. simplifiedFlatCoordinates, 0, simplifiedEndss);
  33468. var simplifiedMultiPolygon = new ol.geom.MultiPolygon(null);
  33469. simplifiedMultiPolygon.setFlatCoordinates(
  33470. ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEndss);
  33471. return simplifiedMultiPolygon;
  33472. };
  33473. /**
  33474. * Return the polygon at the specified index.
  33475. * @param {number} index Index.
  33476. * @return {ol.geom.Polygon} Polygon.
  33477. * @api
  33478. */
  33479. ol.geom.MultiPolygon.prototype.getPolygon = function(index) {
  33480. if (index < 0 || this.endss_.length <= index) {
  33481. return null;
  33482. }
  33483. var offset;
  33484. if (index === 0) {
  33485. offset = 0;
  33486. } else {
  33487. var prevEnds = this.endss_[index - 1];
  33488. offset = prevEnds[prevEnds.length - 1];
  33489. }
  33490. var ends = this.endss_[index].slice();
  33491. var end = ends[ends.length - 1];
  33492. if (offset !== 0) {
  33493. var i, ii;
  33494. for (i = 0, ii = ends.length; i < ii; ++i) {
  33495. ends[i] -= offset;
  33496. }
  33497. }
  33498. var polygon = new ol.geom.Polygon(null);
  33499. polygon.setFlatCoordinates(
  33500. this.layout, this.flatCoordinates.slice(offset, end), ends);
  33501. return polygon;
  33502. };
  33503. /**
  33504. * Return the polygons of this multipolygon.
  33505. * @return {Array.<ol.geom.Polygon>} Polygons.
  33506. * @api
  33507. */
  33508. ol.geom.MultiPolygon.prototype.getPolygons = function() {
  33509. var layout = this.layout;
  33510. var flatCoordinates = this.flatCoordinates;
  33511. var endss = this.endss_;
  33512. var polygons = [];
  33513. var offset = 0;
  33514. var i, ii, j, jj;
  33515. for (i = 0, ii = endss.length; i < ii; ++i) {
  33516. var ends = endss[i].slice();
  33517. var end = ends[ends.length - 1];
  33518. if (offset !== 0) {
  33519. for (j = 0, jj = ends.length; j < jj; ++j) {
  33520. ends[j] -= offset;
  33521. }
  33522. }
  33523. var polygon = new ol.geom.Polygon(null);
  33524. polygon.setFlatCoordinates(
  33525. layout, flatCoordinates.slice(offset, end), ends);
  33526. polygons.push(polygon);
  33527. offset = end;
  33528. }
  33529. return polygons;
  33530. };
  33531. /**
  33532. * @inheritDoc
  33533. * @api
  33534. */
  33535. ol.geom.MultiPolygon.prototype.getType = function() {
  33536. return ol.geom.GeometryType.MULTI_POLYGON;
  33537. };
  33538. /**
  33539. * @inheritDoc
  33540. * @api
  33541. */
  33542. ol.geom.MultiPolygon.prototype.intersectsExtent = function(extent) {
  33543. return ol.geom.flat.intersectsextent.linearRingss(
  33544. this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, extent);
  33545. };
  33546. /**
  33547. * Set the coordinates of the multipolygon.
  33548. * @param {Array.<Array.<Array.<ol.Coordinate>>>} coordinates Coordinates.
  33549. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  33550. * @override
  33551. * @api
  33552. */
  33553. ol.geom.MultiPolygon.prototype.setCoordinates = function(coordinates, opt_layout) {
  33554. if (!coordinates) {
  33555. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null, this.endss_);
  33556. } else {
  33557. this.setLayout(opt_layout, coordinates, 3);
  33558. if (!this.flatCoordinates) {
  33559. this.flatCoordinates = [];
  33560. }
  33561. var endss = ol.geom.flat.deflate.coordinatesss(
  33562. this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
  33563. if (endss.length === 0) {
  33564. this.flatCoordinates.length = 0;
  33565. } else {
  33566. var lastEnds = endss[endss.length - 1];
  33567. this.flatCoordinates.length = lastEnds.length === 0 ?
  33568. 0 : lastEnds[lastEnds.length - 1];
  33569. }
  33570. this.changed();
  33571. }
  33572. };
  33573. /**
  33574. * @param {ol.geom.GeometryLayout} layout Layout.
  33575. * @param {Array.<number>} flatCoordinates Flat coordinates.
  33576. * @param {Array.<Array.<number>>} endss Endss.
  33577. */
  33578. ol.geom.MultiPolygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, endss) {
  33579. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  33580. this.endss_ = endss;
  33581. this.changed();
  33582. };
  33583. /**
  33584. * @param {Array.<ol.geom.Polygon>} polygons Polygons.
  33585. */
  33586. ol.geom.MultiPolygon.prototype.setPolygons = function(polygons) {
  33587. var layout = this.getLayout();
  33588. var flatCoordinates = [];
  33589. var endss = [];
  33590. var i, ii, ends;
  33591. for (i = 0, ii = polygons.length; i < ii; ++i) {
  33592. var polygon = polygons[i];
  33593. if (i === 0) {
  33594. layout = polygon.getLayout();
  33595. }
  33596. var offset = flatCoordinates.length;
  33597. ends = polygon.getEnds();
  33598. var j, jj;
  33599. for (j = 0, jj = ends.length; j < jj; ++j) {
  33600. ends[j] += offset;
  33601. }
  33602. ol.array.extend(flatCoordinates, polygon.getFlatCoordinates());
  33603. endss.push(ends);
  33604. }
  33605. this.setFlatCoordinates(layout, flatCoordinates, endss);
  33606. };
  33607. goog.provide('ol.format.EsriJSON');
  33608. goog.require('ol');
  33609. goog.require('ol.Feature');
  33610. goog.require('ol.asserts');
  33611. goog.require('ol.extent');
  33612. goog.require('ol.format.Feature');
  33613. goog.require('ol.format.JSONFeature');
  33614. goog.require('ol.geom.GeometryLayout');
  33615. goog.require('ol.geom.GeometryType');
  33616. goog.require('ol.geom.LineString');
  33617. goog.require('ol.geom.LinearRing');
  33618. goog.require('ol.geom.MultiLineString');
  33619. goog.require('ol.geom.MultiPoint');
  33620. goog.require('ol.geom.MultiPolygon');
  33621. goog.require('ol.geom.Point');
  33622. goog.require('ol.geom.Polygon');
  33623. goog.require('ol.geom.flat.deflate');
  33624. goog.require('ol.geom.flat.orient');
  33625. goog.require('ol.obj');
  33626. goog.require('ol.proj');
  33627. /**
  33628. * @classdesc
  33629. * Feature format for reading and writing data in the EsriJSON format.
  33630. *
  33631. * @constructor
  33632. * @extends {ol.format.JSONFeature}
  33633. * @param {olx.format.EsriJSONOptions=} opt_options Options.
  33634. * @api
  33635. */
  33636. ol.format.EsriJSON = function(opt_options) {
  33637. var options = opt_options ? opt_options : {};
  33638. ol.format.JSONFeature.call(this);
  33639. /**
  33640. * Name of the geometry attribute for features.
  33641. * @type {string|undefined}
  33642. * @private
  33643. */
  33644. this.geometryName_ = options.geometryName;
  33645. };
  33646. ol.inherits(ol.format.EsriJSON, ol.format.JSONFeature);
  33647. /**
  33648. * @param {EsriJSONGeometry} object Object.
  33649. * @param {olx.format.ReadOptions=} opt_options Read options.
  33650. * @private
  33651. * @return {ol.geom.Geometry} Geometry.
  33652. */
  33653. ol.format.EsriJSON.readGeometry_ = function(object, opt_options) {
  33654. if (!object) {
  33655. return null;
  33656. }
  33657. /** @type {ol.geom.GeometryType} */
  33658. var type;
  33659. if (typeof object.x === 'number' && typeof object.y === 'number') {
  33660. type = ol.geom.GeometryType.POINT;
  33661. } else if (object.points) {
  33662. type = ol.geom.GeometryType.MULTI_POINT;
  33663. } else if (object.paths) {
  33664. if (object.paths.length === 1) {
  33665. type = ol.geom.GeometryType.LINE_STRING;
  33666. } else {
  33667. type = ol.geom.GeometryType.MULTI_LINE_STRING;
  33668. }
  33669. } else if (object.rings) {
  33670. var layout = ol.format.EsriJSON.getGeometryLayout_(object);
  33671. var rings = ol.format.EsriJSON.convertRings_(object.rings, layout);
  33672. object = /** @type {EsriJSONGeometry} */(ol.obj.assign({}, object));
  33673. if (rings.length === 1) {
  33674. type = ol.geom.GeometryType.POLYGON;
  33675. object.rings = rings[0];
  33676. } else {
  33677. type = ol.geom.GeometryType.MULTI_POLYGON;
  33678. object.rings = rings;
  33679. }
  33680. }
  33681. var geometryReader = ol.format.EsriJSON.GEOMETRY_READERS_[type];
  33682. return /** @type {ol.geom.Geometry} */ (
  33683. ol.format.Feature.transformWithOptions(
  33684. geometryReader(object), false, opt_options));
  33685. };
  33686. /**
  33687. * Determines inner and outer rings.
  33688. * Checks if any polygons in this array contain any other polygons in this
  33689. * array. It is used for checking for holes.
  33690. * Logic inspired by: https://github.com/Esri/terraformer-arcgis-parser
  33691. * @param {Array.<!Array.<!Array.<number>>>} rings Rings.
  33692. * @param {ol.geom.GeometryLayout} layout Geometry layout.
  33693. * @private
  33694. * @return {Array.<!Array.<!Array.<number>>>} Transformed rings.
  33695. */
  33696. ol.format.EsriJSON.convertRings_ = function(rings, layout) {
  33697. var flatRing = [];
  33698. var outerRings = [];
  33699. var holes = [];
  33700. var i, ii;
  33701. for (i = 0, ii = rings.length; i < ii; ++i) {
  33702. flatRing.length = 0;
  33703. ol.geom.flat.deflate.coordinates(flatRing, 0, rings[i], layout.length);
  33704. // is this ring an outer ring? is it clockwise?
  33705. var clockwise = ol.geom.flat.orient.linearRingIsClockwise(flatRing, 0,
  33706. flatRing.length, layout.length);
  33707. if (clockwise) {
  33708. outerRings.push([rings[i]]);
  33709. } else {
  33710. holes.push(rings[i]);
  33711. }
  33712. }
  33713. while (holes.length) {
  33714. var hole = holes.shift();
  33715. var matched = false;
  33716. // loop over all outer rings and see if they contain our hole.
  33717. for (i = outerRings.length - 1; i >= 0; i--) {
  33718. var outerRing = outerRings[i][0];
  33719. var containsHole = ol.extent.containsExtent(
  33720. new ol.geom.LinearRing(outerRing).getExtent(),
  33721. new ol.geom.LinearRing(hole).getExtent()
  33722. );
  33723. if (containsHole) {
  33724. // the hole is contained push it into our polygon
  33725. outerRings[i].push(hole);
  33726. matched = true;
  33727. break;
  33728. }
  33729. }
  33730. if (!matched) {
  33731. // no outer rings contain this hole turn it into and outer
  33732. // ring (reverse it)
  33733. outerRings.push([hole.reverse()]);
  33734. }
  33735. }
  33736. return outerRings;
  33737. };
  33738. /**
  33739. * @param {EsriJSONGeometry} object Object.
  33740. * @private
  33741. * @return {ol.geom.Geometry} Point.
  33742. */
  33743. ol.format.EsriJSON.readPointGeometry_ = function(object) {
  33744. var point;
  33745. if (object.m !== undefined && object.z !== undefined) {
  33746. point = new ol.geom.Point([object.x, object.y, object.z, object.m],
  33747. ol.geom.GeometryLayout.XYZM);
  33748. } else if (object.z !== undefined) {
  33749. point = new ol.geom.Point([object.x, object.y, object.z],
  33750. ol.geom.GeometryLayout.XYZ);
  33751. } else if (object.m !== undefined) {
  33752. point = new ol.geom.Point([object.x, object.y, object.m],
  33753. ol.geom.GeometryLayout.XYM);
  33754. } else {
  33755. point = new ol.geom.Point([object.x, object.y]);
  33756. }
  33757. return point;
  33758. };
  33759. /**
  33760. * @param {EsriJSONGeometry} object Object.
  33761. * @private
  33762. * @return {ol.geom.Geometry} LineString.
  33763. */
  33764. ol.format.EsriJSON.readLineStringGeometry_ = function(object) {
  33765. var layout = ol.format.EsriJSON.getGeometryLayout_(object);
  33766. return new ol.geom.LineString(object.paths[0], layout);
  33767. };
  33768. /**
  33769. * @param {EsriJSONGeometry} object Object.
  33770. * @private
  33771. * @return {ol.geom.Geometry} MultiLineString.
  33772. */
  33773. ol.format.EsriJSON.readMultiLineStringGeometry_ = function(object) {
  33774. var layout = ol.format.EsriJSON.getGeometryLayout_(object);
  33775. return new ol.geom.MultiLineString(object.paths, layout);
  33776. };
  33777. /**
  33778. * @param {EsriJSONGeometry} object Object.
  33779. * @private
  33780. * @return {ol.geom.GeometryLayout} The geometry layout to use.
  33781. */
  33782. ol.format.EsriJSON.getGeometryLayout_ = function(object) {
  33783. var layout = ol.geom.GeometryLayout.XY;
  33784. if (object.hasZ === true && object.hasM === true) {
  33785. layout = ol.geom.GeometryLayout.XYZM;
  33786. } else if (object.hasZ === true) {
  33787. layout = ol.geom.GeometryLayout.XYZ;
  33788. } else if (object.hasM === true) {
  33789. layout = ol.geom.GeometryLayout.XYM;
  33790. }
  33791. return layout;
  33792. };
  33793. /**
  33794. * @param {EsriJSONGeometry} object Object.
  33795. * @private
  33796. * @return {ol.geom.Geometry} MultiPoint.
  33797. */
  33798. ol.format.EsriJSON.readMultiPointGeometry_ = function(object) {
  33799. var layout = ol.format.EsriJSON.getGeometryLayout_(object);
  33800. return new ol.geom.MultiPoint(object.points, layout);
  33801. };
  33802. /**
  33803. * @param {EsriJSONGeometry} object Object.
  33804. * @private
  33805. * @return {ol.geom.Geometry} MultiPolygon.
  33806. */
  33807. ol.format.EsriJSON.readMultiPolygonGeometry_ = function(object) {
  33808. var layout = ol.format.EsriJSON.getGeometryLayout_(object);
  33809. return new ol.geom.MultiPolygon(
  33810. /** @type {Array.<Array.<Array.<Array.<number>>>>} */(object.rings),
  33811. layout);
  33812. };
  33813. /**
  33814. * @param {EsriJSONGeometry} object Object.
  33815. * @private
  33816. * @return {ol.geom.Geometry} Polygon.
  33817. */
  33818. ol.format.EsriJSON.readPolygonGeometry_ = function(object) {
  33819. var layout = ol.format.EsriJSON.getGeometryLayout_(object);
  33820. return new ol.geom.Polygon(object.rings, layout);
  33821. };
  33822. /**
  33823. * @param {ol.geom.Geometry} geometry Geometry.
  33824. * @param {olx.format.WriteOptions=} opt_options Write options.
  33825. * @private
  33826. * @return {EsriJSONGeometry} EsriJSON geometry.
  33827. */
  33828. ol.format.EsriJSON.writePointGeometry_ = function(geometry, opt_options) {
  33829. var coordinates = /** @type {ol.geom.Point} */ (geometry).getCoordinates();
  33830. var esriJSON;
  33831. var layout = /** @type {ol.geom.Point} */ (geometry).getLayout();
  33832. if (layout === ol.geom.GeometryLayout.XYZ) {
  33833. esriJSON = /** @type {EsriJSONPoint} */ ({
  33834. x: coordinates[0],
  33835. y: coordinates[1],
  33836. z: coordinates[2]
  33837. });
  33838. } else if (layout === ol.geom.GeometryLayout.XYM) {
  33839. esriJSON = /** @type {EsriJSONPoint} */ ({
  33840. x: coordinates[0],
  33841. y: coordinates[1],
  33842. m: coordinates[2]
  33843. });
  33844. } else if (layout === ol.geom.GeometryLayout.XYZM) {
  33845. esriJSON = /** @type {EsriJSONPoint} */ ({
  33846. x: coordinates[0],
  33847. y: coordinates[1],
  33848. z: coordinates[2],
  33849. m: coordinates[3]
  33850. });
  33851. } else if (layout === ol.geom.GeometryLayout.XY) {
  33852. esriJSON = /** @type {EsriJSONPoint} */ ({
  33853. x: coordinates[0],
  33854. y: coordinates[1]
  33855. });
  33856. } else {
  33857. ol.asserts.assert(false, 34); // Invalid geometry layout
  33858. }
  33859. return /** @type {EsriJSONGeometry} */ (esriJSON);
  33860. };
  33861. /**
  33862. * @param {ol.geom.SimpleGeometry} geometry Geometry.
  33863. * @private
  33864. * @return {Object} Object with boolean hasZ and hasM keys.
  33865. */
  33866. ol.format.EsriJSON.getHasZM_ = function(geometry) {
  33867. var layout = geometry.getLayout();
  33868. return {
  33869. hasZ: (layout === ol.geom.GeometryLayout.XYZ ||
  33870. layout === ol.geom.GeometryLayout.XYZM),
  33871. hasM: (layout === ol.geom.GeometryLayout.XYM ||
  33872. layout === ol.geom.GeometryLayout.XYZM)
  33873. };
  33874. };
  33875. /**
  33876. * @param {ol.geom.Geometry} geometry Geometry.
  33877. * @param {olx.format.WriteOptions=} opt_options Write options.
  33878. * @private
  33879. * @return {EsriJSONPolyline} EsriJSON geometry.
  33880. */
  33881. ol.format.EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
  33882. var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.LineString} */(geometry));
  33883. return /** @type {EsriJSONPolyline} */ ({
  33884. hasZ: hasZM.hasZ,
  33885. hasM: hasZM.hasM,
  33886. paths: [
  33887. /** @type {ol.geom.LineString} */ (geometry).getCoordinates()
  33888. ]
  33889. });
  33890. };
  33891. /**
  33892. * @param {ol.geom.Geometry} geometry Geometry.
  33893. * @param {olx.format.WriteOptions=} opt_options Write options.
  33894. * @private
  33895. * @return {EsriJSONPolygon} EsriJSON geometry.
  33896. */
  33897. ol.format.EsriJSON.writePolygonGeometry_ = function(geometry, opt_options) {
  33898. // Esri geometries use the left-hand rule
  33899. var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.Polygon} */(geometry));
  33900. return /** @type {EsriJSONPolygon} */ ({
  33901. hasZ: hasZM.hasZ,
  33902. hasM: hasZM.hasM,
  33903. rings: /** @type {ol.geom.Polygon} */ (geometry).getCoordinates(false)
  33904. });
  33905. };
  33906. /**
  33907. * @param {ol.geom.Geometry} geometry Geometry.
  33908. * @param {olx.format.WriteOptions=} opt_options Write options.
  33909. * @private
  33910. * @return {EsriJSONPolyline} EsriJSON geometry.
  33911. */
  33912. ol.format.EsriJSON.writeMultiLineStringGeometry_ = function(geometry, opt_options) {
  33913. var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiLineString} */(geometry));
  33914. return /** @type {EsriJSONPolyline} */ ({
  33915. hasZ: hasZM.hasZ,
  33916. hasM: hasZM.hasM,
  33917. paths: /** @type {ol.geom.MultiLineString} */ (geometry).getCoordinates()
  33918. });
  33919. };
  33920. /**
  33921. * @param {ol.geom.Geometry} geometry Geometry.
  33922. * @param {olx.format.WriteOptions=} opt_options Write options.
  33923. * @private
  33924. * @return {EsriJSONMultipoint} EsriJSON geometry.
  33925. */
  33926. ol.format.EsriJSON.writeMultiPointGeometry_ = function(geometry, opt_options) {
  33927. var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiPoint} */(geometry));
  33928. return /** @type {EsriJSONMultipoint} */ ({
  33929. hasZ: hasZM.hasZ,
  33930. hasM: hasZM.hasM,
  33931. points: /** @type {ol.geom.MultiPoint} */ (geometry).getCoordinates()
  33932. });
  33933. };
  33934. /**
  33935. * @param {ol.geom.Geometry} geometry Geometry.
  33936. * @param {olx.format.WriteOptions=} opt_options Write options.
  33937. * @private
  33938. * @return {EsriJSONPolygon} EsriJSON geometry.
  33939. */
  33940. ol.format.EsriJSON.writeMultiPolygonGeometry_ = function(geometry,
  33941. opt_options) {
  33942. var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiPolygon} */(geometry));
  33943. var coordinates = /** @type {ol.geom.MultiPolygon} */ (geometry).getCoordinates(false);
  33944. var output = [];
  33945. for (var i = 0; i < coordinates.length; i++) {
  33946. for (var x = coordinates[i].length - 1; x >= 0; x--) {
  33947. output.push(coordinates[i][x]);
  33948. }
  33949. }
  33950. return /** @type {EsriJSONPolygon} */ ({
  33951. hasZ: hasZM.hasZ,
  33952. hasM: hasZM.hasM,
  33953. rings: output
  33954. });
  33955. };
  33956. /**
  33957. * @const
  33958. * @private
  33959. * @type {Object.<ol.geom.GeometryType, function(EsriJSONGeometry): ol.geom.Geometry>}
  33960. */
  33961. ol.format.EsriJSON.GEOMETRY_READERS_ = {};
  33962. ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.POINT] =
  33963. ol.format.EsriJSON.readPointGeometry_;
  33964. ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.LINE_STRING] =
  33965. ol.format.EsriJSON.readLineStringGeometry_;
  33966. ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.POLYGON] =
  33967. ol.format.EsriJSON.readPolygonGeometry_;
  33968. ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.MULTI_POINT] =
  33969. ol.format.EsriJSON.readMultiPointGeometry_;
  33970. ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.MULTI_LINE_STRING] =
  33971. ol.format.EsriJSON.readMultiLineStringGeometry_;
  33972. ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.MULTI_POLYGON] =
  33973. ol.format.EsriJSON.readMultiPolygonGeometry_;
  33974. /**
  33975. * @const
  33976. * @private
  33977. * @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (EsriJSONGeometry)>}
  33978. */
  33979. ol.format.EsriJSON.GEOMETRY_WRITERS_ = {};
  33980. ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.POINT] =
  33981. ol.format.EsriJSON.writePointGeometry_;
  33982. ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.LINE_STRING] =
  33983. ol.format.EsriJSON.writeLineStringGeometry_;
  33984. ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.POLYGON] =
  33985. ol.format.EsriJSON.writePolygonGeometry_;
  33986. ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.MULTI_POINT] =
  33987. ol.format.EsriJSON.writeMultiPointGeometry_;
  33988. ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.MULTI_LINE_STRING] =
  33989. ol.format.EsriJSON.writeMultiLineStringGeometry_;
  33990. ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.MULTI_POLYGON] =
  33991. ol.format.EsriJSON.writeMultiPolygonGeometry_;
  33992. /**
  33993. * Read a feature from a EsriJSON Feature source. Only works for Feature,
  33994. * use `readFeatures` to read FeatureCollection source.
  33995. *
  33996. * @function
  33997. * @param {ArrayBuffer|Document|Node|Object|string} source Source.
  33998. * @param {olx.format.ReadOptions=} opt_options Read options.
  33999. * @return {ol.Feature} Feature.
  34000. * @api
  34001. */
  34002. ol.format.EsriJSON.prototype.readFeature;
  34003. /**
  34004. * Read all features from a EsriJSON source. Works with both Feature and
  34005. * FeatureCollection sources.
  34006. *
  34007. * @function
  34008. * @param {ArrayBuffer|Document|Node|Object|string} source Source.
  34009. * @param {olx.format.ReadOptions=} opt_options Read options.
  34010. * @return {Array.<ol.Feature>} Features.
  34011. * @api
  34012. */
  34013. ol.format.EsriJSON.prototype.readFeatures;
  34014. /**
  34015. * @inheritDoc
  34016. */
  34017. ol.format.EsriJSON.prototype.readFeatureFromObject = function(
  34018. object, opt_options) {
  34019. var esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
  34020. var geometry = ol.format.EsriJSON.readGeometry_(esriJSONFeature.geometry,
  34021. opt_options);
  34022. var feature = new ol.Feature();
  34023. if (this.geometryName_) {
  34024. feature.setGeometryName(this.geometryName_);
  34025. }
  34026. feature.setGeometry(geometry);
  34027. if (opt_options && opt_options.idField &&
  34028. esriJSONFeature.attributes[opt_options.idField]) {
  34029. feature.setId(/** @type {number} */(
  34030. esriJSONFeature.attributes[opt_options.idField]));
  34031. }
  34032. if (esriJSONFeature.attributes) {
  34033. feature.setProperties(esriJSONFeature.attributes);
  34034. }
  34035. return feature;
  34036. };
  34037. /**
  34038. * @inheritDoc
  34039. */
  34040. ol.format.EsriJSON.prototype.readFeaturesFromObject = function(
  34041. object, opt_options) {
  34042. var esriJSONObject = /** @type {EsriJSONObject} */ (object);
  34043. var options = opt_options ? opt_options : {};
  34044. if (esriJSONObject.features) {
  34045. var esriJSONFeatureCollection = /** @type {EsriJSONFeatureCollection} */
  34046. (object);
  34047. /** @type {Array.<ol.Feature>} */
  34048. var features = [];
  34049. var esriJSONFeatures = esriJSONFeatureCollection.features;
  34050. var i, ii;
  34051. options.idField = object.objectIdFieldName;
  34052. for (i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
  34053. features.push(this.readFeatureFromObject(esriJSONFeatures[i],
  34054. options));
  34055. }
  34056. return features;
  34057. } else {
  34058. return [this.readFeatureFromObject(object, options)];
  34059. }
  34060. };
  34061. /**
  34062. * Read a geometry from a EsriJSON source.
  34063. *
  34064. * @function
  34065. * @param {ArrayBuffer|Document|Node|Object|string} source Source.
  34066. * @param {olx.format.ReadOptions=} opt_options Read options.
  34067. * @return {ol.geom.Geometry} Geometry.
  34068. * @api
  34069. */
  34070. ol.format.EsriJSON.prototype.readGeometry;
  34071. /**
  34072. * @inheritDoc
  34073. */
  34074. ol.format.EsriJSON.prototype.readGeometryFromObject = function(
  34075. object, opt_options) {
  34076. return ol.format.EsriJSON.readGeometry_(
  34077. /** @type {EsriJSONGeometry} */(object), opt_options);
  34078. };
  34079. /**
  34080. * Read the projection from a EsriJSON source.
  34081. *
  34082. * @function
  34083. * @param {ArrayBuffer|Document|Node|Object|string} source Source.
  34084. * @return {ol.proj.Projection} Projection.
  34085. * @api
  34086. */
  34087. ol.format.EsriJSON.prototype.readProjection;
  34088. /**
  34089. * @inheritDoc
  34090. */
  34091. ol.format.EsriJSON.prototype.readProjectionFromObject = function(object) {
  34092. var esriJSONObject = /** @type {EsriJSONObject} */ (object);
  34093. if (esriJSONObject.spatialReference && esriJSONObject.spatialReference.wkid) {
  34094. var crs = esriJSONObject.spatialReference.wkid;
  34095. return ol.proj.get('EPSG:' + crs);
  34096. } else {
  34097. return null;
  34098. }
  34099. };
  34100. /**
  34101. * @param {ol.geom.Geometry} geometry Geometry.
  34102. * @param {olx.format.WriteOptions=} opt_options Write options.
  34103. * @private
  34104. * @return {EsriJSONGeometry} EsriJSON geometry.
  34105. */
  34106. ol.format.EsriJSON.writeGeometry_ = function(geometry, opt_options) {
  34107. var geometryWriter = ol.format.EsriJSON.GEOMETRY_WRITERS_[geometry.getType()];
  34108. return geometryWriter(/** @type {ol.geom.Geometry} */(
  34109. ol.format.Feature.transformWithOptions(geometry, true, opt_options)),
  34110. opt_options);
  34111. };
  34112. /**
  34113. * Encode a geometry as a EsriJSON string.
  34114. *
  34115. * @function
  34116. * @param {ol.geom.Geometry} geometry Geometry.
  34117. * @param {olx.format.WriteOptions=} opt_options Write options.
  34118. * @return {string} EsriJSON.
  34119. * @api
  34120. */
  34121. ol.format.EsriJSON.prototype.writeGeometry;
  34122. /**
  34123. * Encode a geometry as a EsriJSON object.
  34124. *
  34125. * @param {ol.geom.Geometry} geometry Geometry.
  34126. * @param {olx.format.WriteOptions=} opt_options Write options.
  34127. * @return {EsriJSONGeometry} Object.
  34128. * @override
  34129. * @api
  34130. */
  34131. ol.format.EsriJSON.prototype.writeGeometryObject = function(geometry,
  34132. opt_options) {
  34133. return ol.format.EsriJSON.writeGeometry_(geometry,
  34134. this.adaptOptions(opt_options));
  34135. };
  34136. /**
  34137. * Encode a feature as a EsriJSON Feature string.
  34138. *
  34139. * @function
  34140. * @param {ol.Feature} feature Feature.
  34141. * @param {olx.format.WriteOptions=} opt_options Write options.
  34142. * @return {string} EsriJSON.
  34143. * @api
  34144. */
  34145. ol.format.EsriJSON.prototype.writeFeature;
  34146. /**
  34147. * Encode a feature as a esriJSON Feature object.
  34148. *
  34149. * @param {ol.Feature} feature Feature.
  34150. * @param {olx.format.WriteOptions=} opt_options Write options.
  34151. * @return {Object} Object.
  34152. * @override
  34153. * @api
  34154. */
  34155. ol.format.EsriJSON.prototype.writeFeatureObject = function(
  34156. feature, opt_options) {
  34157. opt_options = this.adaptOptions(opt_options);
  34158. var object = {};
  34159. var geometry = feature.getGeometry();
  34160. if (geometry) {
  34161. object['geometry'] =
  34162. ol.format.EsriJSON.writeGeometry_(geometry, opt_options);
  34163. if (opt_options && opt_options.featureProjection) {
  34164. object['geometry']['spatialReference'] = /** @type {EsriJSONCRS} */({
  34165. wkid: ol.proj.get(
  34166. opt_options.featureProjection).getCode().split(':').pop()
  34167. });
  34168. }
  34169. }
  34170. var properties = feature.getProperties();
  34171. delete properties[feature.getGeometryName()];
  34172. if (!ol.obj.isEmpty(properties)) {
  34173. object['attributes'] = properties;
  34174. } else {
  34175. object['attributes'] = {};
  34176. }
  34177. return object;
  34178. };
  34179. /**
  34180. * Encode an array of features as EsriJSON.
  34181. *
  34182. * @function
  34183. * @param {Array.<ol.Feature>} features Features.
  34184. * @param {olx.format.WriteOptions=} opt_options Write options.
  34185. * @return {string} EsriJSON.
  34186. * @api
  34187. */
  34188. ol.format.EsriJSON.prototype.writeFeatures;
  34189. /**
  34190. * Encode an array of features as a EsriJSON object.
  34191. *
  34192. * @param {Array.<ol.Feature>} features Features.
  34193. * @param {olx.format.WriteOptions=} opt_options Write options.
  34194. * @return {Object} EsriJSON Object.
  34195. * @override
  34196. * @api
  34197. */
  34198. ol.format.EsriJSON.prototype.writeFeaturesObject = function(features, opt_options) {
  34199. opt_options = this.adaptOptions(opt_options);
  34200. var objects = [];
  34201. var i, ii;
  34202. for (i = 0, ii = features.length; i < ii; ++i) {
  34203. objects.push(this.writeFeatureObject(features[i], opt_options));
  34204. }
  34205. return /** @type {EsriJSONFeatureCollection} */ ({
  34206. 'features': objects
  34207. });
  34208. };
  34209. goog.provide('ol.format.filter.Filter');
  34210. /**
  34211. * @classdesc
  34212. * Abstract class; normally only used for creating subclasses and not instantiated in apps.
  34213. * Base class for WFS GetFeature filters.
  34214. *
  34215. * deprecated: This class will no longer be exported starting from the next major version.
  34216. *
  34217. * @constructor
  34218. * @abstract
  34219. * @param {!string} tagName The XML tag name for this filter.
  34220. * @struct
  34221. * @api
  34222. */
  34223. ol.format.filter.Filter = function(tagName) {
  34224. /**
  34225. * @private
  34226. * @type {!string}
  34227. */
  34228. this.tagName_ = tagName;
  34229. };
  34230. /**
  34231. * The XML tag name for a filter.
  34232. * @returns {!string} Name.
  34233. */
  34234. ol.format.filter.Filter.prototype.getTagName = function() {
  34235. return this.tagName_;
  34236. };
  34237. goog.provide('ol.format.filter.LogicalNary');
  34238. goog.require('ol');
  34239. goog.require('ol.asserts');
  34240. goog.require('ol.format.filter.Filter');
  34241. /**
  34242. * @classdesc
  34243. * Abstract class; normally only used for creating subclasses and not instantiated in apps.
  34244. * Base class for WFS GetFeature n-ary logical filters.
  34245. *
  34246. * @constructor
  34247. * @abstract
  34248. * @param {!string} tagName The XML tag name for this filter.
  34249. * @param {...ol.format.filter.Filter} conditions Conditions.
  34250. * @extends {ol.format.filter.Filter}
  34251. */
  34252. ol.format.filter.LogicalNary = function(tagName, conditions) {
  34253. ol.format.filter.Filter.call(this, tagName);
  34254. /**
  34255. * @public
  34256. * @type {Array.<ol.format.filter.Filter>}
  34257. */
  34258. this.conditions = Array.prototype.slice.call(arguments, 1);
  34259. ol.asserts.assert(this.conditions.length >= 2, 57); // At least 2 conditions are required.
  34260. };
  34261. ol.inherits(ol.format.filter.LogicalNary, ol.format.filter.Filter);
  34262. goog.provide('ol.format.filter.And');
  34263. goog.require('ol');
  34264. goog.require('ol.format.filter.LogicalNary');
  34265. /**
  34266. * @classdesc
  34267. * Represents a logical `<And>` operator between two or more filter conditions.
  34268. *
  34269. * deprecated: This class will no longer be exported starting from the next major version.
  34270. *
  34271. * @constructor
  34272. * @abstract
  34273. * @param {...ol.format.filter.Filter} conditions Conditions.
  34274. * @extends {ol.format.filter.LogicalNary}
  34275. * @api
  34276. */
  34277. ol.format.filter.And = function(conditions) {
  34278. var params = ['And'].concat(Array.prototype.slice.call(arguments));
  34279. ol.format.filter.LogicalNary.apply(this, params);
  34280. };
  34281. ol.inherits(ol.format.filter.And, ol.format.filter.LogicalNary);
  34282. goog.provide('ol.format.filter.Bbox');
  34283. goog.require('ol');
  34284. goog.require('ol.format.filter.Filter');
  34285. /**
  34286. * @classdesc
  34287. * Represents a `<BBOX>` operator to test whether a geometry-valued property
  34288. * intersects a fixed bounding box
  34289. *
  34290. * @constructor
  34291. * @param {!string} geometryName Geometry name to use.
  34292. * @param {!ol.Extent} extent Extent.
  34293. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34294. * set on geometries when this is not provided.
  34295. * @extends {ol.format.filter.Filter}
  34296. * @api
  34297. */
  34298. ol.format.filter.Bbox = function(geometryName, extent, opt_srsName) {
  34299. ol.format.filter.Filter.call(this, 'BBOX');
  34300. /**
  34301. * @public
  34302. * @type {!string}
  34303. */
  34304. this.geometryName = geometryName;
  34305. /**
  34306. * @public
  34307. * @type {ol.Extent}
  34308. */
  34309. this.extent = extent;
  34310. /**
  34311. * @public
  34312. * @type {string|undefined}
  34313. */
  34314. this.srsName = opt_srsName;
  34315. };
  34316. ol.inherits(ol.format.filter.Bbox, ol.format.filter.Filter);
  34317. goog.provide('ol.format.filter.Spatial');
  34318. goog.require('ol');
  34319. goog.require('ol.format.filter.Filter');
  34320. /**
  34321. * @classdesc
  34322. * Abstract class; normally only used for creating subclasses and not instantiated in apps.
  34323. * Represents a spatial operator to test whether a geometry-valued property
  34324. * relates to a given geometry.
  34325. *
  34326. * deprecated: This class will no longer be exported starting from the next major version.
  34327. *
  34328. * @constructor
  34329. * @abstract
  34330. * @param {!string} tagName The XML tag name for this filter.
  34331. * @param {!string} geometryName Geometry name to use.
  34332. * @param {!ol.geom.Geometry} geometry Geometry.
  34333. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34334. * set on geometries when this is not provided.
  34335. * @extends {ol.format.filter.Filter}
  34336. * @api
  34337. */
  34338. ol.format.filter.Spatial = function(tagName, geometryName, geometry, opt_srsName) {
  34339. ol.format.filter.Filter.call(this, tagName);
  34340. /**
  34341. * @public
  34342. * @type {!string}
  34343. */
  34344. this.geometryName = geometryName || 'the_geom';
  34345. /**
  34346. * @public
  34347. * @type {ol.geom.Geometry}
  34348. */
  34349. this.geometry = geometry;
  34350. /**
  34351. * @public
  34352. * @type {string|undefined}
  34353. */
  34354. this.srsName = opt_srsName;
  34355. };
  34356. ol.inherits(ol.format.filter.Spatial, ol.format.filter.Filter);
  34357. goog.provide('ol.format.filter.Contains');
  34358. goog.require('ol');
  34359. goog.require('ol.format.filter.Spatial');
  34360. /**
  34361. * @classdesc
  34362. * Represents a `<Contains>` operator to test whether a geometry-valued property
  34363. * contains a given geometry.
  34364. *
  34365. * @constructor
  34366. * @param {!string} geometryName Geometry name to use.
  34367. * @param {!ol.geom.Geometry} geometry Geometry.
  34368. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34369. * set on geometries when this is not provided.
  34370. * @extends {ol.format.filter.Spatial}
  34371. * @api
  34372. */
  34373. ol.format.filter.Contains = function(geometryName, geometry, opt_srsName) {
  34374. ol.format.filter.Spatial.call(this, 'Contains', geometryName, geometry, opt_srsName);
  34375. };
  34376. ol.inherits(ol.format.filter.Contains, ol.format.filter.Spatial);
  34377. goog.provide('ol.format.filter.Comparison');
  34378. goog.require('ol');
  34379. goog.require('ol.format.filter.Filter');
  34380. /**
  34381. * @classdesc
  34382. * Abstract class; normally only used for creating subclasses and not instantiated in apps.
  34383. * Base class for WFS GetFeature property comparison filters.
  34384. *
  34385. * deprecated: This class will no longer be exported starting from the next major version.
  34386. *
  34387. * @constructor
  34388. * @abstract
  34389. * @param {!string} tagName The XML tag name for this filter.
  34390. * @param {!string} propertyName Name of the context property to compare.
  34391. * @extends {ol.format.filter.Filter}
  34392. * @api
  34393. */
  34394. ol.format.filter.Comparison = function(tagName, propertyName) {
  34395. ol.format.filter.Filter.call(this, tagName);
  34396. /**
  34397. * @public
  34398. * @type {!string}
  34399. */
  34400. this.propertyName = propertyName;
  34401. };
  34402. ol.inherits(ol.format.filter.Comparison, ol.format.filter.Filter);
  34403. goog.provide('ol.format.filter.During');
  34404. goog.require('ol');
  34405. goog.require('ol.format.filter.Comparison');
  34406. /**
  34407. * @classdesc
  34408. * Represents a `<During>` comparison operator.
  34409. *
  34410. * @constructor
  34411. * @param {!string} propertyName Name of the context property to compare.
  34412. * @param {!string} begin The begin date in ISO-8601 format.
  34413. * @param {!string} end The end date in ISO-8601 format.
  34414. * @extends {ol.format.filter.Comparison}
  34415. * @api
  34416. */
  34417. ol.format.filter.During = function(propertyName, begin, end) {
  34418. ol.format.filter.Comparison.call(this, 'During', propertyName);
  34419. /**
  34420. * @public
  34421. * @type {!string}
  34422. */
  34423. this.begin = begin;
  34424. /**
  34425. * @public
  34426. * @type {!string}
  34427. */
  34428. this.end = end;
  34429. };
  34430. ol.inherits(ol.format.filter.During, ol.format.filter.Comparison);
  34431. goog.provide('ol.format.filter.ComparisonBinary');
  34432. goog.require('ol');
  34433. goog.require('ol.format.filter.Comparison');
  34434. /**
  34435. * @classdesc
  34436. * Abstract class; normally only used for creating subclasses and not instantiated in apps.
  34437. * Base class for WFS GetFeature property binary comparison filters.
  34438. *
  34439. * deprecated: This class will no longer be exported starting from the next major version.
  34440. *
  34441. * @constructor
  34442. * @abstract
  34443. * @param {!string} tagName The XML tag name for this filter.
  34444. * @param {!string} propertyName Name of the context property to compare.
  34445. * @param {!(string|number)} expression The value to compare.
  34446. * @param {boolean=} opt_matchCase Case-sensitive?
  34447. * @extends {ol.format.filter.Comparison}
  34448. * @api
  34449. */
  34450. ol.format.filter.ComparisonBinary = function(
  34451. tagName, propertyName, expression, opt_matchCase) {
  34452. ol.format.filter.Comparison.call(this, tagName, propertyName);
  34453. /**
  34454. * @public
  34455. * @type {!(string|number)}
  34456. */
  34457. this.expression = expression;
  34458. /**
  34459. * @public
  34460. * @type {boolean|undefined}
  34461. */
  34462. this.matchCase = opt_matchCase;
  34463. };
  34464. ol.inherits(ol.format.filter.ComparisonBinary, ol.format.filter.Comparison);
  34465. goog.provide('ol.format.filter.EqualTo');
  34466. goog.require('ol');
  34467. goog.require('ol.format.filter.ComparisonBinary');
  34468. /**
  34469. * @classdesc
  34470. * Represents a `<PropertyIsEqualTo>` comparison operator.
  34471. *
  34472. * @constructor
  34473. * @param {!string} propertyName Name of the context property to compare.
  34474. * @param {!(string|number)} expression The value to compare.
  34475. * @param {boolean=} opt_matchCase Case-sensitive?
  34476. * @extends {ol.format.filter.ComparisonBinary}
  34477. * @api
  34478. */
  34479. ol.format.filter.EqualTo = function(propertyName, expression, opt_matchCase) {
  34480. ol.format.filter.ComparisonBinary.call(this, 'PropertyIsEqualTo', propertyName, expression, opt_matchCase);
  34481. };
  34482. ol.inherits(ol.format.filter.EqualTo, ol.format.filter.ComparisonBinary);
  34483. goog.provide('ol.format.filter.GreaterThan');
  34484. goog.require('ol');
  34485. goog.require('ol.format.filter.ComparisonBinary');
  34486. /**
  34487. * @classdesc
  34488. * Represents a `<PropertyIsGreaterThan>` comparison operator.
  34489. *
  34490. * @constructor
  34491. * @param {!string} propertyName Name of the context property to compare.
  34492. * @param {!number} expression The value to compare.
  34493. * @extends {ol.format.filter.ComparisonBinary}
  34494. * @api
  34495. */
  34496. ol.format.filter.GreaterThan = function(propertyName, expression) {
  34497. ol.format.filter.ComparisonBinary.call(this, 'PropertyIsGreaterThan', propertyName, expression);
  34498. };
  34499. ol.inherits(ol.format.filter.GreaterThan, ol.format.filter.ComparisonBinary);
  34500. goog.provide('ol.format.filter.GreaterThanOrEqualTo');
  34501. goog.require('ol');
  34502. goog.require('ol.format.filter.ComparisonBinary');
  34503. /**
  34504. * @classdesc
  34505. * Represents a `<PropertyIsGreaterThanOrEqualTo>` comparison operator.
  34506. *
  34507. * @constructor
  34508. * @param {!string} propertyName Name of the context property to compare.
  34509. * @param {!number} expression The value to compare.
  34510. * @extends {ol.format.filter.ComparisonBinary}
  34511. * @api
  34512. */
  34513. ol.format.filter.GreaterThanOrEqualTo = function(propertyName, expression) {
  34514. ol.format.filter.ComparisonBinary.call(this, 'PropertyIsGreaterThanOrEqualTo', propertyName, expression);
  34515. };
  34516. ol.inherits(ol.format.filter.GreaterThanOrEqualTo, ol.format.filter.ComparisonBinary);
  34517. goog.provide('ol.format.filter.Intersects');
  34518. goog.require('ol');
  34519. goog.require('ol.format.filter.Spatial');
  34520. /**
  34521. * @classdesc
  34522. * Represents a `<Intersects>` operator to test whether a geometry-valued property
  34523. * intersects a given geometry.
  34524. *
  34525. * @constructor
  34526. * @param {!string} geometryName Geometry name to use.
  34527. * @param {!ol.geom.Geometry} geometry Geometry.
  34528. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34529. * set on geometries when this is not provided.
  34530. * @extends {ol.format.filter.Spatial}
  34531. * @api
  34532. */
  34533. ol.format.filter.Intersects = function(geometryName, geometry, opt_srsName) {
  34534. ol.format.filter.Spatial.call(this, 'Intersects', geometryName, geometry, opt_srsName);
  34535. };
  34536. ol.inherits(ol.format.filter.Intersects, ol.format.filter.Spatial);
  34537. goog.provide('ol.format.filter.IsBetween');
  34538. goog.require('ol');
  34539. goog.require('ol.format.filter.Comparison');
  34540. /**
  34541. * @classdesc
  34542. * Represents a `<PropertyIsBetween>` comparison operator.
  34543. *
  34544. * @constructor
  34545. * @param {!string} propertyName Name of the context property to compare.
  34546. * @param {!number} lowerBoundary The lower bound of the range.
  34547. * @param {!number} upperBoundary The upper bound of the range.
  34548. * @extends {ol.format.filter.Comparison}
  34549. * @api
  34550. */
  34551. ol.format.filter.IsBetween = function(propertyName, lowerBoundary, upperBoundary) {
  34552. ol.format.filter.Comparison.call(this, 'PropertyIsBetween', propertyName);
  34553. /**
  34554. * @public
  34555. * @type {!number}
  34556. */
  34557. this.lowerBoundary = lowerBoundary;
  34558. /**
  34559. * @public
  34560. * @type {!number}
  34561. */
  34562. this.upperBoundary = upperBoundary;
  34563. };
  34564. ol.inherits(ol.format.filter.IsBetween, ol.format.filter.Comparison);
  34565. goog.provide('ol.format.filter.IsLike');
  34566. goog.require('ol');
  34567. goog.require('ol.format.filter.Comparison');
  34568. /**
  34569. * @classdesc
  34570. * Represents a `<PropertyIsLike>` comparison operator.
  34571. *
  34572. * @constructor
  34573. * @param {!string} propertyName Name of the context property to compare.
  34574. * @param {!string} pattern Text pattern.
  34575. * @param {string=} opt_wildCard Pattern character which matches any sequence of
  34576. * zero or more string characters. Default is '*'.
  34577. * @param {string=} opt_singleChar pattern character which matches any single
  34578. * string character. Default is '.'.
  34579. * @param {string=} opt_escapeChar Escape character which can be used to escape
  34580. * the pattern characters. Default is '!'.
  34581. * @param {boolean=} opt_matchCase Case-sensitive?
  34582. * @extends {ol.format.filter.Comparison}
  34583. * @api
  34584. */
  34585. ol.format.filter.IsLike = function(propertyName, pattern,
  34586. opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) {
  34587. ol.format.filter.Comparison.call(this, 'PropertyIsLike', propertyName);
  34588. /**
  34589. * @public
  34590. * @type {!string}
  34591. */
  34592. this.pattern = pattern;
  34593. /**
  34594. * @public
  34595. * @type {!string}
  34596. */
  34597. this.wildCard = (opt_wildCard !== undefined) ? opt_wildCard : '*';
  34598. /**
  34599. * @public
  34600. * @type {!string}
  34601. */
  34602. this.singleChar = (opt_singleChar !== undefined) ? opt_singleChar : '.';
  34603. /**
  34604. * @public
  34605. * @type {!string}
  34606. */
  34607. this.escapeChar = (opt_escapeChar !== undefined) ? opt_escapeChar : '!';
  34608. /**
  34609. * @public
  34610. * @type {boolean|undefined}
  34611. */
  34612. this.matchCase = opt_matchCase;
  34613. };
  34614. ol.inherits(ol.format.filter.IsLike, ol.format.filter.Comparison);
  34615. goog.provide('ol.format.filter.IsNull');
  34616. goog.require('ol');
  34617. goog.require('ol.format.filter.Comparison');
  34618. /**
  34619. * @classdesc
  34620. * Represents a `<PropertyIsNull>` comparison operator.
  34621. *
  34622. * @constructor
  34623. * @param {!string} propertyName Name of the context property to compare.
  34624. * @extends {ol.format.filter.Comparison}
  34625. * @api
  34626. */
  34627. ol.format.filter.IsNull = function(propertyName) {
  34628. ol.format.filter.Comparison.call(this, 'PropertyIsNull', propertyName);
  34629. };
  34630. ol.inherits(ol.format.filter.IsNull, ol.format.filter.Comparison);
  34631. goog.provide('ol.format.filter.LessThan');
  34632. goog.require('ol');
  34633. goog.require('ol.format.filter.ComparisonBinary');
  34634. /**
  34635. * @classdesc
  34636. * Represents a `<PropertyIsLessThan>` comparison operator.
  34637. *
  34638. * @constructor
  34639. * @param {!string} propertyName Name of the context property to compare.
  34640. * @param {!number} expression The value to compare.
  34641. * @extends {ol.format.filter.ComparisonBinary}
  34642. * @api
  34643. */
  34644. ol.format.filter.LessThan = function(propertyName, expression) {
  34645. ol.format.filter.ComparisonBinary.call(this, 'PropertyIsLessThan', propertyName, expression);
  34646. };
  34647. ol.inherits(ol.format.filter.LessThan, ol.format.filter.ComparisonBinary);
  34648. goog.provide('ol.format.filter.LessThanOrEqualTo');
  34649. goog.require('ol');
  34650. goog.require('ol.format.filter.ComparisonBinary');
  34651. /**
  34652. * @classdesc
  34653. * Represents a `<PropertyIsLessThanOrEqualTo>` comparison operator.
  34654. *
  34655. * @constructor
  34656. * @param {!string} propertyName Name of the context property to compare.
  34657. * @param {!number} expression The value to compare.
  34658. * @extends {ol.format.filter.ComparisonBinary}
  34659. * @api
  34660. */
  34661. ol.format.filter.LessThanOrEqualTo = function(propertyName, expression) {
  34662. ol.format.filter.ComparisonBinary.call(this, 'PropertyIsLessThanOrEqualTo', propertyName, expression);
  34663. };
  34664. ol.inherits(ol.format.filter.LessThanOrEqualTo, ol.format.filter.ComparisonBinary);
  34665. goog.provide('ol.format.filter.Not');
  34666. goog.require('ol');
  34667. goog.require('ol.format.filter.Filter');
  34668. /**
  34669. * @classdesc
  34670. * Represents a logical `<Not>` operator for a filter condition.
  34671. *
  34672. * @constructor
  34673. * @param {!ol.format.filter.Filter} condition Filter condition.
  34674. * @extends {ol.format.filter.Filter}
  34675. * @api
  34676. */
  34677. ol.format.filter.Not = function(condition) {
  34678. ol.format.filter.Filter.call(this, 'Not');
  34679. /**
  34680. * @public
  34681. * @type {!ol.format.filter.Filter}
  34682. */
  34683. this.condition = condition;
  34684. };
  34685. ol.inherits(ol.format.filter.Not, ol.format.filter.Filter);
  34686. goog.provide('ol.format.filter.NotEqualTo');
  34687. goog.require('ol');
  34688. goog.require('ol.format.filter.ComparisonBinary');
  34689. /**
  34690. * @classdesc
  34691. * Represents a `<PropertyIsNotEqualTo>` comparison operator.
  34692. *
  34693. * @constructor
  34694. * @param {!string} propertyName Name of the context property to compare.
  34695. * @param {!(string|number)} expression The value to compare.
  34696. * @param {boolean=} opt_matchCase Case-sensitive?
  34697. * @extends {ol.format.filter.ComparisonBinary}
  34698. * @api
  34699. */
  34700. ol.format.filter.NotEqualTo = function(propertyName, expression, opt_matchCase) {
  34701. ol.format.filter.ComparisonBinary.call(this, 'PropertyIsNotEqualTo', propertyName, expression, opt_matchCase);
  34702. };
  34703. ol.inherits(ol.format.filter.NotEqualTo, ol.format.filter.ComparisonBinary);
  34704. goog.provide('ol.format.filter.Or');
  34705. goog.require('ol');
  34706. goog.require('ol.format.filter.LogicalNary');
  34707. /**
  34708. * @classdesc
  34709. * Represents a logical `<Or>` operator between two ore more filter conditions.
  34710. *
  34711. * @constructor
  34712. * @param {...ol.format.filter.Filter} conditions Conditions.
  34713. * @extends {ol.format.filter.LogicalNary}
  34714. * @api
  34715. */
  34716. ol.format.filter.Or = function(conditions) {
  34717. var params = ['Or'].concat(Array.prototype.slice.call(arguments));
  34718. ol.format.filter.LogicalNary.apply(this, params);
  34719. };
  34720. ol.inherits(ol.format.filter.Or, ol.format.filter.LogicalNary);
  34721. goog.provide('ol.format.filter.Within');
  34722. goog.require('ol');
  34723. goog.require('ol.format.filter.Spatial');
  34724. /**
  34725. * @classdesc
  34726. * Represents a `<Within>` operator to test whether a geometry-valued property
  34727. * is within a given geometry.
  34728. *
  34729. * @constructor
  34730. * @param {!string} geometryName Geometry name to use.
  34731. * @param {!ol.geom.Geometry} geometry Geometry.
  34732. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34733. * set on geometries when this is not provided.
  34734. * @extends {ol.format.filter.Spatial}
  34735. * @api
  34736. */
  34737. ol.format.filter.Within = function(geometryName, geometry, opt_srsName) {
  34738. ol.format.filter.Spatial.call(this, 'Within', geometryName, geometry, opt_srsName);
  34739. };
  34740. ol.inherits(ol.format.filter.Within, ol.format.filter.Spatial);
  34741. goog.provide('ol.format.filter');
  34742. goog.require('ol.format.filter.And');
  34743. goog.require('ol.format.filter.Bbox');
  34744. goog.require('ol.format.filter.Contains');
  34745. goog.require('ol.format.filter.During');
  34746. goog.require('ol.format.filter.EqualTo');
  34747. goog.require('ol.format.filter.GreaterThan');
  34748. goog.require('ol.format.filter.GreaterThanOrEqualTo');
  34749. goog.require('ol.format.filter.Intersects');
  34750. goog.require('ol.format.filter.IsBetween');
  34751. goog.require('ol.format.filter.IsLike');
  34752. goog.require('ol.format.filter.IsNull');
  34753. goog.require('ol.format.filter.LessThan');
  34754. goog.require('ol.format.filter.LessThanOrEqualTo');
  34755. goog.require('ol.format.filter.Not');
  34756. goog.require('ol.format.filter.NotEqualTo');
  34757. goog.require('ol.format.filter.Or');
  34758. goog.require('ol.format.filter.Within');
  34759. /**
  34760. * Create a logical `<And>` operator between two or more filter conditions.
  34761. *
  34762. * @param {...ol.format.filter.Filter} conditions Filter conditions.
  34763. * @returns {!ol.format.filter.And} `<And>` operator.
  34764. * @api
  34765. */
  34766. ol.format.filter.and = function(conditions) {
  34767. var params = [null].concat(Array.prototype.slice.call(arguments));
  34768. return new (Function.prototype.bind.apply(ol.format.filter.And, params));
  34769. };
  34770. /**
  34771. * Create a logical `<Or>` operator between two or more filter conditions.
  34772. *
  34773. * @param {...ol.format.filter.Filter} conditions Filter conditions.
  34774. * @returns {!ol.format.filter.Or} `<Or>` operator.
  34775. * @api
  34776. */
  34777. ol.format.filter.or = function(conditions) {
  34778. var params = [null].concat(Array.prototype.slice.call(arguments));
  34779. return new (Function.prototype.bind.apply(ol.format.filter.Or, params));
  34780. };
  34781. /**
  34782. * Represents a logical `<Not>` operator for a filter condition.
  34783. *
  34784. * @param {!ol.format.filter.Filter} condition Filter condition.
  34785. * @returns {!ol.format.filter.Not} `<Not>` operator.
  34786. * @api
  34787. */
  34788. ol.format.filter.not = function(condition) {
  34789. return new ol.format.filter.Not(condition);
  34790. };
  34791. /**
  34792. * Create a `<BBOX>` operator to test whether a geometry-valued property
  34793. * intersects a fixed bounding box
  34794. *
  34795. * @param {!string} geometryName Geometry name to use.
  34796. * @param {!ol.Extent} extent Extent.
  34797. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34798. * set on geometries when this is not provided.
  34799. * @returns {!ol.format.filter.Bbox} `<BBOX>` operator.
  34800. * @api
  34801. */
  34802. ol.format.filter.bbox = function(geometryName, extent, opt_srsName) {
  34803. return new ol.format.filter.Bbox(geometryName, extent, opt_srsName);
  34804. };
  34805. /**
  34806. * Create a `<Contains>` operator to test whether a geometry-valued property
  34807. * contains a given geometry.
  34808. *
  34809. * @param {!string} geometryName Geometry name to use.
  34810. * @param {!ol.geom.Geometry} geometry Geometry.
  34811. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34812. * set on geometries when this is not provided.
  34813. * @returns {!ol.format.filter.Contains} `<Contains>` operator.
  34814. * @api
  34815. */
  34816. ol.format.filter.contains = function(geometryName, geometry, opt_srsName) {
  34817. return new ol.format.filter.Contains(geometryName, geometry, opt_srsName);
  34818. };
  34819. /**
  34820. * Create a `<Intersects>` operator to test whether a geometry-valued property
  34821. * intersects a given geometry.
  34822. *
  34823. * @param {!string} geometryName Geometry name to use.
  34824. * @param {!ol.geom.Geometry} geometry Geometry.
  34825. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34826. * set on geometries when this is not provided.
  34827. * @returns {!ol.format.filter.Intersects} `<Intersects>` operator.
  34828. * @api
  34829. */
  34830. ol.format.filter.intersects = function(geometryName, geometry, opt_srsName) {
  34831. return new ol.format.filter.Intersects(geometryName, geometry, opt_srsName);
  34832. };
  34833. /**
  34834. * Create a `<Within>` operator to test whether a geometry-valued property
  34835. * is within a given geometry.
  34836. *
  34837. * @param {!string} geometryName Geometry name to use.
  34838. * @param {!ol.geom.Geometry} geometry Geometry.
  34839. * @param {string=} opt_srsName SRS name. No srsName attribute will be
  34840. * set on geometries when this is not provided.
  34841. * @returns {!ol.format.filter.Within} `<Within>` operator.
  34842. * @api
  34843. */
  34844. ol.format.filter.within = function(geometryName, geometry, opt_srsName) {
  34845. return new ol.format.filter.Within(geometryName, geometry, opt_srsName);
  34846. };
  34847. /**
  34848. * Creates a `<PropertyIsEqualTo>` comparison operator.
  34849. *
  34850. * @param {!string} propertyName Name of the context property to compare.
  34851. * @param {!(string|number)} expression The value to compare.
  34852. * @param {boolean=} opt_matchCase Case-sensitive?
  34853. * @returns {!ol.format.filter.EqualTo} `<PropertyIsEqualTo>` operator.
  34854. * @api
  34855. */
  34856. ol.format.filter.equalTo = function(propertyName, expression, opt_matchCase) {
  34857. return new ol.format.filter.EqualTo(propertyName, expression, opt_matchCase);
  34858. };
  34859. /**
  34860. * Creates a `<PropertyIsNotEqualTo>` comparison operator.
  34861. *
  34862. * @param {!string} propertyName Name of the context property to compare.
  34863. * @param {!(string|number)} expression The value to compare.
  34864. * @param {boolean=} opt_matchCase Case-sensitive?
  34865. * @returns {!ol.format.filter.NotEqualTo} `<PropertyIsNotEqualTo>` operator.
  34866. * @api
  34867. */
  34868. ol.format.filter.notEqualTo = function(propertyName, expression, opt_matchCase) {
  34869. return new ol.format.filter.NotEqualTo(propertyName, expression, opt_matchCase);
  34870. };
  34871. /**
  34872. * Creates a `<PropertyIsLessThan>` comparison operator.
  34873. *
  34874. * @param {!string} propertyName Name of the context property to compare.
  34875. * @param {!number} expression The value to compare.
  34876. * @returns {!ol.format.filter.LessThan} `<PropertyIsLessThan>` operator.
  34877. * @api
  34878. */
  34879. ol.format.filter.lessThan = function(propertyName, expression) {
  34880. return new ol.format.filter.LessThan(propertyName, expression);
  34881. };
  34882. /**
  34883. * Creates a `<PropertyIsLessThanOrEqualTo>` comparison operator.
  34884. *
  34885. * @param {!string} propertyName Name of the context property to compare.
  34886. * @param {!number} expression The value to compare.
  34887. * @returns {!ol.format.filter.LessThanOrEqualTo} `<PropertyIsLessThanOrEqualTo>` operator.
  34888. * @api
  34889. */
  34890. ol.format.filter.lessThanOrEqualTo = function(propertyName, expression) {
  34891. return new ol.format.filter.LessThanOrEqualTo(propertyName, expression);
  34892. };
  34893. /**
  34894. * Creates a `<PropertyIsGreaterThan>` comparison operator.
  34895. *
  34896. * @param {!string} propertyName Name of the context property to compare.
  34897. * @param {!number} expression The value to compare.
  34898. * @returns {!ol.format.filter.GreaterThan} `<PropertyIsGreaterThan>` operator.
  34899. * @api
  34900. */
  34901. ol.format.filter.greaterThan = function(propertyName, expression) {
  34902. return new ol.format.filter.GreaterThan(propertyName, expression);
  34903. };
  34904. /**
  34905. * Creates a `<PropertyIsGreaterThanOrEqualTo>` comparison operator.
  34906. *
  34907. * @param {!string} propertyName Name of the context property to compare.
  34908. * @param {!number} expression The value to compare.
  34909. * @returns {!ol.format.filter.GreaterThanOrEqualTo} `<PropertyIsGreaterThanOrEqualTo>` operator.
  34910. * @api
  34911. */
  34912. ol.format.filter.greaterThanOrEqualTo = function(propertyName, expression) {
  34913. return new ol.format.filter.GreaterThanOrEqualTo(propertyName, expression);
  34914. };
  34915. /**
  34916. * Creates a `<PropertyIsNull>` comparison operator to test whether a property value
  34917. * is null.
  34918. *
  34919. * @param {!string} propertyName Name of the context property to compare.
  34920. * @returns {!ol.format.filter.IsNull} `<PropertyIsNull>` operator.
  34921. * @api
  34922. */
  34923. ol.format.filter.isNull = function(propertyName) {
  34924. return new ol.format.filter.IsNull(propertyName);
  34925. };
  34926. /**
  34927. * Creates a `<PropertyIsBetween>` comparison operator to test whether an expression
  34928. * value lies within a range given by a lower and upper bound (inclusive).
  34929. *
  34930. * @param {!string} propertyName Name of the context property to compare.
  34931. * @param {!number} lowerBoundary The lower bound of the range.
  34932. * @param {!number} upperBoundary The upper bound of the range.
  34933. * @returns {!ol.format.filter.IsBetween} `<PropertyIsBetween>` operator.
  34934. * @api
  34935. */
  34936. ol.format.filter.between = function(propertyName, lowerBoundary, upperBoundary) {
  34937. return new ol.format.filter.IsBetween(propertyName, lowerBoundary, upperBoundary);
  34938. };
  34939. /**
  34940. * Represents a `<PropertyIsLike>` comparison operator that matches a string property
  34941. * value against a text pattern.
  34942. *
  34943. * @param {!string} propertyName Name of the context property to compare.
  34944. * @param {!string} pattern Text pattern.
  34945. * @param {string=} opt_wildCard Pattern character which matches any sequence of
  34946. * zero or more string characters. Default is '*'.
  34947. * @param {string=} opt_singleChar pattern character which matches any single
  34948. * string character. Default is '.'.
  34949. * @param {string=} opt_escapeChar Escape character which can be used to escape
  34950. * the pattern characters. Default is '!'.
  34951. * @param {boolean=} opt_matchCase Case-sensitive?
  34952. * @returns {!ol.format.filter.IsLike} `<PropertyIsLike>` operator.
  34953. * @api
  34954. */
  34955. ol.format.filter.like = function(propertyName, pattern,
  34956. opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) {
  34957. return new ol.format.filter.IsLike(propertyName, pattern,
  34958. opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase);
  34959. };
  34960. /**
  34961. * Create a `<During>` temporal operator.
  34962. *
  34963. * @param {!string} propertyName Name of the context property to compare.
  34964. * @param {!string} begin The begin date in ISO-8601 format.
  34965. * @param {!string} end The end date in ISO-8601 format.
  34966. * @returns {!ol.format.filter.During} `<During>` operator.
  34967. * @api
  34968. */
  34969. ol.format.filter.during = function(propertyName, begin, end) {
  34970. return new ol.format.filter.During(propertyName, begin, end);
  34971. };
  34972. goog.provide('ol.geom.GeometryCollection');
  34973. goog.require('ol');
  34974. goog.require('ol.events');
  34975. goog.require('ol.events.EventType');
  34976. goog.require('ol.extent');
  34977. goog.require('ol.geom.Geometry');
  34978. goog.require('ol.geom.GeometryType');
  34979. goog.require('ol.obj');
  34980. /**
  34981. * @classdesc
  34982. * An array of {@link ol.geom.Geometry} objects.
  34983. *
  34984. * @constructor
  34985. * @extends {ol.geom.Geometry}
  34986. * @param {Array.<ol.geom.Geometry>=} opt_geometries Geometries.
  34987. * @api
  34988. */
  34989. ol.geom.GeometryCollection = function(opt_geometries) {
  34990. ol.geom.Geometry.call(this);
  34991. /**
  34992. * @private
  34993. * @type {Array.<ol.geom.Geometry>}
  34994. */
  34995. this.geometries_ = opt_geometries ? opt_geometries : null;
  34996. this.listenGeometriesChange_();
  34997. };
  34998. ol.inherits(ol.geom.GeometryCollection, ol.geom.Geometry);
  34999. /**
  35000. * @param {Array.<ol.geom.Geometry>} geometries Geometries.
  35001. * @private
  35002. * @return {Array.<ol.geom.Geometry>} Cloned geometries.
  35003. */
  35004. ol.geom.GeometryCollection.cloneGeometries_ = function(geometries) {
  35005. var clonedGeometries = [];
  35006. var i, ii;
  35007. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35008. clonedGeometries.push(geometries[i].clone());
  35009. }
  35010. return clonedGeometries;
  35011. };
  35012. /**
  35013. * @private
  35014. */
  35015. ol.geom.GeometryCollection.prototype.unlistenGeometriesChange_ = function() {
  35016. var i, ii;
  35017. if (!this.geometries_) {
  35018. return;
  35019. }
  35020. for (i = 0, ii = this.geometries_.length; i < ii; ++i) {
  35021. ol.events.unlisten(
  35022. this.geometries_[i], ol.events.EventType.CHANGE,
  35023. this.changed, this);
  35024. }
  35025. };
  35026. /**
  35027. * @private
  35028. */
  35029. ol.geom.GeometryCollection.prototype.listenGeometriesChange_ = function() {
  35030. var i, ii;
  35031. if (!this.geometries_) {
  35032. return;
  35033. }
  35034. for (i = 0, ii = this.geometries_.length; i < ii; ++i) {
  35035. ol.events.listen(
  35036. this.geometries_[i], ol.events.EventType.CHANGE,
  35037. this.changed, this);
  35038. }
  35039. };
  35040. /**
  35041. * Make a complete copy of the geometry.
  35042. * @return {!ol.geom.GeometryCollection} Clone.
  35043. * @override
  35044. * @api
  35045. */
  35046. ol.geom.GeometryCollection.prototype.clone = function() {
  35047. var geometryCollection = new ol.geom.GeometryCollection(null);
  35048. geometryCollection.setGeometries(this.geometries_);
  35049. return geometryCollection;
  35050. };
  35051. /**
  35052. * @inheritDoc
  35053. */
  35054. ol.geom.GeometryCollection.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  35055. if (minSquaredDistance <
  35056. ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
  35057. return minSquaredDistance;
  35058. }
  35059. var geometries = this.geometries_;
  35060. var i, ii;
  35061. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35062. minSquaredDistance = geometries[i].closestPointXY(
  35063. x, y, closestPoint, minSquaredDistance);
  35064. }
  35065. return minSquaredDistance;
  35066. };
  35067. /**
  35068. * @inheritDoc
  35069. */
  35070. ol.geom.GeometryCollection.prototype.containsXY = function(x, y) {
  35071. var geometries = this.geometries_;
  35072. var i, ii;
  35073. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35074. if (geometries[i].containsXY(x, y)) {
  35075. return true;
  35076. }
  35077. }
  35078. return false;
  35079. };
  35080. /**
  35081. * @inheritDoc
  35082. */
  35083. ol.geom.GeometryCollection.prototype.computeExtent = function(extent) {
  35084. ol.extent.createOrUpdateEmpty(extent);
  35085. var geometries = this.geometries_;
  35086. for (var i = 0, ii = geometries.length; i < ii; ++i) {
  35087. ol.extent.extend(extent, geometries[i].getExtent());
  35088. }
  35089. return extent;
  35090. };
  35091. /**
  35092. * Return the geometries that make up this geometry collection.
  35093. * @return {Array.<ol.geom.Geometry>} Geometries.
  35094. * @api
  35095. */
  35096. ol.geom.GeometryCollection.prototype.getGeometries = function() {
  35097. return ol.geom.GeometryCollection.cloneGeometries_(this.geometries_);
  35098. };
  35099. /**
  35100. * @return {Array.<ol.geom.Geometry>} Geometries.
  35101. */
  35102. ol.geom.GeometryCollection.prototype.getGeometriesArray = function() {
  35103. return this.geometries_;
  35104. };
  35105. /**
  35106. * @inheritDoc
  35107. */
  35108. ol.geom.GeometryCollection.prototype.getSimplifiedGeometry = function(squaredTolerance) {
  35109. if (this.simplifiedGeometryRevision != this.getRevision()) {
  35110. ol.obj.clear(this.simplifiedGeometryCache);
  35111. this.simplifiedGeometryMaxMinSquaredTolerance = 0;
  35112. this.simplifiedGeometryRevision = this.getRevision();
  35113. }
  35114. if (squaredTolerance < 0 ||
  35115. (this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
  35116. squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)) {
  35117. return this;
  35118. }
  35119. var key = squaredTolerance.toString();
  35120. if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
  35121. return this.simplifiedGeometryCache[key];
  35122. } else {
  35123. var simplifiedGeometries = [];
  35124. var geometries = this.geometries_;
  35125. var simplified = false;
  35126. var i, ii;
  35127. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35128. var geometry = geometries[i];
  35129. var simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
  35130. simplifiedGeometries.push(simplifiedGeometry);
  35131. if (simplifiedGeometry !== geometry) {
  35132. simplified = true;
  35133. }
  35134. }
  35135. if (simplified) {
  35136. var simplifiedGeometryCollection = new ol.geom.GeometryCollection(null);
  35137. simplifiedGeometryCollection.setGeometriesArray(simplifiedGeometries);
  35138. this.simplifiedGeometryCache[key] = simplifiedGeometryCollection;
  35139. return simplifiedGeometryCollection;
  35140. } else {
  35141. this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
  35142. return this;
  35143. }
  35144. }
  35145. };
  35146. /**
  35147. * @inheritDoc
  35148. * @api
  35149. */
  35150. ol.geom.GeometryCollection.prototype.getType = function() {
  35151. return ol.geom.GeometryType.GEOMETRY_COLLECTION;
  35152. };
  35153. /**
  35154. * @inheritDoc
  35155. * @api
  35156. */
  35157. ol.geom.GeometryCollection.prototype.intersectsExtent = function(extent) {
  35158. var geometries = this.geometries_;
  35159. var i, ii;
  35160. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35161. if (geometries[i].intersectsExtent(extent)) {
  35162. return true;
  35163. }
  35164. }
  35165. return false;
  35166. };
  35167. /**
  35168. * @return {boolean} Is empty.
  35169. */
  35170. ol.geom.GeometryCollection.prototype.isEmpty = function() {
  35171. return this.geometries_.length === 0;
  35172. };
  35173. /**
  35174. * @inheritDoc
  35175. * @api
  35176. */
  35177. ol.geom.GeometryCollection.prototype.rotate = function(angle, anchor) {
  35178. var geometries = this.geometries_;
  35179. for (var i = 0, ii = geometries.length; i < ii; ++i) {
  35180. geometries[i].rotate(angle, anchor);
  35181. }
  35182. this.changed();
  35183. };
  35184. /**
  35185. * @inheritDoc
  35186. * @api
  35187. */
  35188. ol.geom.GeometryCollection.prototype.scale = function(sx, opt_sy, opt_anchor) {
  35189. var anchor = opt_anchor;
  35190. if (!anchor) {
  35191. anchor = ol.extent.getCenter(this.getExtent());
  35192. }
  35193. var geometries = this.geometries_;
  35194. for (var i = 0, ii = geometries.length; i < ii; ++i) {
  35195. geometries[i].scale(sx, opt_sy, anchor);
  35196. }
  35197. this.changed();
  35198. };
  35199. /**
  35200. * Set the geometries that make up this geometry collection.
  35201. * @param {Array.<ol.geom.Geometry>} geometries Geometries.
  35202. * @api
  35203. */
  35204. ol.geom.GeometryCollection.prototype.setGeometries = function(geometries) {
  35205. this.setGeometriesArray(
  35206. ol.geom.GeometryCollection.cloneGeometries_(geometries));
  35207. };
  35208. /**
  35209. * @param {Array.<ol.geom.Geometry>} geometries Geometries.
  35210. */
  35211. ol.geom.GeometryCollection.prototype.setGeometriesArray = function(geometries) {
  35212. this.unlistenGeometriesChange_();
  35213. this.geometries_ = geometries;
  35214. this.listenGeometriesChange_();
  35215. this.changed();
  35216. };
  35217. /**
  35218. * @inheritDoc
  35219. * @api
  35220. */
  35221. ol.geom.GeometryCollection.prototype.applyTransform = function(transformFn) {
  35222. var geometries = this.geometries_;
  35223. var i, ii;
  35224. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35225. geometries[i].applyTransform(transformFn);
  35226. }
  35227. this.changed();
  35228. };
  35229. /**
  35230. * Translate the geometry.
  35231. * @param {number} deltaX Delta X.
  35232. * @param {number} deltaY Delta Y.
  35233. * @override
  35234. * @api
  35235. */
  35236. ol.geom.GeometryCollection.prototype.translate = function(deltaX, deltaY) {
  35237. var geometries = this.geometries_;
  35238. var i, ii;
  35239. for (i = 0, ii = geometries.length; i < ii; ++i) {
  35240. geometries[i].translate(deltaX, deltaY);
  35241. }
  35242. this.changed();
  35243. };
  35244. /**
  35245. * @inheritDoc
  35246. */
  35247. ol.geom.GeometryCollection.prototype.disposeInternal = function() {
  35248. this.unlistenGeometriesChange_();
  35249. ol.geom.Geometry.prototype.disposeInternal.call(this);
  35250. };
  35251. // TODO: serialize dataProjection as crs member when writing
  35252. // see https://github.com/openlayers/openlayers/issues/2078
  35253. goog.provide('ol.format.GeoJSON');
  35254. goog.require('ol');
  35255. goog.require('ol.asserts');
  35256. goog.require('ol.Feature');
  35257. goog.require('ol.format.Feature');
  35258. goog.require('ol.format.JSONFeature');
  35259. goog.require('ol.geom.GeometryCollection');
  35260. goog.require('ol.geom.LineString');
  35261. goog.require('ol.geom.MultiLineString');
  35262. goog.require('ol.geom.MultiPoint');
  35263. goog.require('ol.geom.MultiPolygon');
  35264. goog.require('ol.geom.Point');
  35265. goog.require('ol.geom.Polygon');
  35266. goog.require('ol.obj');
  35267. goog.require('ol.proj');
  35268. /**
  35269. * @classdesc
  35270. * Feature format for reading and writing data in the GeoJSON format.
  35271. *
  35272. * @constructor
  35273. * @extends {ol.format.JSONFeature}
  35274. * @param {olx.format.GeoJSONOptions=} opt_options Options.
  35275. * @api
  35276. */
  35277. ol.format.GeoJSON = function(opt_options) {
  35278. var options = opt_options ? opt_options : {};
  35279. ol.format.JSONFeature.call(this);
  35280. /**
  35281. * @inheritDoc
  35282. */
  35283. this.defaultDataProjection = ol.proj.get(
  35284. options.defaultDataProjection ?
  35285. options.defaultDataProjection : 'EPSG:4326');
  35286. if (options.featureProjection) {
  35287. this.defaultFeatureProjection = ol.proj.get(options.featureProjection);
  35288. }
  35289. /**
  35290. * Name of the geometry attribute for features.
  35291. * @type {string|undefined}
  35292. * @private
  35293. */
  35294. this.geometryName_ = options.geometryName;
  35295. /**
  35296. * Look for the geometry name in the feature GeoJSON
  35297. * @type {boolean|undefined}
  35298. * @private
  35299. */
  35300. this.extractGeometryName_ = options.extractGeometryName;
  35301. };
  35302. ol.inherits(ol.format.GeoJSON, ol.format.JSONFeature);
  35303. /**
  35304. * @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
  35305. * @param {olx.format.ReadOptions=} opt_options Read options.
  35306. * @private
  35307. * @return {ol.geom.Geometry} Geometry.
  35308. */
  35309. ol.format.GeoJSON.readGeometry_ = function(object, opt_options) {
  35310. if (!object) {
  35311. return null;
  35312. }
  35313. var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
  35314. return /** @type {ol.geom.Geometry} */ (
  35315. ol.format.Feature.transformWithOptions(
  35316. geometryReader(object), false, opt_options));
  35317. };
  35318. /**
  35319. * @param {GeoJSONGeometryCollection} object Object.
  35320. * @param {olx.format.ReadOptions=} opt_options Read options.
  35321. * @private
  35322. * @return {ol.geom.GeometryCollection} Geometry collection.
  35323. */
  35324. ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(
  35325. object, opt_options) {
  35326. var geometries = object.geometries.map(
  35327. /**
  35328. * @param {GeoJSONGeometry} geometry Geometry.
  35329. * @return {ol.geom.Geometry} geometry Geometry.
  35330. */
  35331. function(geometry) {
  35332. return ol.format.GeoJSON.readGeometry_(geometry, opt_options);
  35333. });
  35334. return new ol.geom.GeometryCollection(geometries);
  35335. };
  35336. /**
  35337. * @param {GeoJSONGeometry} object Object.
  35338. * @private
  35339. * @return {ol.geom.Point} Point.
  35340. */
  35341. ol.format.GeoJSON.readPointGeometry_ = function(object) {
  35342. return new ol.geom.Point(object.coordinates);
  35343. };
  35344. /**
  35345. * @param {GeoJSONGeometry} object Object.
  35346. * @private
  35347. * @return {ol.geom.LineString} LineString.
  35348. */
  35349. ol.format.GeoJSON.readLineStringGeometry_ = function(object) {
  35350. return new ol.geom.LineString(object.coordinates);
  35351. };
  35352. /**
  35353. * @param {GeoJSONGeometry} object Object.
  35354. * @private
  35355. * @return {ol.geom.MultiLineString} MultiLineString.
  35356. */
  35357. ol.format.GeoJSON.readMultiLineStringGeometry_ = function(object) {
  35358. return new ol.geom.MultiLineString(object.coordinates);
  35359. };
  35360. /**
  35361. * @param {GeoJSONGeometry} object Object.
  35362. * @private
  35363. * @return {ol.geom.MultiPoint} MultiPoint.
  35364. */
  35365. ol.format.GeoJSON.readMultiPointGeometry_ = function(object) {
  35366. return new ol.geom.MultiPoint(object.coordinates);
  35367. };
  35368. /**
  35369. * @param {GeoJSONGeometry} object Object.
  35370. * @private
  35371. * @return {ol.geom.MultiPolygon} MultiPolygon.
  35372. */
  35373. ol.format.GeoJSON.readMultiPolygonGeometry_ = function(object) {
  35374. return new ol.geom.MultiPolygon(object.coordinates);
  35375. };
  35376. /**
  35377. * @param {GeoJSONGeometry} object Object.
  35378. * @private
  35379. * @return {ol.geom.Polygon} Polygon.
  35380. */
  35381. ol.format.GeoJSON.readPolygonGeometry_ = function(object) {
  35382. return new ol.geom.Polygon(object.coordinates);
  35383. };
  35384. /**
  35385. * @param {ol.geom.Geometry} geometry Geometry.
  35386. * @param {olx.format.WriteOptions=} opt_options Write options.
  35387. * @private
  35388. * @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON geometry.
  35389. */
  35390. ol.format.GeoJSON.writeGeometry_ = function(geometry, opt_options) {
  35391. var geometryWriter = ol.format.GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
  35392. return geometryWriter(/** @type {ol.geom.Geometry} */ (
  35393. ol.format.Feature.transformWithOptions(geometry, true, opt_options)),
  35394. opt_options);
  35395. };
  35396. /**
  35397. * @param {ol.geom.Geometry} geometry Geometry.
  35398. * @private
  35399. * @return {GeoJSONGeometryCollection} Empty GeoJSON geometry collection.
  35400. */
  35401. ol.format.GeoJSON.writeEmptyGeometryCollectionGeometry_ = function(geometry) {
  35402. return /** @type {GeoJSONGeometryCollection} */ ({
  35403. type: 'GeometryCollection',
  35404. geometries: []
  35405. });
  35406. };
  35407. /**
  35408. * @param {ol.geom.GeometryCollection} geometry Geometry.
  35409. * @param {olx.format.WriteOptions=} opt_options Write options.
  35410. * @private
  35411. * @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
  35412. */
  35413. ol.format.GeoJSON.writeGeometryCollectionGeometry_ = function(
  35414. geometry, opt_options) {
  35415. var geometries = geometry.getGeometriesArray().map(function(geometry) {
  35416. var options = ol.obj.assign({}, opt_options);
  35417. delete options.featureProjection;
  35418. return ol.format.GeoJSON.writeGeometry_(geometry, options);
  35419. });
  35420. return /** @type {GeoJSONGeometryCollection} */ ({
  35421. type: 'GeometryCollection',
  35422. geometries: geometries
  35423. });
  35424. };
  35425. /**
  35426. * @param {ol.geom.LineString} geometry Geometry.
  35427. * @param {olx.format.WriteOptions=} opt_options Write options.
  35428. * @private
  35429. * @return {GeoJSONGeometry} GeoJSON geometry.
  35430. */
  35431. ol.format.GeoJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
  35432. return /** @type {GeoJSONGeometry} */ ({
  35433. type: 'LineString',
  35434. coordinates: geometry.getCoordinates()
  35435. });
  35436. };
  35437. /**
  35438. * @param {ol.geom.MultiLineString} geometry Geometry.
  35439. * @param {olx.format.WriteOptions=} opt_options Write options.
  35440. * @private
  35441. * @return {GeoJSONGeometry} GeoJSON geometry.
  35442. */
  35443. ol.format.GeoJSON.writeMultiLineStringGeometry_ = function(geometry, opt_options) {
  35444. return /** @type {GeoJSONGeometry} */ ({
  35445. type: 'MultiLineString',
  35446. coordinates: geometry.getCoordinates()
  35447. });
  35448. };
  35449. /**
  35450. * @param {ol.geom.MultiPoint} geometry Geometry.
  35451. * @param {olx.format.WriteOptions=} opt_options Write options.
  35452. * @private
  35453. * @return {GeoJSONGeometry} GeoJSON geometry.
  35454. */
  35455. ol.format.GeoJSON.writeMultiPointGeometry_ = function(geometry, opt_options) {
  35456. return /** @type {GeoJSONGeometry} */ ({
  35457. type: 'MultiPoint',
  35458. coordinates: geometry.getCoordinates()
  35459. });
  35460. };
  35461. /**
  35462. * @param {ol.geom.MultiPolygon} geometry Geometry.
  35463. * @param {olx.format.WriteOptions=} opt_options Write options.
  35464. * @private
  35465. * @return {GeoJSONGeometry} GeoJSON geometry.
  35466. */
  35467. ol.format.GeoJSON.writeMultiPolygonGeometry_ = function(geometry, opt_options) {
  35468. var right;
  35469. if (opt_options) {
  35470. right = opt_options.rightHanded;
  35471. }
  35472. return /** @type {GeoJSONGeometry} */ ({
  35473. type: 'MultiPolygon',
  35474. coordinates: geometry.getCoordinates(right)
  35475. });
  35476. };
  35477. /**
  35478. * @param {ol.geom.Point} geometry Geometry.
  35479. * @param {olx.format.WriteOptions=} opt_options Write options.
  35480. * @private
  35481. * @return {GeoJSONGeometry} GeoJSON geometry.
  35482. */
  35483. ol.format.GeoJSON.writePointGeometry_ = function(geometry, opt_options) {
  35484. return /** @type {GeoJSONGeometry} */ ({
  35485. type: 'Point',
  35486. coordinates: geometry.getCoordinates()
  35487. });
  35488. };
  35489. /**
  35490. * @param {ol.geom.Polygon} geometry Geometry.
  35491. * @param {olx.format.WriteOptions=} opt_options Write options.
  35492. * @private
  35493. * @return {GeoJSONGeometry} GeoJSON geometry.
  35494. */
  35495. ol.format.GeoJSON.writePolygonGeometry_ = function(geometry, opt_options) {
  35496. var right;
  35497. if (opt_options) {
  35498. right = opt_options.rightHanded;
  35499. }
  35500. return /** @type {GeoJSONGeometry} */ ({
  35501. type: 'Polygon',
  35502. coordinates: geometry.getCoordinates(right)
  35503. });
  35504. };
  35505. /**
  35506. * @const
  35507. * @private
  35508. * @type {Object.<string, function(GeoJSONObject): ol.geom.Geometry>}
  35509. */
  35510. ol.format.GeoJSON.GEOMETRY_READERS_ = {
  35511. 'Point': ol.format.GeoJSON.readPointGeometry_,
  35512. 'LineString': ol.format.GeoJSON.readLineStringGeometry_,
  35513. 'Polygon': ol.format.GeoJSON.readPolygonGeometry_,
  35514. 'MultiPoint': ol.format.GeoJSON.readMultiPointGeometry_,
  35515. 'MultiLineString': ol.format.GeoJSON.readMultiLineStringGeometry_,
  35516. 'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_,
  35517. 'GeometryCollection': ol.format.GeoJSON.readGeometryCollectionGeometry_
  35518. };
  35519. /**
  35520. * @const
  35521. * @private
  35522. * @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (GeoJSONGeometry|GeoJSONGeometryCollection)>}
  35523. */
  35524. ol.format.GeoJSON.GEOMETRY_WRITERS_ = {
  35525. 'Point': ol.format.GeoJSON.writePointGeometry_,
  35526. 'LineString': ol.format.GeoJSON.writeLineStringGeometry_,
  35527. 'Polygon': ol.format.GeoJSON.writePolygonGeometry_,
  35528. 'MultiPoint': ol.format.GeoJSON.writeMultiPointGeometry_,
  35529. 'MultiLineString': ol.format.GeoJSON.writeMultiLineStringGeometry_,
  35530. 'MultiPolygon': ol.format.GeoJSON.writeMultiPolygonGeometry_,
  35531. 'GeometryCollection': ol.format.GeoJSON.writeGeometryCollectionGeometry_,
  35532. 'Circle': ol.format.GeoJSON.writeEmptyGeometryCollectionGeometry_
  35533. };
  35534. /**
  35535. * Read a feature from a GeoJSON Feature source. Only works for Feature or
  35536. * geometry types. Use {@link ol.format.GeoJSON#readFeatures} to read
  35537. * FeatureCollection source. If feature at source has an id, it will be used
  35538. * as Feature id by calling {@link ol.Feature#setId} internally.
  35539. *
  35540. * @function
  35541. * @param {Document|Node|Object|string} source Source.
  35542. * @param {olx.format.ReadOptions=} opt_options Read options.
  35543. * @return {ol.Feature} Feature.
  35544. * @api
  35545. */
  35546. ol.format.GeoJSON.prototype.readFeature;
  35547. /**
  35548. * Read all features from a GeoJSON source. Works for all GeoJSON types.
  35549. * If the source includes only geometries, features will be created with those
  35550. * geometries.
  35551. *
  35552. * @function
  35553. * @param {Document|Node|Object|string} source Source.
  35554. * @param {olx.format.ReadOptions=} opt_options Read options.
  35555. * @return {Array.<ol.Feature>} Features.
  35556. * @api
  35557. */
  35558. ol.format.GeoJSON.prototype.readFeatures;
  35559. /**
  35560. * @inheritDoc
  35561. */
  35562. ol.format.GeoJSON.prototype.readFeatureFromObject = function(
  35563. object, opt_options) {
  35564. /**
  35565. * @type {GeoJSONFeature}
  35566. */
  35567. var geoJSONFeature = null;
  35568. if (object.type === 'Feature') {
  35569. geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
  35570. } else {
  35571. geoJSONFeature = /** @type {GeoJSONFeature} */ ({
  35572. type: 'Feature',
  35573. geometry: /** @type {GeoJSONGeometry|GeoJSONGeometryCollection} */ (object)
  35574. });
  35575. }
  35576. var geometry = ol.format.GeoJSON.readGeometry_(geoJSONFeature.geometry, opt_options);
  35577. var feature = new ol.Feature();
  35578. if (this.geometryName_) {
  35579. feature.setGeometryName(this.geometryName_);
  35580. } else if (this.extractGeometryName_ && geoJSONFeature.geometry_name !== undefined) {
  35581. feature.setGeometryName(geoJSONFeature.geometry_name);
  35582. }
  35583. feature.setGeometry(geometry);
  35584. if (geoJSONFeature.id !== undefined) {
  35585. feature.setId(geoJSONFeature.id);
  35586. }
  35587. if (geoJSONFeature.properties) {
  35588. feature.setProperties(geoJSONFeature.properties);
  35589. }
  35590. return feature;
  35591. };
  35592. /**
  35593. * @inheritDoc
  35594. */
  35595. ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
  35596. object, opt_options) {
  35597. var geoJSONObject = /** @type {GeoJSONObject} */ (object);
  35598. /** @type {Array.<ol.Feature>} */
  35599. var features = null;
  35600. if (geoJSONObject.type === 'FeatureCollection') {
  35601. var geoJSONFeatureCollection = /** @type {GeoJSONFeatureCollection} */
  35602. (object);
  35603. features = [];
  35604. var geoJSONFeatures = geoJSONFeatureCollection.features;
  35605. var i, ii;
  35606. for (i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
  35607. features.push(this.readFeatureFromObject(geoJSONFeatures[i],
  35608. opt_options));
  35609. }
  35610. } else {
  35611. features = [this.readFeatureFromObject(object, opt_options)];
  35612. }
  35613. return features;
  35614. };
  35615. /**
  35616. * Read a geometry from a GeoJSON source.
  35617. *
  35618. * @function
  35619. * @param {Document|Node|Object|string} source Source.
  35620. * @param {olx.format.ReadOptions=} opt_options Read options.
  35621. * @return {ol.geom.Geometry} Geometry.
  35622. * @api
  35623. */
  35624. ol.format.GeoJSON.prototype.readGeometry;
  35625. /**
  35626. * @inheritDoc
  35627. */
  35628. ol.format.GeoJSON.prototype.readGeometryFromObject = function(
  35629. object, opt_options) {
  35630. return ol.format.GeoJSON.readGeometry_(
  35631. /** @type {GeoJSONGeometry} */ (object), opt_options);
  35632. };
  35633. /**
  35634. * Read the projection from a GeoJSON source.
  35635. *
  35636. * @function
  35637. * @param {Document|Node|Object|string} source Source.
  35638. * @return {ol.proj.Projection} Projection.
  35639. * @api
  35640. */
  35641. ol.format.GeoJSON.prototype.readProjection;
  35642. /**
  35643. * @inheritDoc
  35644. */
  35645. ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
  35646. var geoJSONObject = /** @type {GeoJSONObject} */ (object);
  35647. var crs = geoJSONObject.crs;
  35648. var projection;
  35649. if (crs) {
  35650. if (crs.type == 'name') {
  35651. projection = ol.proj.get(crs.properties.name);
  35652. } else {
  35653. ol.asserts.assert(false, 36); // Unknown SRS type
  35654. }
  35655. } else {
  35656. projection = this.defaultDataProjection;
  35657. }
  35658. return /** @type {ol.proj.Projection} */ (projection);
  35659. };
  35660. /**
  35661. * Encode a feature as a GeoJSON Feature string.
  35662. *
  35663. * @function
  35664. * @param {ol.Feature} feature Feature.
  35665. * @param {olx.format.WriteOptions=} opt_options Write options.
  35666. * @return {string} GeoJSON.
  35667. * @override
  35668. * @api
  35669. */
  35670. ol.format.GeoJSON.prototype.writeFeature;
  35671. /**
  35672. * Encode a feature as a GeoJSON Feature object.
  35673. *
  35674. * @param {ol.Feature} feature Feature.
  35675. * @param {olx.format.WriteOptions=} opt_options Write options.
  35676. * @return {GeoJSONFeature} Object.
  35677. * @override
  35678. * @api
  35679. */
  35680. ol.format.GeoJSON.prototype.writeFeatureObject = function(feature, opt_options) {
  35681. opt_options = this.adaptOptions(opt_options);
  35682. var object = /** @type {GeoJSONFeature} */ ({
  35683. 'type': 'Feature'
  35684. });
  35685. var id = feature.getId();
  35686. if (id !== undefined) {
  35687. object.id = id;
  35688. }
  35689. var geometry = feature.getGeometry();
  35690. if (geometry) {
  35691. object.geometry =
  35692. ol.format.GeoJSON.writeGeometry_(geometry, opt_options);
  35693. } else {
  35694. object.geometry = null;
  35695. }
  35696. var properties = feature.getProperties();
  35697. delete properties[feature.getGeometryName()];
  35698. if (!ol.obj.isEmpty(properties)) {
  35699. object.properties = properties;
  35700. } else {
  35701. object.properties = null;
  35702. }
  35703. return object;
  35704. };
  35705. /**
  35706. * Encode an array of features as GeoJSON.
  35707. *
  35708. * @function
  35709. * @param {Array.<ol.Feature>} features Features.
  35710. * @param {olx.format.WriteOptions=} opt_options Write options.
  35711. * @return {string} GeoJSON.
  35712. * @api
  35713. */
  35714. ol.format.GeoJSON.prototype.writeFeatures;
  35715. /**
  35716. * Encode an array of features as a GeoJSON object.
  35717. *
  35718. * @param {Array.<ol.Feature>} features Features.
  35719. * @param {olx.format.WriteOptions=} opt_options Write options.
  35720. * @return {GeoJSONFeatureCollection} GeoJSON Object.
  35721. * @override
  35722. * @api
  35723. */
  35724. ol.format.GeoJSON.prototype.writeFeaturesObject = function(features, opt_options) {
  35725. opt_options = this.adaptOptions(opt_options);
  35726. var objects = [];
  35727. var i, ii;
  35728. for (i = 0, ii = features.length; i < ii; ++i) {
  35729. objects.push(this.writeFeatureObject(features[i], opt_options));
  35730. }
  35731. return /** @type {GeoJSONFeatureCollection} */ ({
  35732. type: 'FeatureCollection',
  35733. features: objects
  35734. });
  35735. };
  35736. /**
  35737. * Encode a geometry as a GeoJSON string.
  35738. *
  35739. * @function
  35740. * @param {ol.geom.Geometry} geometry Geometry.
  35741. * @param {olx.format.WriteOptions=} opt_options Write options.
  35742. * @return {string} GeoJSON.
  35743. * @api
  35744. */
  35745. ol.format.GeoJSON.prototype.writeGeometry;
  35746. /**
  35747. * Encode a geometry as a GeoJSON object.
  35748. *
  35749. * @param {ol.geom.Geometry} geometry Geometry.
  35750. * @param {olx.format.WriteOptions=} opt_options Write options.
  35751. * @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object.
  35752. * @override
  35753. * @api
  35754. */
  35755. ol.format.GeoJSON.prototype.writeGeometryObject = function(geometry,
  35756. opt_options) {
  35757. return ol.format.GeoJSON.writeGeometry_(geometry,
  35758. this.adaptOptions(opt_options));
  35759. };
  35760. goog.provide('ol.format.XMLFeature');
  35761. goog.require('ol');
  35762. goog.require('ol.array');
  35763. goog.require('ol.format.Feature');
  35764. goog.require('ol.format.FormatType');
  35765. goog.require('ol.xml');
  35766. /**
  35767. * @classdesc
  35768. * Abstract base class; normally only used for creating subclasses and not
  35769. * instantiated in apps.
  35770. * Base class for XML feature formats.
  35771. *
  35772. * @constructor
  35773. * @abstract
  35774. * @extends {ol.format.Feature}
  35775. */
  35776. ol.format.XMLFeature = function() {
  35777. /**
  35778. * @type {XMLSerializer}
  35779. * @private
  35780. */
  35781. this.xmlSerializer_ = new XMLSerializer();
  35782. ol.format.Feature.call(this);
  35783. };
  35784. ol.inherits(ol.format.XMLFeature, ol.format.Feature);
  35785. /**
  35786. * @inheritDoc
  35787. */
  35788. ol.format.XMLFeature.prototype.getType = function() {
  35789. return ol.format.FormatType.XML;
  35790. };
  35791. /**
  35792. * @inheritDoc
  35793. */
  35794. ol.format.XMLFeature.prototype.readFeature = function(source, opt_options) {
  35795. if (ol.xml.isDocument(source)) {
  35796. return this.readFeatureFromDocument(
  35797. /** @type {Document} */ (source), opt_options);
  35798. } else if (ol.xml.isNode(source)) {
  35799. return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
  35800. } else if (typeof source === 'string') {
  35801. var doc = ol.xml.parse(source);
  35802. return this.readFeatureFromDocument(doc, opt_options);
  35803. } else {
  35804. return null;
  35805. }
  35806. };
  35807. /**
  35808. * @param {Document} doc Document.
  35809. * @param {olx.format.ReadOptions=} opt_options Options.
  35810. * @return {ol.Feature} Feature.
  35811. */
  35812. ol.format.XMLFeature.prototype.readFeatureFromDocument = function(
  35813. doc, opt_options) {
  35814. var features = this.readFeaturesFromDocument(doc, opt_options);
  35815. if (features.length > 0) {
  35816. return features[0];
  35817. } else {
  35818. return null;
  35819. }
  35820. };
  35821. /**
  35822. * @param {Node} node Node.
  35823. * @param {olx.format.ReadOptions=} opt_options Options.
  35824. * @return {ol.Feature} Feature.
  35825. */
  35826. ol.format.XMLFeature.prototype.readFeatureFromNode = function(node, opt_options) {
  35827. return null; // not implemented
  35828. };
  35829. /**
  35830. * @inheritDoc
  35831. */
  35832. ol.format.XMLFeature.prototype.readFeatures = function(source, opt_options) {
  35833. if (ol.xml.isDocument(source)) {
  35834. return this.readFeaturesFromDocument(
  35835. /** @type {Document} */ (source), opt_options);
  35836. } else if (ol.xml.isNode(source)) {
  35837. return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
  35838. } else if (typeof source === 'string') {
  35839. var doc = ol.xml.parse(source);
  35840. return this.readFeaturesFromDocument(doc, opt_options);
  35841. } else {
  35842. return [];
  35843. }
  35844. };
  35845. /**
  35846. * @param {Document} doc Document.
  35847. * @param {olx.format.ReadOptions=} opt_options Options.
  35848. * @protected
  35849. * @return {Array.<ol.Feature>} Features.
  35850. */
  35851. ol.format.XMLFeature.prototype.readFeaturesFromDocument = function(
  35852. doc, opt_options) {
  35853. /** @type {Array.<ol.Feature>} */
  35854. var features = [];
  35855. var n;
  35856. for (n = doc.firstChild; n; n = n.nextSibling) {
  35857. if (n.nodeType == Node.ELEMENT_NODE) {
  35858. ol.array.extend(features, this.readFeaturesFromNode(n, opt_options));
  35859. }
  35860. }
  35861. return features;
  35862. };
  35863. /**
  35864. * @abstract
  35865. * @param {Node} node Node.
  35866. * @param {olx.format.ReadOptions=} opt_options Options.
  35867. * @protected
  35868. * @return {Array.<ol.Feature>} Features.
  35869. */
  35870. ol.format.XMLFeature.prototype.readFeaturesFromNode = function(node, opt_options) {};
  35871. /**
  35872. * @inheritDoc
  35873. */
  35874. ol.format.XMLFeature.prototype.readGeometry = function(source, opt_options) {
  35875. if (ol.xml.isDocument(source)) {
  35876. return this.readGeometryFromDocument(
  35877. /** @type {Document} */ (source), opt_options);
  35878. } else if (ol.xml.isNode(source)) {
  35879. return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
  35880. } else if (typeof source === 'string') {
  35881. var doc = ol.xml.parse(source);
  35882. return this.readGeometryFromDocument(doc, opt_options);
  35883. } else {
  35884. return null;
  35885. }
  35886. };
  35887. /**
  35888. * @param {Document} doc Document.
  35889. * @param {olx.format.ReadOptions=} opt_options Options.
  35890. * @protected
  35891. * @return {ol.geom.Geometry} Geometry.
  35892. */
  35893. ol.format.XMLFeature.prototype.readGeometryFromDocument = function(doc, opt_options) {
  35894. return null; // not implemented
  35895. };
  35896. /**
  35897. * @param {Node} node Node.
  35898. * @param {olx.format.ReadOptions=} opt_options Options.
  35899. * @protected
  35900. * @return {ol.geom.Geometry} Geometry.
  35901. */
  35902. ol.format.XMLFeature.prototype.readGeometryFromNode = function(node, opt_options) {
  35903. return null; // not implemented
  35904. };
  35905. /**
  35906. * @inheritDoc
  35907. */
  35908. ol.format.XMLFeature.prototype.readProjection = function(source) {
  35909. if (ol.xml.isDocument(source)) {
  35910. return this.readProjectionFromDocument(/** @type {Document} */ (source));
  35911. } else if (ol.xml.isNode(source)) {
  35912. return this.readProjectionFromNode(/** @type {Node} */ (source));
  35913. } else if (typeof source === 'string') {
  35914. var doc = ol.xml.parse(source);
  35915. return this.readProjectionFromDocument(doc);
  35916. } else {
  35917. return null;
  35918. }
  35919. };
  35920. /**
  35921. * @param {Document} doc Document.
  35922. * @protected
  35923. * @return {ol.proj.Projection} Projection.
  35924. */
  35925. ol.format.XMLFeature.prototype.readProjectionFromDocument = function(doc) {
  35926. return this.defaultDataProjection;
  35927. };
  35928. /**
  35929. * @param {Node} node Node.
  35930. * @protected
  35931. * @return {ol.proj.Projection} Projection.
  35932. */
  35933. ol.format.XMLFeature.prototype.readProjectionFromNode = function(node) {
  35934. return this.defaultDataProjection;
  35935. };
  35936. /**
  35937. * @inheritDoc
  35938. */
  35939. ol.format.XMLFeature.prototype.writeFeature = function(feature, opt_options) {
  35940. var node = this.writeFeatureNode(feature, opt_options);
  35941. return this.xmlSerializer_.serializeToString(node);
  35942. };
  35943. /**
  35944. * @param {ol.Feature} feature Feature.
  35945. * @param {olx.format.WriteOptions=} opt_options Options.
  35946. * @protected
  35947. * @return {Node} Node.
  35948. */
  35949. ol.format.XMLFeature.prototype.writeFeatureNode = function(feature, opt_options) {
  35950. return null; // not implemented
  35951. };
  35952. /**
  35953. * @inheritDoc
  35954. */
  35955. ol.format.XMLFeature.prototype.writeFeatures = function(features, opt_options) {
  35956. var node = this.writeFeaturesNode(features, opt_options);
  35957. return this.xmlSerializer_.serializeToString(node);
  35958. };
  35959. /**
  35960. * @param {Array.<ol.Feature>} features Features.
  35961. * @param {olx.format.WriteOptions=} opt_options Options.
  35962. * @return {Node} Node.
  35963. */
  35964. ol.format.XMLFeature.prototype.writeFeaturesNode = function(features, opt_options) {
  35965. return null; // not implemented
  35966. };
  35967. /**
  35968. * @inheritDoc
  35969. */
  35970. ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
  35971. var node = this.writeGeometryNode(geometry, opt_options);
  35972. return this.xmlSerializer_.serializeToString(node);
  35973. };
  35974. /**
  35975. * @param {ol.geom.Geometry} geometry Geometry.
  35976. * @param {olx.format.WriteOptions=} opt_options Options.
  35977. * @return {Node} Node.
  35978. */
  35979. ol.format.XMLFeature.prototype.writeGeometryNode = function(geometry, opt_options) {
  35980. return null; // not implemented
  35981. };
  35982. // FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
  35983. // of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
  35984. // envelopes/extents, only geometries!
  35985. goog.provide('ol.format.GMLBase');
  35986. goog.require('ol');
  35987. goog.require('ol.array');
  35988. goog.require('ol.Feature');
  35989. goog.require('ol.format.Feature');
  35990. goog.require('ol.format.XMLFeature');
  35991. goog.require('ol.geom.GeometryLayout');
  35992. goog.require('ol.geom.LineString');
  35993. goog.require('ol.geom.LinearRing');
  35994. goog.require('ol.geom.MultiLineString');
  35995. goog.require('ol.geom.MultiPoint');
  35996. goog.require('ol.geom.MultiPolygon');
  35997. goog.require('ol.geom.Point');
  35998. goog.require('ol.geom.Polygon');
  35999. goog.require('ol.obj');
  36000. goog.require('ol.proj');
  36001. goog.require('ol.xml');
  36002. /**
  36003. * @classdesc
  36004. * Abstract base class; normally only used for creating subclasses and not
  36005. * instantiated in apps.
  36006. * Feature base format for reading and writing data in the GML format.
  36007. * This class cannot be instantiated, it contains only base content that
  36008. * is shared with versioned format classes ol.format.GML2 and
  36009. * ol.format.GML3.
  36010. *
  36011. * @constructor
  36012. * @abstract
  36013. * @param {olx.format.GMLOptions=} opt_options
  36014. * Optional configuration object.
  36015. * @extends {ol.format.XMLFeature}
  36016. */
  36017. ol.format.GMLBase = function(opt_options) {
  36018. var options = /** @type {olx.format.GMLOptions} */
  36019. (opt_options ? opt_options : {});
  36020. /**
  36021. * @protected
  36022. * @type {Array.<string>|string|undefined}
  36023. */
  36024. this.featureType = options.featureType;
  36025. /**
  36026. * @protected
  36027. * @type {Object.<string, string>|string|undefined}
  36028. */
  36029. this.featureNS = options.featureNS;
  36030. /**
  36031. * @protected
  36032. * @type {string}
  36033. */
  36034. this.srsName = options.srsName;
  36035. /**
  36036. * @protected
  36037. * @type {string}
  36038. */
  36039. this.schemaLocation = '';
  36040. /**
  36041. * @type {Object.<string, Object.<string, Object>>}
  36042. */
  36043. this.FEATURE_COLLECTION_PARSERS = {};
  36044. this.FEATURE_COLLECTION_PARSERS[ol.format.GMLBase.GMLNS] = {
  36045. 'featureMember': ol.xml.makeReplacer(
  36046. ol.format.GMLBase.prototype.readFeaturesInternal),
  36047. 'featureMembers': ol.xml.makeReplacer(
  36048. ol.format.GMLBase.prototype.readFeaturesInternal)
  36049. };
  36050. ol.format.XMLFeature.call(this);
  36051. };
  36052. ol.inherits(ol.format.GMLBase, ol.format.XMLFeature);
  36053. /**
  36054. * @const
  36055. * @type {string}
  36056. */
  36057. ol.format.GMLBase.GMLNS = 'http://www.opengis.net/gml';
  36058. /**
  36059. * A regular expression that matches if a string only contains whitespace
  36060. * characters. It will e.g. match `''`, `' '`, `'\n'` etc. The non-breaking
  36061. * space (0xa0) is explicitly included as IE doesn't include it in its
  36062. * definition of `\s`.
  36063. *
  36064. * Information from `goog.string.isEmptyOrWhitespace`: https://github.com/google/closure-library/blob/e877b1e/closure/goog/string/string.js#L156-L160
  36065. *
  36066. * @const
  36067. * @type {RegExp}
  36068. * @private
  36069. */
  36070. ol.format.GMLBase.ONLY_WHITESPACE_RE_ = /^[\s\xa0]*$/;
  36071. /**
  36072. * @param {Node} node Node.
  36073. * @param {Array.<*>} objectStack Object stack.
  36074. * @return {Array.<ol.Feature> | undefined} Features.
  36075. */
  36076. ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
  36077. var localName = node.localName;
  36078. var features = null;
  36079. if (localName == 'FeatureCollection') {
  36080. if (node.namespaceURI === 'http://www.opengis.net/wfs') {
  36081. features = ol.xml.pushParseAndPop([],
  36082. this.FEATURE_COLLECTION_PARSERS, node,
  36083. objectStack, this);
  36084. } else {
  36085. features = ol.xml.pushParseAndPop(null,
  36086. this.FEATURE_COLLECTION_PARSERS, node,
  36087. objectStack, this);
  36088. }
  36089. } else if (localName == 'featureMembers' || localName == 'featureMember') {
  36090. var context = objectStack[0];
  36091. var featureType = context['featureType'];
  36092. var featureNS = context['featureNS'];
  36093. var i, ii, prefix = 'p', defaultPrefix = 'p0';
  36094. if (!featureType && node.childNodes) {
  36095. featureType = [], featureNS = {};
  36096. for (i = 0, ii = node.childNodes.length; i < ii; ++i) {
  36097. var child = node.childNodes[i];
  36098. if (child.nodeType === 1) {
  36099. var ft = child.nodeName.split(':').pop();
  36100. if (featureType.indexOf(ft) === -1) {
  36101. var key = '';
  36102. var count = 0;
  36103. var uri = child.namespaceURI;
  36104. for (var candidate in featureNS) {
  36105. if (featureNS[candidate] === uri) {
  36106. key = candidate;
  36107. break;
  36108. }
  36109. ++count;
  36110. }
  36111. if (!key) {
  36112. key = prefix + count;
  36113. featureNS[key] = uri;
  36114. }
  36115. featureType.push(key + ':' + ft);
  36116. }
  36117. }
  36118. }
  36119. if (localName != 'featureMember') {
  36120. // recheck featureType for each featureMember
  36121. context['featureType'] = featureType;
  36122. context['featureNS'] = featureNS;
  36123. }
  36124. }
  36125. if (typeof featureNS === 'string') {
  36126. var ns = featureNS;
  36127. featureNS = {};
  36128. featureNS[defaultPrefix] = ns;
  36129. }
  36130. var parsersNS = {};
  36131. var featureTypes = Array.isArray(featureType) ? featureType : [featureType];
  36132. for (var p in featureNS) {
  36133. var parsers = {};
  36134. for (i = 0, ii = featureTypes.length; i < ii; ++i) {
  36135. var featurePrefix = featureTypes[i].indexOf(':') === -1 ?
  36136. defaultPrefix : featureTypes[i].split(':')[0];
  36137. if (featurePrefix === p) {
  36138. parsers[featureTypes[i].split(':').pop()] =
  36139. (localName == 'featureMembers') ?
  36140. ol.xml.makeArrayPusher(this.readFeatureElement, this) :
  36141. ol.xml.makeReplacer(this.readFeatureElement, this);
  36142. }
  36143. }
  36144. parsersNS[featureNS[p]] = parsers;
  36145. }
  36146. if (localName == 'featureMember') {
  36147. features = ol.xml.pushParseAndPop(undefined, parsersNS, node, objectStack);
  36148. } else {
  36149. features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack);
  36150. }
  36151. }
  36152. if (features === null) {
  36153. features = [];
  36154. }
  36155. return features;
  36156. };
  36157. /**
  36158. * @param {Node} node Node.
  36159. * @param {Array.<*>} objectStack Object stack.
  36160. * @return {ol.geom.Geometry|undefined} Geometry.
  36161. */
  36162. ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) {
  36163. var context = /** @type {Object} */ (objectStack[0]);
  36164. context['srsName'] = node.firstElementChild.getAttribute('srsName');
  36165. context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
  36166. /** @type {ol.geom.Geometry} */
  36167. var geometry = ol.xml.pushParseAndPop(null,
  36168. this.GEOMETRY_PARSERS_, node, objectStack, this);
  36169. if (geometry) {
  36170. return /** @type {ol.geom.Geometry} */ (
  36171. ol.format.Feature.transformWithOptions(geometry, false, context));
  36172. } else {
  36173. return undefined;
  36174. }
  36175. };
  36176. /**
  36177. * @param {Node} node Node.
  36178. * @param {Array.<*>} objectStack Object stack.
  36179. * @return {ol.Feature} Feature.
  36180. */
  36181. ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) {
  36182. var n;
  36183. var fid = node.getAttribute('fid') ||
  36184. ol.xml.getAttributeNS(node, ol.format.GMLBase.GMLNS, 'id');
  36185. var values = {}, geometryName;
  36186. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  36187. var localName = n.localName;
  36188. // Assume attribute elements have one child node and that the child
  36189. // is a text or CDATA node (to be treated as text).
  36190. // Otherwise assume it is a geometry node.
  36191. if (n.childNodes.length === 0 ||
  36192. (n.childNodes.length === 1 &&
  36193. (n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
  36194. var value = ol.xml.getAllTextContent(n, false);
  36195. if (ol.format.GMLBase.ONLY_WHITESPACE_RE_.test(value)) {
  36196. value = undefined;
  36197. }
  36198. values[localName] = value;
  36199. } else {
  36200. // boundedBy is an extent and must not be considered as a geometry
  36201. if (localName !== 'boundedBy') {
  36202. geometryName = localName;
  36203. }
  36204. values[localName] = this.readGeometryElement(n, objectStack);
  36205. }
  36206. }
  36207. var feature = new ol.Feature(values);
  36208. if (geometryName) {
  36209. feature.setGeometryName(geometryName);
  36210. }
  36211. if (fid) {
  36212. feature.setId(fid);
  36213. }
  36214. return feature;
  36215. };
  36216. /**
  36217. * @param {Node} node Node.
  36218. * @param {Array.<*>} objectStack Object stack.
  36219. * @return {ol.geom.Point|undefined} Point.
  36220. */
  36221. ol.format.GMLBase.prototype.readPoint = function(node, objectStack) {
  36222. var flatCoordinates =
  36223. this.readFlatCoordinatesFromNode_(node, objectStack);
  36224. if (flatCoordinates) {
  36225. var point = new ol.geom.Point(null);
  36226. point.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
  36227. return point;
  36228. }
  36229. };
  36230. /**
  36231. * @param {Node} node Node.
  36232. * @param {Array.<*>} objectStack Object stack.
  36233. * @return {ol.geom.MultiPoint|undefined} MultiPoint.
  36234. */
  36235. ol.format.GMLBase.prototype.readMultiPoint = function(node, objectStack) {
  36236. /** @type {Array.<Array.<number>>} */
  36237. var coordinates = ol.xml.pushParseAndPop([],
  36238. this.MULTIPOINT_PARSERS_, node, objectStack, this);
  36239. if (coordinates) {
  36240. return new ol.geom.MultiPoint(coordinates);
  36241. } else {
  36242. return undefined;
  36243. }
  36244. };
  36245. /**
  36246. * @param {Node} node Node.
  36247. * @param {Array.<*>} objectStack Object stack.
  36248. * @return {ol.geom.MultiLineString|undefined} MultiLineString.
  36249. */
  36250. ol.format.GMLBase.prototype.readMultiLineString = function(node, objectStack) {
  36251. /** @type {Array.<ol.geom.LineString>} */
  36252. var lineStrings = ol.xml.pushParseAndPop([],
  36253. this.MULTILINESTRING_PARSERS_, node, objectStack, this);
  36254. if (lineStrings) {
  36255. var multiLineString = new ol.geom.MultiLineString(null);
  36256. multiLineString.setLineStrings(lineStrings);
  36257. return multiLineString;
  36258. } else {
  36259. return undefined;
  36260. }
  36261. };
  36262. /**
  36263. * @param {Node} node Node.
  36264. * @param {Array.<*>} objectStack Object stack.
  36265. * @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
  36266. */
  36267. ol.format.GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
  36268. /** @type {Array.<ol.geom.Polygon>} */
  36269. var polygons = ol.xml.pushParseAndPop([],
  36270. this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
  36271. if (polygons) {
  36272. var multiPolygon = new ol.geom.MultiPolygon(null);
  36273. multiPolygon.setPolygons(polygons);
  36274. return multiPolygon;
  36275. } else {
  36276. return undefined;
  36277. }
  36278. };
  36279. /**
  36280. * @param {Node} node Node.
  36281. * @param {Array.<*>} objectStack Object stack.
  36282. * @private
  36283. */
  36284. ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
  36285. ol.xml.parseNode(this.POINTMEMBER_PARSERS_,
  36286. node, objectStack, this);
  36287. };
  36288. /**
  36289. * @param {Node} node Node.
  36290. * @param {Array.<*>} objectStack Object stack.
  36291. * @private
  36292. */
  36293. ol.format.GMLBase.prototype.lineStringMemberParser_ = function(node, objectStack) {
  36294. ol.xml.parseNode(this.LINESTRINGMEMBER_PARSERS_,
  36295. node, objectStack, this);
  36296. };
  36297. /**
  36298. * @param {Node} node Node.
  36299. * @param {Array.<*>} objectStack Object stack.
  36300. * @private
  36301. */
  36302. ol.format.GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
  36303. ol.xml.parseNode(this.POLYGONMEMBER_PARSERS_, node,
  36304. objectStack, this);
  36305. };
  36306. /**
  36307. * @param {Node} node Node.
  36308. * @param {Array.<*>} objectStack Object stack.
  36309. * @return {ol.geom.LineString|undefined} LineString.
  36310. */
  36311. ol.format.GMLBase.prototype.readLineString = function(node, objectStack) {
  36312. var flatCoordinates =
  36313. this.readFlatCoordinatesFromNode_(node, objectStack);
  36314. if (flatCoordinates) {
  36315. var lineString = new ol.geom.LineString(null);
  36316. lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
  36317. return lineString;
  36318. } else {
  36319. return undefined;
  36320. }
  36321. };
  36322. /**
  36323. * @param {Node} node Node.
  36324. * @param {Array.<*>} objectStack Object stack.
  36325. * @private
  36326. * @return {Array.<number>|undefined} LinearRing flat coordinates.
  36327. */
  36328. ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
  36329. var ring = ol.xml.pushParseAndPop(null,
  36330. this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
  36331. objectStack, this);
  36332. if (ring) {
  36333. return ring;
  36334. } else {
  36335. return undefined;
  36336. }
  36337. };
  36338. /**
  36339. * @param {Node} node Node.
  36340. * @param {Array.<*>} objectStack Object stack.
  36341. * @return {ol.geom.LinearRing|undefined} LinearRing.
  36342. */
  36343. ol.format.GMLBase.prototype.readLinearRing = function(node, objectStack) {
  36344. var flatCoordinates =
  36345. this.readFlatCoordinatesFromNode_(node, objectStack);
  36346. if (flatCoordinates) {
  36347. var ring = new ol.geom.LinearRing(null);
  36348. ring.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
  36349. return ring;
  36350. } else {
  36351. return undefined;
  36352. }
  36353. };
  36354. /**
  36355. * @param {Node} node Node.
  36356. * @param {Array.<*>} objectStack Object stack.
  36357. * @return {ol.geom.Polygon|undefined} Polygon.
  36358. */
  36359. ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) {
  36360. /** @type {Array.<Array.<number>>} */
  36361. var flatLinearRings = ol.xml.pushParseAndPop([null],
  36362. this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
  36363. if (flatLinearRings && flatLinearRings[0]) {
  36364. var polygon = new ol.geom.Polygon(null);
  36365. var flatCoordinates = flatLinearRings[0];
  36366. var ends = [flatCoordinates.length];
  36367. var i, ii;
  36368. for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
  36369. ol.array.extend(flatCoordinates, flatLinearRings[i]);
  36370. ends.push(flatCoordinates.length);
  36371. }
  36372. polygon.setFlatCoordinates(
  36373. ol.geom.GeometryLayout.XYZ, flatCoordinates, ends);
  36374. return polygon;
  36375. } else {
  36376. return undefined;
  36377. }
  36378. };
  36379. /**
  36380. * @param {Node} node Node.
  36381. * @param {Array.<*>} objectStack Object stack.
  36382. * @private
  36383. * @return {Array.<number>} Flat coordinates.
  36384. */
  36385. ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ = function(node, objectStack) {
  36386. return ol.xml.pushParseAndPop(null,
  36387. this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
  36388. objectStack, this);
  36389. };
  36390. /**
  36391. * @const
  36392. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36393. * @private
  36394. */
  36395. ol.format.GMLBase.prototype.MULTIPOINT_PARSERS_ = {
  36396. 'http://www.opengis.net/gml': {
  36397. 'pointMember': ol.xml.makeArrayPusher(
  36398. ol.format.GMLBase.prototype.pointMemberParser_),
  36399. 'pointMembers': ol.xml.makeArrayPusher(
  36400. ol.format.GMLBase.prototype.pointMemberParser_)
  36401. }
  36402. };
  36403. /**
  36404. * @const
  36405. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36406. * @private
  36407. */
  36408. ol.format.GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
  36409. 'http://www.opengis.net/gml': {
  36410. 'lineStringMember': ol.xml.makeArrayPusher(
  36411. ol.format.GMLBase.prototype.lineStringMemberParser_),
  36412. 'lineStringMembers': ol.xml.makeArrayPusher(
  36413. ol.format.GMLBase.prototype.lineStringMemberParser_)
  36414. }
  36415. };
  36416. /**
  36417. * @const
  36418. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36419. * @private
  36420. */
  36421. ol.format.GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
  36422. 'http://www.opengis.net/gml': {
  36423. 'polygonMember': ol.xml.makeArrayPusher(
  36424. ol.format.GMLBase.prototype.polygonMemberParser_),
  36425. 'polygonMembers': ol.xml.makeArrayPusher(
  36426. ol.format.GMLBase.prototype.polygonMemberParser_)
  36427. }
  36428. };
  36429. /**
  36430. * @const
  36431. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36432. * @private
  36433. */
  36434. ol.format.GMLBase.prototype.POINTMEMBER_PARSERS_ = {
  36435. 'http://www.opengis.net/gml': {
  36436. 'Point': ol.xml.makeArrayPusher(
  36437. ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_)
  36438. }
  36439. };
  36440. /**
  36441. * @const
  36442. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36443. * @private
  36444. */
  36445. ol.format.GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
  36446. 'http://www.opengis.net/gml': {
  36447. 'LineString': ol.xml.makeArrayPusher(
  36448. ol.format.GMLBase.prototype.readLineString)
  36449. }
  36450. };
  36451. /**
  36452. * @const
  36453. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36454. * @private
  36455. */
  36456. ol.format.GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
  36457. 'http://www.opengis.net/gml': {
  36458. 'Polygon': ol.xml.makeArrayPusher(
  36459. ol.format.GMLBase.prototype.readPolygon)
  36460. }
  36461. };
  36462. /**
  36463. * @const
  36464. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36465. * @protected
  36466. */
  36467. ol.format.GMLBase.prototype.RING_PARSERS = {
  36468. 'http://www.opengis.net/gml': {
  36469. 'LinearRing': ol.xml.makeReplacer(
  36470. ol.format.GMLBase.prototype.readFlatLinearRing_)
  36471. }
  36472. };
  36473. /**
  36474. * @inheritDoc
  36475. */
  36476. ol.format.GMLBase.prototype.readGeometryFromNode = function(node, opt_options) {
  36477. var geometry = this.readGeometryElement(node,
  36478. [this.getReadOptions(node, opt_options ? opt_options : {})]);
  36479. return geometry ? geometry : null;
  36480. };
  36481. /**
  36482. * Read all features from a GML FeatureCollection.
  36483. *
  36484. * @function
  36485. * @param {Document|Node|Object|string} source Source.
  36486. * @param {olx.format.ReadOptions=} opt_options Options.
  36487. * @return {Array.<ol.Feature>} Features.
  36488. * @api
  36489. */
  36490. ol.format.GMLBase.prototype.readFeatures;
  36491. /**
  36492. * @inheritDoc
  36493. */
  36494. ol.format.GMLBase.prototype.readFeaturesFromNode = function(node, opt_options) {
  36495. var options = {
  36496. featureType: this.featureType,
  36497. featureNS: this.featureNS
  36498. };
  36499. if (opt_options) {
  36500. ol.obj.assign(options, this.getReadOptions(node, opt_options));
  36501. }
  36502. var features = this.readFeaturesInternal(node, [options]);
  36503. return features || [];
  36504. };
  36505. /**
  36506. * @inheritDoc
  36507. */
  36508. ol.format.GMLBase.prototype.readProjectionFromNode = function(node) {
  36509. return ol.proj.get(this.srsName ? this.srsName :
  36510. node.firstElementChild.getAttribute('srsName'));
  36511. };
  36512. goog.provide('ol.format.XSD');
  36513. goog.require('ol.xml');
  36514. goog.require('ol.string');
  36515. /**
  36516. * @const
  36517. * @type {string}
  36518. */
  36519. ol.format.XSD.NAMESPACE_URI = 'http://www.w3.org/2001/XMLSchema';
  36520. /**
  36521. * @param {Node} node Node.
  36522. * @return {boolean|undefined} Boolean.
  36523. */
  36524. ol.format.XSD.readBoolean = function(node) {
  36525. var s = ol.xml.getAllTextContent(node, false);
  36526. return ol.format.XSD.readBooleanString(s);
  36527. };
  36528. /**
  36529. * @param {string} string String.
  36530. * @return {boolean|undefined} Boolean.
  36531. */
  36532. ol.format.XSD.readBooleanString = function(string) {
  36533. var m = /^\s*(true|1)|(false|0)\s*$/.exec(string);
  36534. if (m) {
  36535. return m[1] !== undefined || false;
  36536. } else {
  36537. return undefined;
  36538. }
  36539. };
  36540. /**
  36541. * @param {Node} node Node.
  36542. * @return {number|undefined} DateTime in seconds.
  36543. */
  36544. ol.format.XSD.readDateTime = function(node) {
  36545. var s = ol.xml.getAllTextContent(node, false);
  36546. var dateTime = Date.parse(s);
  36547. return isNaN(dateTime) ? undefined : dateTime / 1000;
  36548. };
  36549. /**
  36550. * @param {Node} node Node.
  36551. * @return {number|undefined} Decimal.
  36552. */
  36553. ol.format.XSD.readDecimal = function(node) {
  36554. var s = ol.xml.getAllTextContent(node, false);
  36555. return ol.format.XSD.readDecimalString(s);
  36556. };
  36557. /**
  36558. * @param {string} string String.
  36559. * @return {number|undefined} Decimal.
  36560. */
  36561. ol.format.XSD.readDecimalString = function(string) {
  36562. // FIXME check spec
  36563. var m = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*$/i.exec(string);
  36564. if (m) {
  36565. return parseFloat(m[1]);
  36566. } else {
  36567. return undefined;
  36568. }
  36569. };
  36570. /**
  36571. * @param {Node} node Node.
  36572. * @return {number|undefined} Non negative integer.
  36573. */
  36574. ol.format.XSD.readNonNegativeInteger = function(node) {
  36575. var s = ol.xml.getAllTextContent(node, false);
  36576. return ol.format.XSD.readNonNegativeIntegerString(s);
  36577. };
  36578. /**
  36579. * @param {string} string String.
  36580. * @return {number|undefined} Non negative integer.
  36581. */
  36582. ol.format.XSD.readNonNegativeIntegerString = function(string) {
  36583. var m = /^\s*(\d+)\s*$/.exec(string);
  36584. if (m) {
  36585. return parseInt(m[1], 10);
  36586. } else {
  36587. return undefined;
  36588. }
  36589. };
  36590. /**
  36591. * @param {Node} node Node.
  36592. * @return {string|undefined} String.
  36593. */
  36594. ol.format.XSD.readString = function(node) {
  36595. return ol.xml.getAllTextContent(node, false).trim();
  36596. };
  36597. /**
  36598. * @param {Node} node Node to append a TextNode with the boolean to.
  36599. * @param {boolean} bool Boolean.
  36600. */
  36601. ol.format.XSD.writeBooleanTextNode = function(node, bool) {
  36602. ol.format.XSD.writeStringTextNode(node, (bool) ? '1' : '0');
  36603. };
  36604. /**
  36605. * @param {Node} node Node to append a CDATA Section with the string to.
  36606. * @param {string} string String.
  36607. */
  36608. ol.format.XSD.writeCDATASection = function(node, string) {
  36609. node.appendChild(ol.xml.DOCUMENT.createCDATASection(string));
  36610. };
  36611. /**
  36612. * @param {Node} node Node to append a TextNode with the dateTime to.
  36613. * @param {number} dateTime DateTime in seconds.
  36614. */
  36615. ol.format.XSD.writeDateTimeTextNode = function(node, dateTime) {
  36616. var date = new Date(dateTime * 1000);
  36617. var string = date.getUTCFullYear() + '-' +
  36618. ol.string.padNumber(date.getUTCMonth() + 1, 2) + '-' +
  36619. ol.string.padNumber(date.getUTCDate(), 2) + 'T' +
  36620. ol.string.padNumber(date.getUTCHours(), 2) + ':' +
  36621. ol.string.padNumber(date.getUTCMinutes(), 2) + ':' +
  36622. ol.string.padNumber(date.getUTCSeconds(), 2) + 'Z';
  36623. node.appendChild(ol.xml.DOCUMENT.createTextNode(string));
  36624. };
  36625. /**
  36626. * @param {Node} node Node to append a TextNode with the decimal to.
  36627. * @param {number} decimal Decimal.
  36628. */
  36629. ol.format.XSD.writeDecimalTextNode = function(node, decimal) {
  36630. var string = decimal.toPrecision();
  36631. node.appendChild(ol.xml.DOCUMENT.createTextNode(string));
  36632. };
  36633. /**
  36634. * @param {Node} node Node to append a TextNode with the decimal to.
  36635. * @param {number} nonNegativeInteger Non negative integer.
  36636. */
  36637. ol.format.XSD.writeNonNegativeIntegerTextNode = function(node, nonNegativeInteger) {
  36638. var string = nonNegativeInteger.toString();
  36639. node.appendChild(ol.xml.DOCUMENT.createTextNode(string));
  36640. };
  36641. /**
  36642. * @param {Node} node Node to append a TextNode with the string to.
  36643. * @param {string} string String.
  36644. */
  36645. ol.format.XSD.writeStringTextNode = function(node, string) {
  36646. node.appendChild(ol.xml.DOCUMENT.createTextNode(string));
  36647. };
  36648. goog.provide('ol.format.GML3');
  36649. goog.require('ol');
  36650. goog.require('ol.array');
  36651. goog.require('ol.extent');
  36652. goog.require('ol.format.Feature');
  36653. goog.require('ol.format.GMLBase');
  36654. goog.require('ol.format.XSD');
  36655. goog.require('ol.geom.Geometry');
  36656. goog.require('ol.geom.GeometryLayout');
  36657. goog.require('ol.geom.LineString');
  36658. goog.require('ol.geom.MultiLineString');
  36659. goog.require('ol.geom.MultiPolygon');
  36660. goog.require('ol.geom.Polygon');
  36661. goog.require('ol.obj');
  36662. goog.require('ol.proj');
  36663. goog.require('ol.xml');
  36664. /**
  36665. * @classdesc
  36666. * Feature format for reading and writing data in the GML format
  36667. * version 3.1.1.
  36668. * Currently only supports GML 3.1.1 Simple Features profile.
  36669. *
  36670. * @constructor
  36671. * @param {olx.format.GMLOptions=} opt_options
  36672. * Optional configuration object.
  36673. * @extends {ol.format.GMLBase}
  36674. * @api
  36675. */
  36676. ol.format.GML3 = function(opt_options) {
  36677. var options = /** @type {olx.format.GMLOptions} */
  36678. (opt_options ? opt_options : {});
  36679. ol.format.GMLBase.call(this, options);
  36680. /**
  36681. * @private
  36682. * @type {boolean}
  36683. */
  36684. this.surface_ = options.surface !== undefined ? options.surface : false;
  36685. /**
  36686. * @private
  36687. * @type {boolean}
  36688. */
  36689. this.curve_ = options.curve !== undefined ? options.curve : false;
  36690. /**
  36691. * @private
  36692. * @type {boolean}
  36693. */
  36694. this.multiCurve_ = options.multiCurve !== undefined ?
  36695. options.multiCurve : true;
  36696. /**
  36697. * @private
  36698. * @type {boolean}
  36699. */
  36700. this.multiSurface_ = options.multiSurface !== undefined ?
  36701. options.multiSurface : true;
  36702. /**
  36703. * @inheritDoc
  36704. */
  36705. this.schemaLocation = options.schemaLocation ?
  36706. options.schemaLocation : ol.format.GML3.schemaLocation_;
  36707. /**
  36708. * @private
  36709. * @type {boolean}
  36710. */
  36711. this.hasZ = options.hasZ !== undefined ?
  36712. options.hasZ : false;
  36713. };
  36714. ol.inherits(ol.format.GML3, ol.format.GMLBase);
  36715. /**
  36716. * @const
  36717. * @type {string}
  36718. * @private
  36719. */
  36720. ol.format.GML3.schemaLocation_ = ol.format.GMLBase.GMLNS +
  36721. ' http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
  36722. '1.0.0/gmlsf.xsd';
  36723. /**
  36724. * @param {Node} node Node.
  36725. * @param {Array.<*>} objectStack Object stack.
  36726. * @private
  36727. * @return {ol.geom.MultiLineString|undefined} MultiLineString.
  36728. */
  36729. ol.format.GML3.prototype.readMultiCurve_ = function(node, objectStack) {
  36730. /** @type {Array.<ol.geom.LineString>} */
  36731. var lineStrings = ol.xml.pushParseAndPop([],
  36732. this.MULTICURVE_PARSERS_, node, objectStack, this);
  36733. if (lineStrings) {
  36734. var multiLineString = new ol.geom.MultiLineString(null);
  36735. multiLineString.setLineStrings(lineStrings);
  36736. return multiLineString;
  36737. } else {
  36738. return undefined;
  36739. }
  36740. };
  36741. /**
  36742. * @param {Node} node Node.
  36743. * @param {Array.<*>} objectStack Object stack.
  36744. * @private
  36745. * @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
  36746. */
  36747. ol.format.GML3.prototype.readMultiSurface_ = function(node, objectStack) {
  36748. /** @type {Array.<ol.geom.Polygon>} */
  36749. var polygons = ol.xml.pushParseAndPop([],
  36750. this.MULTISURFACE_PARSERS_, node, objectStack, this);
  36751. if (polygons) {
  36752. var multiPolygon = new ol.geom.MultiPolygon(null);
  36753. multiPolygon.setPolygons(polygons);
  36754. return multiPolygon;
  36755. } else {
  36756. return undefined;
  36757. }
  36758. };
  36759. /**
  36760. * @param {Node} node Node.
  36761. * @param {Array.<*>} objectStack Object stack.
  36762. * @private
  36763. */
  36764. ol.format.GML3.prototype.curveMemberParser_ = function(node, objectStack) {
  36765. ol.xml.parseNode(this.CURVEMEMBER_PARSERS_, node, objectStack, this);
  36766. };
  36767. /**
  36768. * @param {Node} node Node.
  36769. * @param {Array.<*>} objectStack Object stack.
  36770. * @private
  36771. */
  36772. ol.format.GML3.prototype.surfaceMemberParser_ = function(node, objectStack) {
  36773. ol.xml.parseNode(this.SURFACEMEMBER_PARSERS_,
  36774. node, objectStack, this);
  36775. };
  36776. /**
  36777. * @param {Node} node Node.
  36778. * @param {Array.<*>} objectStack Object stack.
  36779. * @private
  36780. * @return {Array.<(Array.<number>)>|undefined} flat coordinates.
  36781. */
  36782. ol.format.GML3.prototype.readPatch_ = function(node, objectStack) {
  36783. return ol.xml.pushParseAndPop([null],
  36784. this.PATCHES_PARSERS_, node, objectStack, this);
  36785. };
  36786. /**
  36787. * @param {Node} node Node.
  36788. * @param {Array.<*>} objectStack Object stack.
  36789. * @private
  36790. * @return {Array.<number>|undefined} flat coordinates.
  36791. */
  36792. ol.format.GML3.prototype.readSegment_ = function(node, objectStack) {
  36793. return ol.xml.pushParseAndPop([null],
  36794. this.SEGMENTS_PARSERS_, node, objectStack, this);
  36795. };
  36796. /**
  36797. * @param {Node} node Node.
  36798. * @param {Array.<*>} objectStack Object stack.
  36799. * @private
  36800. * @return {Array.<(Array.<number>)>|undefined} flat coordinates.
  36801. */
  36802. ol.format.GML3.prototype.readPolygonPatch_ = function(node, objectStack) {
  36803. return ol.xml.pushParseAndPop([null],
  36804. this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
  36805. };
  36806. /**
  36807. * @param {Node} node Node.
  36808. * @param {Array.<*>} objectStack Object stack.
  36809. * @private
  36810. * @return {Array.<number>|undefined} flat coordinates.
  36811. */
  36812. ol.format.GML3.prototype.readLineStringSegment_ = function(node, objectStack) {
  36813. return ol.xml.pushParseAndPop([null],
  36814. this.GEOMETRY_FLAT_COORDINATES_PARSERS_,
  36815. node, objectStack, this);
  36816. };
  36817. /**
  36818. * @param {Node} node Node.
  36819. * @param {Array.<*>} objectStack Object stack.
  36820. * @private
  36821. */
  36822. ol.format.GML3.prototype.interiorParser_ = function(node, objectStack) {
  36823. /** @type {Array.<number>|undefined} */
  36824. var flatLinearRing = ol.xml.pushParseAndPop(undefined,
  36825. this.RING_PARSERS, node, objectStack, this);
  36826. if (flatLinearRing) {
  36827. var flatLinearRings = /** @type {Array.<Array.<number>>} */
  36828. (objectStack[objectStack.length - 1]);
  36829. flatLinearRings.push(flatLinearRing);
  36830. }
  36831. };
  36832. /**
  36833. * @param {Node} node Node.
  36834. * @param {Array.<*>} objectStack Object stack.
  36835. * @private
  36836. */
  36837. ol.format.GML3.prototype.exteriorParser_ = function(node, objectStack) {
  36838. /** @type {Array.<number>|undefined} */
  36839. var flatLinearRing = ol.xml.pushParseAndPop(undefined,
  36840. this.RING_PARSERS, node, objectStack, this);
  36841. if (flatLinearRing) {
  36842. var flatLinearRings = /** @type {Array.<Array.<number>>} */
  36843. (objectStack[objectStack.length - 1]);
  36844. flatLinearRings[0] = flatLinearRing;
  36845. }
  36846. };
  36847. /**
  36848. * @param {Node} node Node.
  36849. * @param {Array.<*>} objectStack Object stack.
  36850. * @private
  36851. * @return {ol.geom.Polygon|undefined} Polygon.
  36852. */
  36853. ol.format.GML3.prototype.readSurface_ = function(node, objectStack) {
  36854. /** @type {Array.<Array.<number>>} */
  36855. var flatLinearRings = ol.xml.pushParseAndPop([null],
  36856. this.SURFACE_PARSERS_, node, objectStack, this);
  36857. if (flatLinearRings && flatLinearRings[0]) {
  36858. var polygon = new ol.geom.Polygon(null);
  36859. var flatCoordinates = flatLinearRings[0];
  36860. var ends = [flatCoordinates.length];
  36861. var i, ii;
  36862. for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
  36863. ol.array.extend(flatCoordinates, flatLinearRings[i]);
  36864. ends.push(flatCoordinates.length);
  36865. }
  36866. polygon.setFlatCoordinates(
  36867. ol.geom.GeometryLayout.XYZ, flatCoordinates, ends);
  36868. return polygon;
  36869. } else {
  36870. return undefined;
  36871. }
  36872. };
  36873. /**
  36874. * @param {Node} node Node.
  36875. * @param {Array.<*>} objectStack Object stack.
  36876. * @private
  36877. * @return {ol.geom.LineString|undefined} LineString.
  36878. */
  36879. ol.format.GML3.prototype.readCurve_ = function(node, objectStack) {
  36880. /** @type {Array.<number>} */
  36881. var flatCoordinates = ol.xml.pushParseAndPop([null],
  36882. this.CURVE_PARSERS_, node, objectStack, this);
  36883. if (flatCoordinates) {
  36884. var lineString = new ol.geom.LineString(null);
  36885. lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
  36886. return lineString;
  36887. } else {
  36888. return undefined;
  36889. }
  36890. };
  36891. /**
  36892. * @param {Node} node Node.
  36893. * @param {Array.<*>} objectStack Object stack.
  36894. * @private
  36895. * @return {ol.Extent|undefined} Envelope.
  36896. */
  36897. ol.format.GML3.prototype.readEnvelope_ = function(node, objectStack) {
  36898. /** @type {Array.<number>} */
  36899. var flatCoordinates = ol.xml.pushParseAndPop([null],
  36900. this.ENVELOPE_PARSERS_, node, objectStack, this);
  36901. return ol.extent.createOrUpdate(flatCoordinates[1][0],
  36902. flatCoordinates[1][1], flatCoordinates[2][0],
  36903. flatCoordinates[2][1]);
  36904. };
  36905. /**
  36906. * @param {Node} node Node.
  36907. * @param {Array.<*>} objectStack Object stack.
  36908. * @private
  36909. * @return {Array.<number>|undefined} Flat coordinates.
  36910. */
  36911. ol.format.GML3.prototype.readFlatPos_ = function(node, objectStack) {
  36912. var s = ol.xml.getAllTextContent(node, false);
  36913. var re = /^\s*([+\-]?\d*\.?\d+(?:[eE][+\-]?\d+)?)\s*/;
  36914. /** @type {Array.<number>} */
  36915. var flatCoordinates = [];
  36916. var m;
  36917. while ((m = re.exec(s))) {
  36918. flatCoordinates.push(parseFloat(m[1]));
  36919. s = s.substr(m[0].length);
  36920. }
  36921. if (s !== '') {
  36922. return undefined;
  36923. }
  36924. var context = objectStack[0];
  36925. var containerSrs = context['srsName'];
  36926. var axisOrientation = 'enu';
  36927. if (containerSrs) {
  36928. var proj = ol.proj.get(containerSrs);
  36929. axisOrientation = proj.getAxisOrientation();
  36930. }
  36931. if (axisOrientation === 'neu') {
  36932. var i, ii;
  36933. for (i = 0, ii = flatCoordinates.length; i < ii; i += 3) {
  36934. var y = flatCoordinates[i];
  36935. var x = flatCoordinates[i + 1];
  36936. flatCoordinates[i] = x;
  36937. flatCoordinates[i + 1] = y;
  36938. }
  36939. }
  36940. var len = flatCoordinates.length;
  36941. if (len == 2) {
  36942. flatCoordinates.push(0);
  36943. }
  36944. if (len === 0) {
  36945. return undefined;
  36946. }
  36947. return flatCoordinates;
  36948. };
  36949. /**
  36950. * @param {Node} node Node.
  36951. * @param {Array.<*>} objectStack Object stack.
  36952. * @private
  36953. * @return {Array.<number>|undefined} Flat coordinates.
  36954. */
  36955. ol.format.GML3.prototype.readFlatPosList_ = function(node, objectStack) {
  36956. var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
  36957. var context = objectStack[0];
  36958. var containerSrs = context['srsName'];
  36959. var contextDimension = context['srsDimension'];
  36960. var axisOrientation = 'enu';
  36961. if (containerSrs) {
  36962. var proj = ol.proj.get(containerSrs);
  36963. axisOrientation = proj.getAxisOrientation();
  36964. }
  36965. var coords = s.split(/\s+/);
  36966. // The "dimension" attribute is from the GML 3.0.1 spec.
  36967. var dim = 2;
  36968. if (node.getAttribute('srsDimension')) {
  36969. dim = ol.format.XSD.readNonNegativeIntegerString(
  36970. node.getAttribute('srsDimension'));
  36971. } else if (node.getAttribute('dimension')) {
  36972. dim = ol.format.XSD.readNonNegativeIntegerString(
  36973. node.getAttribute('dimension'));
  36974. } else if (node.parentNode.getAttribute('srsDimension')) {
  36975. dim = ol.format.XSD.readNonNegativeIntegerString(
  36976. node.parentNode.getAttribute('srsDimension'));
  36977. } else if (contextDimension) {
  36978. dim = ol.format.XSD.readNonNegativeIntegerString(contextDimension);
  36979. }
  36980. var x, y, z;
  36981. var flatCoordinates = [];
  36982. for (var i = 0, ii = coords.length; i < ii; i += dim) {
  36983. x = parseFloat(coords[i]);
  36984. y = parseFloat(coords[i + 1]);
  36985. z = (dim === 3) ? parseFloat(coords[i + 2]) : 0;
  36986. if (axisOrientation.substr(0, 2) === 'en') {
  36987. flatCoordinates.push(x, y, z);
  36988. } else {
  36989. flatCoordinates.push(y, x, z);
  36990. }
  36991. }
  36992. return flatCoordinates;
  36993. };
  36994. /**
  36995. * @const
  36996. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  36997. * @private
  36998. */
  36999. ol.format.GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
  37000. 'http://www.opengis.net/gml': {
  37001. 'pos': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPos_),
  37002. 'posList': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPosList_)
  37003. }
  37004. };
  37005. /**
  37006. * @const
  37007. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37008. * @private
  37009. */
  37010. ol.format.GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
  37011. 'http://www.opengis.net/gml': {
  37012. 'interior': ol.format.GML3.prototype.interiorParser_,
  37013. 'exterior': ol.format.GML3.prototype.exteriorParser_
  37014. }
  37015. };
  37016. /**
  37017. * @const
  37018. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37019. * @private
  37020. */
  37021. ol.format.GML3.prototype.GEOMETRY_PARSERS_ = {
  37022. 'http://www.opengis.net/gml': {
  37023. 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint),
  37024. 'MultiPoint': ol.xml.makeReplacer(
  37025. ol.format.GMLBase.prototype.readMultiPoint),
  37026. 'LineString': ol.xml.makeReplacer(
  37027. ol.format.GMLBase.prototype.readLineString),
  37028. 'MultiLineString': ol.xml.makeReplacer(
  37029. ol.format.GMLBase.prototype.readMultiLineString),
  37030. 'LinearRing': ol.xml.makeReplacer(
  37031. ol.format.GMLBase.prototype.readLinearRing),
  37032. 'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon),
  37033. 'MultiPolygon': ol.xml.makeReplacer(
  37034. ol.format.GMLBase.prototype.readMultiPolygon),
  37035. 'Surface': ol.xml.makeReplacer(ol.format.GML3.prototype.readSurface_),
  37036. 'MultiSurface': ol.xml.makeReplacer(
  37037. ol.format.GML3.prototype.readMultiSurface_),
  37038. 'Curve': ol.xml.makeReplacer(ol.format.GML3.prototype.readCurve_),
  37039. 'MultiCurve': ol.xml.makeReplacer(
  37040. ol.format.GML3.prototype.readMultiCurve_),
  37041. 'Envelope': ol.xml.makeReplacer(ol.format.GML3.prototype.readEnvelope_)
  37042. }
  37043. };
  37044. /**
  37045. * @const
  37046. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37047. * @private
  37048. */
  37049. ol.format.GML3.prototype.MULTICURVE_PARSERS_ = {
  37050. 'http://www.opengis.net/gml': {
  37051. 'curveMember': ol.xml.makeArrayPusher(
  37052. ol.format.GML3.prototype.curveMemberParser_),
  37053. 'curveMembers': ol.xml.makeArrayPusher(
  37054. ol.format.GML3.prototype.curveMemberParser_)
  37055. }
  37056. };
  37057. /**
  37058. * @const
  37059. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37060. * @private
  37061. */
  37062. ol.format.GML3.prototype.MULTISURFACE_PARSERS_ = {
  37063. 'http://www.opengis.net/gml': {
  37064. 'surfaceMember': ol.xml.makeArrayPusher(
  37065. ol.format.GML3.prototype.surfaceMemberParser_),
  37066. 'surfaceMembers': ol.xml.makeArrayPusher(
  37067. ol.format.GML3.prototype.surfaceMemberParser_)
  37068. }
  37069. };
  37070. /**
  37071. * @const
  37072. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37073. * @private
  37074. */
  37075. ol.format.GML3.prototype.CURVEMEMBER_PARSERS_ = {
  37076. 'http://www.opengis.net/gml': {
  37077. 'LineString': ol.xml.makeArrayPusher(
  37078. ol.format.GMLBase.prototype.readLineString),
  37079. 'Curve': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readCurve_)
  37080. }
  37081. };
  37082. /**
  37083. * @const
  37084. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37085. * @private
  37086. */
  37087. ol.format.GML3.prototype.SURFACEMEMBER_PARSERS_ = {
  37088. 'http://www.opengis.net/gml': {
  37089. 'Polygon': ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readPolygon),
  37090. 'Surface': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readSurface_)
  37091. }
  37092. };
  37093. /**
  37094. * @const
  37095. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37096. * @private
  37097. */
  37098. ol.format.GML3.prototype.SURFACE_PARSERS_ = {
  37099. 'http://www.opengis.net/gml': {
  37100. 'patches': ol.xml.makeReplacer(ol.format.GML3.prototype.readPatch_)
  37101. }
  37102. };
  37103. /**
  37104. * @const
  37105. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37106. * @private
  37107. */
  37108. ol.format.GML3.prototype.CURVE_PARSERS_ = {
  37109. 'http://www.opengis.net/gml': {
  37110. 'segments': ol.xml.makeReplacer(ol.format.GML3.prototype.readSegment_)
  37111. }
  37112. };
  37113. /**
  37114. * @const
  37115. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37116. * @private
  37117. */
  37118. ol.format.GML3.prototype.ENVELOPE_PARSERS_ = {
  37119. 'http://www.opengis.net/gml': {
  37120. 'lowerCorner': ol.xml.makeArrayPusher(
  37121. ol.format.GML3.prototype.readFlatPosList_),
  37122. 'upperCorner': ol.xml.makeArrayPusher(
  37123. ol.format.GML3.prototype.readFlatPosList_)
  37124. }
  37125. };
  37126. /**
  37127. * @const
  37128. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37129. * @private
  37130. */
  37131. ol.format.GML3.prototype.PATCHES_PARSERS_ = {
  37132. 'http://www.opengis.net/gml': {
  37133. 'PolygonPatch': ol.xml.makeReplacer(
  37134. ol.format.GML3.prototype.readPolygonPatch_)
  37135. }
  37136. };
  37137. /**
  37138. * @const
  37139. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37140. * @private
  37141. */
  37142. ol.format.GML3.prototype.SEGMENTS_PARSERS_ = {
  37143. 'http://www.opengis.net/gml': {
  37144. 'LineStringSegment': ol.xml.makeReplacer(
  37145. ol.format.GML3.prototype.readLineStringSegment_)
  37146. }
  37147. };
  37148. /**
  37149. * @param {Node} node Node.
  37150. * @param {ol.geom.Point} value Point geometry.
  37151. * @param {Array.<*>} objectStack Node stack.
  37152. * @private
  37153. */
  37154. ol.format.GML3.prototype.writePos_ = function(node, value, objectStack) {
  37155. var context = objectStack[objectStack.length - 1];
  37156. var hasZ = context['hasZ'];
  37157. var srsDimension = hasZ ? 3 : 2;
  37158. node.setAttribute('srsDimension', srsDimension);
  37159. var srsName = context['srsName'];
  37160. var axisOrientation = 'enu';
  37161. if (srsName) {
  37162. axisOrientation = ol.proj.get(srsName).getAxisOrientation();
  37163. }
  37164. var point = value.getCoordinates();
  37165. var coords;
  37166. // only 2d for simple features profile
  37167. if (axisOrientation.substr(0, 2) === 'en') {
  37168. coords = (point[0] + ' ' + point[1]);
  37169. } else {
  37170. coords = (point[1] + ' ' + point[0]);
  37171. }
  37172. if (hasZ) {
  37173. // For newly created points, Z can be undefined.
  37174. var z = point[2] || 0;
  37175. coords += ' ' + z;
  37176. }
  37177. ol.format.XSD.writeStringTextNode(node, coords);
  37178. };
  37179. /**
  37180. * @param {Array.<number>} point Point geometry.
  37181. * @param {string=} opt_srsName Optional srsName
  37182. * @param {boolean=} opt_hasZ whether the geometry has a Z coordinate (is 3D) or not.
  37183. * @return {string} The coords string.
  37184. * @private
  37185. */
  37186. ol.format.GML3.prototype.getCoords_ = function(point, opt_srsName, opt_hasZ) {
  37187. var axisOrientation = 'enu';
  37188. if (opt_srsName) {
  37189. axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation();
  37190. }
  37191. var coords = ((axisOrientation.substr(0, 2) === 'en') ?
  37192. point[0] + ' ' + point[1] :
  37193. point[1] + ' ' + point[0]);
  37194. if (opt_hasZ) {
  37195. // For newly created points, Z can be undefined.
  37196. var z = point[2] || 0;
  37197. coords += ' ' + z;
  37198. }
  37199. return coords;
  37200. };
  37201. /**
  37202. * @param {Node} node Node.
  37203. * @param {ol.geom.LineString|ol.geom.LinearRing} value Geometry.
  37204. * @param {Array.<*>} objectStack Node stack.
  37205. * @private
  37206. */
  37207. ol.format.GML3.prototype.writePosList_ = function(node, value, objectStack) {
  37208. var context = objectStack[objectStack.length - 1];
  37209. var hasZ = context['hasZ'];
  37210. var srsDimension = hasZ ? 3 : 2;
  37211. node.setAttribute('srsDimension', srsDimension);
  37212. var srsName = context['srsName'];
  37213. // only 2d for simple features profile
  37214. var points = value.getCoordinates();
  37215. var len = points.length;
  37216. var parts = new Array(len);
  37217. var point;
  37218. for (var i = 0; i < len; ++i) {
  37219. point = points[i];
  37220. parts[i] = this.getCoords_(point, srsName, hasZ);
  37221. }
  37222. ol.format.XSD.writeStringTextNode(node, parts.join(' '));
  37223. };
  37224. /**
  37225. * @param {Node} node Node.
  37226. * @param {ol.geom.Point} geometry Point geometry.
  37227. * @param {Array.<*>} objectStack Node stack.
  37228. * @private
  37229. */
  37230. ol.format.GML3.prototype.writePoint_ = function(node, geometry, objectStack) {
  37231. var context = objectStack[objectStack.length - 1];
  37232. var srsName = context['srsName'];
  37233. if (srsName) {
  37234. node.setAttribute('srsName', srsName);
  37235. }
  37236. var pos = ol.xml.createElementNS(node.namespaceURI, 'pos');
  37237. node.appendChild(pos);
  37238. this.writePos_(pos, geometry, objectStack);
  37239. };
  37240. /**
  37241. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  37242. * @private
  37243. */
  37244. ol.format.GML3.ENVELOPE_SERIALIZERS_ = {
  37245. 'http://www.opengis.net/gml': {
  37246. 'lowerCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  37247. 'upperCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
  37248. }
  37249. };
  37250. /**
  37251. * @param {Node} node Node.
  37252. * @param {ol.Extent} extent Extent.
  37253. * @param {Array.<*>} objectStack Node stack.
  37254. */
  37255. ol.format.GML3.prototype.writeEnvelope = function(node, extent, objectStack) {
  37256. var context = objectStack[objectStack.length - 1];
  37257. var srsName = context['srsName'];
  37258. if (srsName) {
  37259. node.setAttribute('srsName', srsName);
  37260. }
  37261. var keys = ['lowerCorner', 'upperCorner'];
  37262. var values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
  37263. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  37264. ({node: node}), ol.format.GML3.ENVELOPE_SERIALIZERS_,
  37265. ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  37266. values,
  37267. objectStack, keys, this);
  37268. };
  37269. /**
  37270. * @param {Node} node Node.
  37271. * @param {ol.geom.LinearRing} geometry LinearRing geometry.
  37272. * @param {Array.<*>} objectStack Node stack.
  37273. * @private
  37274. */
  37275. ol.format.GML3.prototype.writeLinearRing_ = function(node, geometry, objectStack) {
  37276. var context = objectStack[objectStack.length - 1];
  37277. var srsName = context['srsName'];
  37278. if (srsName) {
  37279. node.setAttribute('srsName', srsName);
  37280. }
  37281. var posList = ol.xml.createElementNS(node.namespaceURI, 'posList');
  37282. node.appendChild(posList);
  37283. this.writePosList_(posList, geometry, objectStack);
  37284. };
  37285. /**
  37286. * @param {*} value Value.
  37287. * @param {Array.<*>} objectStack Object stack.
  37288. * @param {string=} opt_nodeName Node name.
  37289. * @return {Node} Node.
  37290. * @private
  37291. */
  37292. ol.format.GML3.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  37293. var context = objectStack[objectStack.length - 1];
  37294. var parentNode = context.node;
  37295. var exteriorWritten = context['exteriorWritten'];
  37296. if (exteriorWritten === undefined) {
  37297. context['exteriorWritten'] = true;
  37298. }
  37299. return ol.xml.createElementNS(parentNode.namespaceURI,
  37300. exteriorWritten !== undefined ? 'interior' : 'exterior');
  37301. };
  37302. /**
  37303. * @param {Node} node Node.
  37304. * @param {ol.geom.Polygon} geometry Polygon geometry.
  37305. * @param {Array.<*>} objectStack Node stack.
  37306. * @private
  37307. */
  37308. ol.format.GML3.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) {
  37309. var context = objectStack[objectStack.length - 1];
  37310. var hasZ = context['hasZ'];
  37311. var srsName = context['srsName'];
  37312. if (node.nodeName !== 'PolygonPatch' && srsName) {
  37313. node.setAttribute('srsName', srsName);
  37314. }
  37315. if (node.nodeName === 'Polygon' || node.nodeName === 'PolygonPatch') {
  37316. var rings = geometry.getLinearRings();
  37317. ol.xml.pushSerializeAndPop(
  37318. {node: node, hasZ: hasZ, srsName: srsName},
  37319. ol.format.GML3.RING_SERIALIZERS_,
  37320. this.RING_NODE_FACTORY_,
  37321. rings, objectStack, undefined, this);
  37322. } else if (node.nodeName === 'Surface') {
  37323. var patches = ol.xml.createElementNS(node.namespaceURI, 'patches');
  37324. node.appendChild(patches);
  37325. this.writeSurfacePatches_(
  37326. patches, geometry, objectStack);
  37327. }
  37328. };
  37329. /**
  37330. * @param {Node} node Node.
  37331. * @param {ol.geom.LineString} geometry LineString geometry.
  37332. * @param {Array.<*>} objectStack Node stack.
  37333. * @private
  37334. */
  37335. ol.format.GML3.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) {
  37336. var context = objectStack[objectStack.length - 1];
  37337. var srsName = context['srsName'];
  37338. if (node.nodeName !== 'LineStringSegment' && srsName) {
  37339. node.setAttribute('srsName', srsName);
  37340. }
  37341. if (node.nodeName === 'LineString' ||
  37342. node.nodeName === 'LineStringSegment') {
  37343. var posList = ol.xml.createElementNS(node.namespaceURI, 'posList');
  37344. node.appendChild(posList);
  37345. this.writePosList_(posList, geometry, objectStack);
  37346. } else if (node.nodeName === 'Curve') {
  37347. var segments = ol.xml.createElementNS(node.namespaceURI, 'segments');
  37348. node.appendChild(segments);
  37349. this.writeCurveSegments_(segments,
  37350. geometry, objectStack);
  37351. }
  37352. };
  37353. /**
  37354. * @param {Node} node Node.
  37355. * @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry.
  37356. * @param {Array.<*>} objectStack Node stack.
  37357. * @private
  37358. */
  37359. ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) {
  37360. var context = objectStack[objectStack.length - 1];
  37361. var hasZ = context['hasZ'];
  37362. var srsName = context['srsName'];
  37363. var surface = context['surface'];
  37364. if (srsName) {
  37365. node.setAttribute('srsName', srsName);
  37366. }
  37367. var polygons = geometry.getPolygons();
  37368. ol.xml.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
  37369. ol.format.GML3.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
  37370. this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
  37371. objectStack, undefined, this);
  37372. };
  37373. /**
  37374. * @param {Node} node Node.
  37375. * @param {ol.geom.MultiPoint} geometry MultiPoint geometry.
  37376. * @param {Array.<*>} objectStack Node stack.
  37377. * @private
  37378. */
  37379. ol.format.GML3.prototype.writeMultiPoint_ = function(node, geometry,
  37380. objectStack) {
  37381. var context = objectStack[objectStack.length - 1];
  37382. var srsName = context['srsName'];
  37383. var hasZ = context['hasZ'];
  37384. if (srsName) {
  37385. node.setAttribute('srsName', srsName);
  37386. }
  37387. var points = geometry.getPoints();
  37388. ol.xml.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
  37389. ol.format.GML3.POINTMEMBER_SERIALIZERS_,
  37390. ol.xml.makeSimpleNodeFactory('pointMember'), points,
  37391. objectStack, undefined, this);
  37392. };
  37393. /**
  37394. * @param {Node} node Node.
  37395. * @param {ol.geom.MultiLineString} geometry MultiLineString geometry.
  37396. * @param {Array.<*>} objectStack Node stack.
  37397. * @private
  37398. */
  37399. ol.format.GML3.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) {
  37400. var context = objectStack[objectStack.length - 1];
  37401. var hasZ = context['hasZ'];
  37402. var srsName = context['srsName'];
  37403. var curve = context['curve'];
  37404. if (srsName) {
  37405. node.setAttribute('srsName', srsName);
  37406. }
  37407. var lines = geometry.getLineStrings();
  37408. ol.xml.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
  37409. ol.format.GML3.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
  37410. this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
  37411. objectStack, undefined, this);
  37412. };
  37413. /**
  37414. * @param {Node} node Node.
  37415. * @param {ol.geom.LinearRing} ring LinearRing geometry.
  37416. * @param {Array.<*>} objectStack Node stack.
  37417. * @private
  37418. */
  37419. ol.format.GML3.prototype.writeRing_ = function(node, ring, objectStack) {
  37420. var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing');
  37421. node.appendChild(linearRing);
  37422. this.writeLinearRing_(linearRing, ring, objectStack);
  37423. };
  37424. /**
  37425. * @param {Node} node Node.
  37426. * @param {ol.geom.Polygon} polygon Polygon geometry.
  37427. * @param {Array.<*>} objectStack Node stack.
  37428. * @private
  37429. */
  37430. ol.format.GML3.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) {
  37431. var child = this.GEOMETRY_NODE_FACTORY_(
  37432. polygon, objectStack);
  37433. if (child) {
  37434. node.appendChild(child);
  37435. this.writeSurfaceOrPolygon_(child, polygon, objectStack);
  37436. }
  37437. };
  37438. /**
  37439. * @param {Node} node Node.
  37440. * @param {ol.geom.Point} point Point geometry.
  37441. * @param {Array.<*>} objectStack Node stack.
  37442. * @private
  37443. */
  37444. ol.format.GML3.prototype.writePointMember_ = function(node, point, objectStack) {
  37445. var child = ol.xml.createElementNS(node.namespaceURI, 'Point');
  37446. node.appendChild(child);
  37447. this.writePoint_(child, point, objectStack);
  37448. };
  37449. /**
  37450. * @param {Node} node Node.
  37451. * @param {ol.geom.LineString} line LineString geometry.
  37452. * @param {Array.<*>} objectStack Node stack.
  37453. * @private
  37454. */
  37455. ol.format.GML3.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) {
  37456. var child = this.GEOMETRY_NODE_FACTORY_(line, objectStack);
  37457. if (child) {
  37458. node.appendChild(child);
  37459. this.writeCurveOrLineString_(child, line, objectStack);
  37460. }
  37461. };
  37462. /**
  37463. * @param {Node} node Node.
  37464. * @param {ol.geom.Polygon} polygon Polygon geometry.
  37465. * @param {Array.<*>} objectStack Node stack.
  37466. * @private
  37467. */
  37468. ol.format.GML3.prototype.writeSurfacePatches_ = function(node, polygon, objectStack) {
  37469. var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch');
  37470. node.appendChild(child);
  37471. this.writeSurfaceOrPolygon_(child, polygon, objectStack);
  37472. };
  37473. /**
  37474. * @param {Node} node Node.
  37475. * @param {ol.geom.LineString} line LineString geometry.
  37476. * @param {Array.<*>} objectStack Node stack.
  37477. * @private
  37478. */
  37479. ol.format.GML3.prototype.writeCurveSegments_ = function(node, line, objectStack) {
  37480. var child = ol.xml.createElementNS(node.namespaceURI,
  37481. 'LineStringSegment');
  37482. node.appendChild(child);
  37483. this.writeCurveOrLineString_(child, line, objectStack);
  37484. };
  37485. /**
  37486. * @param {Node} node Node.
  37487. * @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
  37488. * @param {Array.<*>} objectStack Node stack.
  37489. */
  37490. ol.format.GML3.prototype.writeGeometryElement = function(node, geometry, objectStack) {
  37491. var context = /** @type {olx.format.WriteOptions} */ (objectStack[objectStack.length - 1]);
  37492. var item = ol.obj.assign({}, context);
  37493. item.node = node;
  37494. var value;
  37495. if (Array.isArray(geometry)) {
  37496. if (context.dataProjection) {
  37497. value = ol.proj.transformExtent(
  37498. geometry, context.featureProjection, context.dataProjection);
  37499. } else {
  37500. value = geometry;
  37501. }
  37502. } else {
  37503. value =
  37504. ol.format.Feature.transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
  37505. }
  37506. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  37507. (item), ol.format.GML3.GEOMETRY_SERIALIZERS_,
  37508. this.GEOMETRY_NODE_FACTORY_, [value],
  37509. objectStack, undefined, this);
  37510. };
  37511. /**
  37512. * @param {Node} node Node.
  37513. * @param {ol.Feature} feature Feature.
  37514. * @param {Array.<*>} objectStack Node stack.
  37515. */
  37516. ol.format.GML3.prototype.writeFeatureElement = function(node, feature, objectStack) {
  37517. var fid = feature.getId();
  37518. if (fid) {
  37519. node.setAttribute('fid', fid);
  37520. }
  37521. var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  37522. var featureNS = context['featureNS'];
  37523. var geometryName = feature.getGeometryName();
  37524. if (!context.serializers) {
  37525. context.serializers = {};
  37526. context.serializers[featureNS] = {};
  37527. }
  37528. var properties = feature.getProperties();
  37529. var keys = [], values = [];
  37530. for (var key in properties) {
  37531. var value = properties[key];
  37532. if (value !== null) {
  37533. keys.push(key);
  37534. values.push(value);
  37535. if (key == geometryName || value instanceof ol.geom.Geometry) {
  37536. if (!(key in context.serializers[featureNS])) {
  37537. context.serializers[featureNS][key] = ol.xml.makeChildAppender(
  37538. this.writeGeometryElement, this);
  37539. }
  37540. } else {
  37541. if (!(key in context.serializers[featureNS])) {
  37542. context.serializers[featureNS][key] = ol.xml.makeChildAppender(
  37543. ol.format.XSD.writeStringTextNode);
  37544. }
  37545. }
  37546. }
  37547. }
  37548. var item = ol.obj.assign({}, context);
  37549. item.node = node;
  37550. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  37551. (item), context.serializers,
  37552. ol.xml.makeSimpleNodeFactory(undefined, featureNS),
  37553. values,
  37554. objectStack, keys);
  37555. };
  37556. /**
  37557. * @param {Node} node Node.
  37558. * @param {Array.<ol.Feature>} features Features.
  37559. * @param {Array.<*>} objectStack Node stack.
  37560. * @private
  37561. */
  37562. ol.format.GML3.prototype.writeFeatureMembers_ = function(node, features, objectStack) {
  37563. var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  37564. var featureType = context['featureType'];
  37565. var featureNS = context['featureNS'];
  37566. var serializers = {};
  37567. serializers[featureNS] = {};
  37568. serializers[featureNS][featureType] = ol.xml.makeChildAppender(
  37569. this.writeFeatureElement, this);
  37570. var item = ol.obj.assign({}, context);
  37571. item.node = node;
  37572. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  37573. (item),
  37574. serializers,
  37575. ol.xml.makeSimpleNodeFactory(featureType, featureNS), features,
  37576. objectStack);
  37577. };
  37578. /**
  37579. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  37580. * @private
  37581. */
  37582. ol.format.GML3.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
  37583. 'http://www.opengis.net/gml': {
  37584. 'surfaceMember': ol.xml.makeChildAppender(
  37585. ol.format.GML3.prototype.writeSurfaceOrPolygonMember_),
  37586. 'polygonMember': ol.xml.makeChildAppender(
  37587. ol.format.GML3.prototype.writeSurfaceOrPolygonMember_)
  37588. }
  37589. };
  37590. /**
  37591. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  37592. * @private
  37593. */
  37594. ol.format.GML3.POINTMEMBER_SERIALIZERS_ = {
  37595. 'http://www.opengis.net/gml': {
  37596. 'pointMember': ol.xml.makeChildAppender(
  37597. ol.format.GML3.prototype.writePointMember_)
  37598. }
  37599. };
  37600. /**
  37601. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  37602. * @private
  37603. */
  37604. ol.format.GML3.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
  37605. 'http://www.opengis.net/gml': {
  37606. 'lineStringMember': ol.xml.makeChildAppender(
  37607. ol.format.GML3.prototype.writeLineStringOrCurveMember_),
  37608. 'curveMember': ol.xml.makeChildAppender(
  37609. ol.format.GML3.prototype.writeLineStringOrCurveMember_)
  37610. }
  37611. };
  37612. /**
  37613. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  37614. * @private
  37615. */
  37616. ol.format.GML3.RING_SERIALIZERS_ = {
  37617. 'http://www.opengis.net/gml': {
  37618. 'exterior': ol.xml.makeChildAppender(ol.format.GML3.prototype.writeRing_),
  37619. 'interior': ol.xml.makeChildAppender(ol.format.GML3.prototype.writeRing_)
  37620. }
  37621. };
  37622. /**
  37623. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  37624. * @private
  37625. */
  37626. ol.format.GML3.GEOMETRY_SERIALIZERS_ = {
  37627. 'http://www.opengis.net/gml': {
  37628. 'Curve': ol.xml.makeChildAppender(
  37629. ol.format.GML3.prototype.writeCurveOrLineString_),
  37630. 'MultiCurve': ol.xml.makeChildAppender(
  37631. ol.format.GML3.prototype.writeMultiCurveOrLineString_),
  37632. 'Point': ol.xml.makeChildAppender(ol.format.GML3.prototype.writePoint_),
  37633. 'MultiPoint': ol.xml.makeChildAppender(
  37634. ol.format.GML3.prototype.writeMultiPoint_),
  37635. 'LineString': ol.xml.makeChildAppender(
  37636. ol.format.GML3.prototype.writeCurveOrLineString_),
  37637. 'MultiLineString': ol.xml.makeChildAppender(
  37638. ol.format.GML3.prototype.writeMultiCurveOrLineString_),
  37639. 'LinearRing': ol.xml.makeChildAppender(
  37640. ol.format.GML3.prototype.writeLinearRing_),
  37641. 'Polygon': ol.xml.makeChildAppender(
  37642. ol.format.GML3.prototype.writeSurfaceOrPolygon_),
  37643. 'MultiPolygon': ol.xml.makeChildAppender(
  37644. ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_),
  37645. 'Surface': ol.xml.makeChildAppender(
  37646. ol.format.GML3.prototype.writeSurfaceOrPolygon_),
  37647. 'MultiSurface': ol.xml.makeChildAppender(
  37648. ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_),
  37649. 'Envelope': ol.xml.makeChildAppender(
  37650. ol.format.GML3.prototype.writeEnvelope)
  37651. }
  37652. };
  37653. /**
  37654. * @const
  37655. * @type {Object.<string, string>}
  37656. * @private
  37657. */
  37658. ol.format.GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
  37659. 'MultiLineString': 'lineStringMember',
  37660. 'MultiCurve': 'curveMember',
  37661. 'MultiPolygon': 'polygonMember',
  37662. 'MultiSurface': 'surfaceMember'
  37663. };
  37664. /**
  37665. * @const
  37666. * @param {*} value Value.
  37667. * @param {Array.<*>} objectStack Object stack.
  37668. * @param {string=} opt_nodeName Node name.
  37669. * @return {Node|undefined} Node.
  37670. * @private
  37671. */
  37672. ol.format.GML3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  37673. var parentNode = objectStack[objectStack.length - 1].node;
  37674. return ol.xml.createElementNS('http://www.opengis.net/gml',
  37675. ol.format.GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]);
  37676. };
  37677. /**
  37678. * @const
  37679. * @param {*} value Value.
  37680. * @param {Array.<*>} objectStack Object stack.
  37681. * @param {string=} opt_nodeName Node name.
  37682. * @return {Node|undefined} Node.
  37683. * @private
  37684. */
  37685. ol.format.GML3.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  37686. var context = objectStack[objectStack.length - 1];
  37687. var multiSurface = context['multiSurface'];
  37688. var surface = context['surface'];
  37689. var curve = context['curve'];
  37690. var multiCurve = context['multiCurve'];
  37691. var nodeName;
  37692. if (!Array.isArray(value)) {
  37693. nodeName = /** @type {ol.geom.Geometry} */ (value).getType();
  37694. if (nodeName === 'MultiPolygon' && multiSurface === true) {
  37695. nodeName = 'MultiSurface';
  37696. } else if (nodeName === 'Polygon' && surface === true) {
  37697. nodeName = 'Surface';
  37698. } else if (nodeName === 'LineString' && curve === true) {
  37699. nodeName = 'Curve';
  37700. } else if (nodeName === 'MultiLineString' && multiCurve === true) {
  37701. nodeName = 'MultiCurve';
  37702. }
  37703. } else {
  37704. nodeName = 'Envelope';
  37705. }
  37706. return ol.xml.createElementNS('http://www.opengis.net/gml',
  37707. nodeName);
  37708. };
  37709. /**
  37710. * Encode a geometry in GML 3.1.1 Simple Features.
  37711. *
  37712. * @param {ol.geom.Geometry} geometry Geometry.
  37713. * @param {olx.format.WriteOptions=} opt_options Options.
  37714. * @return {Node} Node.
  37715. * @override
  37716. * @api
  37717. */
  37718. ol.format.GML3.prototype.writeGeometryNode = function(geometry, opt_options) {
  37719. opt_options = this.adaptOptions(opt_options);
  37720. var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom');
  37721. var context = {node: geom, hasZ: this.hasZ, srsName: this.srsName,
  37722. curve: this.curve_, surface: this.surface_,
  37723. multiSurface: this.multiSurface_, multiCurve: this.multiCurve_};
  37724. if (opt_options) {
  37725. ol.obj.assign(context, opt_options);
  37726. }
  37727. this.writeGeometryElement(geom, geometry, [context]);
  37728. return geom;
  37729. };
  37730. /**
  37731. * Encode an array of features in GML 3.1.1 Simple Features.
  37732. *
  37733. * @function
  37734. * @param {Array.<ol.Feature>} features Features.
  37735. * @param {olx.format.WriteOptions=} opt_options Options.
  37736. * @return {string} Result.
  37737. * @api
  37738. */
  37739. ol.format.GML3.prototype.writeFeatures;
  37740. /**
  37741. * Encode an array of features in the GML 3.1.1 format as an XML node.
  37742. *
  37743. * @param {Array.<ol.Feature>} features Features.
  37744. * @param {olx.format.WriteOptions=} opt_options Options.
  37745. * @return {Node} Node.
  37746. * @override
  37747. * @api
  37748. */
  37749. ol.format.GML3.prototype.writeFeaturesNode = function(features, opt_options) {
  37750. opt_options = this.adaptOptions(opt_options);
  37751. var node = ol.xml.createElementNS('http://www.opengis.net/gml',
  37752. 'featureMembers');
  37753. ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
  37754. 'xsi:schemaLocation', this.schemaLocation);
  37755. var context = {
  37756. srsName: this.srsName,
  37757. hasZ: this.hasZ,
  37758. curve: this.curve_,
  37759. surface: this.surface_,
  37760. multiSurface: this.multiSurface_,
  37761. multiCurve: this.multiCurve_,
  37762. featureNS: this.featureNS,
  37763. featureType: this.featureType
  37764. };
  37765. if (opt_options) {
  37766. ol.obj.assign(context, opt_options);
  37767. }
  37768. this.writeFeatureMembers_(node, features, [context]);
  37769. return node;
  37770. };
  37771. goog.provide('ol.format.GML');
  37772. goog.require('ol.format.GML3');
  37773. /**
  37774. * @classdesc
  37775. * Feature format for reading and writing data in the GML format
  37776. * version 3.1.1.
  37777. * Currently only supports GML 3.1.1 Simple Features profile.
  37778. *
  37779. * @constructor
  37780. * @param {olx.format.GMLOptions=} opt_options
  37781. * Optional configuration object.
  37782. * @extends {ol.format.GMLBase}
  37783. * @api
  37784. */
  37785. ol.format.GML = ol.format.GML3;
  37786. /**
  37787. * Encode an array of features in GML 3.1.1 Simple Features.
  37788. *
  37789. * @function
  37790. * @param {Array.<ol.Feature>} features Features.
  37791. * @param {olx.format.WriteOptions=} opt_options Options.
  37792. * @return {string} Result.
  37793. * @api
  37794. */
  37795. ol.format.GML.prototype.writeFeatures;
  37796. /**
  37797. * Encode an array of features in the GML 3.1.1 format as an XML node.
  37798. *
  37799. * @function
  37800. * @param {Array.<ol.Feature>} features Features.
  37801. * @param {olx.format.WriteOptions=} opt_options Options.
  37802. * @return {Node} Node.
  37803. * @api
  37804. */
  37805. ol.format.GML.prototype.writeFeaturesNode;
  37806. goog.provide('ol.format.GML2');
  37807. goog.require('ol');
  37808. goog.require('ol.extent');
  37809. goog.require('ol.format.Feature');
  37810. goog.require('ol.format.GMLBase');
  37811. goog.require('ol.format.XSD');
  37812. goog.require('ol.geom.Geometry');
  37813. goog.require('ol.obj');
  37814. goog.require('ol.proj');
  37815. goog.require('ol.xml');
  37816. /**
  37817. * @classdesc
  37818. * Feature format for reading and writing data in the GML format,
  37819. * version 2.1.2.
  37820. *
  37821. * @constructor
  37822. * @param {olx.format.GMLOptions=} opt_options Optional configuration object.
  37823. * @extends {ol.format.GMLBase}
  37824. * @api
  37825. */
  37826. ol.format.GML2 = function(opt_options) {
  37827. var options = /** @type {olx.format.GMLOptions} */
  37828. (opt_options ? opt_options : {});
  37829. ol.format.GMLBase.call(this, options);
  37830. this.FEATURE_COLLECTION_PARSERS[ol.format.GMLBase.GMLNS][
  37831. 'featureMember'] =
  37832. ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readFeaturesInternal);
  37833. /**
  37834. * @inheritDoc
  37835. */
  37836. this.schemaLocation = options.schemaLocation ?
  37837. options.schemaLocation : ol.format.GML2.schemaLocation_;
  37838. };
  37839. ol.inherits(ol.format.GML2, ol.format.GMLBase);
  37840. /**
  37841. * @const
  37842. * @type {string}
  37843. * @private
  37844. */
  37845. ol.format.GML2.schemaLocation_ = ol.format.GMLBase.GMLNS +
  37846. ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
  37847. /**
  37848. * @param {Node} node Node.
  37849. * @param {Array.<*>} objectStack Object stack.
  37850. * @private
  37851. * @return {Array.<number>|undefined} Flat coordinates.
  37852. */
  37853. ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
  37854. var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
  37855. var context = /** @type {ol.XmlNodeStackItem} */ (objectStack[0]);
  37856. var containerSrs = context['srsName'];
  37857. var axisOrientation = 'enu';
  37858. if (containerSrs) {
  37859. var proj = ol.proj.get(containerSrs);
  37860. if (proj) {
  37861. axisOrientation = proj.getAxisOrientation();
  37862. }
  37863. }
  37864. var coordsGroups = s.trim().split(/\s+/);
  37865. var x, y, z;
  37866. var flatCoordinates = [];
  37867. for (var i = 0, ii = coordsGroups.length; i < ii; i++) {
  37868. var coords = coordsGroups[i].split(/,+/);
  37869. x = parseFloat(coords[0]);
  37870. y = parseFloat(coords[1]);
  37871. z = (coords.length === 3) ? parseFloat(coords[2]) : 0;
  37872. if (axisOrientation.substr(0, 2) === 'en') {
  37873. flatCoordinates.push(x, y, z);
  37874. } else {
  37875. flatCoordinates.push(y, x, z);
  37876. }
  37877. }
  37878. return flatCoordinates;
  37879. };
  37880. /**
  37881. * @param {Node} node Node.
  37882. * @param {Array.<*>} objectStack Object stack.
  37883. * @private
  37884. * @return {ol.Extent|undefined} Envelope.
  37885. */
  37886. ol.format.GML2.prototype.readBox_ = function(node, objectStack) {
  37887. /** @type {Array.<number>} */
  37888. var flatCoordinates = ol.xml.pushParseAndPop([null],
  37889. this.BOX_PARSERS_, node, objectStack, this);
  37890. return ol.extent.createOrUpdate(flatCoordinates[1][0],
  37891. flatCoordinates[1][1], flatCoordinates[1][3],
  37892. flatCoordinates[1][4]);
  37893. };
  37894. /**
  37895. * @param {Node} node Node.
  37896. * @param {Array.<*>} objectStack Object stack.
  37897. * @private
  37898. */
  37899. ol.format.GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) {
  37900. /** @type {Array.<number>|undefined} */
  37901. var flatLinearRing = ol.xml.pushParseAndPop(undefined,
  37902. this.RING_PARSERS, node, objectStack, this);
  37903. if (flatLinearRing) {
  37904. var flatLinearRings = /** @type {Array.<Array.<number>>} */
  37905. (objectStack[objectStack.length - 1]);
  37906. flatLinearRings.push(flatLinearRing);
  37907. }
  37908. };
  37909. /**
  37910. * @param {Node} node Node.
  37911. * @param {Array.<*>} objectStack Object stack.
  37912. * @private
  37913. */
  37914. ol.format.GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) {
  37915. /** @type {Array.<number>|undefined} */
  37916. var flatLinearRing = ol.xml.pushParseAndPop(undefined,
  37917. this.RING_PARSERS, node, objectStack, this);
  37918. if (flatLinearRing) {
  37919. var flatLinearRings = /** @type {Array.<Array.<number>>} */
  37920. (objectStack[objectStack.length - 1]);
  37921. flatLinearRings[0] = flatLinearRing;
  37922. }
  37923. };
  37924. /**
  37925. * @const
  37926. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37927. * @private
  37928. */
  37929. ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
  37930. 'http://www.opengis.net/gml': {
  37931. 'coordinates': ol.xml.makeReplacer(
  37932. ol.format.GML2.prototype.readFlatCoordinates_)
  37933. }
  37934. };
  37935. /**
  37936. * @const
  37937. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37938. * @private
  37939. */
  37940. ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
  37941. 'http://www.opengis.net/gml': {
  37942. 'innerBoundaryIs': ol.format.GML2.prototype.innerBoundaryIsParser_,
  37943. 'outerBoundaryIs': ol.format.GML2.prototype.outerBoundaryIsParser_
  37944. }
  37945. };
  37946. /**
  37947. * @const
  37948. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37949. * @private
  37950. */
  37951. ol.format.GML2.prototype.BOX_PARSERS_ = {
  37952. 'http://www.opengis.net/gml': {
  37953. 'coordinates': ol.xml.makeArrayPusher(
  37954. ol.format.GML2.prototype.readFlatCoordinates_)
  37955. }
  37956. };
  37957. /**
  37958. * @const
  37959. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  37960. * @private
  37961. */
  37962. ol.format.GML2.prototype.GEOMETRY_PARSERS_ = {
  37963. 'http://www.opengis.net/gml': {
  37964. 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint),
  37965. 'MultiPoint': ol.xml.makeReplacer(
  37966. ol.format.GMLBase.prototype.readMultiPoint),
  37967. 'LineString': ol.xml.makeReplacer(
  37968. ol.format.GMLBase.prototype.readLineString),
  37969. 'MultiLineString': ol.xml.makeReplacer(
  37970. ol.format.GMLBase.prototype.readMultiLineString),
  37971. 'LinearRing': ol.xml.makeReplacer(
  37972. ol.format.GMLBase.prototype.readLinearRing),
  37973. 'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon),
  37974. 'MultiPolygon': ol.xml.makeReplacer(
  37975. ol.format.GMLBase.prototype.readMultiPolygon),
  37976. 'Box': ol.xml.makeReplacer(ol.format.GML2.prototype.readBox_)
  37977. }
  37978. };
  37979. /**
  37980. * @const
  37981. * @param {*} value Value.
  37982. * @param {Array.<*>} objectStack Object stack.
  37983. * @param {string=} opt_nodeName Node name.
  37984. * @return {Node|undefined} Node.
  37985. * @private
  37986. */
  37987. ol.format.GML2.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  37988. var context = objectStack[objectStack.length - 1];
  37989. var multiSurface = context['multiSurface'];
  37990. var surface = context['surface'];
  37991. var multiCurve = context['multiCurve'];
  37992. var nodeName;
  37993. if (!Array.isArray(value)) {
  37994. nodeName = /** @type {ol.geom.Geometry} */ (value).getType();
  37995. if (nodeName === 'MultiPolygon' && multiSurface === true) {
  37996. nodeName = 'MultiSurface';
  37997. } else if (nodeName === 'Polygon' && surface === true) {
  37998. nodeName = 'Surface';
  37999. } else if (nodeName === 'MultiLineString' && multiCurve === true) {
  38000. nodeName = 'MultiCurve';
  38001. }
  38002. } else {
  38003. nodeName = 'Envelope';
  38004. }
  38005. return ol.xml.createElementNS('http://www.opengis.net/gml',
  38006. nodeName);
  38007. };
  38008. /**
  38009. * @param {Node} node Node.
  38010. * @param {ol.Feature} feature Feature.
  38011. * @param {Array.<*>} objectStack Node stack.
  38012. */
  38013. ol.format.GML2.prototype.writeFeatureElement = function(node, feature, objectStack) {
  38014. var fid = feature.getId();
  38015. if (fid) {
  38016. node.setAttribute('fid', fid);
  38017. }
  38018. var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  38019. var featureNS = context['featureNS'];
  38020. var geometryName = feature.getGeometryName();
  38021. if (!context.serializers) {
  38022. context.serializers = {};
  38023. context.serializers[featureNS] = {};
  38024. }
  38025. var properties = feature.getProperties();
  38026. var keys = [], values = [];
  38027. for (var key in properties) {
  38028. var value = properties[key];
  38029. if (value !== null) {
  38030. keys.push(key);
  38031. values.push(value);
  38032. if (key == geometryName || value instanceof ol.geom.Geometry) {
  38033. if (!(key in context.serializers[featureNS])) {
  38034. context.serializers[featureNS][key] = ol.xml.makeChildAppender(
  38035. this.writeGeometryElement, this);
  38036. }
  38037. } else {
  38038. if (!(key in context.serializers[featureNS])) {
  38039. context.serializers[featureNS][key] = ol.xml.makeChildAppender(
  38040. ol.format.XSD.writeStringTextNode);
  38041. }
  38042. }
  38043. }
  38044. }
  38045. var item = ol.obj.assign({}, context);
  38046. item.node = node;
  38047. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  38048. (item), context.serializers,
  38049. ol.xml.makeSimpleNodeFactory(undefined, featureNS),
  38050. values,
  38051. objectStack, keys);
  38052. };
  38053. /**
  38054. * @param {Node} node Node.
  38055. * @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
  38056. * @param {Array.<*>} objectStack Node stack.
  38057. */
  38058. ol.format.GML2.prototype.writeGeometryElement = function(node, geometry, objectStack) {
  38059. var context = /** @type {olx.format.WriteOptions} */ (objectStack[objectStack.length - 1]);
  38060. var item = ol.obj.assign({}, context);
  38061. item.node = node;
  38062. var value;
  38063. if (Array.isArray(geometry)) {
  38064. if (context.dataProjection) {
  38065. value = ol.proj.transformExtent(
  38066. geometry, context.featureProjection, context.dataProjection);
  38067. } else {
  38068. value = geometry;
  38069. }
  38070. } else {
  38071. value =
  38072. ol.format.Feature.transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
  38073. }
  38074. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  38075. (item), ol.format.GML2.GEOMETRY_SERIALIZERS_,
  38076. this.GEOMETRY_NODE_FACTORY_, [value],
  38077. objectStack, undefined, this);
  38078. };
  38079. /**
  38080. * @param {Node} node Node.
  38081. * @param {ol.geom.LineString} geometry LineString geometry.
  38082. * @param {Array.<*>} objectStack Node stack.
  38083. * @private
  38084. */
  38085. ol.format.GML2.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) {
  38086. var context = objectStack[objectStack.length - 1];
  38087. var srsName = context['srsName'];
  38088. if (node.nodeName !== 'LineStringSegment' && srsName) {
  38089. node.setAttribute('srsName', srsName);
  38090. }
  38091. if (node.nodeName === 'LineString' ||
  38092. node.nodeName === 'LineStringSegment') {
  38093. var coordinates = this.createCoordinatesNode_(node.namespaceURI);
  38094. node.appendChild(coordinates);
  38095. this.writeCoordinates_(coordinates, geometry, objectStack);
  38096. } else if (node.nodeName === 'Curve') {
  38097. var segments = ol.xml.createElementNS(node.namespaceURI, 'segments');
  38098. node.appendChild(segments);
  38099. this.writeCurveSegments_(segments,
  38100. geometry, objectStack);
  38101. }
  38102. };
  38103. /**
  38104. * @param {string} namespaceURI XML namespace.
  38105. * @returns {Node} coordinates node.
  38106. * @private
  38107. */
  38108. ol.format.GML2.prototype.createCoordinatesNode_ = function(namespaceURI) {
  38109. var coordinates = ol.xml.createElementNS(namespaceURI, 'coordinates');
  38110. coordinates.setAttribute('decimal', '.');
  38111. coordinates.setAttribute('cs', ',');
  38112. coordinates.setAttribute('ts', ' ');
  38113. return coordinates;
  38114. };
  38115. /**
  38116. * @param {Node} node Node.
  38117. * @param {ol.geom.LineString|ol.geom.LinearRing} value Geometry.
  38118. * @param {Array.<*>} objectStack Node stack.
  38119. * @private
  38120. */
  38121. ol.format.GML2.prototype.writeCoordinates_ = function(node, value, objectStack) {
  38122. var context = objectStack[objectStack.length - 1];
  38123. var hasZ = context['hasZ'];
  38124. var srsName = context['srsName'];
  38125. // only 2d for simple features profile
  38126. var points = value.getCoordinates();
  38127. var len = points.length;
  38128. var parts = new Array(len);
  38129. var point;
  38130. for (var i = 0; i < len; ++i) {
  38131. point = points[i];
  38132. parts[i] = this.getCoords_(point, srsName, hasZ);
  38133. }
  38134. ol.format.XSD.writeStringTextNode(node, parts.join(' '));
  38135. };
  38136. /**
  38137. * @param {Node} node Node.
  38138. * @param {ol.geom.LineString} line LineString geometry.
  38139. * @param {Array.<*>} objectStack Node stack.
  38140. * @private
  38141. */
  38142. ol.format.GML2.prototype.writeCurveSegments_ = function(node, line, objectStack) {
  38143. var child = ol.xml.createElementNS(node.namespaceURI,
  38144. 'LineStringSegment');
  38145. node.appendChild(child);
  38146. this.writeCurveOrLineString_(child, line, objectStack);
  38147. };
  38148. /**
  38149. * @param {Node} node Node.
  38150. * @param {ol.geom.Polygon} geometry Polygon geometry.
  38151. * @param {Array.<*>} objectStack Node stack.
  38152. * @private
  38153. */
  38154. ol.format.GML2.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) {
  38155. var context = objectStack[objectStack.length - 1];
  38156. var hasZ = context['hasZ'];
  38157. var srsName = context['srsName'];
  38158. if (node.nodeName !== 'PolygonPatch' && srsName) {
  38159. node.setAttribute('srsName', srsName);
  38160. }
  38161. if (node.nodeName === 'Polygon' || node.nodeName === 'PolygonPatch') {
  38162. var rings = geometry.getLinearRings();
  38163. ol.xml.pushSerializeAndPop(
  38164. {node: node, hasZ: hasZ, srsName: srsName},
  38165. ol.format.GML2.RING_SERIALIZERS_,
  38166. this.RING_NODE_FACTORY_,
  38167. rings, objectStack, undefined, this);
  38168. } else if (node.nodeName === 'Surface') {
  38169. var patches = ol.xml.createElementNS(node.namespaceURI, 'patches');
  38170. node.appendChild(patches);
  38171. this.writeSurfacePatches_(
  38172. patches, geometry, objectStack);
  38173. }
  38174. };
  38175. /**
  38176. * @param {*} value Value.
  38177. * @param {Array.<*>} objectStack Object stack.
  38178. * @param {string=} opt_nodeName Node name.
  38179. * @return {Node} Node.
  38180. * @private
  38181. */
  38182. ol.format.GML2.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  38183. var context = objectStack[objectStack.length - 1];
  38184. var parentNode = context.node;
  38185. var exteriorWritten = context['exteriorWritten'];
  38186. if (exteriorWritten === undefined) {
  38187. context['exteriorWritten'] = true;
  38188. }
  38189. return ol.xml.createElementNS(parentNode.namespaceURI,
  38190. exteriorWritten !== undefined ? 'innerBoundaryIs' : 'outerBoundaryIs');
  38191. };
  38192. /**
  38193. * @param {Node} node Node.
  38194. * @param {ol.geom.Polygon} polygon Polygon geometry.
  38195. * @param {Array.<*>} objectStack Node stack.
  38196. * @private
  38197. */
  38198. ol.format.GML2.prototype.writeSurfacePatches_ = function(node, polygon, objectStack) {
  38199. var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch');
  38200. node.appendChild(child);
  38201. this.writeSurfaceOrPolygon_(child, polygon, objectStack);
  38202. };
  38203. /**
  38204. * @param {Node} node Node.
  38205. * @param {ol.geom.LinearRing} ring LinearRing geometry.
  38206. * @param {Array.<*>} objectStack Node stack.
  38207. * @private
  38208. */
  38209. ol.format.GML2.prototype.writeRing_ = function(node, ring, objectStack) {
  38210. var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing');
  38211. node.appendChild(linearRing);
  38212. this.writeLinearRing_(linearRing, ring, objectStack);
  38213. };
  38214. /**
  38215. * @param {Array.<number>} point Point geometry.
  38216. * @param {string=} opt_srsName Optional srsName
  38217. * @param {boolean=} opt_hasZ whether the geometry has a Z coordinate (is 3D) or not.
  38218. * @return {string} The coords string.
  38219. * @private
  38220. */
  38221. ol.format.GML2.prototype.getCoords_ = function(point, opt_srsName, opt_hasZ) {
  38222. var axisOrientation = 'enu';
  38223. if (opt_srsName) {
  38224. axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation();
  38225. }
  38226. var coords = ((axisOrientation.substr(0, 2) === 'en') ?
  38227. point[0] + ',' + point[1] :
  38228. point[1] + ',' + point[0]);
  38229. if (opt_hasZ) {
  38230. // For newly created points, Z can be undefined.
  38231. var z = point[2] || 0;
  38232. coords += ',' + z;
  38233. }
  38234. return coords;
  38235. };
  38236. /**
  38237. * @param {Node} node Node.
  38238. * @param {ol.geom.MultiLineString} geometry MultiLineString geometry.
  38239. * @param {Array.<*>} objectStack Node stack.
  38240. * @private
  38241. */
  38242. ol.format.GML2.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) {
  38243. var context = objectStack[objectStack.length - 1];
  38244. var hasZ = context['hasZ'];
  38245. var srsName = context['srsName'];
  38246. var curve = context['curve'];
  38247. if (srsName) {
  38248. node.setAttribute('srsName', srsName);
  38249. }
  38250. var lines = geometry.getLineStrings();
  38251. ol.xml.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
  38252. ol.format.GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
  38253. this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
  38254. objectStack, undefined, this);
  38255. };
  38256. /**
  38257. * @param {Node} node Node.
  38258. * @param {ol.geom.Point} geometry Point geometry.
  38259. * @param {Array.<*>} objectStack Node stack.
  38260. * @private
  38261. */
  38262. ol.format.GML2.prototype.writePoint_ = function(node, geometry, objectStack) {
  38263. var context = objectStack[objectStack.length - 1];
  38264. var hasZ = context['hasZ'];
  38265. var srsName = context['srsName'];
  38266. if (srsName) {
  38267. node.setAttribute('srsName', srsName);
  38268. }
  38269. var coordinates = this.createCoordinatesNode_(node.namespaceURI);
  38270. node.appendChild(coordinates);
  38271. var point = geometry.getCoordinates();
  38272. var coord = this.getCoords_(point, srsName, hasZ);
  38273. ol.format.XSD.writeStringTextNode(coordinates, coord);
  38274. };
  38275. /**
  38276. * @param {Node} node Node.
  38277. * @param {ol.geom.MultiPoint} geometry MultiPoint geometry.
  38278. * @param {Array.<*>} objectStack Node stack.
  38279. * @private
  38280. */
  38281. ol.format.GML2.prototype.writeMultiPoint_ = function(node, geometry,
  38282. objectStack) {
  38283. var context = objectStack[objectStack.length - 1];
  38284. var hasZ = context['hasZ'];
  38285. var srsName = context['srsName'];
  38286. if (srsName) {
  38287. node.setAttribute('srsName', srsName);
  38288. }
  38289. var points = geometry.getPoints();
  38290. ol.xml.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
  38291. ol.format.GML2.POINTMEMBER_SERIALIZERS_,
  38292. ol.xml.makeSimpleNodeFactory('pointMember'), points,
  38293. objectStack, undefined, this);
  38294. };
  38295. /**
  38296. * @param {Node} node Node.
  38297. * @param {ol.geom.Point} point Point geometry.
  38298. * @param {Array.<*>} objectStack Node stack.
  38299. * @private
  38300. */
  38301. ol.format.GML2.prototype.writePointMember_ = function(node, point, objectStack) {
  38302. var child = ol.xml.createElementNS(node.namespaceURI, 'Point');
  38303. node.appendChild(child);
  38304. this.writePoint_(child, point, objectStack);
  38305. };
  38306. /**
  38307. * @param {Node} node Node.
  38308. * @param {ol.geom.LineString} line LineString geometry.
  38309. * @param {Array.<*>} objectStack Node stack.
  38310. * @private
  38311. */
  38312. ol.format.GML2.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) {
  38313. var child = this.GEOMETRY_NODE_FACTORY_(line, objectStack);
  38314. if (child) {
  38315. node.appendChild(child);
  38316. this.writeCurveOrLineString_(child, line, objectStack);
  38317. }
  38318. };
  38319. /**
  38320. * @param {Node} node Node.
  38321. * @param {ol.geom.LinearRing} geometry LinearRing geometry.
  38322. * @param {Array.<*>} objectStack Node stack.
  38323. * @private
  38324. */
  38325. ol.format.GML2.prototype.writeLinearRing_ = function(node, geometry, objectStack) {
  38326. var context = objectStack[objectStack.length - 1];
  38327. var srsName = context['srsName'];
  38328. if (srsName) {
  38329. node.setAttribute('srsName', srsName);
  38330. }
  38331. var coordinates = this.createCoordinatesNode_(node.namespaceURI);
  38332. node.appendChild(coordinates);
  38333. this.writeCoordinates_(coordinates, geometry, objectStack);
  38334. };
  38335. /**
  38336. * @param {Node} node Node.
  38337. * @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry.
  38338. * @param {Array.<*>} objectStack Node stack.
  38339. * @private
  38340. */
  38341. ol.format.GML2.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) {
  38342. var context = objectStack[objectStack.length - 1];
  38343. var hasZ = context['hasZ'];
  38344. var srsName = context['srsName'];
  38345. var surface = context['surface'];
  38346. if (srsName) {
  38347. node.setAttribute('srsName', srsName);
  38348. }
  38349. var polygons = geometry.getPolygons();
  38350. ol.xml.pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
  38351. ol.format.GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
  38352. this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
  38353. objectStack, undefined, this);
  38354. };
  38355. /**
  38356. * @param {Node} node Node.
  38357. * @param {ol.geom.Polygon} polygon Polygon geometry.
  38358. * @param {Array.<*>} objectStack Node stack.
  38359. * @private
  38360. */
  38361. ol.format.GML2.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) {
  38362. var child = this.GEOMETRY_NODE_FACTORY_(
  38363. polygon, objectStack);
  38364. if (child) {
  38365. node.appendChild(child);
  38366. this.writeSurfaceOrPolygon_(child, polygon, objectStack);
  38367. }
  38368. };
  38369. /**
  38370. * @param {Node} node Node.
  38371. * @param {ol.Extent} extent Extent.
  38372. * @param {Array.<*>} objectStack Node stack.
  38373. * @private
  38374. */
  38375. ol.format.GML2.prototype.writeEnvelope = function(node, extent, objectStack) {
  38376. var context = objectStack[objectStack.length - 1];
  38377. var srsName = context['srsName'];
  38378. if (srsName) {
  38379. node.setAttribute('srsName', srsName);
  38380. }
  38381. var keys = ['lowerCorner', 'upperCorner'];
  38382. var values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
  38383. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  38384. ({node: node}), ol.format.GML2.ENVELOPE_SERIALIZERS_,
  38385. ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  38386. values,
  38387. objectStack, keys, this);
  38388. };
  38389. /**
  38390. * @const
  38391. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  38392. * @private
  38393. */
  38394. ol.format.GML2.GEOMETRY_SERIALIZERS_ = {
  38395. 'http://www.opengis.net/gml': {
  38396. 'Curve': ol.xml.makeChildAppender(
  38397. ol.format.GML2.prototype.writeCurveOrLineString_),
  38398. 'MultiCurve': ol.xml.makeChildAppender(
  38399. ol.format.GML2.prototype.writeMultiCurveOrLineString_),
  38400. 'Point': ol.xml.makeChildAppender(ol.format.GML2.prototype.writePoint_),
  38401. 'MultiPoint': ol.xml.makeChildAppender(
  38402. ol.format.GML2.prototype.writeMultiPoint_),
  38403. 'LineString': ol.xml.makeChildAppender(
  38404. ol.format.GML2.prototype.writeCurveOrLineString_),
  38405. 'MultiLineString': ol.xml.makeChildAppender(
  38406. ol.format.GML2.prototype.writeMultiCurveOrLineString_),
  38407. 'LinearRing': ol.xml.makeChildAppender(
  38408. ol.format.GML2.prototype.writeLinearRing_),
  38409. 'Polygon': ol.xml.makeChildAppender(
  38410. ol.format.GML2.prototype.writeSurfaceOrPolygon_),
  38411. 'MultiPolygon': ol.xml.makeChildAppender(
  38412. ol.format.GML2.prototype.writeMultiSurfaceOrPolygon_),
  38413. 'Surface': ol.xml.makeChildAppender(
  38414. ol.format.GML2.prototype.writeSurfaceOrPolygon_),
  38415. 'MultiSurface': ol.xml.makeChildAppender(
  38416. ol.format.GML2.prototype.writeMultiSurfaceOrPolygon_),
  38417. 'Envelope': ol.xml.makeChildAppender(
  38418. ol.format.GML2.prototype.writeEnvelope)
  38419. }
  38420. };
  38421. /**
  38422. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  38423. * @private
  38424. */
  38425. ol.format.GML2.RING_SERIALIZERS_ = {
  38426. 'http://www.opengis.net/gml': {
  38427. 'outerBoundaryIs': ol.xml.makeChildAppender(ol.format.GML2.prototype.writeRing_),
  38428. 'innerBoundaryIs': ol.xml.makeChildAppender(ol.format.GML2.prototype.writeRing_)
  38429. }
  38430. };
  38431. /**
  38432. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  38433. * @private
  38434. */
  38435. ol.format.GML2.POINTMEMBER_SERIALIZERS_ = {
  38436. 'http://www.opengis.net/gml': {
  38437. 'pointMember': ol.xml.makeChildAppender(
  38438. ol.format.GML2.prototype.writePointMember_)
  38439. }
  38440. };
  38441. /**
  38442. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  38443. * @private
  38444. */
  38445. ol.format.GML2.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
  38446. 'http://www.opengis.net/gml': {
  38447. 'lineStringMember': ol.xml.makeChildAppender(
  38448. ol.format.GML2.prototype.writeLineStringOrCurveMember_),
  38449. 'curveMember': ol.xml.makeChildAppender(
  38450. ol.format.GML2.prototype.writeLineStringOrCurveMember_)
  38451. }
  38452. };
  38453. /**
  38454. * @const
  38455. * @param {*} value Value.
  38456. * @param {Array.<*>} objectStack Object stack.
  38457. * @param {string=} opt_nodeName Node name.
  38458. * @return {Node|undefined} Node.
  38459. * @private
  38460. */
  38461. ol.format.GML2.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  38462. var parentNode = objectStack[objectStack.length - 1].node;
  38463. return ol.xml.createElementNS('http://www.opengis.net/gml',
  38464. ol.format.GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]);
  38465. };
  38466. /**
  38467. * @const
  38468. * @type {Object.<string, string>}
  38469. * @private
  38470. */
  38471. ol.format.GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
  38472. 'MultiLineString': 'lineStringMember',
  38473. 'MultiCurve': 'curveMember',
  38474. 'MultiPolygon': 'polygonMember',
  38475. 'MultiSurface': 'surfaceMember'
  38476. };
  38477. /**
  38478. * @const
  38479. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  38480. * @private
  38481. */
  38482. ol.format.GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
  38483. 'http://www.opengis.net/gml': {
  38484. 'surfaceMember': ol.xml.makeChildAppender(
  38485. ol.format.GML2.prototype.writeSurfaceOrPolygonMember_),
  38486. 'polygonMember': ol.xml.makeChildAppender(
  38487. ol.format.GML2.prototype.writeSurfaceOrPolygonMember_)
  38488. }
  38489. };
  38490. /**
  38491. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  38492. * @private
  38493. */
  38494. ol.format.GML2.ENVELOPE_SERIALIZERS_ = {
  38495. 'http://www.opengis.net/gml': {
  38496. 'lowerCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  38497. 'upperCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
  38498. }
  38499. };
  38500. goog.provide('ol.format.GPX');
  38501. goog.require('ol');
  38502. goog.require('ol.Feature');
  38503. goog.require('ol.array');
  38504. goog.require('ol.format.Feature');
  38505. goog.require('ol.format.XMLFeature');
  38506. goog.require('ol.format.XSD');
  38507. goog.require('ol.geom.GeometryLayout');
  38508. goog.require('ol.geom.LineString');
  38509. goog.require('ol.geom.MultiLineString');
  38510. goog.require('ol.geom.Point');
  38511. goog.require('ol.proj');
  38512. goog.require('ol.xml');
  38513. /**
  38514. * @classdesc
  38515. * Feature format for reading and writing data in the GPX format.
  38516. *
  38517. * @constructor
  38518. * @extends {ol.format.XMLFeature}
  38519. * @param {olx.format.GPXOptions=} opt_options Options.
  38520. * @api
  38521. */
  38522. ol.format.GPX = function(opt_options) {
  38523. var options = opt_options ? opt_options : {};
  38524. ol.format.XMLFeature.call(this);
  38525. /**
  38526. * @inheritDoc
  38527. */
  38528. this.defaultDataProjection = ol.proj.get('EPSG:4326');
  38529. /**
  38530. * @type {function(ol.Feature, Node)|undefined}
  38531. * @private
  38532. */
  38533. this.readExtensions_ = options.readExtensions;
  38534. };
  38535. ol.inherits(ol.format.GPX, ol.format.XMLFeature);
  38536. /**
  38537. * @const
  38538. * @private
  38539. * @type {Array.<string>}
  38540. */
  38541. ol.format.GPX.NAMESPACE_URIS_ = [
  38542. null,
  38543. 'http://www.topografix.com/GPX/1/0',
  38544. 'http://www.topografix.com/GPX/1/1'
  38545. ];
  38546. /**
  38547. * @const
  38548. * @type {string}
  38549. * @private
  38550. */
  38551. ol.format.GPX.SCHEMA_LOCATION_ = 'http://www.topografix.com/GPX/1/1 ' +
  38552. 'http://www.topografix.com/GPX/1/1/gpx.xsd';
  38553. /**
  38554. * @param {Array.<number>} flatCoordinates Flat coordinates.
  38555. * @param {ol.LayoutOptions} layoutOptions Layout options.
  38556. * @param {Node} node Node.
  38557. * @param {Object} values Values.
  38558. * @private
  38559. * @return {Array.<number>} Flat coordinates.
  38560. */
  38561. ol.format.GPX.appendCoordinate_ = function(flatCoordinates, layoutOptions, node, values) {
  38562. flatCoordinates.push(
  38563. parseFloat(node.getAttribute('lon')),
  38564. parseFloat(node.getAttribute('lat')));
  38565. if ('ele' in values) {
  38566. flatCoordinates.push(/** @type {number} */ (values['ele']));
  38567. delete values['ele'];
  38568. layoutOptions.hasZ = true;
  38569. } else {
  38570. flatCoordinates.push(0);
  38571. }
  38572. if ('time' in values) {
  38573. flatCoordinates.push(/** @type {number} */ (values['time']));
  38574. delete values['time'];
  38575. layoutOptions.hasM = true;
  38576. } else {
  38577. flatCoordinates.push(0);
  38578. }
  38579. return flatCoordinates;
  38580. };
  38581. /**
  38582. * Choose GeometryLayout based on flags in layoutOptions and adjust flatCoordinates
  38583. * and ends arrays by shrinking them accordingly (removing unused zero entries).
  38584. *
  38585. * @param {ol.LayoutOptions} layoutOptions Layout options.
  38586. * @param {Array.<number>} flatCoordinates Flat coordinates.
  38587. * @param {Array.<number>=} ends Ends.
  38588. * @return {ol.geom.GeometryLayout} Layout.
  38589. */
  38590. ol.format.GPX.applyLayoutOptions_ = function(layoutOptions, flatCoordinates, ends) {
  38591. var layout = ol.geom.GeometryLayout.XY;
  38592. var stride = 2;
  38593. if (layoutOptions.hasZ && layoutOptions.hasM) {
  38594. layout = ol.geom.GeometryLayout.XYZM;
  38595. stride = 4;
  38596. } else if (layoutOptions.hasZ) {
  38597. layout = ol.geom.GeometryLayout.XYZ;
  38598. stride = 3;
  38599. } else if (layoutOptions.hasM) {
  38600. layout = ol.geom.GeometryLayout.XYM;
  38601. stride = 3;
  38602. }
  38603. if (stride !== 4) {
  38604. var i, ii;
  38605. for (i = 0, ii = flatCoordinates.length / 4; i < ii; i++) {
  38606. flatCoordinates[i * stride] = flatCoordinates[i * 4];
  38607. flatCoordinates[i * stride + 1] = flatCoordinates[i * 4 + 1];
  38608. if (layoutOptions.hasZ) {
  38609. flatCoordinates[i * stride + 2] = flatCoordinates[i * 4 + 2];
  38610. }
  38611. if (layoutOptions.hasM) {
  38612. flatCoordinates[i * stride + 2] = flatCoordinates[i * 4 + 3];
  38613. }
  38614. }
  38615. flatCoordinates.length = flatCoordinates.length / 4 * stride;
  38616. if (ends) {
  38617. for (i = 0, ii = ends.length; i < ii; i++) {
  38618. ends[i] = ends[i] / 4 * stride;
  38619. }
  38620. }
  38621. }
  38622. return layout;
  38623. };
  38624. /**
  38625. * @param {Node} node Node.
  38626. * @param {Array.<*>} objectStack Object stack.
  38627. * @private
  38628. */
  38629. ol.format.GPX.parseLink_ = function(node, objectStack) {
  38630. var values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  38631. var href = node.getAttribute('href');
  38632. if (href !== null) {
  38633. values['link'] = href;
  38634. }
  38635. ol.xml.parseNode(ol.format.GPX.LINK_PARSERS_, node, objectStack);
  38636. };
  38637. /**
  38638. * @param {Node} node Node.
  38639. * @param {Array.<*>} objectStack Object stack.
  38640. * @private
  38641. */
  38642. ol.format.GPX.parseExtensions_ = function(node, objectStack) {
  38643. var values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  38644. values['extensionsNode_'] = node;
  38645. };
  38646. /**
  38647. * @param {Node} node Node.
  38648. * @param {Array.<*>} objectStack Object stack.
  38649. * @private
  38650. */
  38651. ol.format.GPX.parseRtePt_ = function(node, objectStack) {
  38652. var values = ol.xml.pushParseAndPop(
  38653. {}, ol.format.GPX.RTEPT_PARSERS_, node, objectStack);
  38654. if (values) {
  38655. var rteValues = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  38656. var flatCoordinates = /** @type {Array.<number>} */
  38657. (rteValues['flatCoordinates']);
  38658. var layoutOptions = /** @type {ol.LayoutOptions} */
  38659. (rteValues['layoutOptions']);
  38660. ol.format.GPX.appendCoordinate_(flatCoordinates, layoutOptions, node, values);
  38661. }
  38662. };
  38663. /**
  38664. * @param {Node} node Node.
  38665. * @param {Array.<*>} objectStack Object stack.
  38666. * @private
  38667. */
  38668. ol.format.GPX.parseTrkPt_ = function(node, objectStack) {
  38669. var values = ol.xml.pushParseAndPop(
  38670. {}, ol.format.GPX.TRKPT_PARSERS_, node, objectStack);
  38671. if (values) {
  38672. var trkValues = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  38673. var flatCoordinates = /** @type {Array.<number>} */
  38674. (trkValues['flatCoordinates']);
  38675. var layoutOptions = /** @type {ol.LayoutOptions} */
  38676. (trkValues['layoutOptions']);
  38677. ol.format.GPX.appendCoordinate_(flatCoordinates, layoutOptions, node, values);
  38678. }
  38679. };
  38680. /**
  38681. * @param {Node} node Node.
  38682. * @param {Array.<*>} objectStack Object stack.
  38683. * @private
  38684. */
  38685. ol.format.GPX.parseTrkSeg_ = function(node, objectStack) {
  38686. var values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  38687. ol.xml.parseNode(ol.format.GPX.TRKSEG_PARSERS_, node, objectStack);
  38688. var flatCoordinates = /** @type {Array.<number>} */
  38689. (values['flatCoordinates']);
  38690. var ends = /** @type {Array.<number>} */ (values['ends']);
  38691. ends.push(flatCoordinates.length);
  38692. };
  38693. /**
  38694. * @param {Node} node Node.
  38695. * @param {Array.<*>} objectStack Object stack.
  38696. * @private
  38697. * @return {ol.Feature|undefined} Track.
  38698. */
  38699. ol.format.GPX.readRte_ = function(node, objectStack) {
  38700. var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
  38701. var values = ol.xml.pushParseAndPop({
  38702. 'flatCoordinates': [],
  38703. 'layoutOptions': {}
  38704. }, ol.format.GPX.RTE_PARSERS_, node, objectStack);
  38705. if (!values) {
  38706. return undefined;
  38707. }
  38708. var flatCoordinates = /** @type {Array.<number>} */
  38709. (values['flatCoordinates']);
  38710. delete values['flatCoordinates'];
  38711. var layoutOptions = /** @type {ol.LayoutOptions} */ (values['layoutOptions']);
  38712. delete values['layoutOptions'];
  38713. var layout = ol.format.GPX.applyLayoutOptions_(layoutOptions, flatCoordinates);
  38714. var geometry = new ol.geom.LineString(null);
  38715. geometry.setFlatCoordinates(layout, flatCoordinates);
  38716. ol.format.Feature.transformWithOptions(geometry, false, options);
  38717. var feature = new ol.Feature(geometry);
  38718. feature.setProperties(values);
  38719. return feature;
  38720. };
  38721. /**
  38722. * @param {Node} node Node.
  38723. * @param {Array.<*>} objectStack Object stack.
  38724. * @private
  38725. * @return {ol.Feature|undefined} Track.
  38726. */
  38727. ol.format.GPX.readTrk_ = function(node, objectStack) {
  38728. var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
  38729. var values = ol.xml.pushParseAndPop({
  38730. 'flatCoordinates': [],
  38731. 'ends': [],
  38732. 'layoutOptions': {}
  38733. }, ol.format.GPX.TRK_PARSERS_, node, objectStack);
  38734. if (!values) {
  38735. return undefined;
  38736. }
  38737. var flatCoordinates = /** @type {Array.<number>} */
  38738. (values['flatCoordinates']);
  38739. delete values['flatCoordinates'];
  38740. var ends = /** @type {Array.<number>} */ (values['ends']);
  38741. delete values['ends'];
  38742. var layoutOptions = /** @type {ol.LayoutOptions} */ (values['layoutOptions']);
  38743. delete values['layoutOptions'];
  38744. var layout = ol.format.GPX.applyLayoutOptions_(layoutOptions, flatCoordinates, ends);
  38745. var geometry = new ol.geom.MultiLineString(null);
  38746. geometry.setFlatCoordinates(layout, flatCoordinates, ends);
  38747. ol.format.Feature.transformWithOptions(geometry, false, options);
  38748. var feature = new ol.Feature(geometry);
  38749. feature.setProperties(values);
  38750. return feature;
  38751. };
  38752. /**
  38753. * @param {Node} node Node.
  38754. * @param {Array.<*>} objectStack Object stack.
  38755. * @private
  38756. * @return {ol.Feature|undefined} Waypoint.
  38757. */
  38758. ol.format.GPX.readWpt_ = function(node, objectStack) {
  38759. var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
  38760. var values = ol.xml.pushParseAndPop(
  38761. {}, ol.format.GPX.WPT_PARSERS_, node, objectStack);
  38762. if (!values) {
  38763. return undefined;
  38764. }
  38765. var layoutOptions = /** @type {ol.LayoutOptions} */ ({});
  38766. var coordinates = ol.format.GPX.appendCoordinate_([], layoutOptions, node, values);
  38767. var layout = ol.format.GPX.applyLayoutOptions_(layoutOptions, coordinates);
  38768. var geometry = new ol.geom.Point(coordinates, layout);
  38769. ol.format.Feature.transformWithOptions(geometry, false, options);
  38770. var feature = new ol.Feature(geometry);
  38771. feature.setProperties(values);
  38772. return feature;
  38773. };
  38774. /**
  38775. * @const
  38776. * @type {Object.<string, function(Node, Array.<*>): (ol.Feature|undefined)>}
  38777. * @private
  38778. */
  38779. ol.format.GPX.FEATURE_READER_ = {
  38780. 'rte': ol.format.GPX.readRte_,
  38781. 'trk': ol.format.GPX.readTrk_,
  38782. 'wpt': ol.format.GPX.readWpt_
  38783. };
  38784. /**
  38785. * @const
  38786. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38787. * @private
  38788. */
  38789. ol.format.GPX.GPX_PARSERS_ = ol.xml.makeStructureNS(
  38790. ol.format.GPX.NAMESPACE_URIS_, {
  38791. 'rte': ol.xml.makeArrayPusher(ol.format.GPX.readRte_),
  38792. 'trk': ol.xml.makeArrayPusher(ol.format.GPX.readTrk_),
  38793. 'wpt': ol.xml.makeArrayPusher(ol.format.GPX.readWpt_)
  38794. });
  38795. /**
  38796. * @const
  38797. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38798. * @private
  38799. */
  38800. ol.format.GPX.LINK_PARSERS_ = ol.xml.makeStructureNS(
  38801. ol.format.GPX.NAMESPACE_URIS_, {
  38802. 'text':
  38803. ol.xml.makeObjectPropertySetter(ol.format.XSD.readString, 'linkText'),
  38804. 'type':
  38805. ol.xml.makeObjectPropertySetter(ol.format.XSD.readString, 'linkType')
  38806. });
  38807. /**
  38808. * @const
  38809. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38810. * @private
  38811. */
  38812. ol.format.GPX.RTE_PARSERS_ = ol.xml.makeStructureNS(
  38813. ol.format.GPX.NAMESPACE_URIS_, {
  38814. 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38815. 'cmt': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38816. 'desc': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38817. 'src': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38818. 'link': ol.format.GPX.parseLink_,
  38819. 'number':
  38820. ol.xml.makeObjectPropertySetter(ol.format.XSD.readNonNegativeInteger),
  38821. 'extensions': ol.format.GPX.parseExtensions_,
  38822. 'type': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38823. 'rtept': ol.format.GPX.parseRtePt_
  38824. });
  38825. /**
  38826. * @const
  38827. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38828. * @private
  38829. */
  38830. ol.format.GPX.RTEPT_PARSERS_ = ol.xml.makeStructureNS(
  38831. ol.format.GPX.NAMESPACE_URIS_, {
  38832. 'ele': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38833. 'time': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDateTime)
  38834. });
  38835. /**
  38836. * @const
  38837. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38838. * @private
  38839. */
  38840. ol.format.GPX.TRK_PARSERS_ = ol.xml.makeStructureNS(
  38841. ol.format.GPX.NAMESPACE_URIS_, {
  38842. 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38843. 'cmt': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38844. 'desc': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38845. 'src': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38846. 'link': ol.format.GPX.parseLink_,
  38847. 'number':
  38848. ol.xml.makeObjectPropertySetter(ol.format.XSD.readNonNegativeInteger),
  38849. 'type': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38850. 'extensions': ol.format.GPX.parseExtensions_,
  38851. 'trkseg': ol.format.GPX.parseTrkSeg_
  38852. });
  38853. /**
  38854. * @const
  38855. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38856. * @private
  38857. */
  38858. ol.format.GPX.TRKSEG_PARSERS_ = ol.xml.makeStructureNS(
  38859. ol.format.GPX.NAMESPACE_URIS_, {
  38860. 'trkpt': ol.format.GPX.parseTrkPt_
  38861. });
  38862. /**
  38863. * @const
  38864. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38865. * @private
  38866. */
  38867. ol.format.GPX.TRKPT_PARSERS_ = ol.xml.makeStructureNS(
  38868. ol.format.GPX.NAMESPACE_URIS_, {
  38869. 'ele': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38870. 'time': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDateTime)
  38871. });
  38872. /**
  38873. * @const
  38874. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  38875. * @private
  38876. */
  38877. ol.format.GPX.WPT_PARSERS_ = ol.xml.makeStructureNS(
  38878. ol.format.GPX.NAMESPACE_URIS_, {
  38879. 'ele': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38880. 'time': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDateTime),
  38881. 'magvar': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38882. 'geoidheight': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38883. 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38884. 'cmt': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38885. 'desc': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38886. 'src': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38887. 'link': ol.format.GPX.parseLink_,
  38888. 'sym': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38889. 'type': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38890. 'fix': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  38891. 'sat': ol.xml.makeObjectPropertySetter(
  38892. ol.format.XSD.readNonNegativeInteger),
  38893. 'hdop': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38894. 'vdop': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38895. 'pdop': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38896. 'ageofdgpsdata':
  38897. ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  38898. 'dgpsid':
  38899. ol.xml.makeObjectPropertySetter(ol.format.XSD.readNonNegativeInteger),
  38900. 'extensions': ol.format.GPX.parseExtensions_
  38901. });
  38902. /**
  38903. * @param {Array.<ol.Feature>} features List of features.
  38904. * @private
  38905. */
  38906. ol.format.GPX.prototype.handleReadExtensions_ = function(features) {
  38907. if (!features) {
  38908. features = [];
  38909. }
  38910. for (var i = 0, ii = features.length; i < ii; ++i) {
  38911. var feature = features[i];
  38912. if (this.readExtensions_) {
  38913. var extensionsNode = feature.get('extensionsNode_') || null;
  38914. this.readExtensions_(feature, extensionsNode);
  38915. }
  38916. feature.set('extensionsNode_', undefined);
  38917. }
  38918. };
  38919. /**
  38920. * Read the first feature from a GPX source.
  38921. * Routes (`<rte>`) are converted into LineString geometries, and tracks (`<trk>`)
  38922. * into MultiLineString. Any properties on route and track waypoints are ignored.
  38923. *
  38924. * @function
  38925. * @param {Document|Node|Object|string} source Source.
  38926. * @param {olx.format.ReadOptions=} opt_options Read options.
  38927. * @return {ol.Feature} Feature.
  38928. * @api
  38929. */
  38930. ol.format.GPX.prototype.readFeature;
  38931. /**
  38932. * @inheritDoc
  38933. */
  38934. ol.format.GPX.prototype.readFeatureFromNode = function(node, opt_options) {
  38935. if (!ol.array.includes(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) {
  38936. return null;
  38937. }
  38938. var featureReader = ol.format.GPX.FEATURE_READER_[node.localName];
  38939. if (!featureReader) {
  38940. return null;
  38941. }
  38942. var feature = featureReader(node, [this.getReadOptions(node, opt_options)]);
  38943. if (!feature) {
  38944. return null;
  38945. }
  38946. this.handleReadExtensions_([feature]);
  38947. return feature;
  38948. };
  38949. /**
  38950. * Read all features from a GPX source.
  38951. * Routes (`<rte>`) are converted into LineString geometries, and tracks (`<trk>`)
  38952. * into MultiLineString. Any properties on route and track waypoints are ignored.
  38953. *
  38954. * @function
  38955. * @param {Document|Node|Object|string} source Source.
  38956. * @param {olx.format.ReadOptions=} opt_options Read options.
  38957. * @return {Array.<ol.Feature>} Features.
  38958. * @api
  38959. */
  38960. ol.format.GPX.prototype.readFeatures;
  38961. /**
  38962. * @inheritDoc
  38963. */
  38964. ol.format.GPX.prototype.readFeaturesFromNode = function(node, opt_options) {
  38965. if (!ol.array.includes(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) {
  38966. return [];
  38967. }
  38968. if (node.localName == 'gpx') {
  38969. /** @type {Array.<ol.Feature>} */
  38970. var features = ol.xml.pushParseAndPop([], ol.format.GPX.GPX_PARSERS_,
  38971. node, [this.getReadOptions(node, opt_options)]);
  38972. if (features) {
  38973. this.handleReadExtensions_(features);
  38974. return features;
  38975. } else {
  38976. return [];
  38977. }
  38978. }
  38979. return [];
  38980. };
  38981. /**
  38982. * Read the projection from a GPX source.
  38983. *
  38984. * @function
  38985. * @param {Document|Node|Object|string} source Source.
  38986. * @return {ol.proj.Projection} Projection.
  38987. * @api
  38988. */
  38989. ol.format.GPX.prototype.readProjection;
  38990. /**
  38991. * @param {Node} node Node.
  38992. * @param {string} value Value for the link's `href` attribute.
  38993. * @param {Array.<*>} objectStack Node stack.
  38994. * @private
  38995. */
  38996. ol.format.GPX.writeLink_ = function(node, value, objectStack) {
  38997. node.setAttribute('href', value);
  38998. var context = objectStack[objectStack.length - 1];
  38999. var properties = context['properties'];
  39000. var link = [
  39001. properties['linkText'],
  39002. properties['linkType']
  39003. ];
  39004. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */ ({node: node}),
  39005. ol.format.GPX.LINK_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  39006. link, objectStack, ol.format.GPX.LINK_SEQUENCE_);
  39007. };
  39008. /**
  39009. * @param {Node} node Node.
  39010. * @param {ol.Coordinate} coordinate Coordinate.
  39011. * @param {Array.<*>} objectStack Object stack.
  39012. * @private
  39013. */
  39014. ol.format.GPX.writeWptType_ = function(node, coordinate, objectStack) {
  39015. var context = objectStack[objectStack.length - 1];
  39016. var parentNode = context.node;
  39017. var namespaceURI = parentNode.namespaceURI;
  39018. var properties = context['properties'];
  39019. //FIXME Projection handling
  39020. ol.xml.setAttributeNS(node, null, 'lat', coordinate[1]);
  39021. ol.xml.setAttributeNS(node, null, 'lon', coordinate[0]);
  39022. var geometryLayout = context['geometryLayout'];
  39023. switch (geometryLayout) {
  39024. case ol.geom.GeometryLayout.XYZM:
  39025. if (coordinate[3] !== 0) {
  39026. properties['time'] = coordinate[3];
  39027. }
  39028. // fall through
  39029. case ol.geom.GeometryLayout.XYZ:
  39030. if (coordinate[2] !== 0) {
  39031. properties['ele'] = coordinate[2];
  39032. }
  39033. break;
  39034. case ol.geom.GeometryLayout.XYM:
  39035. if (coordinate[2] !== 0) {
  39036. properties['time'] = coordinate[2];
  39037. }
  39038. break;
  39039. default:
  39040. // pass
  39041. }
  39042. var orderedKeys = (node.nodeName == 'rtept') ?
  39043. ol.format.GPX.RTEPT_TYPE_SEQUENCE_[namespaceURI] :
  39044. ol.format.GPX.WPT_TYPE_SEQUENCE_[namespaceURI];
  39045. var values = ol.xml.makeSequence(properties, orderedKeys);
  39046. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  39047. ({node: node, 'properties': properties}),
  39048. ol.format.GPX.WPT_TYPE_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  39049. values, objectStack, orderedKeys);
  39050. };
  39051. /**
  39052. * @param {Node} node Node.
  39053. * @param {ol.Feature} feature Feature.
  39054. * @param {Array.<*>} objectStack Object stack.
  39055. * @private
  39056. */
  39057. ol.format.GPX.writeRte_ = function(node, feature, objectStack) {
  39058. var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
  39059. var properties = feature.getProperties();
  39060. var context = {node: node, 'properties': properties};
  39061. var geometry = feature.getGeometry();
  39062. if (geometry) {
  39063. geometry = /** @type {ol.geom.LineString} */
  39064. (ol.format.Feature.transformWithOptions(geometry, true, options));
  39065. context['geometryLayout'] = geometry.getLayout();
  39066. properties['rtept'] = geometry.getCoordinates();
  39067. }
  39068. var parentNode = objectStack[objectStack.length - 1].node;
  39069. var orderedKeys = ol.format.GPX.RTE_SEQUENCE_[parentNode.namespaceURI];
  39070. var values = ol.xml.makeSequence(properties, orderedKeys);
  39071. ol.xml.pushSerializeAndPop(context,
  39072. ol.format.GPX.RTE_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  39073. values, objectStack, orderedKeys);
  39074. };
  39075. /**
  39076. * @param {Node} node Node.
  39077. * @param {ol.Feature} feature Feature.
  39078. * @param {Array.<*>} objectStack Object stack.
  39079. * @private
  39080. */
  39081. ol.format.GPX.writeTrk_ = function(node, feature, objectStack) {
  39082. var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
  39083. var properties = feature.getProperties();
  39084. /** @type {ol.XmlNodeStackItem} */
  39085. var context = {node: node, 'properties': properties};
  39086. var geometry = feature.getGeometry();
  39087. if (geometry) {
  39088. geometry = /** @type {ol.geom.MultiLineString} */
  39089. (ol.format.Feature.transformWithOptions(geometry, true, options));
  39090. properties['trkseg'] = geometry.getLineStrings();
  39091. }
  39092. var parentNode = objectStack[objectStack.length - 1].node;
  39093. var orderedKeys = ol.format.GPX.TRK_SEQUENCE_[parentNode.namespaceURI];
  39094. var values = ol.xml.makeSequence(properties, orderedKeys);
  39095. ol.xml.pushSerializeAndPop(context,
  39096. ol.format.GPX.TRK_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  39097. values, objectStack, orderedKeys);
  39098. };
  39099. /**
  39100. * @param {Node} node Node.
  39101. * @param {ol.geom.LineString} lineString LineString.
  39102. * @param {Array.<*>} objectStack Object stack.
  39103. * @private
  39104. */
  39105. ol.format.GPX.writeTrkSeg_ = function(node, lineString, objectStack) {
  39106. /** @type {ol.XmlNodeStackItem} */
  39107. var context = {node: node, 'geometryLayout': lineString.getLayout(),
  39108. 'properties': {}};
  39109. ol.xml.pushSerializeAndPop(context,
  39110. ol.format.GPX.TRKSEG_SERIALIZERS_, ol.format.GPX.TRKSEG_NODE_FACTORY_,
  39111. lineString.getCoordinates(), objectStack);
  39112. };
  39113. /**
  39114. * @param {Node} node Node.
  39115. * @param {ol.Feature} feature Feature.
  39116. * @param {Array.<*>} objectStack Object stack.
  39117. * @private
  39118. */
  39119. ol.format.GPX.writeWpt_ = function(node, feature, objectStack) {
  39120. var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
  39121. var context = objectStack[objectStack.length - 1];
  39122. context['properties'] = feature.getProperties();
  39123. var geometry = feature.getGeometry();
  39124. if (geometry) {
  39125. geometry = /** @type {ol.geom.Point} */
  39126. (ol.format.Feature.transformWithOptions(geometry, true, options));
  39127. context['geometryLayout'] = geometry.getLayout();
  39128. ol.format.GPX.writeWptType_(node, geometry.getCoordinates(), objectStack);
  39129. }
  39130. };
  39131. /**
  39132. * @const
  39133. * @type {Array.<string>}
  39134. * @private
  39135. */
  39136. ol.format.GPX.LINK_SEQUENCE_ = ['text', 'type'];
  39137. /**
  39138. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  39139. * @private
  39140. */
  39141. ol.format.GPX.LINK_SERIALIZERS_ = ol.xml.makeStructureNS(
  39142. ol.format.GPX.NAMESPACE_URIS_, {
  39143. 'text': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39144. 'type': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
  39145. });
  39146. /**
  39147. * @const
  39148. * @type {Object.<string, Array.<string>>}
  39149. * @private
  39150. */
  39151. ol.format.GPX.RTE_SEQUENCE_ = ol.xml.makeStructureNS(
  39152. ol.format.GPX.NAMESPACE_URIS_, [
  39153. 'name', 'cmt', 'desc', 'src', 'link', 'number', 'type', 'rtept'
  39154. ]);
  39155. /**
  39156. * @const
  39157. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  39158. * @private
  39159. */
  39160. ol.format.GPX.RTE_SERIALIZERS_ = ol.xml.makeStructureNS(
  39161. ol.format.GPX.NAMESPACE_URIS_, {
  39162. 'name': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39163. 'cmt': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39164. 'desc': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39165. 'src': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39166. 'link': ol.xml.makeChildAppender(ol.format.GPX.writeLink_),
  39167. 'number': ol.xml.makeChildAppender(
  39168. ol.format.XSD.writeNonNegativeIntegerTextNode),
  39169. 'type': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39170. 'rtept': ol.xml.makeArraySerializer(ol.xml.makeChildAppender(
  39171. ol.format.GPX.writeWptType_))
  39172. });
  39173. /**
  39174. * @const
  39175. * @type {Object.<string, Array.<string>>}
  39176. * @private
  39177. */
  39178. ol.format.GPX.RTEPT_TYPE_SEQUENCE_ = ol.xml.makeStructureNS(
  39179. ol.format.GPX.NAMESPACE_URIS_, [
  39180. 'ele', 'time'
  39181. ]);
  39182. /**
  39183. * @const
  39184. * @type {Object.<string, Array.<string>>}
  39185. * @private
  39186. */
  39187. ol.format.GPX.TRK_SEQUENCE_ = ol.xml.makeStructureNS(
  39188. ol.format.GPX.NAMESPACE_URIS_, [
  39189. 'name', 'cmt', 'desc', 'src', 'link', 'number', 'type', 'trkseg'
  39190. ]);
  39191. /**
  39192. * @const
  39193. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  39194. * @private
  39195. */
  39196. ol.format.GPX.TRK_SERIALIZERS_ = ol.xml.makeStructureNS(
  39197. ol.format.GPX.NAMESPACE_URIS_, {
  39198. 'name': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39199. 'cmt': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39200. 'desc': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39201. 'src': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39202. 'link': ol.xml.makeChildAppender(ol.format.GPX.writeLink_),
  39203. 'number': ol.xml.makeChildAppender(
  39204. ol.format.XSD.writeNonNegativeIntegerTextNode),
  39205. 'type': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39206. 'trkseg': ol.xml.makeArraySerializer(ol.xml.makeChildAppender(
  39207. ol.format.GPX.writeTrkSeg_))
  39208. });
  39209. /**
  39210. * @const
  39211. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  39212. * @private
  39213. */
  39214. ol.format.GPX.TRKSEG_NODE_FACTORY_ = ol.xml.makeSimpleNodeFactory('trkpt');
  39215. /**
  39216. * @const
  39217. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  39218. * @private
  39219. */
  39220. ol.format.GPX.TRKSEG_SERIALIZERS_ = ol.xml.makeStructureNS(
  39221. ol.format.GPX.NAMESPACE_URIS_, {
  39222. 'trkpt': ol.xml.makeChildAppender(ol.format.GPX.writeWptType_)
  39223. });
  39224. /**
  39225. * @const
  39226. * @type {Object.<string, Array.<string>>}
  39227. * @private
  39228. */
  39229. ol.format.GPX.WPT_TYPE_SEQUENCE_ = ol.xml.makeStructureNS(
  39230. ol.format.GPX.NAMESPACE_URIS_, [
  39231. 'ele', 'time', 'magvar', 'geoidheight', 'name', 'cmt', 'desc', 'src',
  39232. 'link', 'sym', 'type', 'fix', 'sat', 'hdop', 'vdop', 'pdop',
  39233. 'ageofdgpsdata', 'dgpsid'
  39234. ]);
  39235. /**
  39236. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  39237. * @private
  39238. */
  39239. ol.format.GPX.WPT_TYPE_SERIALIZERS_ = ol.xml.makeStructureNS(
  39240. ol.format.GPX.NAMESPACE_URIS_, {
  39241. 'ele': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  39242. 'time': ol.xml.makeChildAppender(ol.format.XSD.writeDateTimeTextNode),
  39243. 'magvar': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  39244. 'geoidheight': ol.xml.makeChildAppender(
  39245. ol.format.XSD.writeDecimalTextNode),
  39246. 'name': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39247. 'cmt': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39248. 'desc': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39249. 'src': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39250. 'link': ol.xml.makeChildAppender(ol.format.GPX.writeLink_),
  39251. 'sym': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39252. 'type': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39253. 'fix': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  39254. 'sat': ol.xml.makeChildAppender(
  39255. ol.format.XSD.writeNonNegativeIntegerTextNode),
  39256. 'hdop': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  39257. 'vdop': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  39258. 'pdop': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  39259. 'ageofdgpsdata': ol.xml.makeChildAppender(
  39260. ol.format.XSD.writeDecimalTextNode),
  39261. 'dgpsid': ol.xml.makeChildAppender(
  39262. ol.format.XSD.writeNonNegativeIntegerTextNode)
  39263. });
  39264. /**
  39265. * @const
  39266. * @type {Object.<string, string>}
  39267. * @private
  39268. */
  39269. ol.format.GPX.GEOMETRY_TYPE_TO_NODENAME_ = {
  39270. 'Point': 'wpt',
  39271. 'LineString': 'rte',
  39272. 'MultiLineString': 'trk'
  39273. };
  39274. /**
  39275. * @const
  39276. * @param {*} value Value.
  39277. * @param {Array.<*>} objectStack Object stack.
  39278. * @param {string=} opt_nodeName Node name.
  39279. * @return {Node|undefined} Node.
  39280. * @private
  39281. */
  39282. ol.format.GPX.GPX_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  39283. var geometry = /** @type {ol.Feature} */ (value).getGeometry();
  39284. if (geometry) {
  39285. var nodeName = ol.format.GPX.GEOMETRY_TYPE_TO_NODENAME_[geometry.getType()];
  39286. if (nodeName) {
  39287. var parentNode = objectStack[objectStack.length - 1].node;
  39288. return ol.xml.createElementNS(parentNode.namespaceURI, nodeName);
  39289. }
  39290. }
  39291. };
  39292. /**
  39293. * @const
  39294. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  39295. * @private
  39296. */
  39297. ol.format.GPX.GPX_SERIALIZERS_ = ol.xml.makeStructureNS(
  39298. ol.format.GPX.NAMESPACE_URIS_, {
  39299. 'rte': ol.xml.makeChildAppender(ol.format.GPX.writeRte_),
  39300. 'trk': ol.xml.makeChildAppender(ol.format.GPX.writeTrk_),
  39301. 'wpt': ol.xml.makeChildAppender(ol.format.GPX.writeWpt_)
  39302. });
  39303. /**
  39304. * Encode an array of features in the GPX format.
  39305. * LineString geometries are output as routes (`<rte>`), and MultiLineString
  39306. * as tracks (`<trk>`).
  39307. *
  39308. * @function
  39309. * @param {Array.<ol.Feature>} features Features.
  39310. * @param {olx.format.WriteOptions=} opt_options Write options.
  39311. * @return {string} Result.
  39312. * @api
  39313. */
  39314. ol.format.GPX.prototype.writeFeatures;
  39315. /**
  39316. * Encode an array of features in the GPX format as an XML node.
  39317. * LineString geometries are output as routes (`<rte>`), and MultiLineString
  39318. * as tracks (`<trk>`).
  39319. *
  39320. * @param {Array.<ol.Feature>} features Features.
  39321. * @param {olx.format.WriteOptions=} opt_options Options.
  39322. * @return {Node} Node.
  39323. * @override
  39324. * @api
  39325. */
  39326. ol.format.GPX.prototype.writeFeaturesNode = function(features, opt_options) {
  39327. opt_options = this.adaptOptions(opt_options);
  39328. //FIXME Serialize metadata
  39329. var gpx = ol.xml.createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
  39330. var xmlnsUri = 'http://www.w3.org/2000/xmlns/';
  39331. var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance';
  39332. ol.xml.setAttributeNS(gpx, xmlnsUri, 'xmlns:xsi', xmlSchemaInstanceUri);
  39333. ol.xml.setAttributeNS(gpx, xmlSchemaInstanceUri, 'xsi:schemaLocation',
  39334. ol.format.GPX.SCHEMA_LOCATION_);
  39335. gpx.setAttribute('version', '1.1');
  39336. gpx.setAttribute('creator', 'OpenLayers');
  39337. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
  39338. ({node: gpx}), ol.format.GPX.GPX_SERIALIZERS_,
  39339. ol.format.GPX.GPX_NODE_FACTORY_, features, [opt_options]);
  39340. return gpx;
  39341. };
  39342. goog.provide('ol.format.IGCZ');
  39343. /**
  39344. * IGC altitude/z. One of 'barometric', 'gps', 'none'.
  39345. * @enum {string}
  39346. */
  39347. ol.format.IGCZ = {
  39348. BAROMETRIC: 'barometric',
  39349. GPS: 'gps',
  39350. NONE: 'none'
  39351. };
  39352. goog.provide('ol.format.TextFeature');
  39353. goog.require('ol');
  39354. goog.require('ol.format.Feature');
  39355. goog.require('ol.format.FormatType');
  39356. /**
  39357. * @classdesc
  39358. * Abstract base class; normally only used for creating subclasses and not
  39359. * instantiated in apps.
  39360. * Base class for text feature formats.
  39361. *
  39362. * @constructor
  39363. * @abstract
  39364. * @extends {ol.format.Feature}
  39365. */
  39366. ol.format.TextFeature = function() {
  39367. ol.format.Feature.call(this);
  39368. };
  39369. ol.inherits(ol.format.TextFeature, ol.format.Feature);
  39370. /**
  39371. * @param {Document|Node|Object|string} source Source.
  39372. * @private
  39373. * @return {string} Text.
  39374. */
  39375. ol.format.TextFeature.prototype.getText_ = function(source) {
  39376. if (typeof source === 'string') {
  39377. return source;
  39378. } else {
  39379. return '';
  39380. }
  39381. };
  39382. /**
  39383. * @inheritDoc
  39384. */
  39385. ol.format.TextFeature.prototype.getType = function() {
  39386. return ol.format.FormatType.TEXT;
  39387. };
  39388. /**
  39389. * @inheritDoc
  39390. */
  39391. ol.format.TextFeature.prototype.readFeature = function(source, opt_options) {
  39392. return this.readFeatureFromText(
  39393. this.getText_(source), this.adaptOptions(opt_options));
  39394. };
  39395. /**
  39396. * @abstract
  39397. * @param {string} text Text.
  39398. * @param {olx.format.ReadOptions=} opt_options Read options.
  39399. * @protected
  39400. * @return {ol.Feature} Feature.
  39401. */
  39402. ol.format.TextFeature.prototype.readFeatureFromText = function(text, opt_options) {};
  39403. /**
  39404. * @inheritDoc
  39405. */
  39406. ol.format.TextFeature.prototype.readFeatures = function(source, opt_options) {
  39407. return this.readFeaturesFromText(
  39408. this.getText_(source), this.adaptOptions(opt_options));
  39409. };
  39410. /**
  39411. * @abstract
  39412. * @param {string} text Text.
  39413. * @param {olx.format.ReadOptions=} opt_options Read options.
  39414. * @protected
  39415. * @return {Array.<ol.Feature>} Features.
  39416. */
  39417. ol.format.TextFeature.prototype.readFeaturesFromText = function(text, opt_options) {};
  39418. /**
  39419. * @inheritDoc
  39420. */
  39421. ol.format.TextFeature.prototype.readGeometry = function(source, opt_options) {
  39422. return this.readGeometryFromText(
  39423. this.getText_(source), this.adaptOptions(opt_options));
  39424. };
  39425. /**
  39426. * @abstract
  39427. * @param {string} text Text.
  39428. * @param {olx.format.ReadOptions=} opt_options Read options.
  39429. * @protected
  39430. * @return {ol.geom.Geometry} Geometry.
  39431. */
  39432. ol.format.TextFeature.prototype.readGeometryFromText = function(text, opt_options) {};
  39433. /**
  39434. * @inheritDoc
  39435. */
  39436. ol.format.TextFeature.prototype.readProjection = function(source) {
  39437. return this.readProjectionFromText(this.getText_(source));
  39438. };
  39439. /**
  39440. * @param {string} text Text.
  39441. * @protected
  39442. * @return {ol.proj.Projection} Projection.
  39443. */
  39444. ol.format.TextFeature.prototype.readProjectionFromText = function(text) {
  39445. return this.defaultDataProjection;
  39446. };
  39447. /**
  39448. * @inheritDoc
  39449. */
  39450. ol.format.TextFeature.prototype.writeFeature = function(feature, opt_options) {
  39451. return this.writeFeatureText(feature, this.adaptOptions(opt_options));
  39452. };
  39453. /**
  39454. * @abstract
  39455. * @param {ol.Feature} feature Features.
  39456. * @param {olx.format.WriteOptions=} opt_options Write options.
  39457. * @protected
  39458. * @return {string} Text.
  39459. */
  39460. ol.format.TextFeature.prototype.writeFeatureText = function(feature, opt_options) {};
  39461. /**
  39462. * @inheritDoc
  39463. */
  39464. ol.format.TextFeature.prototype.writeFeatures = function(
  39465. features, opt_options) {
  39466. return this.writeFeaturesText(features, this.adaptOptions(opt_options));
  39467. };
  39468. /**
  39469. * @abstract
  39470. * @param {Array.<ol.Feature>} features Features.
  39471. * @param {olx.format.WriteOptions=} opt_options Write options.
  39472. * @protected
  39473. * @return {string} Text.
  39474. */
  39475. ol.format.TextFeature.prototype.writeFeaturesText = function(features, opt_options) {};
  39476. /**
  39477. * @inheritDoc
  39478. */
  39479. ol.format.TextFeature.prototype.writeGeometry = function(
  39480. geometry, opt_options) {
  39481. return this.writeGeometryText(geometry, this.adaptOptions(opt_options));
  39482. };
  39483. /**
  39484. * @abstract
  39485. * @param {ol.geom.Geometry} geometry Geometry.
  39486. * @param {olx.format.WriteOptions=} opt_options Write options.
  39487. * @protected
  39488. * @return {string} Text.
  39489. */
  39490. ol.format.TextFeature.prototype.writeGeometryText = function(geometry, opt_options) {};
  39491. goog.provide('ol.format.IGC');
  39492. goog.require('ol');
  39493. goog.require('ol.Feature');
  39494. goog.require('ol.format.Feature');
  39495. goog.require('ol.format.IGCZ');
  39496. goog.require('ol.format.TextFeature');
  39497. goog.require('ol.geom.GeometryLayout');
  39498. goog.require('ol.geom.LineString');
  39499. goog.require('ol.proj');
  39500. /**
  39501. * @classdesc
  39502. * Feature format for `*.igc` flight recording files.
  39503. *
  39504. * @constructor
  39505. * @extends {ol.format.TextFeature}
  39506. * @param {olx.format.IGCOptions=} opt_options Options.
  39507. * @api
  39508. */
  39509. ol.format.IGC = function(opt_options) {
  39510. var options = opt_options ? opt_options : {};
  39511. ol.format.TextFeature.call(this);
  39512. /**
  39513. * @inheritDoc
  39514. */
  39515. this.defaultDataProjection = ol.proj.get('EPSG:4326');
  39516. /**
  39517. * @private
  39518. * @type {ol.format.IGCZ}
  39519. */
  39520. this.altitudeMode_ = options.altitudeMode ?
  39521. options.altitudeMode : ol.format.IGCZ.NONE;
  39522. };
  39523. ol.inherits(ol.format.IGC, ol.format.TextFeature);
  39524. /**
  39525. * @const
  39526. * @type {RegExp}
  39527. * @private
  39528. */
  39529. ol.format.IGC.B_RECORD_RE_ =
  39530. /^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
  39531. /**
  39532. * @const
  39533. * @type {RegExp}
  39534. * @private
  39535. */
  39536. ol.format.IGC.H_RECORD_RE_ = /^H.([A-Z]{3}).*?:(.*)/;
  39537. /**
  39538. * @const
  39539. * @type {RegExp}
  39540. * @private
  39541. */
  39542. ol.format.IGC.HFDTE_RECORD_RE_ = /^HFDTE(\d{2})(\d{2})(\d{2})/;
  39543. /**
  39544. * A regular expression matching the newline characters `\r\n`, `\r` and `\n`.
  39545. *
  39546. * @const
  39547. * @type {RegExp}
  39548. * @private
  39549. */
  39550. ol.format.IGC.NEWLINE_RE_ = /\r\n|\r|\n/;
  39551. /**
  39552. * Read the feature from the IGC source.
  39553. *
  39554. * @function
  39555. * @param {Document|Node|Object|string} source Source.
  39556. * @param {olx.format.ReadOptions=} opt_options Read options.
  39557. * @return {ol.Feature} Feature.
  39558. * @api
  39559. */
  39560. ol.format.IGC.prototype.readFeature;
  39561. /**
  39562. * @inheritDoc
  39563. */
  39564. ol.format.IGC.prototype.readFeatureFromText = function(text, opt_options) {
  39565. var altitudeMode = this.altitudeMode_;
  39566. var lines = text.split(ol.format.IGC.NEWLINE_RE_);
  39567. /** @type {Object.<string, string>} */
  39568. var properties = {};
  39569. var flatCoordinates = [];
  39570. var year = 2000;
  39571. var month = 0;
  39572. var day = 1;
  39573. var lastDateTime = -1;
  39574. var i, ii;
  39575. for (i = 0, ii = lines.length; i < ii; ++i) {
  39576. var line = lines[i];
  39577. var m;
  39578. if (line.charAt(0) == 'B') {
  39579. m = ol.format.IGC.B_RECORD_RE_.exec(line);
  39580. if (m) {
  39581. var hour = parseInt(m[1], 10);
  39582. var minute = parseInt(m[2], 10);
  39583. var second = parseInt(m[3], 10);
  39584. var y = parseInt(m[4], 10) + parseInt(m[5], 10) / 60000;
  39585. if (m[6] == 'S') {
  39586. y = -y;
  39587. }
  39588. var x = parseInt(m[7], 10) + parseInt(m[8], 10) / 60000;
  39589. if (m[9] == 'W') {
  39590. x = -x;
  39591. }
  39592. flatCoordinates.push(x, y);
  39593. if (altitudeMode != ol.format.IGCZ.NONE) {
  39594. var z;
  39595. if (altitudeMode == ol.format.IGCZ.GPS) {
  39596. z = parseInt(m[11], 10);
  39597. } else if (altitudeMode == ol.format.IGCZ.BAROMETRIC) {
  39598. z = parseInt(m[12], 10);
  39599. } else {
  39600. z = 0;
  39601. }
  39602. flatCoordinates.push(z);
  39603. }
  39604. var dateTime = Date.UTC(year, month, day, hour, minute, second);
  39605. // Detect UTC midnight wrap around.
  39606. if (dateTime < lastDateTime) {
  39607. dateTime = Date.UTC(year, month, day + 1, hour, minute, second);
  39608. }
  39609. flatCoordinates.push(dateTime / 1000);
  39610. lastDateTime = dateTime;
  39611. }
  39612. } else if (line.charAt(0) == 'H') {
  39613. m = ol.format.IGC.HFDTE_RECORD_RE_.exec(line);
  39614. if (m) {
  39615. day = parseInt(m[1], 10);
  39616. month = parseInt(m[2], 10) - 1;
  39617. year = 2000 + parseInt(m[3], 10);
  39618. } else {
  39619. m = ol.format.IGC.H_RECORD_RE_.exec(line);
  39620. if (m) {
  39621. properties[m[1]] = m[2].trim();
  39622. }
  39623. }
  39624. }
  39625. }
  39626. if (flatCoordinates.length === 0) {
  39627. return null;
  39628. }
  39629. var lineString = new ol.geom.LineString(null);
  39630. var layout = altitudeMode == ol.format.IGCZ.NONE ?
  39631. ol.geom.GeometryLayout.XYM : ol.geom.GeometryLayout.XYZM;
  39632. lineString.setFlatCoordinates(layout, flatCoordinates);
  39633. var feature = new ol.Feature(ol.format.Feature.transformWithOptions(
  39634. lineString, false, opt_options));
  39635. feature.setProperties(properties);
  39636. return feature;
  39637. };
  39638. /**
  39639. * Read the feature from the source. As IGC sources contain a single
  39640. * feature, this will return the feature in an array.
  39641. *
  39642. * @function
  39643. * @param {Document|Node|Object|string} source Source.
  39644. * @param {olx.format.ReadOptions=} opt_options Read options.
  39645. * @return {Array.<ol.Feature>} Features.
  39646. * @api
  39647. */
  39648. ol.format.IGC.prototype.readFeatures;
  39649. /**
  39650. * @inheritDoc
  39651. */
  39652. ol.format.IGC.prototype.readFeaturesFromText = function(text, opt_options) {
  39653. var feature = this.readFeatureFromText(text, opt_options);
  39654. if (feature) {
  39655. return [feature];
  39656. } else {
  39657. return [];
  39658. }
  39659. };
  39660. /**
  39661. * Read the projection from the IGC source.
  39662. *
  39663. * @function
  39664. * @param {Document|Node|Object|string} source Source.
  39665. * @return {ol.proj.Projection} Projection.
  39666. * @api
  39667. */
  39668. ol.format.IGC.prototype.readProjection;
  39669. /**
  39670. * Not implemented.
  39671. * @inheritDoc
  39672. */
  39673. ol.format.IGC.prototype.writeFeatureText = function(feature, opt_options) {};
  39674. /**
  39675. * Not implemented.
  39676. * @inheritDoc
  39677. */
  39678. ol.format.IGC.prototype.writeFeaturesText = function(features, opt_options) {};
  39679. /**
  39680. * Not implemented.
  39681. * @inheritDoc
  39682. */
  39683. ol.format.IGC.prototype.writeGeometryText = function(geometry, opt_options) {};
  39684. /**
  39685. * Not implemented.
  39686. * @inheritDoc
  39687. */
  39688. ol.format.IGC.prototype.readGeometryFromText = function(text, opt_options) {};
  39689. goog.provide('ol.style.IconAnchorUnits');
  39690. /**
  39691. * Icon anchor units. One of 'fraction', 'pixels'.
  39692. * @enum {string}
  39693. */
  39694. ol.style.IconAnchorUnits = {
  39695. FRACTION: 'fraction',
  39696. PIXELS: 'pixels'
  39697. };
  39698. goog.provide('ol.style.IconImage');
  39699. goog.require('ol');
  39700. goog.require('ol.dom');
  39701. goog.require('ol.events');
  39702. goog.require('ol.events.EventTarget');
  39703. goog.require('ol.events.EventType');
  39704. goog.require('ol.ImageState');
  39705. goog.require('ol.style');
  39706. /**
  39707. * @constructor
  39708. * @param {Image|HTMLCanvasElement} image Image.
  39709. * @param {string|undefined} src Src.
  39710. * @param {ol.Size} size Size.
  39711. * @param {?string} crossOrigin Cross origin.
  39712. * @param {ol.ImageState} imageState Image state.
  39713. * @param {ol.Color} color Color.
  39714. * @extends {ol.events.EventTarget}
  39715. */
  39716. ol.style.IconImage = function(image, src, size, crossOrigin, imageState,
  39717. color) {
  39718. ol.events.EventTarget.call(this);
  39719. /**
  39720. * @private
  39721. * @type {Image|HTMLCanvasElement}
  39722. */
  39723. this.hitDetectionImage_ = null;
  39724. /**
  39725. * @private
  39726. * @type {Image|HTMLCanvasElement}
  39727. */
  39728. this.image_ = !image ? new Image() : image;
  39729. if (crossOrigin !== null) {
  39730. this.image_.crossOrigin = crossOrigin;
  39731. }
  39732. /**
  39733. * @private
  39734. * @type {HTMLCanvasElement}
  39735. */
  39736. this.canvas_ = color ?
  39737. /** @type {HTMLCanvasElement} */ (document.createElement('CANVAS')) :
  39738. null;
  39739. /**
  39740. * @private
  39741. * @type {ol.Color}
  39742. */
  39743. this.color_ = color;
  39744. /**
  39745. * @private
  39746. * @type {Array.<ol.EventsKey>}
  39747. */
  39748. this.imageListenerKeys_ = null;
  39749. /**
  39750. * @private
  39751. * @type {ol.ImageState}
  39752. */
  39753. this.imageState_ = imageState;
  39754. /**
  39755. * @private
  39756. * @type {ol.Size}
  39757. */
  39758. this.size_ = size;
  39759. /**
  39760. * @private
  39761. * @type {string|undefined}
  39762. */
  39763. this.src_ = src;
  39764. /**
  39765. * @private
  39766. * @type {boolean}
  39767. */
  39768. this.tainting_ = false;
  39769. if (this.imageState_ == ol.ImageState.LOADED) {
  39770. this.determineTainting_();
  39771. }
  39772. };
  39773. ol.inherits(ol.style.IconImage, ol.events.EventTarget);
  39774. /**
  39775. * @param {Image|HTMLCanvasElement} image Image.
  39776. * @param {string} src Src.
  39777. * @param {ol.Size} size Size.
  39778. * @param {?string} crossOrigin Cross origin.
  39779. * @param {ol.ImageState} imageState Image state.
  39780. * @param {ol.Color} color Color.
  39781. * @return {ol.style.IconImage} Icon image.
  39782. */
  39783. ol.style.IconImage.get = function(image, src, size, crossOrigin, imageState,
  39784. color) {
  39785. var iconImageCache = ol.style.iconImageCache;
  39786. var iconImage = iconImageCache.get(src, crossOrigin, color);
  39787. if (!iconImage) {
  39788. iconImage = new ol.style.IconImage(
  39789. image, src, size, crossOrigin, imageState, color);
  39790. iconImageCache.set(src, crossOrigin, color, iconImage);
  39791. }
  39792. return iconImage;
  39793. };
  39794. /**
  39795. * @private
  39796. */
  39797. ol.style.IconImage.prototype.determineTainting_ = function() {
  39798. var context = ol.dom.createCanvasContext2D(1, 1);
  39799. try {
  39800. context.drawImage(this.image_, 0, 0);
  39801. context.getImageData(0, 0, 1, 1);
  39802. } catch (e) {
  39803. this.tainting_ = true;
  39804. }
  39805. };
  39806. /**
  39807. * @private
  39808. */
  39809. ol.style.IconImage.prototype.dispatchChangeEvent_ = function() {
  39810. this.dispatchEvent(ol.events.EventType.CHANGE);
  39811. };
  39812. /**
  39813. * @private
  39814. */
  39815. ol.style.IconImage.prototype.handleImageError_ = function() {
  39816. this.imageState_ = ol.ImageState.ERROR;
  39817. this.unlistenImage_();
  39818. this.dispatchChangeEvent_();
  39819. };
  39820. /**
  39821. * @private
  39822. */
  39823. ol.style.IconImage.prototype.handleImageLoad_ = function() {
  39824. this.imageState_ = ol.ImageState.LOADED;
  39825. if (this.size_) {
  39826. this.image_.width = this.size_[0];
  39827. this.image_.height = this.size_[1];
  39828. }
  39829. this.size_ = [this.image_.width, this.image_.height];
  39830. this.unlistenImage_();
  39831. this.determineTainting_();
  39832. this.replaceColor_();
  39833. this.dispatchChangeEvent_();
  39834. };
  39835. /**
  39836. * @param {number} pixelRatio Pixel ratio.
  39837. * @return {Image|HTMLCanvasElement} Image or Canvas element.
  39838. */
  39839. ol.style.IconImage.prototype.getImage = function(pixelRatio) {
  39840. return this.canvas_ ? this.canvas_ : this.image_;
  39841. };
  39842. /**
  39843. * @return {ol.ImageState} Image state.
  39844. */
  39845. ol.style.IconImage.prototype.getImageState = function() {
  39846. return this.imageState_;
  39847. };
  39848. /**
  39849. * @param {number} pixelRatio Pixel ratio.
  39850. * @return {Image|HTMLCanvasElement} Image element.
  39851. */
  39852. ol.style.IconImage.prototype.getHitDetectionImage = function(pixelRatio) {
  39853. if (!this.hitDetectionImage_) {
  39854. if (this.tainting_) {
  39855. var width = this.size_[0];
  39856. var height = this.size_[1];
  39857. var context = ol.dom.createCanvasContext2D(width, height);
  39858. context.fillRect(0, 0, width, height);
  39859. this.hitDetectionImage_ = context.canvas;
  39860. } else {
  39861. this.hitDetectionImage_ = this.image_;
  39862. }
  39863. }
  39864. return this.hitDetectionImage_;
  39865. };
  39866. /**
  39867. * @return {ol.Size} Image size.
  39868. */
  39869. ol.style.IconImage.prototype.getSize = function() {
  39870. return this.size_;
  39871. };
  39872. /**
  39873. * @return {string|undefined} Image src.
  39874. */
  39875. ol.style.IconImage.prototype.getSrc = function() {
  39876. return this.src_;
  39877. };
  39878. /**
  39879. * Load not yet loaded URI.
  39880. */
  39881. ol.style.IconImage.prototype.load = function() {
  39882. if (this.imageState_ == ol.ImageState.IDLE) {
  39883. this.imageState_ = ol.ImageState.LOADING;
  39884. this.imageListenerKeys_ = [
  39885. ol.events.listenOnce(this.image_, ol.events.EventType.ERROR,
  39886. this.handleImageError_, this),
  39887. ol.events.listenOnce(this.image_, ol.events.EventType.LOAD,
  39888. this.handleImageLoad_, this)
  39889. ];
  39890. try {
  39891. this.image_.src = this.src_;
  39892. } catch (e) {
  39893. this.handleImageError_();
  39894. }
  39895. }
  39896. };
  39897. /**
  39898. * @private
  39899. */
  39900. ol.style.IconImage.prototype.replaceColor_ = function() {
  39901. if (this.tainting_ || this.color_ === null) {
  39902. return;
  39903. }
  39904. this.canvas_.width = this.image_.width;
  39905. this.canvas_.height = this.image_.height;
  39906. var ctx = this.canvas_.getContext('2d');
  39907. ctx.drawImage(this.image_, 0, 0);
  39908. var imgData = ctx.getImageData(0, 0, this.image_.width, this.image_.height);
  39909. var data = imgData.data;
  39910. var r = this.color_[0] / 255.0;
  39911. var g = this.color_[1] / 255.0;
  39912. var b = this.color_[2] / 255.0;
  39913. for (var i = 0, ii = data.length; i < ii; i += 4) {
  39914. data[i] *= r;
  39915. data[i + 1] *= g;
  39916. data[i + 2] *= b;
  39917. }
  39918. ctx.putImageData(imgData, 0, 0);
  39919. };
  39920. /**
  39921. * Discards event handlers which listen for load completion or errors.
  39922. *
  39923. * @private
  39924. */
  39925. ol.style.IconImage.prototype.unlistenImage_ = function() {
  39926. this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
  39927. this.imageListenerKeys_ = null;
  39928. };
  39929. goog.provide('ol.style.IconOrigin');
  39930. /**
  39931. * Icon origin. One of 'bottom-left', 'bottom-right', 'top-left', 'top-right'.
  39932. * @enum {string}
  39933. */
  39934. ol.style.IconOrigin = {
  39935. BOTTOM_LEFT: 'bottom-left',
  39936. BOTTOM_RIGHT: 'bottom-right',
  39937. TOP_LEFT: 'top-left',
  39938. TOP_RIGHT: 'top-right'
  39939. };
  39940. goog.provide('ol.style.Icon');
  39941. goog.require('ol');
  39942. goog.require('ol.ImageState');
  39943. goog.require('ol.asserts');
  39944. goog.require('ol.color');
  39945. goog.require('ol.events');
  39946. goog.require('ol.events.EventType');
  39947. goog.require('ol.style.IconAnchorUnits');
  39948. goog.require('ol.style.IconImage');
  39949. goog.require('ol.style.IconOrigin');
  39950. goog.require('ol.style.Image');
  39951. /**
  39952. * @classdesc
  39953. * Set icon style for vector features.
  39954. *
  39955. * @constructor
  39956. * @param {olx.style.IconOptions=} opt_options Options.
  39957. * @extends {ol.style.Image}
  39958. * @api
  39959. */
  39960. ol.style.Icon = function(opt_options) {
  39961. var options = opt_options || {};
  39962. /**
  39963. * @private
  39964. * @type {Array.<number>}
  39965. */
  39966. this.anchor_ = options.anchor !== undefined ? options.anchor : [0.5, 0.5];
  39967. /**
  39968. * @private
  39969. * @type {Array.<number>}
  39970. */
  39971. this.normalizedAnchor_ = null;
  39972. /**
  39973. * @private
  39974. * @type {ol.style.IconOrigin}
  39975. */
  39976. this.anchorOrigin_ = options.anchorOrigin !== undefined ?
  39977. options.anchorOrigin : ol.style.IconOrigin.TOP_LEFT;
  39978. /**
  39979. * @private
  39980. * @type {ol.style.IconAnchorUnits}
  39981. */
  39982. this.anchorXUnits_ = options.anchorXUnits !== undefined ?
  39983. options.anchorXUnits : ol.style.IconAnchorUnits.FRACTION;
  39984. /**
  39985. * @private
  39986. * @type {ol.style.IconAnchorUnits}
  39987. */
  39988. this.anchorYUnits_ = options.anchorYUnits !== undefined ?
  39989. options.anchorYUnits : ol.style.IconAnchorUnits.FRACTION;
  39990. /**
  39991. * @private
  39992. * @type {?string}
  39993. */
  39994. this.crossOrigin_ =
  39995. options.crossOrigin !== undefined ? options.crossOrigin : null;
  39996. /**
  39997. * @type {Image|HTMLCanvasElement}
  39998. */
  39999. var image = options.img !== undefined ? options.img : null;
  40000. /**
  40001. * @type {ol.Size}
  40002. */
  40003. var imgSize = options.imgSize !== undefined ? options.imgSize : null;
  40004. /**
  40005. * @type {string|undefined}
  40006. */
  40007. var src = options.src;
  40008. ol.asserts.assert(!(src !== undefined && image),
  40009. 4); // `image` and `src` cannot be provided at the same time
  40010. ol.asserts.assert(!image || (image && imgSize),
  40011. 5); // `imgSize` must be set when `image` is provided
  40012. if ((src === undefined || src.length === 0) && image) {
  40013. src = image.src || ol.getUid(image).toString();
  40014. }
  40015. ol.asserts.assert(src !== undefined && src.length > 0,
  40016. 6); // A defined and non-empty `src` or `image` must be provided
  40017. /**
  40018. * @type {ol.ImageState}
  40019. */
  40020. var imageState = options.src !== undefined ?
  40021. ol.ImageState.IDLE : ol.ImageState.LOADED;
  40022. /**
  40023. * @private
  40024. * @type {ol.Color}
  40025. */
  40026. this.color_ = options.color !== undefined ? ol.color.asArray(options.color) :
  40027. null;
  40028. /**
  40029. * @private
  40030. * @type {ol.style.IconImage}
  40031. */
  40032. this.iconImage_ = ol.style.IconImage.get(
  40033. image, /** @type {string} */ (src), imgSize, this.crossOrigin_, imageState, this.color_);
  40034. /**
  40035. * @private
  40036. * @type {Array.<number>}
  40037. */
  40038. this.offset_ = options.offset !== undefined ? options.offset : [0, 0];
  40039. /**
  40040. * @private
  40041. * @type {ol.style.IconOrigin}
  40042. */
  40043. this.offsetOrigin_ = options.offsetOrigin !== undefined ?
  40044. options.offsetOrigin : ol.style.IconOrigin.TOP_LEFT;
  40045. /**
  40046. * @private
  40047. * @type {Array.<number>}
  40048. */
  40049. this.origin_ = null;
  40050. /**
  40051. * @private
  40052. * @type {ol.Size}
  40053. */
  40054. this.size_ = options.size !== undefined ? options.size : null;
  40055. /**
  40056. * @type {number}
  40057. */
  40058. var opacity = options.opacity !== undefined ? options.opacity : 1;
  40059. /**
  40060. * @type {boolean}
  40061. */
  40062. var rotateWithView = options.rotateWithView !== undefined ?
  40063. options.rotateWithView : false;
  40064. /**
  40065. * @type {number}
  40066. */
  40067. var rotation = options.rotation !== undefined ? options.rotation : 0;
  40068. /**
  40069. * @type {number}
  40070. */
  40071. var scale = options.scale !== undefined ? options.scale : 1;
  40072. /**
  40073. * @type {boolean}
  40074. */
  40075. var snapToPixel = options.snapToPixel !== undefined ?
  40076. options.snapToPixel : true;
  40077. ol.style.Image.call(this, {
  40078. opacity: opacity,
  40079. rotation: rotation,
  40080. scale: scale,
  40081. snapToPixel: snapToPixel,
  40082. rotateWithView: rotateWithView
  40083. });
  40084. };
  40085. ol.inherits(ol.style.Icon, ol.style.Image);
  40086. /**
  40087. * Clones the style. The underlying Image/HTMLCanvasElement is not cloned.
  40088. * @return {ol.style.Icon} The cloned style.
  40089. * @api
  40090. */
  40091. ol.style.Icon.prototype.clone = function() {
  40092. return new ol.style.Icon({
  40093. anchor: this.anchor_.slice(),
  40094. anchorOrigin: this.anchorOrigin_,
  40095. anchorXUnits: this.anchorXUnits_,
  40096. anchorYUnits: this.anchorYUnits_,
  40097. crossOrigin: this.crossOrigin_,
  40098. color: (this.color_ && this.color_.slice) ? this.color_.slice() : this.color_ || undefined,
  40099. src: this.getSrc(),
  40100. offset: this.offset_.slice(),
  40101. offsetOrigin: this.offsetOrigin_,
  40102. size: this.size_ !== null ? this.size_.slice() : undefined,
  40103. opacity: this.getOpacity(),
  40104. scale: this.getScale(),
  40105. snapToPixel: this.getSnapToPixel(),
  40106. rotation: this.getRotation(),
  40107. rotateWithView: this.getRotateWithView()
  40108. });
  40109. };
  40110. /**
  40111. * @inheritDoc
  40112. * @api
  40113. */
  40114. ol.style.Icon.prototype.getAnchor = function() {
  40115. if (this.normalizedAnchor_) {
  40116. return this.normalizedAnchor_;
  40117. }
  40118. var anchor = this.anchor_;
  40119. var size = this.getSize();
  40120. if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
  40121. this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
  40122. if (!size) {
  40123. return null;
  40124. }
  40125. anchor = this.anchor_.slice();
  40126. if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION) {
  40127. anchor[0] *= size[0];
  40128. }
  40129. if (this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
  40130. anchor[1] *= size[1];
  40131. }
  40132. }
  40133. if (this.anchorOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
  40134. if (!size) {
  40135. return null;
  40136. }
  40137. if (anchor === this.anchor_) {
  40138. anchor = this.anchor_.slice();
  40139. }
  40140. if (this.anchorOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
  40141. this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
  40142. anchor[0] = -anchor[0] + size[0];
  40143. }
  40144. if (this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
  40145. this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
  40146. anchor[1] = -anchor[1] + size[1];
  40147. }
  40148. }
  40149. this.normalizedAnchor_ = anchor;
  40150. return this.normalizedAnchor_;
  40151. };
  40152. /**
  40153. * Get the icon color.
  40154. * @return {ol.Color} Color.
  40155. * @api
  40156. */
  40157. ol.style.Icon.prototype.getColor = function() {
  40158. return this.color_;
  40159. };
  40160. /**
  40161. * Get the image icon.
  40162. * @param {number} pixelRatio Pixel ratio.
  40163. * @return {Image|HTMLCanvasElement} Image or Canvas element.
  40164. * @override
  40165. * @api
  40166. */
  40167. ol.style.Icon.prototype.getImage = function(pixelRatio) {
  40168. return this.iconImage_.getImage(pixelRatio);
  40169. };
  40170. /**
  40171. * @override
  40172. */
  40173. ol.style.Icon.prototype.getImageSize = function() {
  40174. return this.iconImage_.getSize();
  40175. };
  40176. /**
  40177. * @override
  40178. */
  40179. ol.style.Icon.prototype.getHitDetectionImageSize = function() {
  40180. return this.getImageSize();
  40181. };
  40182. /**
  40183. * @override
  40184. */
  40185. ol.style.Icon.prototype.getImageState = function() {
  40186. return this.iconImage_.getImageState();
  40187. };
  40188. /**
  40189. * @override
  40190. */
  40191. ol.style.Icon.prototype.getHitDetectionImage = function(pixelRatio) {
  40192. return this.iconImage_.getHitDetectionImage(pixelRatio);
  40193. };
  40194. /**
  40195. * @inheritDoc
  40196. * @api
  40197. */
  40198. ol.style.Icon.prototype.getOrigin = function() {
  40199. if (this.origin_) {
  40200. return this.origin_;
  40201. }
  40202. var offset = this.offset_;
  40203. if (this.offsetOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
  40204. var size = this.getSize();
  40205. var iconImageSize = this.iconImage_.getSize();
  40206. if (!size || !iconImageSize) {
  40207. return null;
  40208. }
  40209. offset = offset.slice();
  40210. if (this.offsetOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
  40211. this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
  40212. offset[0] = iconImageSize[0] - size[0] - offset[0];
  40213. }
  40214. if (this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
  40215. this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
  40216. offset[1] = iconImageSize[1] - size[1] - offset[1];
  40217. }
  40218. }
  40219. this.origin_ = offset;
  40220. return this.origin_;
  40221. };
  40222. /**
  40223. * Get the image URL.
  40224. * @return {string|undefined} Image src.
  40225. * @api
  40226. */
  40227. ol.style.Icon.prototype.getSrc = function() {
  40228. return this.iconImage_.getSrc();
  40229. };
  40230. /**
  40231. * @inheritDoc
  40232. * @api
  40233. */
  40234. ol.style.Icon.prototype.getSize = function() {
  40235. return !this.size_ ? this.iconImage_.getSize() : this.size_;
  40236. };
  40237. /**
  40238. * @override
  40239. */
  40240. ol.style.Icon.prototype.listenImageChange = function(listener, thisArg) {
  40241. return ol.events.listen(this.iconImage_, ol.events.EventType.CHANGE,
  40242. listener, thisArg);
  40243. };
  40244. /**
  40245. * Load not yet loaded URI.
  40246. * When rendering a feature with an icon style, the vector renderer will
  40247. * automatically call this method. However, you might want to call this
  40248. * method yourself for preloading or other purposes.
  40249. * @override
  40250. * @api
  40251. */
  40252. ol.style.Icon.prototype.load = function() {
  40253. this.iconImage_.load();
  40254. };
  40255. /**
  40256. * @override
  40257. */
  40258. ol.style.Icon.prototype.unlistenImageChange = function(listener, thisArg) {
  40259. ol.events.unlisten(this.iconImage_, ol.events.EventType.CHANGE,
  40260. listener, thisArg);
  40261. };
  40262. goog.provide('ol.style.Text');
  40263. goog.require('ol.style.Fill');
  40264. goog.require('ol.style.TextPlacement');
  40265. /**
  40266. * @classdesc
  40267. * Set text style for vector features.
  40268. *
  40269. * @constructor
  40270. * @param {olx.style.TextOptions=} opt_options Options.
  40271. * @api
  40272. */
  40273. ol.style.Text = function(opt_options) {
  40274. var options = opt_options || {};
  40275. /**
  40276. * @private
  40277. * @type {string|undefined}
  40278. */
  40279. this.font_ = options.font;
  40280. /**
  40281. * @private
  40282. * @type {number|undefined}
  40283. */
  40284. this.rotation_ = options.rotation;
  40285. /**
  40286. * @private
  40287. * @type {boolean|undefined}
  40288. */
  40289. this.rotateWithView_ = options.rotateWithView;
  40290. /**
  40291. * @private
  40292. * @type {number|undefined}
  40293. */
  40294. this.scale_ = options.scale;
  40295. /**
  40296. * @private
  40297. * @type {string|undefined}
  40298. */
  40299. this.text_ = options.text;
  40300. /**
  40301. * @private
  40302. * @type {string|undefined}
  40303. */
  40304. this.textAlign_ = options.textAlign;
  40305. /**
  40306. * @private
  40307. * @type {string|undefined}
  40308. */
  40309. this.textBaseline_ = options.textBaseline;
  40310. /**
  40311. * @private
  40312. * @type {ol.style.Fill}
  40313. */
  40314. this.fill_ = options.fill !== undefined ? options.fill :
  40315. new ol.style.Fill({color: ol.style.Text.DEFAULT_FILL_COLOR_});
  40316. /**
  40317. * @private
  40318. * @type {number}
  40319. */
  40320. this.maxAngle_ = options.maxAngle !== undefined ? options.maxAngle : Math.PI / 4;
  40321. /**
  40322. * @private
  40323. * @type {ol.style.TextPlacement|string}
  40324. */
  40325. this.placement_ = options.placement !== undefined ? options.placement : ol.style.TextPlacement.POINT;
  40326. //TODO Use options.overflow directly after removing @deprecated exceedLength
  40327. var overflow = options.overflow === undefined ? options.exceedLength : options.overflow;
  40328. /**
  40329. * @private
  40330. * @type {boolean}
  40331. */
  40332. this.overflow_ = overflow !== undefined ? overflow : false;
  40333. /**
  40334. * @private
  40335. * @type {ol.style.Stroke}
  40336. */
  40337. this.stroke_ = options.stroke !== undefined ? options.stroke : null;
  40338. /**
  40339. * @private
  40340. * @type {number}
  40341. */
  40342. this.offsetX_ = options.offsetX !== undefined ? options.offsetX : 0;
  40343. /**
  40344. * @private
  40345. * @type {number}
  40346. */
  40347. this.offsetY_ = options.offsetY !== undefined ? options.offsetY : 0;
  40348. /**
  40349. * @private
  40350. * @type {ol.style.Fill}
  40351. */
  40352. this.backgroundFill_ = options.backgroundFill ? options.backgroundFill : null;
  40353. /**
  40354. * @private
  40355. * @type {ol.style.Stroke}
  40356. */
  40357. this.backgroundStroke_ = options.backgroundStroke ? options.backgroundStroke : null;
  40358. /**
  40359. * @private
  40360. * @type {Array.<number>}
  40361. */
  40362. this.padding_ = options.padding === undefined ? null : options.padding;
  40363. };
  40364. /**
  40365. * The default fill color to use if no fill was set at construction time; a
  40366. * blackish `#333`.
  40367. *
  40368. * @const {string}
  40369. * @private
  40370. */
  40371. ol.style.Text.DEFAULT_FILL_COLOR_ = '#333';
  40372. /**
  40373. * Clones the style.
  40374. * @return {ol.style.Text} The cloned style.
  40375. * @api
  40376. */
  40377. ol.style.Text.prototype.clone = function() {
  40378. return new ol.style.Text({
  40379. font: this.getFont(),
  40380. placement: this.getPlacement(),
  40381. maxAngle: this.getMaxAngle(),
  40382. overflow: this.getOverflow(),
  40383. rotation: this.getRotation(),
  40384. rotateWithView: this.getRotateWithView(),
  40385. scale: this.getScale(),
  40386. text: this.getText(),
  40387. textAlign: this.getTextAlign(),
  40388. textBaseline: this.getTextBaseline(),
  40389. fill: this.getFill() ? this.getFill().clone() : undefined,
  40390. stroke: this.getStroke() ? this.getStroke().clone() : undefined,
  40391. offsetX: this.getOffsetX(),
  40392. offsetY: this.getOffsetY()
  40393. });
  40394. };
  40395. /**
  40396. * Get the `overflow` configuration.
  40397. * @return {boolean} Let text overflow the length of the path they follow.
  40398. * @api
  40399. */
  40400. ol.style.Text.prototype.getOverflow = function() {
  40401. return this.overflow_;
  40402. };
  40403. /**
  40404. * Get the font name.
  40405. * @return {string|undefined} Font.
  40406. * @api
  40407. */
  40408. ol.style.Text.prototype.getFont = function() {
  40409. return this.font_;
  40410. };
  40411. /**
  40412. * Get the maximum angle between adjacent characters.
  40413. * @return {number} Angle in radians.
  40414. * @api
  40415. */
  40416. ol.style.Text.prototype.getMaxAngle = function() {
  40417. return this.maxAngle_;
  40418. };
  40419. /**
  40420. * Get the label placement.
  40421. * @return {ol.style.TextPlacement|string} Text placement.
  40422. * @api
  40423. */
  40424. ol.style.Text.prototype.getPlacement = function() {
  40425. return this.placement_;
  40426. };
  40427. /**
  40428. * Get the x-offset for the text.
  40429. * @return {number} Horizontal text offset.
  40430. * @api
  40431. */
  40432. ol.style.Text.prototype.getOffsetX = function() {
  40433. return this.offsetX_;
  40434. };
  40435. /**
  40436. * Get the y-offset for the text.
  40437. * @return {number} Vertical text offset.
  40438. * @api
  40439. */
  40440. ol.style.Text.prototype.getOffsetY = function() {
  40441. return this.offsetY_;
  40442. };
  40443. /**
  40444. * Get the fill style for the text.
  40445. * @return {ol.style.Fill} Fill style.
  40446. * @api
  40447. */
  40448. ol.style.Text.prototype.getFill = function() {
  40449. return this.fill_;
  40450. };
  40451. /**
  40452. * Determine whether the text rotates with the map.
  40453. * @return {boolean|undefined} Rotate with map.
  40454. * @api
  40455. */
  40456. ol.style.Text.prototype.getRotateWithView = function() {
  40457. return this.rotateWithView_;
  40458. };
  40459. /**
  40460. * Get the text rotation.
  40461. * @return {number|undefined} Rotation.
  40462. * @api
  40463. */
  40464. ol.style.Text.prototype.getRotation = function() {
  40465. return this.rotation_;
  40466. };
  40467. /**
  40468. * Get the text scale.
  40469. * @return {number|undefined} Scale.
  40470. * @api
  40471. */
  40472. ol.style.Text.prototype.getScale = function() {
  40473. return this.scale_;
  40474. };
  40475. /**
  40476. * Get the stroke style for the text.
  40477. * @return {ol.style.Stroke} Stroke style.
  40478. * @api
  40479. */
  40480. ol.style.Text.prototype.getStroke = function() {
  40481. return this.stroke_;
  40482. };
  40483. /**
  40484. * Get the text to be rendered.
  40485. * @return {string|undefined} Text.
  40486. * @api
  40487. */
  40488. ol.style.Text.prototype.getText = function() {
  40489. return this.text_;
  40490. };
  40491. /**
  40492. * Get the text alignment.
  40493. * @return {string|undefined} Text align.
  40494. * @api
  40495. */
  40496. ol.style.Text.prototype.getTextAlign = function() {
  40497. return this.textAlign_;
  40498. };
  40499. /**
  40500. * Get the text baseline.
  40501. * @return {string|undefined} Text baseline.
  40502. * @api
  40503. */
  40504. ol.style.Text.prototype.getTextBaseline = function() {
  40505. return this.textBaseline_;
  40506. };
  40507. /**
  40508. * Get the background fill style for the text.
  40509. * @return {ol.style.Fill} Fill style.
  40510. * @api
  40511. */
  40512. ol.style.Text.prototype.getBackgroundFill = function() {
  40513. return this.backgroundFill_;
  40514. };
  40515. /**
  40516. * Get the background stroke style for the text.
  40517. * @return {ol.style.Stroke} Stroke style.
  40518. * @api
  40519. */
  40520. ol.style.Text.prototype.getBackgroundStroke = function() {
  40521. return this.backgroundStroke_;
  40522. };
  40523. /**
  40524. * Get the padding for the text.
  40525. * @return {Array.<number>} Padding.
  40526. * @api
  40527. */
  40528. ol.style.Text.prototype.getPadding = function() {
  40529. return this.padding_;
  40530. };
  40531. /**
  40532. * Set the `overflow` property.
  40533. *
  40534. * @param {boolean} overflow Let text overflow the path that it follows.
  40535. * @api
  40536. */
  40537. ol.style.Text.prototype.setOverflow = function(overflow) {
  40538. this.overflow_ = overflow;
  40539. };
  40540. /**
  40541. * Set the font.
  40542. *
  40543. * @param {string|undefined} font Font.
  40544. * @api
  40545. */
  40546. ol.style.Text.prototype.setFont = function(font) {
  40547. this.font_ = font;
  40548. };
  40549. /**
  40550. * Set the maximum angle between adjacent characters.
  40551. *
  40552. * @param {number} maxAngle Angle in radians.
  40553. * @api
  40554. */
  40555. ol.style.Text.prototype.setMaxAngle = function(maxAngle) {
  40556. this.maxAngle_ = maxAngle;
  40557. };
  40558. /**
  40559. * Set the x offset.
  40560. *
  40561. * @param {number} offsetX Horizontal text offset.
  40562. * @api
  40563. */
  40564. ol.style.Text.prototype.setOffsetX = function(offsetX) {
  40565. this.offsetX_ = offsetX;
  40566. };
  40567. /**
  40568. * Set the y offset.
  40569. *
  40570. * @param {number} offsetY Vertical text offset.
  40571. * @api
  40572. */
  40573. ol.style.Text.prototype.setOffsetY = function(offsetY) {
  40574. this.offsetY_ = offsetY;
  40575. };
  40576. /**
  40577. * Set the text placement.
  40578. *
  40579. * @param {ol.style.TextPlacement|string} placement Placement.
  40580. * @api
  40581. */
  40582. ol.style.Text.prototype.setPlacement = function(placement) {
  40583. this.placement_ = placement;
  40584. };
  40585. /**
  40586. * Set the fill.
  40587. *
  40588. * @param {ol.style.Fill} fill Fill style.
  40589. * @api
  40590. */
  40591. ol.style.Text.prototype.setFill = function(fill) {
  40592. this.fill_ = fill;
  40593. };
  40594. /**
  40595. * Set the rotation.
  40596. *
  40597. * @param {number|undefined} rotation Rotation.
  40598. * @api
  40599. */
  40600. ol.style.Text.prototype.setRotation = function(rotation) {
  40601. this.rotation_ = rotation;
  40602. };
  40603. /**
  40604. * Set the scale.
  40605. *
  40606. * @param {number|undefined} scale Scale.
  40607. * @api
  40608. */
  40609. ol.style.Text.prototype.setScale = function(scale) {
  40610. this.scale_ = scale;
  40611. };
  40612. /**
  40613. * Set the stroke.
  40614. *
  40615. * @param {ol.style.Stroke} stroke Stroke style.
  40616. * @api
  40617. */
  40618. ol.style.Text.prototype.setStroke = function(stroke) {
  40619. this.stroke_ = stroke;
  40620. };
  40621. /**
  40622. * Set the text.
  40623. *
  40624. * @param {string|undefined} text Text.
  40625. * @api
  40626. */
  40627. ol.style.Text.prototype.setText = function(text) {
  40628. this.text_ = text;
  40629. };
  40630. /**
  40631. * Set the text alignment.
  40632. *
  40633. * @param {string|undefined} textAlign Text align.
  40634. * @api
  40635. */
  40636. ol.style.Text.prototype.setTextAlign = function(textAlign) {
  40637. this.textAlign_ = textAlign;
  40638. };
  40639. /**
  40640. * Set the text baseline.
  40641. *
  40642. * @param {string|undefined} textBaseline Text baseline.
  40643. * @api
  40644. */
  40645. ol.style.Text.prototype.setTextBaseline = function(textBaseline) {
  40646. this.textBaseline_ = textBaseline;
  40647. };
  40648. /**
  40649. * Set the background fill.
  40650. *
  40651. * @param {ol.style.Fill} fill Fill style.
  40652. * @api
  40653. */
  40654. ol.style.Text.prototype.setBackgroundFill = function(fill) {
  40655. this.backgroundFill_ = fill;
  40656. };
  40657. /**
  40658. * Set the background stroke.
  40659. *
  40660. * @param {ol.style.Stroke} stroke Stroke style.
  40661. * @api
  40662. */
  40663. ol.style.Text.prototype.setBackgroundStroke = function(stroke) {
  40664. this.backgroundStroke_ = stroke;
  40665. };
  40666. /**
  40667. * Set the padding (`[top, right, bottom, left]`).
  40668. *
  40669. * @param {!Array.<number>} padding Padding.
  40670. * @api
  40671. */
  40672. ol.style.Text.prototype.setPadding = function(padding) {
  40673. this.padding_ = padding;
  40674. };
  40675. // FIXME http://earth.google.com/kml/1.0 namespace?
  40676. // FIXME why does node.getAttribute return an unknown type?
  40677. // FIXME serialize arbitrary feature properties
  40678. // FIXME don't parse style if extractStyles is false
  40679. goog.provide('ol.format.KML');
  40680. goog.require('ol');
  40681. goog.require('ol.Feature');
  40682. goog.require('ol.array');
  40683. goog.require('ol.asserts');
  40684. goog.require('ol.color');
  40685. goog.require('ol.format.Feature');
  40686. goog.require('ol.format.XMLFeature');
  40687. goog.require('ol.format.XSD');
  40688. goog.require('ol.geom.GeometryCollection');
  40689. goog.require('ol.geom.GeometryLayout');
  40690. goog.require('ol.geom.GeometryType');
  40691. goog.require('ol.geom.LineString');
  40692. goog.require('ol.geom.MultiLineString');
  40693. goog.require('ol.geom.MultiPoint');
  40694. goog.require('ol.geom.MultiPolygon');
  40695. goog.require('ol.geom.Point');
  40696. goog.require('ol.geom.Polygon');
  40697. goog.require('ol.math');
  40698. goog.require('ol.proj');
  40699. goog.require('ol.style.Fill');
  40700. goog.require('ol.style.Icon');
  40701. goog.require('ol.style.IconAnchorUnits');
  40702. goog.require('ol.style.IconOrigin');
  40703. goog.require('ol.style.Stroke');
  40704. goog.require('ol.style.Style');
  40705. goog.require('ol.style.Text');
  40706. goog.require('ol.xml');
  40707. /**
  40708. * @classdesc
  40709. * Feature format for reading and writing data in the KML format.
  40710. *
  40711. * Note that the KML format uses the URL() constructor. Older browsers such as IE
  40712. * which do not support this will need a URL polyfill to be loaded before use.
  40713. *
  40714. * @constructor
  40715. * @extends {ol.format.XMLFeature}
  40716. * @param {olx.format.KMLOptions=} opt_options Options.
  40717. * @api
  40718. */
  40719. ol.format.KML = function(opt_options) {
  40720. var options = opt_options ? opt_options : {};
  40721. ol.format.XMLFeature.call(this);
  40722. if (!ol.format.KML.DEFAULT_STYLE_ARRAY_) {
  40723. ol.format.KML.createStyleDefaults_();
  40724. }
  40725. /**
  40726. * @inheritDoc
  40727. */
  40728. this.defaultDataProjection = ol.proj.get('EPSG:4326');
  40729. /**
  40730. * @private
  40731. * @type {Array.<ol.style.Style>}
  40732. */
  40733. this.defaultStyle_ = options.defaultStyle ?
  40734. options.defaultStyle : ol.format.KML.DEFAULT_STYLE_ARRAY_;
  40735. /**
  40736. * @private
  40737. * @type {boolean}
  40738. */
  40739. this.extractStyles_ = options.extractStyles !== undefined ?
  40740. options.extractStyles : true;
  40741. /**
  40742. * @private
  40743. * @type {boolean}
  40744. */
  40745. this.writeStyles_ = options.writeStyles !== undefined ?
  40746. options.writeStyles : true;
  40747. /**
  40748. * @private
  40749. * @type {Object.<string, (Array.<ol.style.Style>|string)>}
  40750. */
  40751. this.sharedStyles_ = {};
  40752. /**
  40753. * @private
  40754. * @type {boolean}
  40755. */
  40756. this.showPointNames_ = options.showPointNames !== undefined ?
  40757. options.showPointNames : true;
  40758. };
  40759. ol.inherits(ol.format.KML, ol.format.XMLFeature);
  40760. /**
  40761. * @const
  40762. * @type {Array.<string>}
  40763. * @private
  40764. */
  40765. ol.format.KML.GX_NAMESPACE_URIS_ = [
  40766. 'http://www.google.com/kml/ext/2.2'
  40767. ];
  40768. /**
  40769. * @const
  40770. * @type {Array.<string>}
  40771. * @private
  40772. */
  40773. ol.format.KML.NAMESPACE_URIS_ = [
  40774. null,
  40775. 'http://earth.google.com/kml/2.0',
  40776. 'http://earth.google.com/kml/2.1',
  40777. 'http://earth.google.com/kml/2.2',
  40778. 'http://www.opengis.net/kml/2.2'
  40779. ];
  40780. /**
  40781. * @const
  40782. * @type {string}
  40783. * @private
  40784. */
  40785. ol.format.KML.SCHEMA_LOCATION_ = 'http://www.opengis.net/kml/2.2 ' +
  40786. 'https://developers.google.com/kml/schema/kml22gx.xsd';
  40787. /**
  40788. * @return {Array.<ol.style.Style>} Default style.
  40789. * @private
  40790. */
  40791. ol.format.KML.createStyleDefaults_ = function() {
  40792. /**
  40793. * @const
  40794. * @type {ol.Color}
  40795. * @private
  40796. */
  40797. ol.format.KML.DEFAULT_COLOR_ = [255, 255, 255, 1];
  40798. /**
  40799. * @const
  40800. * @type {ol.style.Fill}
  40801. * @private
  40802. */
  40803. ol.format.KML.DEFAULT_FILL_STYLE_ = new ol.style.Fill({
  40804. color: ol.format.KML.DEFAULT_COLOR_
  40805. });
  40806. /**
  40807. * @const
  40808. * @type {ol.Size}
  40809. * @private
  40810. */
  40811. ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_ = [20, 2]; // FIXME maybe [8, 32] ?
  40812. /**
  40813. * @const
  40814. * @type {ol.style.IconAnchorUnits}
  40815. * @private
  40816. */
  40817. ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ =
  40818. ol.style.IconAnchorUnits.PIXELS;
  40819. /**
  40820. * @const
  40821. * @type {ol.style.IconAnchorUnits}
  40822. * @private
  40823. */
  40824. ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ =
  40825. ol.style.IconAnchorUnits.PIXELS;
  40826. /**
  40827. * @const
  40828. * @type {ol.Size}
  40829. * @private
  40830. */
  40831. ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_ = [64, 64];
  40832. /**
  40833. * @const
  40834. * @type {string}
  40835. * @private
  40836. */
  40837. ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_ =
  40838. 'https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png';
  40839. /**
  40840. * @const
  40841. * @type {number}
  40842. * @private
  40843. */
  40844. ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_ = 0.5;
  40845. /**
  40846. * @const
  40847. * @type {ol.style.Image}
  40848. * @private
  40849. */
  40850. ol.format.KML.DEFAULT_IMAGE_STYLE_ = new ol.style.Icon({
  40851. anchor: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_,
  40852. anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
  40853. anchorXUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_,
  40854. anchorYUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_,
  40855. crossOrigin: 'anonymous',
  40856. rotation: 0,
  40857. scale: ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_,
  40858. size: ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_,
  40859. src: ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_
  40860. });
  40861. /**
  40862. * @const
  40863. * @type {string}
  40864. * @private
  40865. */
  40866. ol.format.KML.DEFAULT_NO_IMAGE_STYLE_ = 'NO_IMAGE';
  40867. /**
  40868. * @const
  40869. * @type {ol.style.Stroke}
  40870. * @private
  40871. */
  40872. ol.format.KML.DEFAULT_STROKE_STYLE_ = new ol.style.Stroke({
  40873. color: ol.format.KML.DEFAULT_COLOR_,
  40874. width: 1
  40875. });
  40876. /**
  40877. * @const
  40878. * @type {ol.style.Stroke}
  40879. * @private
  40880. */
  40881. ol.format.KML.DEFAULT_TEXT_STROKE_STYLE_ = new ol.style.Stroke({
  40882. color: [51, 51, 51, 1],
  40883. width: 2
  40884. });
  40885. /**
  40886. * @const
  40887. * @type {ol.style.Text}
  40888. * @private
  40889. */
  40890. ol.format.KML.DEFAULT_TEXT_STYLE_ = new ol.style.Text({
  40891. font: 'bold 16px Helvetica',
  40892. fill: ol.format.KML.DEFAULT_FILL_STYLE_,
  40893. stroke: ol.format.KML.DEFAULT_TEXT_STROKE_STYLE_,
  40894. scale: 0.8
  40895. });
  40896. /**
  40897. * @const
  40898. * @type {ol.style.Style}
  40899. * @private
  40900. */
  40901. ol.format.KML.DEFAULT_STYLE_ = new ol.style.Style({
  40902. fill: ol.format.KML.DEFAULT_FILL_STYLE_,
  40903. image: ol.format.KML.DEFAULT_IMAGE_STYLE_,
  40904. text: ol.format.KML.DEFAULT_TEXT_STYLE_,
  40905. stroke: ol.format.KML.DEFAULT_STROKE_STYLE_,
  40906. zIndex: 0
  40907. });
  40908. /**
  40909. * @const
  40910. * @type {Array.<ol.style.Style>}
  40911. * @private
  40912. */
  40913. ol.format.KML.DEFAULT_STYLE_ARRAY_ = [ol.format.KML.DEFAULT_STYLE_];
  40914. return ol.format.KML.DEFAULT_STYLE_ARRAY_;
  40915. };
  40916. /**
  40917. * @const
  40918. * @type {Object.<string, ol.style.IconAnchorUnits>}
  40919. * @private
  40920. */
  40921. ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = {
  40922. 'fraction': ol.style.IconAnchorUnits.FRACTION,
  40923. 'pixels': ol.style.IconAnchorUnits.PIXELS,
  40924. 'insetPixels': ol.style.IconAnchorUnits.PIXELS
  40925. };
  40926. /**
  40927. * @param {ol.style.Style|undefined} foundStyle Style.
  40928. * @param {string} name Name.
  40929. * @return {ol.style.Style} style Style.
  40930. * @private
  40931. */
  40932. ol.format.KML.createNameStyleFunction_ = function(foundStyle, name) {
  40933. var textStyle = null;
  40934. var textOffset = [0, 0];
  40935. var textAlign = 'start';
  40936. if (foundStyle.getImage()) {
  40937. var imageSize = foundStyle.getImage().getImageSize();
  40938. if (imageSize === null) {
  40939. imageSize = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
  40940. }
  40941. if (imageSize.length == 2) {
  40942. var imageScale = foundStyle.getImage().getScale();
  40943. // Offset the label to be centered to the right of the icon, if there is
  40944. // one.
  40945. textOffset[0] = imageScale * imageSize[0] / 2;
  40946. textOffset[1] = -imageScale * imageSize[1] / 2;
  40947. textAlign = 'left';
  40948. }
  40949. }
  40950. if (foundStyle.getText() !== null) {
  40951. // clone the text style, customizing it with name, alignments and offset.
  40952. // Note that kml does not support many text options that OpenLayers does (rotation, textBaseline).
  40953. var foundText = foundStyle.getText();
  40954. textStyle = foundText.clone();
  40955. textStyle.setFont(foundText.getFont() || ol.format.KML.DEFAULT_TEXT_STYLE_.getFont());
  40956. textStyle.setScale(foundText.getScale() || ol.format.KML.DEFAULT_TEXT_STYLE_.getScale());
  40957. textStyle.setFill(foundText.getFill() || ol.format.KML.DEFAULT_TEXT_STYLE_.getFill());
  40958. textStyle.setStroke(foundText.getStroke() || ol.format.KML.DEFAULT_TEXT_STROKE_STYLE_);
  40959. } else {
  40960. textStyle = ol.format.KML.DEFAULT_TEXT_STYLE_.clone();
  40961. }
  40962. textStyle.setText(name);
  40963. textStyle.setOffsetX(textOffset[0]);
  40964. textStyle.setOffsetY(textOffset[1]);
  40965. textStyle.setTextAlign(textAlign);
  40966. var nameStyle = new ol.style.Style({
  40967. text: textStyle
  40968. });
  40969. return nameStyle;
  40970. };
  40971. /**
  40972. * @param {Array.<ol.style.Style>|undefined} style Style.
  40973. * @param {string} styleUrl Style URL.
  40974. * @param {Array.<ol.style.Style>} defaultStyle Default style.
  40975. * @param {Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles Shared
  40976. * styles.
  40977. * @param {boolean|undefined} showPointNames true to show names for point
  40978. * placemarks.
  40979. * @return {ol.FeatureStyleFunction} Feature style function.
  40980. * @private
  40981. */
  40982. ol.format.KML.createFeatureStyleFunction_ = function(style, styleUrl,
  40983. defaultStyle, sharedStyles, showPointNames) {
  40984. return (
  40985. /**
  40986. * @param {number} resolution Resolution.
  40987. * @return {Array.<ol.style.Style>} Style.
  40988. * @this {ol.Feature}
  40989. */
  40990. function(resolution) {
  40991. var drawName = showPointNames;
  40992. /** @type {ol.style.Style|undefined} */
  40993. var nameStyle;
  40994. var name = '';
  40995. if (drawName) {
  40996. if (this.getGeometry()) {
  40997. drawName = (this.getGeometry().getType() ===
  40998. ol.geom.GeometryType.POINT);
  40999. }
  41000. }
  41001. if (drawName) {
  41002. name = /** @type {string} */ (this.get('name'));
  41003. drawName = drawName && name;
  41004. }
  41005. if (style) {
  41006. if (drawName) {
  41007. nameStyle = ol.format.KML.createNameStyleFunction_(style[0],
  41008. name);
  41009. return style.concat(nameStyle);
  41010. }
  41011. return style;
  41012. }
  41013. if (styleUrl) {
  41014. var foundStyle = ol.format.KML.findStyle_(styleUrl, defaultStyle,
  41015. sharedStyles);
  41016. if (drawName) {
  41017. nameStyle = ol.format.KML.createNameStyleFunction_(foundStyle[0],
  41018. name);
  41019. return foundStyle.concat(nameStyle);
  41020. }
  41021. return foundStyle;
  41022. }
  41023. if (drawName) {
  41024. nameStyle = ol.format.KML.createNameStyleFunction_(defaultStyle[0],
  41025. name);
  41026. return defaultStyle.concat(nameStyle);
  41027. }
  41028. return defaultStyle;
  41029. });
  41030. };
  41031. /**
  41032. * @param {Array.<ol.style.Style>|string|undefined} styleValue Style value.
  41033. * @param {Array.<ol.style.Style>} defaultStyle Default style.
  41034. * @param {Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles
  41035. * Shared styles.
  41036. * @return {Array.<ol.style.Style>} Style.
  41037. * @private
  41038. */
  41039. ol.format.KML.findStyle_ = function(styleValue, defaultStyle, sharedStyles) {
  41040. if (Array.isArray(styleValue)) {
  41041. return styleValue;
  41042. } else if (typeof styleValue === 'string') {
  41043. // KML files in the wild occasionally forget the leading `#` on styleUrls
  41044. // defined in the same document. Add a leading `#` if it enables to find
  41045. // a style.
  41046. if (!(styleValue in sharedStyles) && ('#' + styleValue in sharedStyles)) {
  41047. styleValue = '#' + styleValue;
  41048. }
  41049. return ol.format.KML.findStyle_(
  41050. sharedStyles[styleValue], defaultStyle, sharedStyles);
  41051. } else {
  41052. return defaultStyle;
  41053. }
  41054. };
  41055. /**
  41056. * @param {Node} node Node.
  41057. * @private
  41058. * @return {ol.Color|undefined} Color.
  41059. */
  41060. ol.format.KML.readColor_ = function(node) {
  41061. var s = ol.xml.getAllTextContent(node, false);
  41062. // The KML specification states that colors should not include a leading `#`
  41063. // but we tolerate them.
  41064. var m = /^\s*#?\s*([0-9A-Fa-f]{8})\s*$/.exec(s);
  41065. if (m) {
  41066. var hexColor = m[1];
  41067. return [
  41068. parseInt(hexColor.substr(6, 2), 16),
  41069. parseInt(hexColor.substr(4, 2), 16),
  41070. parseInt(hexColor.substr(2, 2), 16),
  41071. parseInt(hexColor.substr(0, 2), 16) / 255
  41072. ];
  41073. } else {
  41074. return undefined;
  41075. }
  41076. };
  41077. /**
  41078. * @param {Node} node Node.
  41079. * @private
  41080. * @return {Array.<number>|undefined} Flat coordinates.
  41081. */
  41082. ol.format.KML.readFlatCoordinates_ = function(node) {
  41083. var s = ol.xml.getAllTextContent(node, false);
  41084. var flatCoordinates = [];
  41085. // The KML specification states that coordinate tuples should not include
  41086. // spaces, but we tolerate them.
  41087. var re =
  41088. /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*,\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)(?:\s*,\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?))?\s*/i;
  41089. var m;
  41090. while ((m = re.exec(s))) {
  41091. var x = parseFloat(m[1]);
  41092. var y = parseFloat(m[2]);
  41093. var z = m[3] ? parseFloat(m[3]) : 0;
  41094. flatCoordinates.push(x, y, z);
  41095. s = s.substr(m[0].length);
  41096. }
  41097. if (s !== '') {
  41098. return undefined;
  41099. }
  41100. return flatCoordinates;
  41101. };
  41102. /**
  41103. * @param {Node} node Node.
  41104. * @private
  41105. * @return {string} URI.
  41106. */
  41107. ol.format.KML.readURI_ = function(node) {
  41108. var s = ol.xml.getAllTextContent(node, false).trim();
  41109. var baseURI = node.baseURI;
  41110. if (!baseURI || baseURI == 'about:blank') {
  41111. baseURI = window.location.href;
  41112. }
  41113. if (baseURI) {
  41114. var url = new URL(s, baseURI);
  41115. return url.href;
  41116. } else {
  41117. return s;
  41118. }
  41119. };
  41120. /**
  41121. * @param {Node} node Node.
  41122. * @private
  41123. * @return {ol.KMLVec2_} Vec2.
  41124. */
  41125. ol.format.KML.readVec2_ = function(node) {
  41126. var xunits = node.getAttribute('xunits');
  41127. var yunits = node.getAttribute('yunits');
  41128. var origin;
  41129. if (xunits !== 'insetPixels') {
  41130. if (yunits !== 'insetPixels') {
  41131. origin = ol.style.IconOrigin.BOTTOM_LEFT;
  41132. } else {
  41133. origin = ol.style.IconOrigin.TOP_LEFT;
  41134. }
  41135. } else {
  41136. if (yunits !== 'insetPixels') {
  41137. origin = ol.style.IconOrigin.BOTTOM_RIGHT;
  41138. } else {
  41139. origin = ol.style.IconOrigin.TOP_RIGHT;
  41140. }
  41141. }
  41142. return {
  41143. x: parseFloat(node.getAttribute('x')),
  41144. xunits: ol.format.KML.ICON_ANCHOR_UNITS_MAP_[xunits],
  41145. y: parseFloat(node.getAttribute('y')),
  41146. yunits: ol.format.KML.ICON_ANCHOR_UNITS_MAP_[yunits],
  41147. origin: origin
  41148. };
  41149. };
  41150. /**
  41151. * @param {Node} node Node.
  41152. * @private
  41153. * @return {number|undefined} Scale.
  41154. */
  41155. ol.format.KML.readScale_ = function(node) {
  41156. return ol.format.XSD.readDecimal(node);
  41157. };
  41158. /**
  41159. * @param {Node} node Node.
  41160. * @param {Array.<*>} objectStack Object stack.
  41161. * @private
  41162. * @return {Array.<ol.style.Style>|string|undefined} StyleMap.
  41163. */
  41164. ol.format.KML.readStyleMapValue_ = function(node, objectStack) {
  41165. return ol.xml.pushParseAndPop(undefined,
  41166. ol.format.KML.STYLE_MAP_PARSERS_, node, objectStack);
  41167. };
  41168. /**
  41169. * @param {Node} node Node.
  41170. * @param {Array.<*>} objectStack Object stack.
  41171. * @private
  41172. */
  41173. ol.format.KML.IconStyleParser_ = function(node, objectStack) {
  41174. // FIXME refreshMode
  41175. // FIXME refreshInterval
  41176. // FIXME viewRefreshTime
  41177. // FIXME viewBoundScale
  41178. // FIXME viewFormat
  41179. // FIXME httpQuery
  41180. var object = ol.xml.pushParseAndPop(
  41181. {}, ol.format.KML.ICON_STYLE_PARSERS_, node, objectStack);
  41182. if (!object) {
  41183. return;
  41184. }
  41185. var styleObject = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  41186. var IconObject = 'Icon' in object ? object['Icon'] : {};
  41187. var drawIcon = (!('Icon' in object) || Object.keys(IconObject).length > 0);
  41188. var src;
  41189. var href = /** @type {string|undefined} */
  41190. (IconObject['href']);
  41191. if (href) {
  41192. src = href;
  41193. } else if (drawIcon) {
  41194. src = ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_;
  41195. }
  41196. var anchor, anchorXUnits, anchorYUnits;
  41197. var anchorOrigin = ol.style.IconOrigin.BOTTOM_LEFT;
  41198. var hotSpot = /** @type {ol.KMLVec2_|undefined} */
  41199. (object['hotSpot']);
  41200. if (hotSpot) {
  41201. anchor = [hotSpot.x, hotSpot.y];
  41202. anchorXUnits = hotSpot.xunits;
  41203. anchorYUnits = hotSpot.yunits;
  41204. anchorOrigin = hotSpot.origin;
  41205. } else if (src === ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
  41206. anchor = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_;
  41207. anchorXUnits = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_;
  41208. anchorYUnits = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_;
  41209. } else if (/^http:\/\/maps\.(?:google|gstatic)\.com\//.test(src)) {
  41210. anchor = [0.5, 0];
  41211. anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
  41212. anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
  41213. }
  41214. var offset;
  41215. var x = /** @type {number|undefined} */
  41216. (IconObject['x']);
  41217. var y = /** @type {number|undefined} */
  41218. (IconObject['y']);
  41219. if (x !== undefined && y !== undefined) {
  41220. offset = [x, y];
  41221. }
  41222. var size;
  41223. var w = /** @type {number|undefined} */
  41224. (IconObject['w']);
  41225. var h = /** @type {number|undefined} */
  41226. (IconObject['h']);
  41227. if (w !== undefined && h !== undefined) {
  41228. size = [w, h];
  41229. }
  41230. var rotation;
  41231. var heading = /** @type {number} */
  41232. (object['heading']);
  41233. if (heading !== undefined) {
  41234. rotation = ol.math.toRadians(heading);
  41235. }
  41236. var scale = /** @type {number|undefined} */
  41237. (object['scale']);
  41238. if (drawIcon) {
  41239. if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
  41240. size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
  41241. if (scale === undefined) {
  41242. scale = ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_;
  41243. }
  41244. }
  41245. var imageStyle = new ol.style.Icon({
  41246. anchor: anchor,
  41247. anchorOrigin: anchorOrigin,
  41248. anchorXUnits: anchorXUnits,
  41249. anchorYUnits: anchorYUnits,
  41250. crossOrigin: 'anonymous', // FIXME should this be configurable?
  41251. offset: offset,
  41252. offsetOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
  41253. rotation: rotation,
  41254. scale: scale,
  41255. size: size,
  41256. src: src
  41257. });
  41258. styleObject['imageStyle'] = imageStyle;
  41259. } else {
  41260. // handle the case when we explicitly want to draw no icon.
  41261. styleObject['imageStyle'] = ol.format.KML.DEFAULT_NO_IMAGE_STYLE_;
  41262. }
  41263. };
  41264. /**
  41265. * @param {Node} node Node.
  41266. * @param {Array.<*>} objectStack Object stack.
  41267. * @private
  41268. */
  41269. ol.format.KML.LabelStyleParser_ = function(node, objectStack) {
  41270. // FIXME colorMode
  41271. var object = ol.xml.pushParseAndPop(
  41272. {}, ol.format.KML.LABEL_STYLE_PARSERS_, node, objectStack);
  41273. if (!object) {
  41274. return;
  41275. }
  41276. var styleObject = objectStack[objectStack.length - 1];
  41277. var textStyle = new ol.style.Text({
  41278. fill: new ol.style.Fill({
  41279. color: /** @type {ol.Color} */
  41280. ('color' in object ? object['color'] : ol.format.KML.DEFAULT_COLOR_)
  41281. }),
  41282. scale: /** @type {number|undefined} */
  41283. (object['scale'])
  41284. });
  41285. styleObject['textStyle'] = textStyle;
  41286. };
  41287. /**
  41288. * @param {Node} node Node.
  41289. * @param {Array.<*>} objectStack Object stack.
  41290. * @private
  41291. */
  41292. ol.format.KML.LineStyleParser_ = function(node, objectStack) {
  41293. // FIXME colorMode
  41294. // FIXME gx:outerColor
  41295. // FIXME gx:outerWidth
  41296. // FIXME gx:physicalWidth
  41297. // FIXME gx:labelVisibility
  41298. var object = ol.xml.pushParseAndPop(
  41299. {}, ol.format.KML.LINE_STYLE_PARSERS_, node, objectStack);
  41300. if (!object) {
  41301. return;
  41302. }
  41303. var styleObject = objectStack[objectStack.length - 1];
  41304. var strokeStyle = new ol.style.Stroke({
  41305. color: /** @type {ol.Color} */
  41306. ('color' in object ? object['color'] : ol.format.KML.DEFAULT_COLOR_),
  41307. width: /** @type {number} */ ('width' in object ? object['width'] : 1)
  41308. });
  41309. styleObject['strokeStyle'] = strokeStyle;
  41310. };
  41311. /**
  41312. * @param {Node} node Node.
  41313. * @param {Array.<*>} objectStack Object stack.
  41314. * @private
  41315. */
  41316. ol.format.KML.PolyStyleParser_ = function(node, objectStack) {
  41317. // FIXME colorMode
  41318. var object = ol.xml.pushParseAndPop(
  41319. {}, ol.format.KML.POLY_STYLE_PARSERS_, node, objectStack);
  41320. if (!object) {
  41321. return;
  41322. }
  41323. var styleObject = objectStack[objectStack.length - 1];
  41324. var fillStyle = new ol.style.Fill({
  41325. color: /** @type {ol.Color} */
  41326. ('color' in object ? object['color'] : ol.format.KML.DEFAULT_COLOR_)
  41327. });
  41328. styleObject['fillStyle'] = fillStyle;
  41329. var fill = /** @type {boolean|undefined} */ (object['fill']);
  41330. if (fill !== undefined) {
  41331. styleObject['fill'] = fill;
  41332. }
  41333. var outline =
  41334. /** @type {boolean|undefined} */ (object['outline']);
  41335. if (outline !== undefined) {
  41336. styleObject['outline'] = outline;
  41337. }
  41338. };
  41339. /**
  41340. * @param {Node} node Node.
  41341. * @param {Array.<*>} objectStack Object stack.
  41342. * @private
  41343. * @return {Array.<number>} LinearRing flat coordinates.
  41344. */
  41345. ol.format.KML.readFlatLinearRing_ = function(node, objectStack) {
  41346. return ol.xml.pushParseAndPop(null,
  41347. ol.format.KML.FLAT_LINEAR_RING_PARSERS_, node, objectStack);
  41348. };
  41349. /**
  41350. * @param {Node} node Node.
  41351. * @param {Array.<*>} objectStack Object stack.
  41352. * @private
  41353. */
  41354. ol.format.KML.gxCoordParser_ = function(node, objectStack) {
  41355. var gxTrackObject = /** @type {ol.KMLGxTrackObject_} */
  41356. (objectStack[objectStack.length - 1]);
  41357. var flatCoordinates = gxTrackObject.flatCoordinates;
  41358. var s = ol.xml.getAllTextContent(node, false);
  41359. var re =
  41360. /^\s*([+\-]?\d+(?:\.\d*)?(?:e[+\-]?\d*)?)\s+([+\-]?\d+(?:\.\d*)?(?:e[+\-]?\d*)?)\s+([+\-]?\d+(?:\.\d*)?(?:e[+\-]?\d*)?)\s*$/i;
  41361. var m = re.exec(s);
  41362. if (m) {
  41363. var x = parseFloat(m[1]);
  41364. var y = parseFloat(m[2]);
  41365. var z = parseFloat(m[3]);
  41366. flatCoordinates.push(x, y, z, 0);
  41367. } else {
  41368. flatCoordinates.push(0, 0, 0, 0);
  41369. }
  41370. };
  41371. /**
  41372. * @param {Node} node Node.
  41373. * @param {Array.<*>} objectStack Object stack.
  41374. * @private
  41375. * @return {ol.geom.MultiLineString|undefined} MultiLineString.
  41376. */
  41377. ol.format.KML.readGxMultiTrack_ = function(node, objectStack) {
  41378. var lineStrings = ol.xml.pushParseAndPop([],
  41379. ol.format.KML.GX_MULTITRACK_GEOMETRY_PARSERS_, node, objectStack);
  41380. if (!lineStrings) {
  41381. return undefined;
  41382. }
  41383. var multiLineString = new ol.geom.MultiLineString(null);
  41384. multiLineString.setLineStrings(lineStrings);
  41385. return multiLineString;
  41386. };
  41387. /**
  41388. * @param {Node} node Node.
  41389. * @param {Array.<*>} objectStack Object stack.
  41390. * @private
  41391. * @return {ol.geom.LineString|undefined} LineString.
  41392. */
  41393. ol.format.KML.readGxTrack_ = function(node, objectStack) {
  41394. var gxTrackObject = ol.xml.pushParseAndPop(
  41395. /** @type {ol.KMLGxTrackObject_} */ ({
  41396. flatCoordinates: [],
  41397. whens: []
  41398. }), ol.format.KML.GX_TRACK_PARSERS_, node, objectStack);
  41399. if (!gxTrackObject) {
  41400. return undefined;
  41401. }
  41402. var flatCoordinates = gxTrackObject.flatCoordinates;
  41403. var whens = gxTrackObject.whens;
  41404. var i, ii;
  41405. for (i = 0, ii = Math.min(flatCoordinates.length, whens.length); i < ii;
  41406. ++i) {
  41407. flatCoordinates[4 * i + 3] = whens[i];
  41408. }
  41409. var lineString = new ol.geom.LineString(null);
  41410. lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZM, flatCoordinates);
  41411. return lineString;
  41412. };
  41413. /**
  41414. * @param {Node} node Node.
  41415. * @param {Array.<*>} objectStack Object stack.
  41416. * @private
  41417. * @return {Object} Icon object.
  41418. */
  41419. ol.format.KML.readIcon_ = function(node, objectStack) {
  41420. var iconObject = ol.xml.pushParseAndPop(
  41421. {}, ol.format.KML.ICON_PARSERS_, node, objectStack);
  41422. if (iconObject) {
  41423. return iconObject;
  41424. } else {
  41425. return null;
  41426. }
  41427. };
  41428. /**
  41429. * @param {Node} node Node.
  41430. * @param {Array.<*>} objectStack Object stack.
  41431. * @private
  41432. * @return {Array.<number>} Flat coordinates.
  41433. */
  41434. ol.format.KML.readFlatCoordinatesFromNode_ = function(node, objectStack) {
  41435. return ol.xml.pushParseAndPop(null,
  41436. ol.format.KML.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack);
  41437. };
  41438. /**
  41439. * @param {Node} node Node.
  41440. * @param {Array.<*>} objectStack Object stack.
  41441. * @private
  41442. * @return {ol.geom.LineString|undefined} LineString.
  41443. */
  41444. ol.format.KML.readLineString_ = function(node, objectStack) {
  41445. var properties = ol.xml.pushParseAndPop({},
  41446. ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
  41447. objectStack);
  41448. var flatCoordinates =
  41449. ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
  41450. if (flatCoordinates) {
  41451. var lineString = new ol.geom.LineString(null);
  41452. lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
  41453. lineString.setProperties(properties);
  41454. return lineString;
  41455. } else {
  41456. return undefined;
  41457. }
  41458. };
  41459. /**
  41460. * @param {Node} node Node.
  41461. * @param {Array.<*>} objectStack Object stack.
  41462. * @private
  41463. * @return {ol.geom.Polygon|undefined} Polygon.
  41464. */
  41465. ol.format.KML.readLinearRing_ = function(node, objectStack) {
  41466. var properties = ol.xml.pushParseAndPop({},
  41467. ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
  41468. objectStack);
  41469. var flatCoordinates =
  41470. ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
  41471. if (flatCoordinates) {
  41472. var polygon = new ol.geom.Polygon(null);
  41473. polygon.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates,
  41474. [flatCoordinates.length]);
  41475. polygon.setProperties(properties);
  41476. return polygon;
  41477. } else {
  41478. return undefined;
  41479. }
  41480. };
  41481. /**
  41482. * @param {Node} node Node.
  41483. * @param {Array.<*>} objectStack Object stack.
  41484. * @private
  41485. * @return {ol.geom.Geometry} Geometry.
  41486. */
  41487. ol.format.KML.readMultiGeometry_ = function(node, objectStack) {
  41488. var geometries = ol.xml.pushParseAndPop([],
  41489. ol.format.KML.MULTI_GEOMETRY_PARSERS_, node, objectStack);
  41490. if (!geometries) {
  41491. return null;
  41492. }
  41493. if (geometries.length === 0) {
  41494. return new ol.geom.GeometryCollection(geometries);
  41495. }
  41496. /** @type {ol.geom.Geometry} */
  41497. var multiGeometry;
  41498. var homogeneous = true;
  41499. var type = geometries[0].getType();
  41500. var geometry, i, ii;
  41501. for (i = 1, ii = geometries.length; i < ii; ++i) {
  41502. geometry = geometries[i];
  41503. if (geometry.getType() != type) {
  41504. homogeneous = false;
  41505. break;
  41506. }
  41507. }
  41508. if (homogeneous) {
  41509. var layout;
  41510. var flatCoordinates;
  41511. if (type == ol.geom.GeometryType.POINT) {
  41512. var point = geometries[0];
  41513. layout = point.getLayout();
  41514. flatCoordinates = point.getFlatCoordinates();
  41515. for (i = 1, ii = geometries.length; i < ii; ++i) {
  41516. geometry = geometries[i];
  41517. ol.array.extend(flatCoordinates, geometry.getFlatCoordinates());
  41518. }
  41519. multiGeometry = new ol.geom.MultiPoint(null);
  41520. multiGeometry.setFlatCoordinates(layout, flatCoordinates);
  41521. ol.format.KML.setCommonGeometryProperties_(multiGeometry, geometries);
  41522. } else if (type == ol.geom.GeometryType.LINE_STRING) {
  41523. multiGeometry = new ol.geom.MultiLineString(null);
  41524. multiGeometry.setLineStrings(geometries);
  41525. ol.format.KML.setCommonGeometryProperties_(multiGeometry, geometries);
  41526. } else if (type == ol.geom.GeometryType.POLYGON) {
  41527. multiGeometry = new ol.geom.MultiPolygon(null);
  41528. multiGeometry.setPolygons(geometries);
  41529. ol.format.KML.setCommonGeometryProperties_(multiGeometry, geometries);
  41530. } else if (type == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
  41531. multiGeometry = new ol.geom.GeometryCollection(geometries);
  41532. } else {
  41533. ol.asserts.assert(false, 37); // Unknown geometry type found
  41534. }
  41535. } else {
  41536. multiGeometry = new ol.geom.GeometryCollection(geometries);
  41537. }
  41538. return /** @type {ol.geom.Geometry} */ (multiGeometry);
  41539. };
  41540. /**
  41541. * @param {Node} node Node.
  41542. * @param {Array.<*>} objectStack Object stack.
  41543. * @private
  41544. * @return {ol.geom.Point|undefined} Point.
  41545. */
  41546. ol.format.KML.readPoint_ = function(node, objectStack) {
  41547. var properties = ol.xml.pushParseAndPop({},
  41548. ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
  41549. objectStack);
  41550. var flatCoordinates =
  41551. ol.format.KML.readFlatCoordinatesFromNode_(node, objectStack);
  41552. if (flatCoordinates) {
  41553. var point = new ol.geom.Point(null);
  41554. point.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
  41555. point.setProperties(properties);
  41556. return point;
  41557. } else {
  41558. return undefined;
  41559. }
  41560. };
  41561. /**
  41562. * @param {Node} node Node.
  41563. * @param {Array.<*>} objectStack Object stack.
  41564. * @private
  41565. * @return {ol.geom.Polygon|undefined} Polygon.
  41566. */
  41567. ol.format.KML.readPolygon_ = function(node, objectStack) {
  41568. var properties = ol.xml.pushParseAndPop(/** @type {Object<string,*>} */ ({}),
  41569. ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_, node,
  41570. objectStack);
  41571. var flatLinearRings = ol.xml.pushParseAndPop([null],
  41572. ol.format.KML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack);
  41573. if (flatLinearRings && flatLinearRings[0]) {
  41574. var polygon = new ol.geom.Polygon(null);
  41575. var flatCoordinates = flatLinearRings[0];
  41576. var ends = [flatCoordinates.length];
  41577. var i, ii;
  41578. for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
  41579. ol.array.extend(flatCoordinates, flatLinearRings[i]);
  41580. ends.push(flatCoordinates.length);
  41581. }
  41582. polygon.setFlatCoordinates(
  41583. ol.geom.GeometryLayout.XYZ, flatCoordinates, ends);
  41584. polygon.setProperties(properties);
  41585. return polygon;
  41586. } else {
  41587. return undefined;
  41588. }
  41589. };
  41590. /**
  41591. * @param {Node} node Node.
  41592. * @param {Array.<*>} objectStack Object stack.
  41593. * @private
  41594. * @return {Array.<ol.style.Style>} Style.
  41595. */
  41596. ol.format.KML.readStyle_ = function(node, objectStack) {
  41597. var styleObject = ol.xml.pushParseAndPop(
  41598. {}, ol.format.KML.STYLE_PARSERS_, node, objectStack);
  41599. if (!styleObject) {
  41600. return null;
  41601. }
  41602. var fillStyle = /** @type {ol.style.Fill} */
  41603. ('fillStyle' in styleObject ?
  41604. styleObject['fillStyle'] : ol.format.KML.DEFAULT_FILL_STYLE_);
  41605. var fill = /** @type {boolean|undefined} */ (styleObject['fill']);
  41606. if (fill !== undefined && !fill) {
  41607. fillStyle = null;
  41608. }
  41609. var imageStyle = /** @type {ol.style.Image} */
  41610. ('imageStyle' in styleObject ?
  41611. styleObject['imageStyle'] : ol.format.KML.DEFAULT_IMAGE_STYLE_);
  41612. if (imageStyle == ol.format.KML.DEFAULT_NO_IMAGE_STYLE_) {
  41613. imageStyle = undefined;
  41614. }
  41615. var textStyle = /** @type {ol.style.Text} */
  41616. ('textStyle' in styleObject ?
  41617. styleObject['textStyle'] : ol.format.KML.DEFAULT_TEXT_STYLE_);
  41618. var strokeStyle = /** @type {ol.style.Stroke} */
  41619. ('strokeStyle' in styleObject ?
  41620. styleObject['strokeStyle'] : ol.format.KML.DEFAULT_STROKE_STYLE_);
  41621. var outline = /** @type {boolean|undefined} */
  41622. (styleObject['outline']);
  41623. if (outline !== undefined && !outline) {
  41624. strokeStyle = null;
  41625. }
  41626. return [new ol.style.Style({
  41627. fill: fillStyle,
  41628. image: imageStyle,
  41629. stroke: strokeStyle,
  41630. text: textStyle,
  41631. zIndex: undefined // FIXME
  41632. })];
  41633. };
  41634. /**
  41635. * Reads an array of geometries and creates arrays for common geometry
  41636. * properties. Then sets them to the multi geometry.
  41637. * @param {ol.geom.MultiPoint|ol.geom.MultiLineString|ol.geom.MultiPolygon}
  41638. * multiGeometry A multi-geometry.
  41639. * @param {Array.<ol.geom.Geometry>} geometries List of geometries.
  41640. * @private
  41641. */
  41642. ol.format.KML.setCommonGeometryProperties_ = function(multiGeometry,
  41643. geometries) {
  41644. var ii = geometries.length;
  41645. var extrudes = new Array(geometries.length);
  41646. var tessellates = new Array(geometries.length);
  41647. var altitudeModes = new Array(geometries.length);
  41648. var geometry, i, hasExtrude, hasTessellate, hasAltitudeMode;
  41649. hasExtrude = hasTessellate = hasAltitudeMode = false;
  41650. for (i = 0; i < ii; ++i) {
  41651. geometry = geometries[i];
  41652. extrudes[i] = geometry.get('extrude');
  41653. tessellates[i] = geometry.get('tessellate');
  41654. altitudeModes[i] = geometry.get('altitudeMode');
  41655. hasExtrude = hasExtrude || extrudes[i] !== undefined;
  41656. hasTessellate = hasTessellate || tessellates[i] !== undefined;
  41657. hasAltitudeMode = hasAltitudeMode || altitudeModes[i];
  41658. }
  41659. if (hasExtrude) {
  41660. multiGeometry.set('extrude', extrudes);
  41661. }
  41662. if (hasTessellate) {
  41663. multiGeometry.set('tessellate', tessellates);
  41664. }
  41665. if (hasAltitudeMode) {
  41666. multiGeometry.set('altitudeMode', altitudeModes);
  41667. }
  41668. };
  41669. /**
  41670. * @param {Node} node Node.
  41671. * @param {Array.<*>} objectStack Object stack.
  41672. * @private
  41673. */
  41674. ol.format.KML.DataParser_ = function(node, objectStack) {
  41675. var name = node.getAttribute('name');
  41676. ol.xml.parseNode(ol.format.KML.DATA_PARSERS_, node, objectStack);
  41677. var featureObject = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  41678. if (name !== null) {
  41679. featureObject[name] = featureObject.value;
  41680. } else if (featureObject.displayName !== null) {
  41681. featureObject[featureObject.displayName] = featureObject.value;
  41682. }
  41683. delete featureObject['value'];
  41684. };
  41685. /**
  41686. * @param {Node} node Node.
  41687. * @param {Array.<*>} objectStack Object stack.
  41688. * @private
  41689. */
  41690. ol.format.KML.ExtendedDataParser_ = function(node, objectStack) {
  41691. ol.xml.parseNode(ol.format.KML.EXTENDED_DATA_PARSERS_, node, objectStack);
  41692. };
  41693. /**
  41694. * @param {Node} node Node.
  41695. * @param {Array.<*>} objectStack Object stack.
  41696. * @private
  41697. */
  41698. ol.format.KML.RegionParser_ = function(node, objectStack) {
  41699. ol.xml.parseNode(ol.format.KML.REGION_PARSERS_, node, objectStack);
  41700. };
  41701. /**
  41702. * @param {Node} node Node.
  41703. * @param {Array.<*>} objectStack Object stack.
  41704. * @private
  41705. */
  41706. ol.format.KML.PairDataParser_ = function(node, objectStack) {
  41707. var pairObject = ol.xml.pushParseAndPop(
  41708. {}, ol.format.KML.PAIR_PARSERS_, node, objectStack);
  41709. if (!pairObject) {
  41710. return;
  41711. }
  41712. var key = /** @type {string|undefined} */
  41713. (pairObject['key']);
  41714. if (key && key == 'normal') {
  41715. var styleUrl = /** @type {string|undefined} */
  41716. (pairObject['styleUrl']);
  41717. if (styleUrl) {
  41718. objectStack[objectStack.length - 1] = styleUrl;
  41719. }
  41720. var Style = /** @type {ol.style.Style} */
  41721. (pairObject['Style']);
  41722. if (Style) {
  41723. objectStack[objectStack.length - 1] = Style;
  41724. }
  41725. }
  41726. };
  41727. /**
  41728. * @param {Node} node Node.
  41729. * @param {Array.<*>} objectStack Object stack.
  41730. * @private
  41731. */
  41732. ol.format.KML.PlacemarkStyleMapParser_ = function(node, objectStack) {
  41733. var styleMapValue = ol.format.KML.readStyleMapValue_(node, objectStack);
  41734. if (!styleMapValue) {
  41735. return;
  41736. }
  41737. var placemarkObject = objectStack[objectStack.length - 1];
  41738. if (Array.isArray(styleMapValue)) {
  41739. placemarkObject['Style'] = styleMapValue;
  41740. } else if (typeof styleMapValue === 'string') {
  41741. placemarkObject['styleUrl'] = styleMapValue;
  41742. } else {
  41743. ol.asserts.assert(false, 38); // `styleMapValue` has an unknown type
  41744. }
  41745. };
  41746. /**
  41747. * @param {Node} node Node.
  41748. * @param {Array.<*>} objectStack Object stack.
  41749. * @private
  41750. */
  41751. ol.format.KML.SchemaDataParser_ = function(node, objectStack) {
  41752. ol.xml.parseNode(ol.format.KML.SCHEMA_DATA_PARSERS_, node, objectStack);
  41753. };
  41754. /**
  41755. * @param {Node} node Node.
  41756. * @param {Array.<*>} objectStack Object stack.
  41757. * @private
  41758. */
  41759. ol.format.KML.SimpleDataParser_ = function(node, objectStack) {
  41760. var name = node.getAttribute('name');
  41761. if (name !== null) {
  41762. var data = ol.format.XSD.readString(node);
  41763. var featureObject =
  41764. /** @type {Object} */ (objectStack[objectStack.length - 1]);
  41765. featureObject[name] = data;
  41766. }
  41767. };
  41768. /**
  41769. * @param {Node} node Node.
  41770. * @param {Array.<*>} objectStack Object stack.
  41771. * @private
  41772. */
  41773. ol.format.KML.LatLonAltBoxParser_ = function(node, objectStack) {
  41774. var object = ol.xml.pushParseAndPop({}, ol.format.KML.LAT_LON_ALT_BOX_PARSERS_, node, objectStack);
  41775. if (!object) {
  41776. return;
  41777. }
  41778. var regionObject = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  41779. var extent = [
  41780. parseFloat(object['west']),
  41781. parseFloat(object['south']),
  41782. parseFloat(object['east']),
  41783. parseFloat(object['north'])
  41784. ];
  41785. regionObject['extent'] = extent;
  41786. regionObject['altitudeMode'] = object['altitudeMode'];
  41787. regionObject['minAltitude'] = parseFloat(object['minAltitude']);
  41788. regionObject['maxAltitude'] = parseFloat(object['maxAltitude']);
  41789. };
  41790. /**
  41791. * @param {Node} node Node.
  41792. * @param {Array.<*>} objectStack Object stack.
  41793. * @private
  41794. */
  41795. ol.format.KML.LodParser_ = function(node, objectStack) {
  41796. var object = ol.xml.pushParseAndPop({}, ol.format.KML.LOD_PARSERS_, node, objectStack);
  41797. if (!object) {
  41798. return;
  41799. }
  41800. var lodObject = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  41801. lodObject['minLodPixels'] = parseFloat(object['minLodPixels']);
  41802. lodObject['maxLodPixels'] = parseFloat(object['maxLodPixels']);
  41803. lodObject['minFadeExtent'] = parseFloat(object['minFadeExtent']);
  41804. lodObject['maxFadeExtent'] = parseFloat(object['maxFadeExtent']);
  41805. };
  41806. /**
  41807. * @param {Node} node Node.
  41808. * @param {Array.<*>} objectStack Object stack.
  41809. * @private
  41810. */
  41811. ol.format.KML.innerBoundaryIsParser_ = function(node, objectStack) {
  41812. /** @type {Array.<number>|undefined} */
  41813. var flatLinearRing = ol.xml.pushParseAndPop(undefined,
  41814. ol.format.KML.INNER_BOUNDARY_IS_PARSERS_, node, objectStack);
  41815. if (flatLinearRing) {
  41816. var flatLinearRings = /** @type {Array.<Array.<number>>} */
  41817. (objectStack[objectStack.length - 1]);
  41818. flatLinearRings.push(flatLinearRing);
  41819. }
  41820. };
  41821. /**
  41822. * @param {Node} node Node.
  41823. * @param {Array.<*>} objectStack Object stack.
  41824. * @private
  41825. */
  41826. ol.format.KML.outerBoundaryIsParser_ = function(node, objectStack) {
  41827. /** @type {Array.<number>|undefined} */
  41828. var flatLinearRing = ol.xml.pushParseAndPop(undefined,
  41829. ol.format.KML.OUTER_BOUNDARY_IS_PARSERS_, node, objectStack);
  41830. if (flatLinearRing) {
  41831. var flatLinearRings = /** @type {Array.<Array.<number>>} */
  41832. (objectStack[objectStack.length - 1]);
  41833. flatLinearRings[0] = flatLinearRing;
  41834. }
  41835. };
  41836. /**
  41837. * @param {Node} node Node.
  41838. * @param {Array.<*>} objectStack Object stack.
  41839. * @private
  41840. */
  41841. ol.format.KML.LinkParser_ = function(node, objectStack) {
  41842. ol.xml.parseNode(ol.format.KML.LINK_PARSERS_, node, objectStack);
  41843. };
  41844. /**
  41845. * @param {Node} node Node.
  41846. * @param {Array.<*>} objectStack Object stack.
  41847. * @private
  41848. */
  41849. ol.format.KML.whenParser_ = function(node, objectStack) {
  41850. var gxTrackObject = /** @type {ol.KMLGxTrackObject_} */
  41851. (objectStack[objectStack.length - 1]);
  41852. var whens = gxTrackObject.whens;
  41853. var s = ol.xml.getAllTextContent(node, false);
  41854. var when = Date.parse(s);
  41855. whens.push(isNaN(when) ? 0 : when);
  41856. };
  41857. /**
  41858. * @const
  41859. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41860. * @private
  41861. */
  41862. ol.format.KML.DATA_PARSERS_ = ol.xml.makeStructureNS(
  41863. ol.format.KML.NAMESPACE_URIS_, {
  41864. 'displayName': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  41865. 'value': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
  41866. });
  41867. /**
  41868. * @const
  41869. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41870. * @private
  41871. */
  41872. ol.format.KML.EXTENDED_DATA_PARSERS_ = ol.xml.makeStructureNS(
  41873. ol.format.KML.NAMESPACE_URIS_, {
  41874. 'Data': ol.format.KML.DataParser_,
  41875. 'SchemaData': ol.format.KML.SchemaDataParser_
  41876. });
  41877. /**
  41878. * @const
  41879. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41880. * @private
  41881. */
  41882. ol.format.KML.REGION_PARSERS_ = ol.xml.makeStructureNS(
  41883. ol.format.KML.NAMESPACE_URIS_, {
  41884. 'LatLonAltBox': ol.format.KML.LatLonAltBoxParser_,
  41885. 'Lod': ol.format.KML.LodParser_
  41886. });
  41887. /**
  41888. * @const
  41889. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41890. * @private
  41891. */
  41892. ol.format.KML.LAT_LON_ALT_BOX_PARSERS_ = ol.xml.makeStructureNS(
  41893. ol.format.KML.NAMESPACE_URIS_, {
  41894. 'altitudeMode': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  41895. 'minAltitude': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41896. 'maxAltitude': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41897. 'north': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41898. 'south': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41899. 'east': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41900. 'west': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal)
  41901. });
  41902. /**
  41903. * @const
  41904. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41905. * @private
  41906. */
  41907. ol.format.KML.LOD_PARSERS_ = ol.xml.makeStructureNS(
  41908. ol.format.KML.NAMESPACE_URIS_, {
  41909. 'minLodPixels': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41910. 'maxLodPixels': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41911. 'minFadeExtent': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41912. 'maxFadeExtent': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal)
  41913. });
  41914. /**
  41915. * @const
  41916. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41917. * @private
  41918. */
  41919. ol.format.KML.EXTRUDE_AND_ALTITUDE_MODE_PARSERS_ = ol.xml.makeStructureNS(
  41920. ol.format.KML.NAMESPACE_URIS_, {
  41921. 'extrude': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
  41922. 'tessellate': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
  41923. 'altitudeMode': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
  41924. });
  41925. /**
  41926. * @const
  41927. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41928. * @private
  41929. */
  41930. ol.format.KML.FLAT_LINEAR_RING_PARSERS_ = ol.xml.makeStructureNS(
  41931. ol.format.KML.NAMESPACE_URIS_, {
  41932. 'coordinates': ol.xml.makeReplacer(ol.format.KML.readFlatCoordinates_)
  41933. });
  41934. /**
  41935. * @const
  41936. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41937. * @private
  41938. */
  41939. ol.format.KML.FLAT_LINEAR_RINGS_PARSERS_ = ol.xml.makeStructureNS(
  41940. ol.format.KML.NAMESPACE_URIS_, {
  41941. 'innerBoundaryIs': ol.format.KML.innerBoundaryIsParser_,
  41942. 'outerBoundaryIs': ol.format.KML.outerBoundaryIsParser_
  41943. });
  41944. /**
  41945. * @const
  41946. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41947. * @private
  41948. */
  41949. ol.format.KML.GX_TRACK_PARSERS_ = ol.xml.makeStructureNS(
  41950. ol.format.KML.NAMESPACE_URIS_, {
  41951. 'when': ol.format.KML.whenParser_
  41952. }, ol.xml.makeStructureNS(
  41953. ol.format.KML.GX_NAMESPACE_URIS_, {
  41954. 'coord': ol.format.KML.gxCoordParser_
  41955. }));
  41956. /**
  41957. * @const
  41958. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41959. * @private
  41960. */
  41961. ol.format.KML.GEOMETRY_FLAT_COORDINATES_PARSERS_ = ol.xml.makeStructureNS(
  41962. ol.format.KML.NAMESPACE_URIS_, {
  41963. 'coordinates': ol.xml.makeReplacer(ol.format.KML.readFlatCoordinates_)
  41964. });
  41965. /**
  41966. * @const
  41967. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41968. * @private
  41969. */
  41970. ol.format.KML.ICON_PARSERS_ = ol.xml.makeStructureNS(
  41971. ol.format.KML.NAMESPACE_URIS_, {
  41972. 'href': ol.xml.makeObjectPropertySetter(ol.format.KML.readURI_)
  41973. }, ol.xml.makeStructureNS(
  41974. ol.format.KML.GX_NAMESPACE_URIS_, {
  41975. 'x': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41976. 'y': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41977. 'w': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41978. 'h': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal)
  41979. }));
  41980. /**
  41981. * @const
  41982. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41983. * @private
  41984. */
  41985. ol.format.KML.ICON_STYLE_PARSERS_ = ol.xml.makeStructureNS(
  41986. ol.format.KML.NAMESPACE_URIS_, {
  41987. 'Icon': ol.xml.makeObjectPropertySetter(ol.format.KML.readIcon_),
  41988. 'heading': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal),
  41989. 'hotSpot': ol.xml.makeObjectPropertySetter(ol.format.KML.readVec2_),
  41990. 'scale': ol.xml.makeObjectPropertySetter(ol.format.KML.readScale_)
  41991. });
  41992. /**
  41993. * @const
  41994. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  41995. * @private
  41996. */
  41997. ol.format.KML.INNER_BOUNDARY_IS_PARSERS_ = ol.xml.makeStructureNS(
  41998. ol.format.KML.NAMESPACE_URIS_, {
  41999. 'LinearRing': ol.xml.makeReplacer(ol.format.KML.readFlatLinearRing_)
  42000. });
  42001. /**
  42002. * @const
  42003. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42004. * @private
  42005. */
  42006. ol.format.KML.LABEL_STYLE_PARSERS_ = ol.xml.makeStructureNS(
  42007. ol.format.KML.NAMESPACE_URIS_, {
  42008. 'color': ol.xml.makeObjectPropertySetter(ol.format.KML.readColor_),
  42009. 'scale': ol.xml.makeObjectPropertySetter(ol.format.KML.readScale_)
  42010. });
  42011. /**
  42012. * @const
  42013. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42014. * @private
  42015. */
  42016. ol.format.KML.LINE_STYLE_PARSERS_ = ol.xml.makeStructureNS(
  42017. ol.format.KML.NAMESPACE_URIS_, {
  42018. 'color': ol.xml.makeObjectPropertySetter(ol.format.KML.readColor_),
  42019. 'width': ol.xml.makeObjectPropertySetter(ol.format.XSD.readDecimal)
  42020. });
  42021. /**
  42022. * @const
  42023. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42024. * @private
  42025. */
  42026. ol.format.KML.MULTI_GEOMETRY_PARSERS_ = ol.xml.makeStructureNS(
  42027. ol.format.KML.NAMESPACE_URIS_, {
  42028. 'LineString': ol.xml.makeArrayPusher(ol.format.KML.readLineString_),
  42029. 'LinearRing': ol.xml.makeArrayPusher(ol.format.KML.readLinearRing_),
  42030. 'MultiGeometry': ol.xml.makeArrayPusher(ol.format.KML.readMultiGeometry_),
  42031. 'Point': ol.xml.makeArrayPusher(ol.format.KML.readPoint_),
  42032. 'Polygon': ol.xml.makeArrayPusher(ol.format.KML.readPolygon_)
  42033. });
  42034. /**
  42035. * @const
  42036. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42037. * @private
  42038. */
  42039. ol.format.KML.GX_MULTITRACK_GEOMETRY_PARSERS_ = ol.xml.makeStructureNS(
  42040. ol.format.KML.GX_NAMESPACE_URIS_, {
  42041. 'Track': ol.xml.makeArrayPusher(ol.format.KML.readGxTrack_)
  42042. });
  42043. /**
  42044. * @const
  42045. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42046. * @private
  42047. */
  42048. ol.format.KML.NETWORK_LINK_PARSERS_ = ol.xml.makeStructureNS(
  42049. ol.format.KML.NAMESPACE_URIS_, {
  42050. 'ExtendedData': ol.format.KML.ExtendedDataParser_,
  42051. 'Region': ol.format.KML.RegionParser_,
  42052. 'Link': ol.format.KML.LinkParser_,
  42053. 'address': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42054. 'description': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42055. 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42056. 'open': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
  42057. 'phoneNumber': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42058. 'visibility': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean)
  42059. });
  42060. /**
  42061. * @const
  42062. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42063. * @private
  42064. */
  42065. ol.format.KML.LINK_PARSERS_ = ol.xml.makeStructureNS(
  42066. ol.format.KML.NAMESPACE_URIS_, {
  42067. 'href': ol.xml.makeObjectPropertySetter(ol.format.KML.readURI_)
  42068. });
  42069. /**
  42070. * @const
  42071. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42072. * @private
  42073. */
  42074. ol.format.KML.OUTER_BOUNDARY_IS_PARSERS_ = ol.xml.makeStructureNS(
  42075. ol.format.KML.NAMESPACE_URIS_, {
  42076. 'LinearRing': ol.xml.makeReplacer(ol.format.KML.readFlatLinearRing_)
  42077. });
  42078. /**
  42079. * @const
  42080. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42081. * @private
  42082. */
  42083. ol.format.KML.PAIR_PARSERS_ = ol.xml.makeStructureNS(
  42084. ol.format.KML.NAMESPACE_URIS_, {
  42085. 'Style': ol.xml.makeObjectPropertySetter(ol.format.KML.readStyle_),
  42086. 'key': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42087. 'styleUrl': ol.xml.makeObjectPropertySetter(ol.format.KML.readURI_)
  42088. });
  42089. /**
  42090. * @const
  42091. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42092. * @private
  42093. */
  42094. ol.format.KML.PLACEMARK_PARSERS_ = ol.xml.makeStructureNS(
  42095. ol.format.KML.NAMESPACE_URIS_, {
  42096. 'ExtendedData': ol.format.KML.ExtendedDataParser_,
  42097. 'Region': ol.format.KML.RegionParser_,
  42098. 'MultiGeometry': ol.xml.makeObjectPropertySetter(
  42099. ol.format.KML.readMultiGeometry_, 'geometry'),
  42100. 'LineString': ol.xml.makeObjectPropertySetter(
  42101. ol.format.KML.readLineString_, 'geometry'),
  42102. 'LinearRing': ol.xml.makeObjectPropertySetter(
  42103. ol.format.KML.readLinearRing_, 'geometry'),
  42104. 'Point': ol.xml.makeObjectPropertySetter(
  42105. ol.format.KML.readPoint_, 'geometry'),
  42106. 'Polygon': ol.xml.makeObjectPropertySetter(
  42107. ol.format.KML.readPolygon_, 'geometry'),
  42108. 'Style': ol.xml.makeObjectPropertySetter(ol.format.KML.readStyle_),
  42109. 'StyleMap': ol.format.KML.PlacemarkStyleMapParser_,
  42110. 'address': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42111. 'description': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42112. 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42113. 'open': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
  42114. 'phoneNumber': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  42115. 'styleUrl': ol.xml.makeObjectPropertySetter(ol.format.KML.readURI_),
  42116. 'visibility': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean)
  42117. }, ol.xml.makeStructureNS(
  42118. ol.format.KML.GX_NAMESPACE_URIS_, {
  42119. 'MultiTrack': ol.xml.makeObjectPropertySetter(
  42120. ol.format.KML.readGxMultiTrack_, 'geometry'),
  42121. 'Track': ol.xml.makeObjectPropertySetter(
  42122. ol.format.KML.readGxTrack_, 'geometry')
  42123. }
  42124. ));
  42125. /**
  42126. * @const
  42127. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42128. * @private
  42129. */
  42130. ol.format.KML.POLY_STYLE_PARSERS_ = ol.xml.makeStructureNS(
  42131. ol.format.KML.NAMESPACE_URIS_, {
  42132. 'color': ol.xml.makeObjectPropertySetter(ol.format.KML.readColor_),
  42133. 'fill': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean),
  42134. 'outline': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean)
  42135. });
  42136. /**
  42137. * @const
  42138. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42139. * @private
  42140. */
  42141. ol.format.KML.SCHEMA_DATA_PARSERS_ = ol.xml.makeStructureNS(
  42142. ol.format.KML.NAMESPACE_URIS_, {
  42143. 'SimpleData': ol.format.KML.SimpleDataParser_
  42144. });
  42145. /**
  42146. * @const
  42147. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42148. * @private
  42149. */
  42150. ol.format.KML.STYLE_PARSERS_ = ol.xml.makeStructureNS(
  42151. ol.format.KML.NAMESPACE_URIS_, {
  42152. 'IconStyle': ol.format.KML.IconStyleParser_,
  42153. 'LabelStyle': ol.format.KML.LabelStyleParser_,
  42154. 'LineStyle': ol.format.KML.LineStyleParser_,
  42155. 'PolyStyle': ol.format.KML.PolyStyleParser_
  42156. });
  42157. /**
  42158. * @const
  42159. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  42160. * @private
  42161. */
  42162. ol.format.KML.STYLE_MAP_PARSERS_ = ol.xml.makeStructureNS(
  42163. ol.format.KML.NAMESPACE_URIS_, {
  42164. 'Pair': ol.format.KML.PairDataParser_
  42165. });
  42166. /**
  42167. * @param {Node} node Node.
  42168. * @param {Array.<*>} objectStack Object stack.
  42169. * @private
  42170. * @return {Array.<ol.Feature>|undefined} Features.
  42171. */
  42172. ol.format.KML.prototype.readDocumentOrFolder_ = function(node, objectStack) {
  42173. // FIXME use scope somehow
  42174. var parsersNS = ol.xml.makeStructureNS(
  42175. ol.format.KML.NAMESPACE_URIS_, {
  42176. 'Document': ol.xml.makeArrayExtender(this.readDocumentOrFolder_, this),
  42177. 'Folder': ol.xml.makeArrayExtender(this.readDocumentOrFolder_, this),
  42178. 'Placemark': ol.xml.makeArrayPusher(this.readPlacemark_, this),
  42179. 'Style': this.readSharedStyle_.bind(this),
  42180. 'StyleMap': this.readSharedStyleMap_.bind(this)
  42181. });
  42182. /** @type {Array.<ol.Feature>} */
  42183. var features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack, this);
  42184. if (features) {
  42185. return features;
  42186. } else {
  42187. return undefined;
  42188. }
  42189. };
  42190. /**
  42191. * @param {Node} node Node.
  42192. * @param {Array.<*>} objectStack Object stack.
  42193. * @private
  42194. * @return {ol.Feature|undefined} Feature.
  42195. */
  42196. ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
  42197. var object = ol.xml.pushParseAndPop({'geometry': null},
  42198. ol.format.KML.PLACEMARK_PARSERS_, node, objectStack);
  42199. if (!object) {
  42200. return undefined;
  42201. }
  42202. var feature = new ol.Feature();
  42203. var id = node.getAttribute('id');
  42204. if (id !== null) {
  42205. feature.setId(id);
  42206. }
  42207. var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
  42208. var geometry = object['geometry'];
  42209. if (geometry) {
  42210. ol.format.Feature.transformWithOptions(geometry, false, options);
  42211. }
  42212. feature.setGeometry(geometry);
  42213. delete object['geometry'];
  42214. if (this.extractStyles_) {
  42215. var style = object['Style'];
  42216. var styleUrl = object['styleUrl'];
  42217. var styleFunction = ol.format.KML.createFeatureStyleFunction_(
  42218. style, styleUrl, this.defaultStyle_, this.sharedStyles_,
  42219. this.showPointNames_);
  42220. feature.setStyle(styleFunction);
  42221. }
  42222. delete object['Style'];
  42223. // we do not remove the styleUrl property from the object, so it
  42224. // gets stored on feature when setProperties is called
  42225. feature.setProperties(object);
  42226. return feature;
  42227. };
  42228. /**
  42229. * @param {Node} node Node.
  42230. * @param {Array.<*>} objectStack Object stack.
  42231. * @private
  42232. */
  42233. ol.format.KML.prototype.readSharedStyle_ = function(node, objectStack) {
  42234. var id = node.getAttribute('id');
  42235. if (id !== null) {
  42236. var style = ol.format.KML.readStyle_(node, objectStack);
  42237. if (style) {
  42238. var styleUri;
  42239. var baseURI = node.baseURI;
  42240. if (!baseURI || baseURI == 'about:blank') {
  42241. baseURI = window.location.href;
  42242. }
  42243. if (baseURI) {
  42244. var url = new URL('#' + id, baseURI);
  42245. styleUri = url.href;
  42246. } else {
  42247. styleUri = '#' + id;
  42248. }
  42249. this.sharedStyles_[styleUri] = style;
  42250. }
  42251. }
  42252. };
  42253. /**
  42254. * @param {Node} node Node.
  42255. * @param {Array.<*>} objectStack Object stack.
  42256. * @private
  42257. */
  42258. ol.format.KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
  42259. var id = node.getAttribute('id');
  42260. if (id === null) {
  42261. return;
  42262. }
  42263. var styleMapValue = ol.format.KML.readStyleMapValue_(node, objectStack);
  42264. if (!styleMapValue) {
  42265. return;
  42266. }
  42267. var styleUri;
  42268. var baseURI = node.baseURI;
  42269. if (!baseURI || baseURI == 'about:blank') {
  42270. baseURI = window.location.href;
  42271. }
  42272. if (baseURI) {
  42273. var url = new URL('#' + id, baseURI);
  42274. styleUri = url.href;
  42275. } else {
  42276. styleUri = '#' + id;
  42277. }
  42278. this.sharedStyles_[styleUri] = styleMapValue;
  42279. };
  42280. /**
  42281. * Read the first feature from a KML source. MultiGeometries are converted into
  42282. * GeometryCollections if they are a mix of geometry types, and into MultiPoint/
  42283. * MultiLineString/MultiPolygon if they are all of the same type.
  42284. *
  42285. * @function
  42286. * @param {Document|Node|Object|string} source Source.
  42287. * @param {olx.format.ReadOptions=} opt_options Read options.
  42288. * @return {ol.Feature} Feature.
  42289. * @api
  42290. */
  42291. ol.format.KML.prototype.readFeature;
  42292. /**
  42293. * @inheritDoc
  42294. */
  42295. ol.format.KML.prototype.readFeatureFromNode = function(node, opt_options) {
  42296. if (!ol.array.includes(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) {
  42297. return null;
  42298. }
  42299. var feature = this.readPlacemark_(
  42300. node, [this.getReadOptions(node, opt_options)]);
  42301. if (feature) {
  42302. return feature;
  42303. } else {
  42304. return null;
  42305. }
  42306. };
  42307. /**
  42308. * Read all features from a KML source. MultiGeometries are converted into
  42309. * GeometryCollections if they are a mix of geometry types, and into MultiPoint/
  42310. * MultiLineString/MultiPolygon if they are all of the same type.
  42311. *
  42312. * @function
  42313. * @param {Document|Node|Object|string} source Source.
  42314. * @param {olx.format.ReadOptions=} opt_options Read options.
  42315. * @return {Array.<ol.Feature>} Features.
  42316. * @api
  42317. */
  42318. ol.format.KML.prototype.readFeatures;
  42319. /**
  42320. * @inheritDoc
  42321. */
  42322. ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) {
  42323. if (!ol.array.includes(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) {
  42324. return [];
  42325. }
  42326. var features;
  42327. var localName = node.localName;
  42328. if (localName == 'Document' || localName == 'Folder') {
  42329. features = this.readDocumentOrFolder_(
  42330. node, [this.getReadOptions(node, opt_options)]);
  42331. if (features) {
  42332. return features;
  42333. } else {
  42334. return [];
  42335. }
  42336. } else if (localName == 'Placemark') {
  42337. var feature = this.readPlacemark_(
  42338. node, [this.getReadOptions(node, opt_options)]);
  42339. if (feature) {
  42340. return [feature];
  42341. } else {
  42342. return [];
  42343. }
  42344. } else if (localName == 'kml') {
  42345. features = [];
  42346. var n;
  42347. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42348. var fs = this.readFeaturesFromNode(n, opt_options);
  42349. if (fs) {
  42350. ol.array.extend(features, fs);
  42351. }
  42352. }
  42353. return features;
  42354. } else {
  42355. return [];
  42356. }
  42357. };
  42358. /**
  42359. * Read the name of the KML.
  42360. *
  42361. * @param {Document|Node|string} source Souce.
  42362. * @return {string|undefined} Name.
  42363. * @api
  42364. */
  42365. ol.format.KML.prototype.readName = function(source) {
  42366. if (ol.xml.isDocument(source)) {
  42367. return this.readNameFromDocument(/** @type {Document} */ (source));
  42368. } else if (ol.xml.isNode(source)) {
  42369. return this.readNameFromNode(/** @type {Node} */ (source));
  42370. } else if (typeof source === 'string') {
  42371. var doc = ol.xml.parse(source);
  42372. return this.readNameFromDocument(doc);
  42373. } else {
  42374. return undefined;
  42375. }
  42376. };
  42377. /**
  42378. * @param {Document} doc Document.
  42379. * @return {string|undefined} Name.
  42380. */
  42381. ol.format.KML.prototype.readNameFromDocument = function(doc) {
  42382. var n;
  42383. for (n = doc.firstChild; n; n = n.nextSibling) {
  42384. if (n.nodeType == Node.ELEMENT_NODE) {
  42385. var name = this.readNameFromNode(n);
  42386. if (name) {
  42387. return name;
  42388. }
  42389. }
  42390. }
  42391. return undefined;
  42392. };
  42393. /**
  42394. * @param {Node} node Node.
  42395. * @return {string|undefined} Name.
  42396. */
  42397. ol.format.KML.prototype.readNameFromNode = function(node) {
  42398. var n;
  42399. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42400. if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
  42401. n.localName == 'name') {
  42402. return ol.format.XSD.readString(n);
  42403. }
  42404. }
  42405. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42406. var localName = n.localName;
  42407. if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
  42408. (localName == 'Document' ||
  42409. localName == 'Folder' ||
  42410. localName == 'Placemark' ||
  42411. localName == 'kml')) {
  42412. var name = this.readNameFromNode(n);
  42413. if (name) {
  42414. return name;
  42415. }
  42416. }
  42417. }
  42418. return undefined;
  42419. };
  42420. /**
  42421. * Read the network links of the KML.
  42422. *
  42423. * @param {Document|Node|string} source Source.
  42424. * @return {Array.<Object>} Network links.
  42425. * @api
  42426. */
  42427. ol.format.KML.prototype.readNetworkLinks = function(source) {
  42428. var networkLinks = [];
  42429. if (ol.xml.isDocument(source)) {
  42430. ol.array.extend(networkLinks, this.readNetworkLinksFromDocument(
  42431. /** @type {Document} */ (source)));
  42432. } else if (ol.xml.isNode(source)) {
  42433. ol.array.extend(networkLinks, this.readNetworkLinksFromNode(
  42434. /** @type {Node} */ (source)));
  42435. } else if (typeof source === 'string') {
  42436. var doc = ol.xml.parse(source);
  42437. ol.array.extend(networkLinks, this.readNetworkLinksFromDocument(doc));
  42438. }
  42439. return networkLinks;
  42440. };
  42441. /**
  42442. * @param {Document} doc Document.
  42443. * @return {Array.<Object>} Network links.
  42444. */
  42445. ol.format.KML.prototype.readNetworkLinksFromDocument = function(doc) {
  42446. var n, networkLinks = [];
  42447. for (n = doc.firstChild; n; n = n.nextSibling) {
  42448. if (n.nodeType == Node.ELEMENT_NODE) {
  42449. ol.array.extend(networkLinks, this.readNetworkLinksFromNode(n));
  42450. }
  42451. }
  42452. return networkLinks;
  42453. };
  42454. /**
  42455. * @param {Node} node Node.
  42456. * @return {Array.<Object>} Network links.
  42457. */
  42458. ol.format.KML.prototype.readNetworkLinksFromNode = function(node) {
  42459. var n, networkLinks = [];
  42460. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42461. if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
  42462. n.localName == 'NetworkLink') {
  42463. var obj = ol.xml.pushParseAndPop({}, ol.format.KML.NETWORK_LINK_PARSERS_,
  42464. n, []);
  42465. networkLinks.push(obj);
  42466. }
  42467. }
  42468. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42469. var localName = n.localName;
  42470. if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
  42471. (localName == 'Document' ||
  42472. localName == 'Folder' ||
  42473. localName == 'kml')) {
  42474. ol.array.extend(networkLinks, this.readNetworkLinksFromNode(n));
  42475. }
  42476. }
  42477. return networkLinks;
  42478. };
  42479. /**
  42480. * Read the regions of the KML.
  42481. *
  42482. * @param {Document|Node|string} source Source.
  42483. * @return {Array.<Object>} Regions.
  42484. * @api
  42485. */
  42486. ol.format.KML.prototype.readRegion = function(source) {
  42487. var regions = [];
  42488. if (ol.xml.isDocument(source)) {
  42489. ol.array.extend(regions, this.readRegionFromDocument(
  42490. /** @type {Document} */ (source)));
  42491. } else if (ol.xml.isNode(source)) {
  42492. ol.array.extend(regions, this.readRegionFromNode(
  42493. /** @type {Node} */ (source)));
  42494. } else if (typeof source === 'string') {
  42495. var doc = ol.xml.parse(source);
  42496. ol.array.extend(regions, this.readRegionFromDocument(doc));
  42497. }
  42498. return regions;
  42499. };
  42500. /**
  42501. * @param {Document} doc Document.
  42502. * @return {Array.<Object>} Region.
  42503. */
  42504. ol.format.KML.prototype.readRegionFromDocument = function(doc) {
  42505. var n, regions = [];
  42506. for (n = doc.firstChild; n; n = n.nextSibling) {
  42507. if (n.nodeType == Node.ELEMENT_NODE) {
  42508. ol.array.extend(regions, this.readRegionFromNode(n));
  42509. }
  42510. }
  42511. return regions;
  42512. };
  42513. /**
  42514. * @param {Node} node Node.
  42515. * @return {Array.<Object>} Region.
  42516. * @api
  42517. */
  42518. ol.format.KML.prototype.readRegionFromNode = function(node) {
  42519. var n, regions = [];
  42520. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42521. if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
  42522. n.localName == 'Region') {
  42523. var obj = ol.xml.pushParseAndPop({}, ol.format.KML.REGION_PARSERS_,
  42524. n, []);
  42525. regions.push(obj);
  42526. }
  42527. }
  42528. for (n = node.firstElementChild; n; n = n.nextElementSibling) {
  42529. var localName = n.localName;
  42530. if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
  42531. (localName == 'Document' ||
  42532. localName == 'Folder' ||
  42533. localName == 'kml')) {
  42534. ol.array.extend(regions, this.readRegionFromNode(n));
  42535. }
  42536. }
  42537. return regions;
  42538. };
  42539. /**
  42540. * Read the projection from a KML source.
  42541. *
  42542. * @function
  42543. * @param {Document|Node|Object|string} source Source.
  42544. * @return {ol.proj.Projection} Projection.
  42545. * @api
  42546. */
  42547. ol.format.KML.prototype.readProjection;
  42548. /**
  42549. * @param {Node} node Node to append a TextNode with the color to.
  42550. * @param {ol.Color|string} color Color.
  42551. * @private
  42552. */
  42553. ol.format.KML.writeColorTextNode_ = function(node, color) {
  42554. var rgba = ol.color.asArray(color);
  42555. var opacity = (rgba.length == 4) ? rgba[3] : 1;
  42556. var abgr = [opacity * 255, rgba[2], rgba[1], rgba[0]];
  42557. var i;
  42558. for (i = 0; i < 4; ++i) {
  42559. var hex = parseInt(abgr[i], 10).toString(16);
  42560. abgr[i] = (hex.length == 1) ? '0' + hex : hex;
  42561. }
  42562. ol.format.XSD.writeStringTextNode(node, abgr.join(''));
  42563. };
  42564. /**
  42565. * @param {Node} node Node to append a TextNode with the coordinates to.
  42566. * @param {Array.<number>} coordinates Coordinates.
  42567. * @param {Array.<*>} objectStack Object stack.
  42568. * @private
  42569. */
  42570. ol.format.KML.writeCoordinatesTextNode_ = function(node, coordinates, objectStack) {
  42571. var context = objectStack[objectStack.length - 1];
  42572. var layout = context['layout'];
  42573. var stride = context['stride'];
  42574. var dimension;
  42575. if (layout == ol.geom.GeometryLayout.XY ||
  42576. layout == ol.geom.GeometryLayout.XYM) {
  42577. dimension = 2;
  42578. } else if (layout == ol.geom.GeometryLayout.XYZ ||
  42579. layout == ol.geom.GeometryLayout.XYZM) {
  42580. dimension = 3;
  42581. } else {
  42582. ol.asserts.assert(false, 34); // Invalid geometry layout
  42583. }
  42584. var d, i;
  42585. var ii = coordinates.length;
  42586. var text = '';
  42587. if (ii > 0) {
  42588. text += coordinates[0];
  42589. for (d = 1; d < dimension; ++d) {
  42590. text += ',' + coordinates[d];
  42591. }
  42592. for (i = stride; i < ii; i += stride) {
  42593. text += ' ' + coordinates[i];
  42594. for (d = 1; d < dimension; ++d) {
  42595. text += ',' + coordinates[i + d];
  42596. }
  42597. }
  42598. }
  42599. ol.format.XSD.writeStringTextNode(node, text);
  42600. };
  42601. /**
  42602. * @param {Node} node Node.
  42603. * @param {{name: *, value: *}} pair Name value pair.
  42604. * @param {Array.<*>} objectStack Object stack.
  42605. * @private
  42606. */
  42607. ol.format.KML.writeDataNode_ = function(node, pair, objectStack) {
  42608. node.setAttribute('name', pair.name);
  42609. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42610. var value = pair.value;
  42611. if (typeof value == 'object') {
  42612. if (value !== null && value.displayName) {
  42613. ol.xml.pushSerializeAndPop(context, ol.format.KML.EXTENDEDDATA_NODE_SERIALIZERS_,
  42614. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, [value.displayName], objectStack, ['displayName']);
  42615. }
  42616. if (value !== null && value.value) {
  42617. ol.xml.pushSerializeAndPop(context, ol.format.KML.EXTENDEDDATA_NODE_SERIALIZERS_,
  42618. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, [value.value], objectStack, ['value']);
  42619. }
  42620. } else {
  42621. ol.xml.pushSerializeAndPop(context, ol.format.KML.EXTENDEDDATA_NODE_SERIALIZERS_,
  42622. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, [value], objectStack, ['value']);
  42623. }
  42624. };
  42625. /**
  42626. * @param {Node} node Node to append a TextNode with the name to.
  42627. * @param {string} name DisplayName.
  42628. * @private
  42629. */
  42630. ol.format.KML.writeDataNodeName_ = function(node, name) {
  42631. ol.format.XSD.writeCDATASection(node, name);
  42632. };
  42633. /**
  42634. * @param {Node} node Node to append a CDATA Section with the value to.
  42635. * @param {string} value Value.
  42636. * @private
  42637. */
  42638. ol.format.KML.writeDataNodeValue_ = function(node, value) {
  42639. ol.format.XSD.writeStringTextNode(node, value);
  42640. };
  42641. /**
  42642. * @param {Node} node Node.
  42643. * @param {Array.<ol.Feature>} features Features.
  42644. * @param {Array.<*>} objectStack Object stack.
  42645. * @this {ol.format.KML}
  42646. * @private
  42647. */
  42648. ol.format.KML.writeDocument_ = function(node, features, objectStack) {
  42649. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42650. ol.xml.pushSerializeAndPop(context, ol.format.KML.DOCUMENT_SERIALIZERS_,
  42651. ol.format.KML.DOCUMENT_NODE_FACTORY_, features, objectStack, undefined,
  42652. this);
  42653. };
  42654. /**
  42655. * @param {Node} node Node.
  42656. * @param {{names: Array<string>, values: (Array<*>)}} namesAndValues Names and values.
  42657. * @param {Array.<*>} objectStack Object stack.
  42658. * @private
  42659. */
  42660. ol.format.KML.writeExtendedData_ = function(node, namesAndValues, objectStack) {
  42661. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42662. var names = namesAndValues.names, values = namesAndValues.values;
  42663. var length = names.length;
  42664. for (var i = 0; i < length; i++) {
  42665. ol.xml.pushSerializeAndPop(context, ol.format.KML.EXTENDEDDATA_NODE_SERIALIZERS_,
  42666. ol.format.KML.DATA_NODE_FACTORY_, [{name: names[i], value: values[i]}], objectStack);
  42667. }
  42668. };
  42669. /**
  42670. * @param {Node} node Node.
  42671. * @param {Object} icon Icon object.
  42672. * @param {Array.<*>} objectStack Object stack.
  42673. * @private
  42674. */
  42675. ol.format.KML.writeIcon_ = function(node, icon, objectStack) {
  42676. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42677. var parentNode = objectStack[objectStack.length - 1].node;
  42678. var orderedKeys = ol.format.KML.ICON_SEQUENCE_[parentNode.namespaceURI];
  42679. var values = ol.xml.makeSequence(icon, orderedKeys);
  42680. ol.xml.pushSerializeAndPop(context,
  42681. ol.format.KML.ICON_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
  42682. values, objectStack, orderedKeys);
  42683. orderedKeys =
  42684. ol.format.KML.ICON_SEQUENCE_[ol.format.KML.GX_NAMESPACE_URIS_[0]];
  42685. values = ol.xml.makeSequence(icon, orderedKeys);
  42686. ol.xml.pushSerializeAndPop(context, ol.format.KML.ICON_SERIALIZERS_,
  42687. ol.format.KML.GX_NODE_FACTORY_, values, objectStack, orderedKeys);
  42688. };
  42689. /**
  42690. * @param {Node} node Node.
  42691. * @param {ol.style.Icon} style Icon style.
  42692. * @param {Array.<*>} objectStack Object stack.
  42693. * @private
  42694. */
  42695. ol.format.KML.writeIconStyle_ = function(node, style, objectStack) {
  42696. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42697. var properties = {};
  42698. var src = style.getSrc();
  42699. var size = style.getSize();
  42700. var iconImageSize = style.getImageSize();
  42701. var iconProperties = {
  42702. 'href': src
  42703. };
  42704. if (size) {
  42705. iconProperties['w'] = size[0];
  42706. iconProperties['h'] = size[1];
  42707. var anchor = style.getAnchor(); // top-left
  42708. var origin = style.getOrigin(); // top-left
  42709. if (origin && iconImageSize && origin[0] !== 0 && origin[1] !== size[1]) {
  42710. iconProperties['x'] = origin[0];
  42711. iconProperties['y'] = iconImageSize[1] - (origin[1] + size[1]);
  42712. }
  42713. if (anchor && (anchor[0] !== size[0] / 2 || anchor[1] !== size[1] / 2)) {
  42714. var /** @type {ol.KMLVec2_} */ hotSpot = {
  42715. x: anchor[0],
  42716. xunits: ol.style.IconAnchorUnits.PIXELS,
  42717. y: size[1] - anchor[1],
  42718. yunits: ol.style.IconAnchorUnits.PIXELS
  42719. };
  42720. properties['hotSpot'] = hotSpot;
  42721. }
  42722. }
  42723. properties['Icon'] = iconProperties;
  42724. var scale = style.getScale();
  42725. if (scale !== 1) {
  42726. properties['scale'] = scale;
  42727. }
  42728. var rotation = style.getRotation();
  42729. if (rotation !== 0) {
  42730. properties['heading'] = rotation; // 0-360
  42731. }
  42732. var parentNode = objectStack[objectStack.length - 1].node;
  42733. var orderedKeys = ol.format.KML.ICON_STYLE_SEQUENCE_[parentNode.namespaceURI];
  42734. var values = ol.xml.makeSequence(properties, orderedKeys);
  42735. ol.xml.pushSerializeAndPop(context, ol.format.KML.ICON_STYLE_SERIALIZERS_,
  42736. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
  42737. };
  42738. /**
  42739. * @param {Node} node Node.
  42740. * @param {ol.style.Text} style style.
  42741. * @param {Array.<*>} objectStack Object stack.
  42742. * @private
  42743. */
  42744. ol.format.KML.writeLabelStyle_ = function(node, style, objectStack) {
  42745. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42746. var properties = {};
  42747. var fill = style.getFill();
  42748. if (fill) {
  42749. properties['color'] = fill.getColor();
  42750. }
  42751. var scale = style.getScale();
  42752. if (scale && scale !== 1) {
  42753. properties['scale'] = scale;
  42754. }
  42755. var parentNode = objectStack[objectStack.length - 1].node;
  42756. var orderedKeys =
  42757. ol.format.KML.LABEL_STYLE_SEQUENCE_[parentNode.namespaceURI];
  42758. var values = ol.xml.makeSequence(properties, orderedKeys);
  42759. ol.xml.pushSerializeAndPop(context, ol.format.KML.LABEL_STYLE_SERIALIZERS_,
  42760. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
  42761. };
  42762. /**
  42763. * @param {Node} node Node.
  42764. * @param {ol.style.Stroke} style style.
  42765. * @param {Array.<*>} objectStack Object stack.
  42766. * @private
  42767. */
  42768. ol.format.KML.writeLineStyle_ = function(node, style, objectStack) {
  42769. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42770. var properties = {
  42771. 'color': style.getColor(),
  42772. 'width': style.getWidth()
  42773. };
  42774. var parentNode = objectStack[objectStack.length - 1].node;
  42775. var orderedKeys = ol.format.KML.LINE_STYLE_SEQUENCE_[parentNode.namespaceURI];
  42776. var values = ol.xml.makeSequence(properties, orderedKeys);
  42777. ol.xml.pushSerializeAndPop(context, ol.format.KML.LINE_STYLE_SERIALIZERS_,
  42778. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
  42779. };
  42780. /**
  42781. * @param {Node} node Node.
  42782. * @param {ol.geom.Geometry} geometry Geometry.
  42783. * @param {Array.<*>} objectStack Object stack.
  42784. * @private
  42785. */
  42786. ol.format.KML.writeMultiGeometry_ = function(node, geometry, objectStack) {
  42787. /** @type {ol.XmlNodeStackItem} */
  42788. var context = {node: node};
  42789. var type = geometry.getType();
  42790. /** @type {Array.<ol.geom.Geometry>} */
  42791. var geometries;
  42792. /** @type {function(*, Array.<*>, string=): (Node|undefined)} */
  42793. var factory;
  42794. if (type == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
  42795. geometries = /** @type {ol.geom.GeometryCollection} */ (geometry).getGeometries();
  42796. factory = ol.format.KML.GEOMETRY_NODE_FACTORY_;
  42797. } else if (type == ol.geom.GeometryType.MULTI_POINT) {
  42798. geometries = /** @type {ol.geom.MultiPoint} */ (geometry).getPoints();
  42799. factory = ol.format.KML.POINT_NODE_FACTORY_;
  42800. } else if (type == ol.geom.GeometryType.MULTI_LINE_STRING) {
  42801. geometries =
  42802. (/** @type {ol.geom.MultiLineString} */ (geometry)).getLineStrings();
  42803. factory = ol.format.KML.LINE_STRING_NODE_FACTORY_;
  42804. } else if (type == ol.geom.GeometryType.MULTI_POLYGON) {
  42805. geometries =
  42806. (/** @type {ol.geom.MultiPolygon} */ (geometry)).getPolygons();
  42807. factory = ol.format.KML.POLYGON_NODE_FACTORY_;
  42808. } else {
  42809. ol.asserts.assert(false, 39); // Unknown geometry type
  42810. }
  42811. ol.xml.pushSerializeAndPop(context,
  42812. ol.format.KML.MULTI_GEOMETRY_SERIALIZERS_, factory,
  42813. geometries, objectStack);
  42814. };
  42815. /**
  42816. * @param {Node} node Node.
  42817. * @param {ol.geom.LinearRing} linearRing Linear ring.
  42818. * @param {Array.<*>} objectStack Object stack.
  42819. * @private
  42820. */
  42821. ol.format.KML.writeBoundaryIs_ = function(node, linearRing, objectStack) {
  42822. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42823. ol.xml.pushSerializeAndPop(context,
  42824. ol.format.KML.BOUNDARY_IS_SERIALIZERS_,
  42825. ol.format.KML.LINEAR_RING_NODE_FACTORY_, [linearRing], objectStack);
  42826. };
  42827. /**
  42828. * FIXME currently we do serialize arbitrary/custom feature properties
  42829. * (ExtendedData).
  42830. * @param {Node} node Node.
  42831. * @param {ol.Feature} feature Feature.
  42832. * @param {Array.<*>} objectStack Object stack.
  42833. * @this {ol.format.KML}
  42834. * @private
  42835. */
  42836. ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
  42837. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42838. // set id
  42839. if (feature.getId()) {
  42840. node.setAttribute('id', feature.getId());
  42841. }
  42842. // serialize properties (properties unknown to KML are not serialized)
  42843. var properties = feature.getProperties();
  42844. // don't export these to ExtendedData
  42845. var filter = {'address': 1, 'description': 1, 'name': 1, 'open': 1,
  42846. 'phoneNumber': 1, 'styleUrl': 1, 'visibility': 1};
  42847. filter[feature.getGeometryName()] = 1;
  42848. var keys = Object.keys(properties || {}).sort().filter(function(v) {
  42849. return !filter[v];
  42850. });
  42851. if (keys.length > 0) {
  42852. var sequence = ol.xml.makeSequence(properties, keys);
  42853. var namesAndValues = {names: keys, values: sequence};
  42854. ol.xml.pushSerializeAndPop(context, ol.format.KML.PLACEMARK_SERIALIZERS_,
  42855. ol.format.KML.EXTENDEDDATA_NODE_FACTORY_, [namesAndValues], objectStack);
  42856. }
  42857. var styleFunction = feature.getStyleFunction();
  42858. if (styleFunction) {
  42859. // FIXME the styles returned by the style function are supposed to be
  42860. // resolution-independent here
  42861. var styles = styleFunction.call(feature, 0);
  42862. if (styles) {
  42863. var style = Array.isArray(styles) ? styles[0] : styles;
  42864. if (this.writeStyles_) {
  42865. properties['Style'] = style;
  42866. }
  42867. var textStyle = style.getText();
  42868. if (textStyle) {
  42869. properties['name'] = textStyle.getText();
  42870. }
  42871. }
  42872. }
  42873. var parentNode = objectStack[objectStack.length - 1].node;
  42874. var orderedKeys = ol.format.KML.PLACEMARK_SEQUENCE_[parentNode.namespaceURI];
  42875. var values = ol.xml.makeSequence(properties, orderedKeys);
  42876. ol.xml.pushSerializeAndPop(context, ol.format.KML.PLACEMARK_SERIALIZERS_,
  42877. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
  42878. // serialize geometry
  42879. var options = /** @type {olx.format.WriteOptions} */ (objectStack[0]);
  42880. var geometry = feature.getGeometry();
  42881. if (geometry) {
  42882. geometry =
  42883. ol.format.Feature.transformWithOptions(geometry, true, options);
  42884. }
  42885. ol.xml.pushSerializeAndPop(context, ol.format.KML.PLACEMARK_SERIALIZERS_,
  42886. ol.format.KML.GEOMETRY_NODE_FACTORY_, [geometry], objectStack);
  42887. };
  42888. /**
  42889. * @param {Node} node Node.
  42890. * @param {ol.geom.SimpleGeometry} geometry Geometry.
  42891. * @param {Array.<*>} objectStack Object stack.
  42892. * @private
  42893. */
  42894. ol.format.KML.writePrimitiveGeometry_ = function(node, geometry, objectStack) {
  42895. var flatCoordinates = geometry.getFlatCoordinates();
  42896. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42897. context['layout'] = geometry.getLayout();
  42898. context['stride'] = geometry.getStride();
  42899. // serialize properties (properties unknown to KML are not serialized)
  42900. var properties = geometry.getProperties();
  42901. properties.coordinates = flatCoordinates;
  42902. var parentNode = objectStack[objectStack.length - 1].node;
  42903. var orderedKeys = ol.format.KML.PRIMITIVE_GEOMETRY_SEQUENCE_[parentNode.namespaceURI];
  42904. var values = ol.xml.makeSequence(properties, orderedKeys);
  42905. ol.xml.pushSerializeAndPop(context, ol.format.KML.PRIMITIVE_GEOMETRY_SERIALIZERS_,
  42906. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
  42907. };
  42908. /**
  42909. * @param {Node} node Node.
  42910. * @param {ol.geom.Polygon} polygon Polygon.
  42911. * @param {Array.<*>} objectStack Object stack.
  42912. * @private
  42913. */
  42914. ol.format.KML.writePolygon_ = function(node, polygon, objectStack) {
  42915. var linearRings = polygon.getLinearRings();
  42916. var outerRing = linearRings.shift();
  42917. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42918. // inner rings
  42919. ol.xml.pushSerializeAndPop(context,
  42920. ol.format.KML.POLYGON_SERIALIZERS_,
  42921. ol.format.KML.INNER_BOUNDARY_NODE_FACTORY_,
  42922. linearRings, objectStack);
  42923. // outer ring
  42924. ol.xml.pushSerializeAndPop(context,
  42925. ol.format.KML.POLYGON_SERIALIZERS_,
  42926. ol.format.KML.OUTER_BOUNDARY_NODE_FACTORY_,
  42927. [outerRing], objectStack);
  42928. };
  42929. /**
  42930. * @param {Node} node Node.
  42931. * @param {ol.style.Fill} style Style.
  42932. * @param {Array.<*>} objectStack Object stack.
  42933. * @private
  42934. */
  42935. ol.format.KML.writePolyStyle_ = function(node, style, objectStack) {
  42936. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42937. ol.xml.pushSerializeAndPop(context, ol.format.KML.POLY_STYLE_SERIALIZERS_,
  42938. ol.format.KML.COLOR_NODE_FACTORY_, [style.getColor()], objectStack);
  42939. };
  42940. /**
  42941. * @param {Node} node Node to append a TextNode with the scale to.
  42942. * @param {number|undefined} scale Scale.
  42943. * @private
  42944. */
  42945. ol.format.KML.writeScaleTextNode_ = function(node, scale) {
  42946. // the Math is to remove any excess decimals created by float arithmetic
  42947. ol.format.XSD.writeDecimalTextNode(node,
  42948. Math.round(scale * 1e6) / 1e6);
  42949. };
  42950. /**
  42951. * @param {Node} node Node.
  42952. * @param {ol.style.Style} style Style.
  42953. * @param {Array.<*>} objectStack Object stack.
  42954. * @private
  42955. */
  42956. ol.format.KML.writeStyle_ = function(node, style, objectStack) {
  42957. var /** @type {ol.XmlNodeStackItem} */ context = {node: node};
  42958. var properties = {};
  42959. var fillStyle = style.getFill();
  42960. var strokeStyle = style.getStroke();
  42961. var imageStyle = style.getImage();
  42962. var textStyle = style.getText();
  42963. if (imageStyle instanceof ol.style.Icon) {
  42964. properties['IconStyle'] = imageStyle;
  42965. }
  42966. if (textStyle) {
  42967. properties['LabelStyle'] = textStyle;
  42968. }
  42969. if (strokeStyle) {
  42970. properties['LineStyle'] = strokeStyle;
  42971. }
  42972. if (fillStyle) {
  42973. properties['PolyStyle'] = fillStyle;
  42974. }
  42975. var parentNode = objectStack[objectStack.length - 1].node;
  42976. var orderedKeys = ol.format.KML.STYLE_SEQUENCE_[parentNode.namespaceURI];
  42977. var values = ol.xml.makeSequence(properties, orderedKeys);
  42978. ol.xml.pushSerializeAndPop(context, ol.format.KML.STYLE_SERIALIZERS_,
  42979. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
  42980. };
  42981. /**
  42982. * @param {Node} node Node to append a TextNode with the Vec2 to.
  42983. * @param {ol.KMLVec2_} vec2 Vec2.
  42984. * @private
  42985. */
  42986. ol.format.KML.writeVec2_ = function(node, vec2) {
  42987. node.setAttribute('x', vec2.x);
  42988. node.setAttribute('y', vec2.y);
  42989. node.setAttribute('xunits', vec2.xunits);
  42990. node.setAttribute('yunits', vec2.yunits);
  42991. };
  42992. /**
  42993. * @const
  42994. * @type {Object.<string, Array.<string>>}
  42995. * @private
  42996. */
  42997. ol.format.KML.KML_SEQUENCE_ = ol.xml.makeStructureNS(
  42998. ol.format.KML.NAMESPACE_URIS_, [
  42999. 'Document', 'Placemark'
  43000. ]);
  43001. /**
  43002. * @const
  43003. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43004. * @private
  43005. */
  43006. ol.format.KML.KML_SERIALIZERS_ = ol.xml.makeStructureNS(
  43007. ol.format.KML.NAMESPACE_URIS_, {
  43008. 'Document': ol.xml.makeChildAppender(ol.format.KML.writeDocument_),
  43009. 'Placemark': ol.xml.makeChildAppender(ol.format.KML.writePlacemark_)
  43010. });
  43011. /**
  43012. * @const
  43013. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43014. * @private
  43015. */
  43016. ol.format.KML.DOCUMENT_SERIALIZERS_ = ol.xml.makeStructureNS(
  43017. ol.format.KML.NAMESPACE_URIS_, {
  43018. 'Placemark': ol.xml.makeChildAppender(ol.format.KML.writePlacemark_)
  43019. });
  43020. /**
  43021. * @const
  43022. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43023. * @private
  43024. */
  43025. ol.format.KML.EXTENDEDDATA_NODE_SERIALIZERS_ = ol.xml.makeStructureNS(
  43026. ol.format.KML.NAMESPACE_URIS_, {
  43027. 'Data': ol.xml.makeChildAppender(ol.format.KML.writeDataNode_),
  43028. 'value': ol.xml.makeChildAppender(ol.format.KML.writeDataNodeValue_),
  43029. 'displayName': ol.xml.makeChildAppender(ol.format.KML.writeDataNodeName_)
  43030. });
  43031. /**
  43032. * @const
  43033. * @type {Object.<string, string>}
  43034. * @private
  43035. */
  43036. ol.format.KML.GEOMETRY_TYPE_TO_NODENAME_ = {
  43037. 'Point': 'Point',
  43038. 'LineString': 'LineString',
  43039. 'LinearRing': 'LinearRing',
  43040. 'Polygon': 'Polygon',
  43041. 'MultiPoint': 'MultiGeometry',
  43042. 'MultiLineString': 'MultiGeometry',
  43043. 'MultiPolygon': 'MultiGeometry',
  43044. 'GeometryCollection': 'MultiGeometry'
  43045. };
  43046. /**
  43047. * @const
  43048. * @type {Object.<string, Array.<string>>}
  43049. * @private
  43050. */
  43051. ol.format.KML.ICON_SEQUENCE_ = ol.xml.makeStructureNS(
  43052. ol.format.KML.NAMESPACE_URIS_, [
  43053. 'href'
  43054. ],
  43055. ol.xml.makeStructureNS(ol.format.KML.GX_NAMESPACE_URIS_, [
  43056. 'x', 'y', 'w', 'h'
  43057. ]));
  43058. /**
  43059. * @const
  43060. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43061. * @private
  43062. */
  43063. ol.format.KML.ICON_SERIALIZERS_ = ol.xml.makeStructureNS(
  43064. ol.format.KML.NAMESPACE_URIS_, {
  43065. 'href': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
  43066. }, ol.xml.makeStructureNS(
  43067. ol.format.KML.GX_NAMESPACE_URIS_, {
  43068. 'x': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  43069. 'y': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  43070. 'w': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  43071. 'h': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode)
  43072. }));
  43073. /**
  43074. * @const
  43075. * @type {Object.<string, Array.<string>>}
  43076. * @private
  43077. */
  43078. ol.format.KML.ICON_STYLE_SEQUENCE_ = ol.xml.makeStructureNS(
  43079. ol.format.KML.NAMESPACE_URIS_, [
  43080. 'scale', 'heading', 'Icon', 'hotSpot'
  43081. ]);
  43082. /**
  43083. * @const
  43084. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43085. * @private
  43086. */
  43087. ol.format.KML.ICON_STYLE_SERIALIZERS_ = ol.xml.makeStructureNS(
  43088. ol.format.KML.NAMESPACE_URIS_, {
  43089. 'Icon': ol.xml.makeChildAppender(ol.format.KML.writeIcon_),
  43090. 'heading': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode),
  43091. 'hotSpot': ol.xml.makeChildAppender(ol.format.KML.writeVec2_),
  43092. 'scale': ol.xml.makeChildAppender(ol.format.KML.writeScaleTextNode_)
  43093. });
  43094. /**
  43095. * @const
  43096. * @type {Object.<string, Array.<string>>}
  43097. * @private
  43098. */
  43099. ol.format.KML.LABEL_STYLE_SEQUENCE_ = ol.xml.makeStructureNS(
  43100. ol.format.KML.NAMESPACE_URIS_, [
  43101. 'color', 'scale'
  43102. ]);
  43103. /**
  43104. * @const
  43105. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43106. * @private
  43107. */
  43108. ol.format.KML.LABEL_STYLE_SERIALIZERS_ = ol.xml.makeStructureNS(
  43109. ol.format.KML.NAMESPACE_URIS_, {
  43110. 'color': ol.xml.makeChildAppender(ol.format.KML.writeColorTextNode_),
  43111. 'scale': ol.xml.makeChildAppender(ol.format.KML.writeScaleTextNode_)
  43112. });
  43113. /**
  43114. * @const
  43115. * @type {Object.<string, Array.<string>>}
  43116. * @private
  43117. */
  43118. ol.format.KML.LINE_STYLE_SEQUENCE_ = ol.xml.makeStructureNS(
  43119. ol.format.KML.NAMESPACE_URIS_, [
  43120. 'color', 'width'
  43121. ]);
  43122. /**
  43123. * @const
  43124. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43125. * @private
  43126. */
  43127. ol.format.KML.LINE_STYLE_SERIALIZERS_ = ol.xml.makeStructureNS(
  43128. ol.format.KML.NAMESPACE_URIS_, {
  43129. 'color': ol.xml.makeChildAppender(ol.format.KML.writeColorTextNode_),
  43130. 'width': ol.xml.makeChildAppender(ol.format.XSD.writeDecimalTextNode)
  43131. });
  43132. /**
  43133. * @const
  43134. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43135. * @private
  43136. */
  43137. ol.format.KML.BOUNDARY_IS_SERIALIZERS_ = ol.xml.makeStructureNS(
  43138. ol.format.KML.NAMESPACE_URIS_, {
  43139. 'LinearRing': ol.xml.makeChildAppender(
  43140. ol.format.KML.writePrimitiveGeometry_)
  43141. });
  43142. /**
  43143. * @const
  43144. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43145. * @private
  43146. */
  43147. ol.format.KML.MULTI_GEOMETRY_SERIALIZERS_ = ol.xml.makeStructureNS(
  43148. ol.format.KML.NAMESPACE_URIS_, {
  43149. 'LineString': ol.xml.makeChildAppender(
  43150. ol.format.KML.writePrimitiveGeometry_),
  43151. 'Point': ol.xml.makeChildAppender(
  43152. ol.format.KML.writePrimitiveGeometry_),
  43153. 'Polygon': ol.xml.makeChildAppender(ol.format.KML.writePolygon_),
  43154. 'GeometryCollection': ol.xml.makeChildAppender(
  43155. ol.format.KML.writeMultiGeometry_)
  43156. });
  43157. /**
  43158. * @const
  43159. * @type {Object.<string, Array.<string>>}
  43160. * @private
  43161. */
  43162. ol.format.KML.PLACEMARK_SEQUENCE_ = ol.xml.makeStructureNS(
  43163. ol.format.KML.NAMESPACE_URIS_, [
  43164. 'name', 'open', 'visibility', 'address', 'phoneNumber', 'description',
  43165. 'styleUrl', 'Style'
  43166. ]);
  43167. /**
  43168. * @const
  43169. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43170. * @private
  43171. */
  43172. ol.format.KML.PLACEMARK_SERIALIZERS_ = ol.xml.makeStructureNS(
  43173. ol.format.KML.NAMESPACE_URIS_, {
  43174. 'ExtendedData': ol.xml.makeChildAppender(
  43175. ol.format.KML.writeExtendedData_),
  43176. 'MultiGeometry': ol.xml.makeChildAppender(
  43177. ol.format.KML.writeMultiGeometry_),
  43178. 'LineString': ol.xml.makeChildAppender(
  43179. ol.format.KML.writePrimitiveGeometry_),
  43180. 'LinearRing': ol.xml.makeChildAppender(
  43181. ol.format.KML.writePrimitiveGeometry_),
  43182. 'Point': ol.xml.makeChildAppender(
  43183. ol.format.KML.writePrimitiveGeometry_),
  43184. 'Polygon': ol.xml.makeChildAppender(ol.format.KML.writePolygon_),
  43185. 'Style': ol.xml.makeChildAppender(ol.format.KML.writeStyle_),
  43186. 'address': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  43187. 'description': ol.xml.makeChildAppender(
  43188. ol.format.XSD.writeStringTextNode),
  43189. 'name': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  43190. 'open': ol.xml.makeChildAppender(ol.format.XSD.writeBooleanTextNode),
  43191. 'phoneNumber': ol.xml.makeChildAppender(
  43192. ol.format.XSD.writeStringTextNode),
  43193. 'styleUrl': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  43194. 'visibility': ol.xml.makeChildAppender(
  43195. ol.format.XSD.writeBooleanTextNode)
  43196. });
  43197. /**
  43198. * @const
  43199. * @type {Object.<string, Array.<string>>}
  43200. * @private
  43201. */
  43202. ol.format.KML.PRIMITIVE_GEOMETRY_SEQUENCE_ = ol.xml.makeStructureNS(
  43203. ol.format.KML.NAMESPACE_URIS_, [
  43204. 'extrude', 'tessellate', 'altitudeMode', 'coordinates'
  43205. ]);
  43206. /**
  43207. * @const
  43208. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43209. * @private
  43210. */
  43211. ol.format.KML.PRIMITIVE_GEOMETRY_SERIALIZERS_ = ol.xml.makeStructureNS(
  43212. ol.format.KML.NAMESPACE_URIS_, {
  43213. 'extrude': ol.xml.makeChildAppender(ol.format.XSD.writeBooleanTextNode),
  43214. 'tessellate': ol.xml.makeChildAppender(ol.format.XSD.writeBooleanTextNode),
  43215. 'altitudeMode': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
  43216. 'coordinates': ol.xml.makeChildAppender(
  43217. ol.format.KML.writeCoordinatesTextNode_)
  43218. });
  43219. /**
  43220. * @const
  43221. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43222. * @private
  43223. */
  43224. ol.format.KML.POLYGON_SERIALIZERS_ = ol.xml.makeStructureNS(
  43225. ol.format.KML.NAMESPACE_URIS_, {
  43226. 'outerBoundaryIs': ol.xml.makeChildAppender(
  43227. ol.format.KML.writeBoundaryIs_),
  43228. 'innerBoundaryIs': ol.xml.makeChildAppender(
  43229. ol.format.KML.writeBoundaryIs_)
  43230. });
  43231. /**
  43232. * @const
  43233. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43234. * @private
  43235. */
  43236. ol.format.KML.POLY_STYLE_SERIALIZERS_ = ol.xml.makeStructureNS(
  43237. ol.format.KML.NAMESPACE_URIS_, {
  43238. 'color': ol.xml.makeChildAppender(ol.format.KML.writeColorTextNode_)
  43239. });
  43240. /**
  43241. * @const
  43242. * @type {Object.<string, Array.<string>>}
  43243. * @private
  43244. */
  43245. ol.format.KML.STYLE_SEQUENCE_ = ol.xml.makeStructureNS(
  43246. ol.format.KML.NAMESPACE_URIS_, [
  43247. 'IconStyle', 'LabelStyle', 'LineStyle', 'PolyStyle'
  43248. ]);
  43249. /**
  43250. * @const
  43251. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  43252. * @private
  43253. */
  43254. ol.format.KML.STYLE_SERIALIZERS_ = ol.xml.makeStructureNS(
  43255. ol.format.KML.NAMESPACE_URIS_, {
  43256. 'IconStyle': ol.xml.makeChildAppender(ol.format.KML.writeIconStyle_),
  43257. 'LabelStyle': ol.xml.makeChildAppender(ol.format.KML.writeLabelStyle_),
  43258. 'LineStyle': ol.xml.makeChildAppender(ol.format.KML.writeLineStyle_),
  43259. 'PolyStyle': ol.xml.makeChildAppender(ol.format.KML.writePolyStyle_)
  43260. });
  43261. /**
  43262. * @const
  43263. * @param {*} value Value.
  43264. * @param {Array.<*>} objectStack Object stack.
  43265. * @param {string=} opt_nodeName Node name.
  43266. * @return {Node|undefined} Node.
  43267. * @private
  43268. */
  43269. ol.format.KML.GX_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
  43270. return ol.xml.createElementNS(ol.format.KML.GX_NAMESPACE_URIS_[0],
  43271. 'gx:' + opt_nodeName);
  43272. };
  43273. /**
  43274. * @const
  43275. * @param {*} value Value.
  43276. * @param {Array.<*>} objectStack Object stack.
  43277. * @param {string=} opt_nodeName Node name.
  43278. * @return {Node|undefined} Node.
  43279. * @private
  43280. */
  43281. ol.format.KML.DOCUMENT_NODE_FACTORY_ = function(value, objectStack,
  43282. opt_nodeName) {
  43283. var parentNode = objectStack[objectStack.length - 1].node;
  43284. return ol.xml.createElementNS(parentNode.namespaceURI, 'Placemark');
  43285. };
  43286. /**
  43287. * @const
  43288. * @param {*} value Value.
  43289. * @param {Array.<*>} objectStack Object stack.
  43290. * @param {string=} opt_nodeName Node name.
  43291. * @return {Node|undefined} Node.
  43292. * @private
  43293. */
  43294. ol.format.KML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
  43295. opt_nodeName) {
  43296. if (value) {
  43297. var parentNode = objectStack[objectStack.length - 1].node;
  43298. return ol.xml.createElementNS(parentNode.namespaceURI,
  43299. ol.format.KML.GEOMETRY_TYPE_TO_NODENAME_[/** @type {ol.geom.Geometry} */ (value).getType()]);
  43300. }
  43301. };
  43302. /**
  43303. * A factory for creating coordinates nodes.
  43304. * @const
  43305. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43306. * @private
  43307. */
  43308. ol.format.KML.COLOR_NODE_FACTORY_ = ol.xml.makeSimpleNodeFactory('color');
  43309. /**
  43310. * A factory for creating Data nodes.
  43311. * @const
  43312. * @type {function(*, Array.<*>): (Node|undefined)}
  43313. * @private
  43314. */
  43315. ol.format.KML.DATA_NODE_FACTORY_ =
  43316. ol.xml.makeSimpleNodeFactory('Data');
  43317. /**
  43318. * A factory for creating ExtendedData nodes.
  43319. * @const
  43320. * @type {function(*, Array.<*>): (Node|undefined)}
  43321. * @private
  43322. */
  43323. ol.format.KML.EXTENDEDDATA_NODE_FACTORY_ =
  43324. ol.xml.makeSimpleNodeFactory('ExtendedData');
  43325. /**
  43326. * A factory for creating innerBoundaryIs nodes.
  43327. * @const
  43328. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43329. * @private
  43330. */
  43331. ol.format.KML.INNER_BOUNDARY_NODE_FACTORY_ =
  43332. ol.xml.makeSimpleNodeFactory('innerBoundaryIs');
  43333. /**
  43334. * A factory for creating Point nodes.
  43335. * @const
  43336. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43337. * @private
  43338. */
  43339. ol.format.KML.POINT_NODE_FACTORY_ =
  43340. ol.xml.makeSimpleNodeFactory('Point');
  43341. /**
  43342. * A factory for creating LineString nodes.
  43343. * @const
  43344. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43345. * @private
  43346. */
  43347. ol.format.KML.LINE_STRING_NODE_FACTORY_ =
  43348. ol.xml.makeSimpleNodeFactory('LineString');
  43349. /**
  43350. * A factory for creating LinearRing nodes.
  43351. * @const
  43352. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43353. * @private
  43354. */
  43355. ol.format.KML.LINEAR_RING_NODE_FACTORY_ =
  43356. ol.xml.makeSimpleNodeFactory('LinearRing');
  43357. /**
  43358. * A factory for creating Polygon nodes.
  43359. * @const
  43360. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43361. * @private
  43362. */
  43363. ol.format.KML.POLYGON_NODE_FACTORY_ =
  43364. ol.xml.makeSimpleNodeFactory('Polygon');
  43365. /**
  43366. * A factory for creating outerBoundaryIs nodes.
  43367. * @const
  43368. * @type {function(*, Array.<*>, string=): (Node|undefined)}
  43369. * @private
  43370. */
  43371. ol.format.KML.OUTER_BOUNDARY_NODE_FACTORY_ =
  43372. ol.xml.makeSimpleNodeFactory('outerBoundaryIs');
  43373. /**
  43374. * Encode an array of features in the KML format. GeometryCollections, MultiPoints,
  43375. * MultiLineStrings, and MultiPolygons are output as MultiGeometries.
  43376. *
  43377. * @function
  43378. * @param {Array.<ol.Feature>} features Features.
  43379. * @param {olx.format.WriteOptions=} opt_options Options.
  43380. * @return {string} Result.
  43381. * @api
  43382. */
  43383. ol.format.KML.prototype.writeFeatures;
  43384. /**
  43385. * Encode an array of features in the KML format as an XML node. GeometryCollections,
  43386. * MultiPoints, MultiLineStrings, and MultiPolygons are output as MultiGeometries.
  43387. *
  43388. * @param {Array.<ol.Feature>} features Features.
  43389. * @param {olx.format.WriteOptions=} opt_options Options.
  43390. * @return {Node} Node.
  43391. * @override
  43392. * @api
  43393. */
  43394. ol.format.KML.prototype.writeFeaturesNode = function(features, opt_options) {
  43395. opt_options = this.adaptOptions(opt_options);
  43396. var kml = ol.xml.createElementNS(ol.format.KML.NAMESPACE_URIS_[4], 'kml');
  43397. var xmlnsUri = 'http://www.w3.org/2000/xmlns/';
  43398. var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance';
  43399. ol.xml.setAttributeNS(kml, xmlnsUri, 'xmlns:gx',
  43400. ol.format.KML.GX_NAMESPACE_URIS_[0]);
  43401. ol.xml.setAttributeNS(kml, xmlnsUri, 'xmlns:xsi', xmlSchemaInstanceUri);
  43402. ol.xml.setAttributeNS(kml, xmlSchemaInstanceUri, 'xsi:schemaLocation',
  43403. ol.format.KML.SCHEMA_LOCATION_);
  43404. var /** @type {ol.XmlNodeStackItem} */ context = {node: kml};
  43405. var properties = {};
  43406. if (features.length > 1) {
  43407. properties['Document'] = features;
  43408. } else if (features.length == 1) {
  43409. properties['Placemark'] = features[0];
  43410. }
  43411. var orderedKeys = ol.format.KML.KML_SEQUENCE_[kml.namespaceURI];
  43412. var values = ol.xml.makeSequence(properties, orderedKeys);
  43413. ol.xml.pushSerializeAndPop(context, ol.format.KML.KML_SERIALIZERS_,
  43414. ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, [opt_options], orderedKeys,
  43415. this);
  43416. return kml;
  43417. };
  43418. /**
  43419. * @fileoverview
  43420. * @suppress {accessControls, ambiguousFunctionDecl, checkDebuggerStatement, checkRegExp, checkTypes, checkVars, const, constantProperty, deprecated, duplicate, es5Strict, fileoverviewTags, missingProperties, nonStandardJsDocs, strictModuleDepCheck, suspiciousCode, undefinedNames, undefinedVars, unknownDefines, unusedLocalVariables, uselessCode, visibility}
  43421. */
  43422. goog.provide('ol.ext.PBF');
  43423. /** @typedef {function(*)} */
  43424. ol.ext.PBF = function() {};
  43425. (function() {(function (exports) {
  43426. 'use strict';
  43427. var read = function (buffer, offset, isLE, mLen, nBytes) {
  43428. var e, m;
  43429. var eLen = (nBytes * 8) - mLen - 1;
  43430. var eMax = (1 << eLen) - 1;
  43431. var eBias = eMax >> 1;
  43432. var nBits = -7;
  43433. var i = isLE ? (nBytes - 1) : 0;
  43434. var d = isLE ? -1 : 1;
  43435. var s = buffer[offset + i];
  43436. i += d;
  43437. e = s & ((1 << (-nBits)) - 1);
  43438. s >>= (-nBits);
  43439. nBits += eLen;
  43440. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  43441. m = e & ((1 << (-nBits)) - 1);
  43442. e >>= (-nBits);
  43443. nBits += mLen;
  43444. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  43445. if (e === 0) {
  43446. e = 1 - eBias;
  43447. } else if (e === eMax) {
  43448. return m ? NaN : ((s ? -1 : 1) * Infinity)
  43449. } else {
  43450. m = m + Math.pow(2, mLen);
  43451. e = e - eBias;
  43452. }
  43453. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  43454. };
  43455. var write = function (buffer, value, offset, isLE, mLen, nBytes) {
  43456. var e, m, c;
  43457. var eLen = (nBytes * 8) - mLen - 1;
  43458. var eMax = (1 << eLen) - 1;
  43459. var eBias = eMax >> 1;
  43460. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  43461. var i = isLE ? 0 : (nBytes - 1);
  43462. var d = isLE ? 1 : -1;
  43463. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  43464. value = Math.abs(value);
  43465. if (isNaN(value) || value === Infinity) {
  43466. m = isNaN(value) ? 1 : 0;
  43467. e = eMax;
  43468. } else {
  43469. e = Math.floor(Math.log(value) / Math.LN2);
  43470. if (value * (c = Math.pow(2, -e)) < 1) {
  43471. e--;
  43472. c *= 2;
  43473. }
  43474. if (e + eBias >= 1) {
  43475. value += rt / c;
  43476. } else {
  43477. value += rt * Math.pow(2, 1 - eBias);
  43478. }
  43479. if (value * c >= 2) {
  43480. e++;
  43481. c /= 2;
  43482. }
  43483. if (e + eBias >= eMax) {
  43484. m = 0;
  43485. e = eMax;
  43486. } else if (e + eBias >= 1) {
  43487. m = ((value * c) - 1) * Math.pow(2, mLen);
  43488. e = e + eBias;
  43489. } else {
  43490. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  43491. e = 0;
  43492. }
  43493. }
  43494. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  43495. e = (e << mLen) | m;
  43496. eLen += mLen;
  43497. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  43498. buffer[offset + i - d] |= s * 128;
  43499. };
  43500. var ieee754 = {
  43501. read: read,
  43502. write: write
  43503. };
  43504. var pbf = Pbf;
  43505. function Pbf(buf) {
  43506. this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
  43507. this.pos = 0;
  43508. this.type = 0;
  43509. this.length = this.buf.length;
  43510. }
  43511. Pbf.Varint = 0;
  43512. Pbf.Fixed64 = 1;
  43513. Pbf.Bytes = 2;
  43514. Pbf.Fixed32 = 5;
  43515. var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
  43516. var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
  43517. Pbf.prototype = {
  43518. destroy: function() {
  43519. this.buf = null;
  43520. },
  43521. readFields: function(readField, result, end) {
  43522. end = end || this.length;
  43523. while (this.pos < end) {
  43524. var val = this.readVarint(),
  43525. tag = val >> 3,
  43526. startPos = this.pos;
  43527. this.type = val & 0x7;
  43528. readField(tag, result, this);
  43529. if (this.pos === startPos) this.skip(val);
  43530. }
  43531. return result;
  43532. },
  43533. readMessage: function(readField, result) {
  43534. return this.readFields(readField, result, this.readVarint() + this.pos);
  43535. },
  43536. readFixed32: function() {
  43537. var val = readUInt32(this.buf, this.pos);
  43538. this.pos += 4;
  43539. return val;
  43540. },
  43541. readSFixed32: function() {
  43542. var val = readInt32(this.buf, this.pos);
  43543. this.pos += 4;
  43544. return val;
  43545. },
  43546. readFixed64: function() {
  43547. var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
  43548. this.pos += 8;
  43549. return val;
  43550. },
  43551. readSFixed64: function() {
  43552. var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
  43553. this.pos += 8;
  43554. return val;
  43555. },
  43556. readFloat: function() {
  43557. var val = ieee754.read(this.buf, this.pos, true, 23, 4);
  43558. this.pos += 4;
  43559. return val;
  43560. },
  43561. readDouble: function() {
  43562. var val = ieee754.read(this.buf, this.pos, true, 52, 8);
  43563. this.pos += 8;
  43564. return val;
  43565. },
  43566. readVarint: function(isSigned) {
  43567. var buf = this.buf,
  43568. val, b;
  43569. b = buf[this.pos++]; val = b & 0x7f; if (b < 0x80) return val;
  43570. b = buf[this.pos++]; val |= (b & 0x7f) << 7; if (b < 0x80) return val;
  43571. b = buf[this.pos++]; val |= (b & 0x7f) << 14; if (b < 0x80) return val;
  43572. b = buf[this.pos++]; val |= (b & 0x7f) << 21; if (b < 0x80) return val;
  43573. b = buf[this.pos]; val |= (b & 0x0f) << 28;
  43574. return readVarintRemainder(val, isSigned, this);
  43575. },
  43576. readVarint64: function() {
  43577. return this.readVarint(true);
  43578. },
  43579. readSVarint: function() {
  43580. var num = this.readVarint();
  43581. return num % 2 === 1 ? (num + 1) / -2 : num / 2;
  43582. },
  43583. readBoolean: function() {
  43584. return Boolean(this.readVarint());
  43585. },
  43586. readString: function() {
  43587. var end = this.readVarint() + this.pos,
  43588. str = readUtf8(this.buf, this.pos, end);
  43589. this.pos = end;
  43590. return str;
  43591. },
  43592. readBytes: function() {
  43593. var end = this.readVarint() + this.pos,
  43594. buffer = this.buf.subarray(this.pos, end);
  43595. this.pos = end;
  43596. return buffer;
  43597. },
  43598. readPackedVarint: function(arr, isSigned) {
  43599. var end = readPackedEnd(this);
  43600. arr = arr || [];
  43601. while (this.pos < end) arr.push(this.readVarint(isSigned));
  43602. return arr;
  43603. },
  43604. readPackedSVarint: function(arr) {
  43605. var end = readPackedEnd(this);
  43606. arr = arr || [];
  43607. while (this.pos < end) arr.push(this.readSVarint());
  43608. return arr;
  43609. },
  43610. readPackedBoolean: function(arr) {
  43611. var end = readPackedEnd(this);
  43612. arr = arr || [];
  43613. while (this.pos < end) arr.push(this.readBoolean());
  43614. return arr;
  43615. },
  43616. readPackedFloat: function(arr) {
  43617. var end = readPackedEnd(this);
  43618. arr = arr || [];
  43619. while (this.pos < end) arr.push(this.readFloat());
  43620. return arr;
  43621. },
  43622. readPackedDouble: function(arr) {
  43623. var end = readPackedEnd(this);
  43624. arr = arr || [];
  43625. while (this.pos < end) arr.push(this.readDouble());
  43626. return arr;
  43627. },
  43628. readPackedFixed32: function(arr) {
  43629. var end = readPackedEnd(this);
  43630. arr = arr || [];
  43631. while (this.pos < end) arr.push(this.readFixed32());
  43632. return arr;
  43633. },
  43634. readPackedSFixed32: function(arr) {
  43635. var end = readPackedEnd(this);
  43636. arr = arr || [];
  43637. while (this.pos < end) arr.push(this.readSFixed32());
  43638. return arr;
  43639. },
  43640. readPackedFixed64: function(arr) {
  43641. var end = readPackedEnd(this);
  43642. arr = arr || [];
  43643. while (this.pos < end) arr.push(this.readFixed64());
  43644. return arr;
  43645. },
  43646. readPackedSFixed64: function(arr) {
  43647. var end = readPackedEnd(this);
  43648. arr = arr || [];
  43649. while (this.pos < end) arr.push(this.readSFixed64());
  43650. return arr;
  43651. },
  43652. skip: function(val) {
  43653. var type = val & 0x7;
  43654. if (type === Pbf.Varint) while (this.buf[this.pos++] > 0x7f) {}
  43655. else if (type === Pbf.Bytes) this.pos = this.readVarint() + this.pos;
  43656. else if (type === Pbf.Fixed32) this.pos += 4;
  43657. else if (type === Pbf.Fixed64) this.pos += 8;
  43658. else throw new Error('Unimplemented type: ' + type);
  43659. },
  43660. writeTag: function(tag, type) {
  43661. this.writeVarint((tag << 3) | type);
  43662. },
  43663. realloc: function(min) {
  43664. var length = this.length || 16;
  43665. while (length < this.pos + min) length *= 2;
  43666. if (length !== this.length) {
  43667. var buf = new Uint8Array(length);
  43668. buf.set(this.buf);
  43669. this.buf = buf;
  43670. this.length = length;
  43671. }
  43672. },
  43673. finish: function() {
  43674. this.length = this.pos;
  43675. this.pos = 0;
  43676. return this.buf.subarray(0, this.length);
  43677. },
  43678. writeFixed32: function(val) {
  43679. this.realloc(4);
  43680. writeInt32(this.buf, val, this.pos);
  43681. this.pos += 4;
  43682. },
  43683. writeSFixed32: function(val) {
  43684. this.realloc(4);
  43685. writeInt32(this.buf, val, this.pos);
  43686. this.pos += 4;
  43687. },
  43688. writeFixed64: function(val) {
  43689. this.realloc(8);
  43690. writeInt32(this.buf, val & -1, this.pos);
  43691. writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
  43692. this.pos += 8;
  43693. },
  43694. writeSFixed64: function(val) {
  43695. this.realloc(8);
  43696. writeInt32(this.buf, val & -1, this.pos);
  43697. writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
  43698. this.pos += 8;
  43699. },
  43700. writeVarint: function(val) {
  43701. val = +val || 0;
  43702. if (val > 0xfffffff || val < 0) {
  43703. writeBigVarint(val, this);
  43704. return;
  43705. }
  43706. this.realloc(4);
  43707. this.buf[this.pos++] = val & 0x7f | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;
  43708. this.buf[this.pos++] = ((val >>>= 7) & 0x7f) | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;
  43709. this.buf[this.pos++] = ((val >>>= 7) & 0x7f) | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;
  43710. this.buf[this.pos++] = (val >>> 7) & 0x7f;
  43711. },
  43712. writeSVarint: function(val) {
  43713. this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
  43714. },
  43715. writeBoolean: function(val) {
  43716. this.writeVarint(Boolean(val));
  43717. },
  43718. writeString: function(str) {
  43719. str = String(str);
  43720. this.realloc(str.length * 4);
  43721. this.pos++;
  43722. var startPos = this.pos;
  43723. this.pos = writeUtf8(this.buf, str, this.pos);
  43724. var len = this.pos - startPos;
  43725. if (len >= 0x80) makeRoomForExtraLength(startPos, len, this);
  43726. this.pos = startPos - 1;
  43727. this.writeVarint(len);
  43728. this.pos += len;
  43729. },
  43730. writeFloat: function(val) {
  43731. this.realloc(4);
  43732. ieee754.write(this.buf, val, this.pos, true, 23, 4);
  43733. this.pos += 4;
  43734. },
  43735. writeDouble: function(val) {
  43736. this.realloc(8);
  43737. ieee754.write(this.buf, val, this.pos, true, 52, 8);
  43738. this.pos += 8;
  43739. },
  43740. writeBytes: function(buffer) {
  43741. var len = buffer.length;
  43742. this.writeVarint(len);
  43743. this.realloc(len);
  43744. for (var i = 0; i < len; i++) this.buf[this.pos++] = buffer[i];
  43745. },
  43746. writeRawMessage: function(fn, obj) {
  43747. this.pos++;
  43748. var startPos = this.pos;
  43749. fn(obj, this);
  43750. var len = this.pos - startPos;
  43751. if (len >= 0x80) makeRoomForExtraLength(startPos, len, this);
  43752. this.pos = startPos - 1;
  43753. this.writeVarint(len);
  43754. this.pos += len;
  43755. },
  43756. writeMessage: function(tag, fn, obj) {
  43757. this.writeTag(tag, Pbf.Bytes);
  43758. this.writeRawMessage(fn, obj);
  43759. },
  43760. writePackedVarint: function(tag, arr) { this.writeMessage(tag, writePackedVarint, arr); },
  43761. writePackedSVarint: function(tag, arr) { this.writeMessage(tag, writePackedSVarint, arr); },
  43762. writePackedBoolean: function(tag, arr) { this.writeMessage(tag, writePackedBoolean, arr); },
  43763. writePackedFloat: function(tag, arr) { this.writeMessage(tag, writePackedFloat, arr); },
  43764. writePackedDouble: function(tag, arr) { this.writeMessage(tag, writePackedDouble, arr); },
  43765. writePackedFixed32: function(tag, arr) { this.writeMessage(tag, writePackedFixed32, arr); },
  43766. writePackedSFixed32: function(tag, arr) { this.writeMessage(tag, writePackedSFixed32, arr); },
  43767. writePackedFixed64: function(tag, arr) { this.writeMessage(tag, writePackedFixed64, arr); },
  43768. writePackedSFixed64: function(tag, arr) { this.writeMessage(tag, writePackedSFixed64, arr); },
  43769. writeBytesField: function(tag, buffer) {
  43770. this.writeTag(tag, Pbf.Bytes);
  43771. this.writeBytes(buffer);
  43772. },
  43773. writeFixed32Field: function(tag, val) {
  43774. this.writeTag(tag, Pbf.Fixed32);
  43775. this.writeFixed32(val);
  43776. },
  43777. writeSFixed32Field: function(tag, val) {
  43778. this.writeTag(tag, Pbf.Fixed32);
  43779. this.writeSFixed32(val);
  43780. },
  43781. writeFixed64Field: function(tag, val) {
  43782. this.writeTag(tag, Pbf.Fixed64);
  43783. this.writeFixed64(val);
  43784. },
  43785. writeSFixed64Field: function(tag, val) {
  43786. this.writeTag(tag, Pbf.Fixed64);
  43787. this.writeSFixed64(val);
  43788. },
  43789. writeVarintField: function(tag, val) {
  43790. this.writeTag(tag, Pbf.Varint);
  43791. this.writeVarint(val);
  43792. },
  43793. writeSVarintField: function(tag, val) {
  43794. this.writeTag(tag, Pbf.Varint);
  43795. this.writeSVarint(val);
  43796. },
  43797. writeStringField: function(tag, str) {
  43798. this.writeTag(tag, Pbf.Bytes);
  43799. this.writeString(str);
  43800. },
  43801. writeFloatField: function(tag, val) {
  43802. this.writeTag(tag, Pbf.Fixed32);
  43803. this.writeFloat(val);
  43804. },
  43805. writeDoubleField: function(tag, val) {
  43806. this.writeTag(tag, Pbf.Fixed64);
  43807. this.writeDouble(val);
  43808. },
  43809. writeBooleanField: function(tag, val) {
  43810. this.writeVarintField(tag, Boolean(val));
  43811. }
  43812. };
  43813. function readVarintRemainder(l, s, p) {
  43814. var buf = p.buf,
  43815. h, b;
  43816. b = buf[p.pos++]; h = (b & 0x70) >> 4; if (b < 0x80) return toNum(l, h, s);
  43817. b = buf[p.pos++]; h |= (b & 0x7f) << 3; if (b < 0x80) return toNum(l, h, s);
  43818. b = buf[p.pos++]; h |= (b & 0x7f) << 10; if (b < 0x80) return toNum(l, h, s);
  43819. b = buf[p.pos++]; h |= (b & 0x7f) << 17; if (b < 0x80) return toNum(l, h, s);
  43820. b = buf[p.pos++]; h |= (b & 0x7f) << 24; if (b < 0x80) return toNum(l, h, s);
  43821. b = buf[p.pos++]; h |= (b & 0x01) << 31; if (b < 0x80) return toNum(l, h, s);
  43822. throw new Error('Expected varint not more than 10 bytes');
  43823. }
  43824. function readPackedEnd(pbf) {
  43825. return pbf.type === Pbf.Bytes ?
  43826. pbf.readVarint() + pbf.pos : pbf.pos + 1;
  43827. }
  43828. function toNum(low, high, isSigned) {
  43829. if (isSigned) {
  43830. return high * 0x100000000 + (low >>> 0);
  43831. }
  43832. return ((high >>> 0) * 0x100000000) + (low >>> 0);
  43833. }
  43834. function writeBigVarint(val, pbf) {
  43835. var low, high;
  43836. if (val >= 0) {
  43837. low = (val % 0x100000000) | 0;
  43838. high = (val / 0x100000000) | 0;
  43839. } else {
  43840. low = ~(-val % 0x100000000);
  43841. high = ~(-val / 0x100000000);
  43842. if (low ^ 0xffffffff) {
  43843. low = (low + 1) | 0;
  43844. } else {
  43845. low = 0;
  43846. high = (high + 1) | 0;
  43847. }
  43848. }
  43849. if (val >= 0x10000000000000000 || val < -0x10000000000000000) {
  43850. throw new Error('Given varint doesn\'t fit into 10 bytes');
  43851. }
  43852. pbf.realloc(10);
  43853. writeBigVarintLow(low, high, pbf);
  43854. writeBigVarintHigh(high, pbf);
  43855. }
  43856. function writeBigVarintLow(low, high, pbf) {
  43857. pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
  43858. pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
  43859. pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
  43860. pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
  43861. pbf.buf[pbf.pos] = low & 0x7f;
  43862. }
  43863. function writeBigVarintHigh(high, pbf) {
  43864. var lsb = (high & 0x07) << 4;
  43865. pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 0x80 : 0); if (!high) return;
  43866. pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
  43867. pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
  43868. pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
  43869. pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
  43870. pbf.buf[pbf.pos++] = high & 0x7f;
  43871. }
  43872. function makeRoomForExtraLength(startPos, len, pbf) {
  43873. var extraLen =
  43874. len <= 0x3fff ? 1 :
  43875. len <= 0x1fffff ? 2 :
  43876. len <= 0xfffffff ? 3 : Math.ceil(Math.log(len) / (Math.LN2 * 7));
  43877. pbf.realloc(extraLen);
  43878. for (var i = pbf.pos - 1; i >= startPos; i--) pbf.buf[i + extraLen] = pbf.buf[i];
  43879. }
  43880. function writePackedVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeVarint(arr[i]); }
  43881. function writePackedSVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSVarint(arr[i]); }
  43882. function writePackedFloat(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFloat(arr[i]); }
  43883. function writePackedDouble(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeDouble(arr[i]); }
  43884. function writePackedBoolean(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeBoolean(arr[i]); }
  43885. function writePackedFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed32(arr[i]); }
  43886. function writePackedSFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed32(arr[i]); }
  43887. function writePackedFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed64(arr[i]); }
  43888. function writePackedSFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed64(arr[i]); }
  43889. function readUInt32(buf, pos) {
  43890. return ((buf[pos]) |
  43891. (buf[pos + 1] << 8) |
  43892. (buf[pos + 2] << 16)) +
  43893. (buf[pos + 3] * 0x1000000);
  43894. }
  43895. function writeInt32(buf, val, pos) {
  43896. buf[pos] = val;
  43897. buf[pos + 1] = (val >>> 8);
  43898. buf[pos + 2] = (val >>> 16);
  43899. buf[pos + 3] = (val >>> 24);
  43900. }
  43901. function readInt32(buf, pos) {
  43902. return ((buf[pos]) |
  43903. (buf[pos + 1] << 8) |
  43904. (buf[pos + 2] << 16)) +
  43905. (buf[pos + 3] << 24);
  43906. }
  43907. function readUtf8(buf, pos, end) {
  43908. var str = '';
  43909. var i = pos;
  43910. while (i < end) {
  43911. var b0 = buf[i];
  43912. var c = null;
  43913. var bytesPerSequence =
  43914. b0 > 0xEF ? 4 :
  43915. b0 > 0xDF ? 3 :
  43916. b0 > 0xBF ? 2 : 1;
  43917. if (i + bytesPerSequence > end) break;
  43918. var b1, b2, b3;
  43919. if (bytesPerSequence === 1) {
  43920. if (b0 < 0x80) {
  43921. c = b0;
  43922. }
  43923. } else if (bytesPerSequence === 2) {
  43924. b1 = buf[i + 1];
  43925. if ((b1 & 0xC0) === 0x80) {
  43926. c = (b0 & 0x1F) << 0x6 | (b1 & 0x3F);
  43927. if (c <= 0x7F) {
  43928. c = null;
  43929. }
  43930. }
  43931. } else if (bytesPerSequence === 3) {
  43932. b1 = buf[i + 1];
  43933. b2 = buf[i + 2];
  43934. if ((b1 & 0xC0) === 0x80 && (b2 & 0xC0) === 0x80) {
  43935. c = (b0 & 0xF) << 0xC | (b1 & 0x3F) << 0x6 | (b2 & 0x3F);
  43936. if (c <= 0x7FF || (c >= 0xD800 && c <= 0xDFFF)) {
  43937. c = null;
  43938. }
  43939. }
  43940. } else if (bytesPerSequence === 4) {
  43941. b1 = buf[i + 1];
  43942. b2 = buf[i + 2];
  43943. b3 = buf[i + 3];
  43944. if ((b1 & 0xC0) === 0x80 && (b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80) {
  43945. c = (b0 & 0xF) << 0x12 | (b1 & 0x3F) << 0xC | (b2 & 0x3F) << 0x6 | (b3 & 0x3F);
  43946. if (c <= 0xFFFF || c >= 0x110000) {
  43947. c = null;
  43948. }
  43949. }
  43950. }
  43951. if (c === null) {
  43952. c = 0xFFFD;
  43953. bytesPerSequence = 1;
  43954. } else if (c > 0xFFFF) {
  43955. c -= 0x10000;
  43956. str += String.fromCharCode(c >>> 10 & 0x3FF | 0xD800);
  43957. c = 0xDC00 | c & 0x3FF;
  43958. }
  43959. str += String.fromCharCode(c);
  43960. i += bytesPerSequence;
  43961. }
  43962. return str;
  43963. }
  43964. function writeUtf8(buf, str, pos) {
  43965. for (var i = 0, c, lead; i < str.length; i++) {
  43966. c = str.charCodeAt(i);
  43967. if (c > 0xD7FF && c < 0xE000) {
  43968. if (lead) {
  43969. if (c < 0xDC00) {
  43970. buf[pos++] = 0xEF;
  43971. buf[pos++] = 0xBF;
  43972. buf[pos++] = 0xBD;
  43973. lead = c;
  43974. continue;
  43975. } else {
  43976. c = lead - 0xD800 << 10 | c - 0xDC00 | 0x10000;
  43977. lead = null;
  43978. }
  43979. } else {
  43980. if (c > 0xDBFF || (i + 1 === str.length)) {
  43981. buf[pos++] = 0xEF;
  43982. buf[pos++] = 0xBF;
  43983. buf[pos++] = 0xBD;
  43984. } else {
  43985. lead = c;
  43986. }
  43987. continue;
  43988. }
  43989. } else if (lead) {
  43990. buf[pos++] = 0xEF;
  43991. buf[pos++] = 0xBF;
  43992. buf[pos++] = 0xBD;
  43993. lead = null;
  43994. }
  43995. if (c < 0x80) {
  43996. buf[pos++] = c;
  43997. } else {
  43998. if (c < 0x800) {
  43999. buf[pos++] = c >> 0x6 | 0xC0;
  44000. } else {
  44001. if (c < 0x10000) {
  44002. buf[pos++] = c >> 0xC | 0xE0;
  44003. } else {
  44004. buf[pos++] = c >> 0x12 | 0xF0;
  44005. buf[pos++] = c >> 0xC & 0x3F | 0x80;
  44006. }
  44007. buf[pos++] = c >> 0x6 & 0x3F | 0x80;
  44008. }
  44009. buf[pos++] = c & 0x3F | 0x80;
  44010. }
  44011. }
  44012. return pos;
  44013. }
  44014. exports['default'] = pbf;
  44015. }((this.PBF = this.PBF || {})));}).call(ol.ext);
  44016. ol.ext.PBF = ol.ext.PBF.default;
  44017. goog.provide('ol.render.Feature');
  44018. goog.require('ol');
  44019. goog.require('ol.array');
  44020. goog.require('ol.extent');
  44021. goog.require('ol.geom.GeometryType');
  44022. goog.require('ol.geom.flat.center');
  44023. goog.require('ol.geom.flat.interiorpoint');
  44024. goog.require('ol.geom.flat.interpolate');
  44025. goog.require('ol.geom.flat.transform');
  44026. goog.require('ol.transform');
  44027. /**
  44028. * Lightweight, read-only, {@link ol.Feature} and {@link ol.geom.Geometry} like
  44029. * structure, optimized for vector tile rendering and styling. Geometry access
  44030. * through the API is limited to getting the type and extent of the geometry.
  44031. *
  44032. * @constructor
  44033. * @param {ol.geom.GeometryType} type Geometry type.
  44034. * @param {Array.<number>} flatCoordinates Flat coordinates. These always need
  44035. * to be right-handed for polygons.
  44036. * @param {Array.<number>|Array.<Array.<number>>} ends Ends or Endss.
  44037. * @param {Object.<string, *>} properties Properties.
  44038. * @param {number|string|undefined} id Feature id.
  44039. */
  44040. ol.render.Feature = function(type, flatCoordinates, ends, properties, id) {
  44041. /**
  44042. * @private
  44043. * @type {ol.Extent|undefined}
  44044. */
  44045. this.extent_;
  44046. /**
  44047. * @private
  44048. * @type {number|string|undefined}
  44049. */
  44050. this.id_ = id;
  44051. /**
  44052. * @private
  44053. * @type {ol.geom.GeometryType}
  44054. */
  44055. this.type_ = type;
  44056. /**
  44057. * @private
  44058. * @type {Array.<number>}
  44059. */
  44060. this.flatCoordinates_ = flatCoordinates;
  44061. /**
  44062. * @private
  44063. * @type {Array.<number>}
  44064. */
  44065. this.flatInteriorPoints_ = null;
  44066. /**
  44067. * @private
  44068. * @type {Array.<number>}
  44069. */
  44070. this.flatMidpoints_ = null;
  44071. /**
  44072. * @private
  44073. * @type {Array.<number>|Array.<Array.<number>>}
  44074. */
  44075. this.ends_ = ends;
  44076. /**
  44077. * @private
  44078. * @type {Object.<string, *>}
  44079. */
  44080. this.properties_ = properties;
  44081. /**
  44082. * @private
  44083. * @type {ol.Transform}
  44084. */
  44085. this.tmpTransform_ = ol.transform.create();
  44086. };
  44087. /**
  44088. * Get a feature property by its key.
  44089. * @param {string} key Key
  44090. * @return {*} Value for the requested key.
  44091. * @api
  44092. */
  44093. ol.render.Feature.prototype.get = function(key) {
  44094. return this.properties_[key];
  44095. };
  44096. /**
  44097. * @return {Array.<number>|Array.<Array.<number>>} Ends or endss.
  44098. */
  44099. ol.render.Feature.prototype.getEnds =
  44100. ol.render.Feature.prototype.getEndss = function() {
  44101. return this.ends_;
  44102. };
  44103. /**
  44104. * Get the extent of this feature's geometry.
  44105. * @return {ol.Extent} Extent.
  44106. * @api
  44107. */
  44108. ol.render.Feature.prototype.getExtent = function() {
  44109. if (!this.extent_) {
  44110. this.extent_ = this.type_ === ol.geom.GeometryType.POINT ?
  44111. ol.extent.createOrUpdateFromCoordinate(this.flatCoordinates_) :
  44112. ol.extent.createOrUpdateFromFlatCoordinates(
  44113. this.flatCoordinates_, 0, this.flatCoordinates_.length, 2);
  44114. }
  44115. return this.extent_;
  44116. };
  44117. /**
  44118. * @return {Array.<number>} Flat interior points.
  44119. */
  44120. ol.render.Feature.prototype.getFlatInteriorPoint = function() {
  44121. if (!this.flatInteriorPoints_) {
  44122. var flatCenter = ol.extent.getCenter(this.getExtent());
  44123. this.flatInteriorPoints_ = ol.geom.flat.interiorpoint.linearRings(
  44124. this.flatCoordinates_, 0, this.ends_, 2, flatCenter, 0);
  44125. }
  44126. return this.flatInteriorPoints_;
  44127. };
  44128. /**
  44129. * @return {Array.<number>} Flat interior points.
  44130. */
  44131. ol.render.Feature.prototype.getFlatInteriorPoints = function() {
  44132. if (!this.flatInteriorPoints_) {
  44133. var flatCenters = ol.geom.flat.center.linearRingss(
  44134. this.flatCoordinates_, 0, this.ends_, 2);
  44135. this.flatInteriorPoints_ = ol.geom.flat.interiorpoint.linearRingss(
  44136. this.flatCoordinates_, 0, this.ends_, 2, flatCenters);
  44137. }
  44138. return this.flatInteriorPoints_;
  44139. };
  44140. /**
  44141. * @return {Array.<number>} Flat midpoint.
  44142. */
  44143. ol.render.Feature.prototype.getFlatMidpoint = function() {
  44144. if (!this.flatMidpoints_) {
  44145. this.flatMidpoints_ = ol.geom.flat.interpolate.lineString(
  44146. this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5);
  44147. }
  44148. return this.flatMidpoints_;
  44149. };
  44150. /**
  44151. * @return {Array.<number>} Flat midpoints.
  44152. */
  44153. ol.render.Feature.prototype.getFlatMidpoints = function() {
  44154. if (!this.flatMidpoints_) {
  44155. this.flatMidpoints_ = [];
  44156. var flatCoordinates = this.flatCoordinates_;
  44157. var offset = 0;
  44158. var ends = this.ends_;
  44159. for (var i = 0, ii = ends.length; i < ii; ++i) {
  44160. var end = ends[i];
  44161. var midpoint = ol.geom.flat.interpolate.lineString(
  44162. flatCoordinates, offset, end, 2, 0.5);
  44163. ol.array.extend(this.flatMidpoints_, midpoint);
  44164. offset = end;
  44165. }
  44166. }
  44167. return this.flatMidpoints_;
  44168. };
  44169. /**
  44170. * Get the feature identifier. This is a stable identifier for the feature and
  44171. * is set when reading data from a remote source.
  44172. * @return {number|string|undefined} Id.
  44173. * @api
  44174. */
  44175. ol.render.Feature.prototype.getId = function() {
  44176. return this.id_;
  44177. };
  44178. /**
  44179. * @return {Array.<number>} Flat coordinates.
  44180. */
  44181. ol.render.Feature.prototype.getOrientedFlatCoordinates = function() {
  44182. return this.flatCoordinates_;
  44183. };
  44184. /**
  44185. * @return {Array.<number>} Flat coordinates.
  44186. */
  44187. ol.render.Feature.prototype.getFlatCoordinates =
  44188. ol.render.Feature.prototype.getOrientedFlatCoordinates;
  44189. /**
  44190. * For API compatibility with {@link ol.Feature}, this method is useful when
  44191. * determining the geometry type in style function (see {@link #getType}).
  44192. * @return {ol.render.Feature} Feature.
  44193. * @api
  44194. */
  44195. ol.render.Feature.prototype.getGeometry = function() {
  44196. return this;
  44197. };
  44198. /**
  44199. * Get the feature properties.
  44200. * @return {Object.<string, *>} Feature properties.
  44201. * @api
  44202. */
  44203. ol.render.Feature.prototype.getProperties = function() {
  44204. return this.properties_;
  44205. };
  44206. /**
  44207. * Get the feature for working with its geometry.
  44208. * @return {ol.render.Feature} Feature.
  44209. */
  44210. ol.render.Feature.prototype.getSimplifiedGeometry =
  44211. ol.render.Feature.prototype.getGeometry;
  44212. /**
  44213. * @return {number} Stride.
  44214. */
  44215. ol.render.Feature.prototype.getStride = function() {
  44216. return 2;
  44217. };
  44218. /**
  44219. * @return {undefined}
  44220. */
  44221. ol.render.Feature.prototype.getStyleFunction = ol.nullFunction;
  44222. /**
  44223. * Get the type of this feature's geometry.
  44224. * @return {ol.geom.GeometryType} Geometry type.
  44225. * @api
  44226. */
  44227. ol.render.Feature.prototype.getType = function() {
  44228. return this.type_;
  44229. };
  44230. /**
  44231. * Transform geometry coordinates from tile pixel space to projected.
  44232. * The SRS of the source and destination are expected to be the same.
  44233. *
  44234. * @param {ol.ProjectionLike} source The current projection
  44235. * @param {ol.ProjectionLike} destination The desired projection.
  44236. */
  44237. ol.render.Feature.prototype.transform = function(source, destination) {
  44238. var pixelExtent = source.getExtent();
  44239. var projectedExtent = source.getWorldExtent();
  44240. var scale = ol.extent.getHeight(projectedExtent) / ol.extent.getHeight(pixelExtent);
  44241. var transform = this.tmpTransform_;
  44242. ol.transform.compose(transform,
  44243. projectedExtent[0], projectedExtent[3],
  44244. scale, -scale, 0,
  44245. 0, 0);
  44246. ol.geom.flat.transform.transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2,
  44247. transform, this.flatCoordinates_);
  44248. };
  44249. //FIXME Implement projection handling
  44250. goog.provide('ol.format.MVT');
  44251. goog.require('ol');
  44252. goog.require('ol.asserts');
  44253. goog.require('ol.ext.PBF');
  44254. goog.require('ol.format.Feature');
  44255. goog.require('ol.format.FormatType');
  44256. goog.require('ol.geom.GeometryLayout');
  44257. goog.require('ol.geom.GeometryType');
  44258. goog.require('ol.geom.LineString');
  44259. goog.require('ol.geom.MultiLineString');
  44260. goog.require('ol.geom.MultiPoint');
  44261. goog.require('ol.geom.MultiPolygon');
  44262. goog.require('ol.geom.Point');
  44263. goog.require('ol.geom.Polygon');
  44264. goog.require('ol.geom.flat.orient');
  44265. goog.require('ol.proj.Projection');
  44266. goog.require('ol.proj.Units');
  44267. goog.require('ol.render.Feature');
  44268. /**
  44269. * @classdesc
  44270. * Feature format for reading data in the Mapbox MVT format.
  44271. *
  44272. * @constructor
  44273. * @extends {ol.format.Feature}
  44274. * @param {olx.format.MVTOptions=} opt_options Options.
  44275. * @api
  44276. */
  44277. ol.format.MVT = function(opt_options) {
  44278. ol.format.Feature.call(this);
  44279. var options = opt_options ? opt_options : {};
  44280. /**
  44281. * @type {ol.proj.Projection}
  44282. */
  44283. this.defaultDataProjection = new ol.proj.Projection({
  44284. code: 'EPSG:3857',
  44285. units: ol.proj.Units.TILE_PIXELS
  44286. });
  44287. /**
  44288. * @private
  44289. * @type {function((ol.geom.Geometry|Object.<string,*>)=)|
  44290. * function(ol.geom.GeometryType,Array.<number>,
  44291. * (Array.<number>|Array.<Array.<number>>),Object.<string,*>,number)}
  44292. */
  44293. this.featureClass_ = options.featureClass ?
  44294. options.featureClass : ol.render.Feature;
  44295. /**
  44296. * @private
  44297. * @type {string|undefined}
  44298. */
  44299. this.geometryName_ = options.geometryName;
  44300. /**
  44301. * @private
  44302. * @type {string}
  44303. */
  44304. this.layerName_ = options.layerName ? options.layerName : 'layer';
  44305. /**
  44306. * @private
  44307. * @type {Array.<string>}
  44308. */
  44309. this.layers_ = options.layers ? options.layers : null;
  44310. /**
  44311. * @private
  44312. * @type {ol.Extent}
  44313. */
  44314. this.extent_ = null;
  44315. };
  44316. ol.inherits(ol.format.MVT, ol.format.Feature);
  44317. /**
  44318. * Reader callbacks for parsing the PBF.
  44319. * @type {Object.<string, function(number, Object, ol.ext.PBF)>}
  44320. */
  44321. ol.format.MVT.pbfReaders_ = {
  44322. layers: function(tag, layers, pbf) {
  44323. if (tag === 3) {
  44324. var layer = {
  44325. keys: [],
  44326. values: [],
  44327. features: []
  44328. };
  44329. var end = pbf.readVarint() + pbf.pos;
  44330. pbf.readFields(ol.format.MVT.pbfReaders_.layer, layer, end);
  44331. layer.length = layer.features.length;
  44332. if (layer.length) {
  44333. layers[layer.name] = layer;
  44334. }
  44335. }
  44336. },
  44337. layer: function(tag, layer, pbf) {
  44338. if (tag === 15) {
  44339. layer.version = pbf.readVarint();
  44340. } else if (tag === 1) {
  44341. layer.name = pbf.readString();
  44342. } else if (tag === 5) {
  44343. layer.extent = pbf.readVarint();
  44344. } else if (tag === 2) {
  44345. layer.features.push(pbf.pos);
  44346. } else if (tag === 3) {
  44347. layer.keys.push(pbf.readString());
  44348. } else if (tag === 4) {
  44349. var value = null;
  44350. var end = pbf.readVarint() + pbf.pos;
  44351. while (pbf.pos < end) {
  44352. tag = pbf.readVarint() >> 3;
  44353. value = tag === 1 ? pbf.readString() :
  44354. tag === 2 ? pbf.readFloat() :
  44355. tag === 3 ? pbf.readDouble() :
  44356. tag === 4 ? pbf.readVarint64() :
  44357. tag === 5 ? pbf.readVarint() :
  44358. tag === 6 ? pbf.readSVarint() :
  44359. tag === 7 ? pbf.readBoolean() : null;
  44360. }
  44361. layer.values.push(value);
  44362. }
  44363. },
  44364. feature: function(tag, feature, pbf) {
  44365. if (tag == 1) {
  44366. feature.id = pbf.readVarint();
  44367. } else if (tag == 2) {
  44368. var end = pbf.readVarint() + pbf.pos;
  44369. while (pbf.pos < end) {
  44370. var key = feature.layer.keys[pbf.readVarint()];
  44371. var value = feature.layer.values[pbf.readVarint()];
  44372. feature.properties[key] = value;
  44373. }
  44374. } else if (tag == 3) {
  44375. feature.type = pbf.readVarint();
  44376. } else if (tag == 4) {
  44377. feature.geometry = pbf.pos;
  44378. }
  44379. }
  44380. };
  44381. /**
  44382. * Read a raw feature from the pbf offset stored at index `i` in the raw layer.
  44383. * @suppress {missingProperties}
  44384. * @private
  44385. * @param {ol.ext.PBF} pbf PBF.
  44386. * @param {Object} layer Raw layer.
  44387. * @param {number} i Index of the feature in the raw layer's `features` array.
  44388. * @return {Object} Raw feature.
  44389. */
  44390. ol.format.MVT.readRawFeature_ = function(pbf, layer, i) {
  44391. pbf.pos = layer.features[i];
  44392. var end = pbf.readVarint() + pbf.pos;
  44393. var feature = {
  44394. layer: layer,
  44395. type: 0,
  44396. properties: {}
  44397. };
  44398. pbf.readFields(ol.format.MVT.pbfReaders_.feature, feature, end);
  44399. return feature;
  44400. };
  44401. /**
  44402. * Read the raw geometry from the pbf offset stored in a raw feature's geometry
  44403. * proeprty.
  44404. * @suppress {missingProperties}
  44405. * @private
  44406. * @param {ol.ext.PBF} pbf PBF.
  44407. * @param {Object} feature Raw feature.
  44408. * @param {Array.<number>} flatCoordinates Array to store flat coordinates in.
  44409. * @param {Array.<number>} ends Array to store ends in.
  44410. */
  44411. ol.format.MVT.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) {
  44412. pbf.pos = feature.geometry;
  44413. var end = pbf.readVarint() + pbf.pos;
  44414. var cmd = 1;
  44415. var length = 0;
  44416. var x = 0;
  44417. var y = 0;
  44418. var coordsLen = 0;
  44419. var currentEnd = 0;
  44420. while (pbf.pos < end) {
  44421. if (!length) {
  44422. var cmdLen = pbf.readVarint();
  44423. cmd = cmdLen & 0x7;
  44424. length = cmdLen >> 3;
  44425. }
  44426. length--;
  44427. if (cmd === 1 || cmd === 2) {
  44428. x += pbf.readSVarint();
  44429. y += pbf.readSVarint();
  44430. if (cmd === 1) { // moveTo
  44431. if (coordsLen > currentEnd) {
  44432. ends.push(coordsLen);
  44433. currentEnd = coordsLen;
  44434. }
  44435. }
  44436. flatCoordinates.push(x, y);
  44437. coordsLen += 2;
  44438. } else if (cmd === 7) {
  44439. if (coordsLen > currentEnd) {
  44440. // close polygon
  44441. flatCoordinates.push(
  44442. flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
  44443. coordsLen += 2;
  44444. }
  44445. } else {
  44446. ol.asserts.assert(false, 59); // Invalid command found in the PBF
  44447. }
  44448. }
  44449. if (coordsLen > currentEnd) {
  44450. ends.push(coordsLen);
  44451. currentEnd = coordsLen;
  44452. }
  44453. };
  44454. /**
  44455. * @suppress {missingProperties}
  44456. * @private
  44457. * @param {number} type The raw feature's geometry type
  44458. * @param {number} numEnds Number of ends of the flat coordinates of the
  44459. * geometry.
  44460. * @return {ol.geom.GeometryType} The geometry type.
  44461. */
  44462. ol.format.MVT.getGeometryType_ = function(type, numEnds) {
  44463. /** @type {ol.geom.GeometryType} */
  44464. var geometryType;
  44465. if (type === 1) {
  44466. geometryType = numEnds === 1 ?
  44467. ol.geom.GeometryType.POINT : ol.geom.GeometryType.MULTI_POINT;
  44468. } else if (type === 2) {
  44469. geometryType = numEnds === 1 ?
  44470. ol.geom.GeometryType.LINE_STRING :
  44471. ol.geom.GeometryType.MULTI_LINE_STRING;
  44472. } else if (type === 3) {
  44473. geometryType = ol.geom.GeometryType.POLYGON;
  44474. // MultiPolygon not relevant for rendering - winding order determines
  44475. // outer rings of polygons.
  44476. }
  44477. return geometryType;
  44478. };
  44479. /**
  44480. * @private
  44481. * @param {ol.ext.PBF} pbf PBF
  44482. * @param {Object} rawFeature Raw Mapbox feature.
  44483. * @param {olx.format.ReadOptions=} opt_options Read options.
  44484. * @return {ol.Feature|ol.render.Feature} Feature.
  44485. */
  44486. ol.format.MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
  44487. var type = rawFeature.type;
  44488. if (type === 0) {
  44489. return null;
  44490. }
  44491. var feature;
  44492. var id = rawFeature.id;
  44493. var values = rawFeature.properties;
  44494. values[this.layerName_] = rawFeature.layer.name;
  44495. var flatCoordinates = [];
  44496. var ends = [];
  44497. ol.format.MVT.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends);
  44498. var geometryType = ol.format.MVT.getGeometryType_(type, ends.length);
  44499. if (this.featureClass_ === ol.render.Feature) {
  44500. feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
  44501. } else {
  44502. var geom;
  44503. if (geometryType == ol.geom.GeometryType.POLYGON) {
  44504. var endss = [];
  44505. var offset = 0;
  44506. var prevEndIndex = 0;
  44507. for (var i = 0, ii = ends.length; i < ii; ++i) {
  44508. var end = ends[i];
  44509. if (!ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates, offset, end, 2)) {
  44510. endss.push(ends.slice(prevEndIndex, i));
  44511. prevEndIndex = i;
  44512. }
  44513. offset = end;
  44514. }
  44515. if (endss.length > 1) {
  44516. ends = endss;
  44517. geom = new ol.geom.MultiPolygon(null);
  44518. } else {
  44519. geom = new ol.geom.Polygon(null);
  44520. }
  44521. } else {
  44522. geom = geometryType === ol.geom.GeometryType.POINT ? new ol.geom.Point(null) :
  44523. geometryType === ol.geom.GeometryType.LINE_STRING ? new ol.geom.LineString(null) :
  44524. geometryType === ol.geom.GeometryType.POLYGON ? new ol.geom.Polygon(null) :
  44525. geometryType === ol.geom.GeometryType.MULTI_POINT ? new ol.geom.MultiPoint (null) :
  44526. geometryType === ol.geom.GeometryType.MULTI_LINE_STRING ? new ol.geom.MultiLineString(null) :
  44527. null;
  44528. }
  44529. geom.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates, ends);
  44530. feature = new this.featureClass_();
  44531. if (this.geometryName_) {
  44532. feature.setGeometryName(this.geometryName_);
  44533. }
  44534. var geometry = ol.format.Feature.transformWithOptions(geom, false, this.adaptOptions(opt_options));
  44535. feature.setGeometry(geometry);
  44536. feature.setId(id);
  44537. feature.setProperties(values);
  44538. }
  44539. return feature;
  44540. };
  44541. /**
  44542. * @inheritDoc
  44543. * @api
  44544. */
  44545. ol.format.MVT.prototype.getLastExtent = function() {
  44546. return this.extent_;
  44547. };
  44548. /**
  44549. * @inheritDoc
  44550. */
  44551. ol.format.MVT.prototype.getType = function() {
  44552. return ol.format.FormatType.ARRAY_BUFFER;
  44553. };
  44554. /**
  44555. * @inheritDoc
  44556. * @api
  44557. */
  44558. ol.format.MVT.prototype.readFeatures = function(source, opt_options) {
  44559. var layers = this.layers_;
  44560. var pbf = new ol.ext.PBF(/** @type {ArrayBuffer} */ (source));
  44561. var pbfLayers = pbf.readFields(ol.format.MVT.pbfReaders_.layers, {});
  44562. /** @type {Array.<ol.Feature|ol.render.Feature>} */
  44563. var features = [];
  44564. var pbfLayer;
  44565. for (var name in pbfLayers) {
  44566. if (layers && layers.indexOf(name) == -1) {
  44567. continue;
  44568. }
  44569. if(opt_options !== undefined){
  44570. var needSourceLayerNames = opt_options.needSourceLayerNames;
  44571. if(needSourceLayerNames !== undefined && needSourceLayerNames[name] === undefined){
  44572. continue;
  44573. }
  44574. }
  44575. pbfLayer = pbfLayers[name];
  44576. var rawFeature;
  44577. for (var i = 0, ii = pbfLayer.length; i < ii; ++i) {
  44578. rawFeature = ol.format.MVT.readRawFeature_(pbf, pbfLayer, i);
  44579. features.push(this.createFeature_(pbf, rawFeature));
  44580. }
  44581. this.extent_ = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null;
  44582. }
  44583. return features;
  44584. };
  44585. /**
  44586. * @inheritDoc
  44587. * @api
  44588. */
  44589. ol.format.MVT.prototype.readProjection = function(source) {
  44590. return this.defaultDataProjection;
  44591. };
  44592. /**
  44593. * Sets the layers that features will be read from.
  44594. * @param {Array.<string>} layers Layers.
  44595. * @api
  44596. */
  44597. ol.format.MVT.prototype.setLayers = function(layers) {
  44598. this.layers_ = layers;
  44599. };
  44600. /**
  44601. * Not implemented.
  44602. * @override
  44603. */
  44604. ol.format.MVT.prototype.readFeature = function() {};
  44605. /**
  44606. * Not implemented.
  44607. * @override
  44608. */
  44609. ol.format.MVT.prototype.readGeometry = function() {};
  44610. /**
  44611. * Not implemented.
  44612. * @override
  44613. */
  44614. ol.format.MVT.prototype.writeFeature = function() {};
  44615. /**
  44616. * Not implemented.
  44617. * @override
  44618. */
  44619. ol.format.MVT.prototype.writeGeometry = function() {};
  44620. /**
  44621. * Not implemented.
  44622. * @override
  44623. */
  44624. ol.format.MVT.prototype.writeFeatures = function() {};
  44625. // FIXME add typedef for stack state objects
  44626. goog.provide('ol.format.OSMXML');
  44627. goog.require('ol');
  44628. goog.require('ol.array');
  44629. goog.require('ol.Feature');
  44630. goog.require('ol.format.Feature');
  44631. goog.require('ol.format.XMLFeature');
  44632. goog.require('ol.geom.GeometryLayout');
  44633. goog.require('ol.geom.LineString');
  44634. goog.require('ol.geom.Point');
  44635. goog.require('ol.geom.Polygon');
  44636. goog.require('ol.obj');
  44637. goog.require('ol.proj');
  44638. goog.require('ol.xml');
  44639. /**
  44640. * @classdesc
  44641. * Feature format for reading data in the
  44642. * [OSMXML format](http://wiki.openstreetmap.org/wiki/OSM_XML).
  44643. *
  44644. * @constructor
  44645. * @extends {ol.format.XMLFeature}
  44646. * @api
  44647. */
  44648. ol.format.OSMXML = function() {
  44649. ol.format.XMLFeature.call(this);
  44650. /**
  44651. * @inheritDoc
  44652. */
  44653. this.defaultDataProjection = ol.proj.get('EPSG:4326');
  44654. };
  44655. ol.inherits(ol.format.OSMXML, ol.format.XMLFeature);
  44656. /**
  44657. * @param {Node} node Node.
  44658. * @param {Array.<*>} objectStack Object stack.
  44659. * @private
  44660. */
  44661. ol.format.OSMXML.readNode_ = function(node, objectStack) {
  44662. var options = /** @type {olx.format.ReadOptions} */ (objectStack[0]);
  44663. var state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  44664. var id = node.getAttribute('id');
  44665. /** @type {ol.Coordinate} */
  44666. var coordinates = [
  44667. parseFloat(node.getAttribute('lon')),
  44668. parseFloat(node.getAttribute('lat'))
  44669. ];
  44670. state.nodes[id] = coordinates;
  44671. var values = ol.xml.pushParseAndPop({
  44672. tags: {}
  44673. }, ol.format.OSMXML.NODE_PARSERS_, node, objectStack);
  44674. if (!ol.obj.isEmpty(values.tags)) {
  44675. var geometry = new ol.geom.Point(coordinates);
  44676. ol.format.Feature.transformWithOptions(geometry, false, options);
  44677. var feature = new ol.Feature(geometry);
  44678. feature.setId(id);
  44679. feature.setProperties(values.tags);
  44680. state.features.push(feature);
  44681. }
  44682. };
  44683. /**
  44684. * @param {Node} node Node.
  44685. * @param {Array.<*>} objectStack Object stack.
  44686. * @private
  44687. */
  44688. ol.format.OSMXML.readWay_ = function(node, objectStack) {
  44689. var id = node.getAttribute('id');
  44690. var values = ol.xml.pushParseAndPop({
  44691. id: id,
  44692. ndrefs: [],
  44693. tags: {}
  44694. }, ol.format.OSMXML.WAY_PARSERS_, node, objectStack);
  44695. var state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  44696. state.ways.push(values);
  44697. };
  44698. /**
  44699. * @param {Node} node Node.
  44700. * @param {Array.<*>} objectStack Object stack.
  44701. * @private
  44702. */
  44703. ol.format.OSMXML.readNd_ = function(node, objectStack) {
  44704. var values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  44705. values.ndrefs.push(node.getAttribute('ref'));
  44706. };
  44707. /**
  44708. * @param {Node} node Node.
  44709. * @param {Array.<*>} objectStack Object stack.
  44710. * @private
  44711. */
  44712. ol.format.OSMXML.readTag_ = function(node, objectStack) {
  44713. var values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  44714. values.tags[node.getAttribute('k')] = node.getAttribute('v');
  44715. };
  44716. /**
  44717. * @const
  44718. * @private
  44719. * @type {Array.<string>}
  44720. */
  44721. ol.format.OSMXML.NAMESPACE_URIS_ = [
  44722. null
  44723. ];
  44724. /**
  44725. * @const
  44726. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  44727. * @private
  44728. */
  44729. ol.format.OSMXML.WAY_PARSERS_ = ol.xml.makeStructureNS(
  44730. ol.format.OSMXML.NAMESPACE_URIS_, {
  44731. 'nd': ol.format.OSMXML.readNd_,
  44732. 'tag': ol.format.OSMXML.readTag_
  44733. });
  44734. /**
  44735. * @const
  44736. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  44737. * @private
  44738. */
  44739. ol.format.OSMXML.PARSERS_ = ol.xml.makeStructureNS(
  44740. ol.format.OSMXML.NAMESPACE_URIS_, {
  44741. 'node': ol.format.OSMXML.readNode_,
  44742. 'way': ol.format.OSMXML.readWay_
  44743. });
  44744. /**
  44745. * @const
  44746. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  44747. * @private
  44748. */
  44749. ol.format.OSMXML.NODE_PARSERS_ = ol.xml.makeStructureNS(
  44750. ol.format.OSMXML.NAMESPACE_URIS_, {
  44751. 'tag': ol.format.OSMXML.readTag_
  44752. });
  44753. /**
  44754. * Read all features from an OSM source.
  44755. *
  44756. * @function
  44757. * @param {Document|Node|Object|string} source Source.
  44758. * @param {olx.format.ReadOptions=} opt_options Read options.
  44759. * @return {Array.<ol.Feature>} Features.
  44760. * @api
  44761. */
  44762. ol.format.OSMXML.prototype.readFeatures;
  44763. /**
  44764. * @inheritDoc
  44765. */
  44766. ol.format.OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) {
  44767. var options = this.getReadOptions(node, opt_options);
  44768. if (node.localName == 'osm') {
  44769. var state = ol.xml.pushParseAndPop({
  44770. nodes: {},
  44771. ways: [],
  44772. features: []
  44773. }, ol.format.OSMXML.PARSERS_, node, [options]);
  44774. // parse nodes in ways
  44775. for (var j = 0; j < state.ways.length; j++) {
  44776. var values = /** @type {Object} */ (state.ways[j]);
  44777. /** @type {Array.<number>} */
  44778. var flatCoordinates = [];
  44779. for (var i = 0, ii = values.ndrefs.length; i < ii; i++) {
  44780. var point = state.nodes[values.ndrefs[i]];
  44781. ol.array.extend(flatCoordinates, point);
  44782. }
  44783. var geometry;
  44784. if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
  44785. // closed way
  44786. geometry = new ol.geom.Polygon(null);
  44787. geometry.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates,
  44788. [flatCoordinates.length]);
  44789. } else {
  44790. geometry = new ol.geom.LineString(null);
  44791. geometry.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates);
  44792. }
  44793. ol.format.Feature.transformWithOptions(geometry, false, options);
  44794. var feature = new ol.Feature(geometry);
  44795. feature.setId(values.id);
  44796. feature.setProperties(values.tags);
  44797. state.features.push(feature);
  44798. }
  44799. if (state.features) {
  44800. return state.features;
  44801. }
  44802. }
  44803. return [];
  44804. };
  44805. /**
  44806. * Read the projection from an OSM source.
  44807. *
  44808. * @function
  44809. * @param {Document|Node|Object|string} source Source.
  44810. * @return {ol.proj.Projection} Projection.
  44811. * @api
  44812. */
  44813. ol.format.OSMXML.prototype.readProjection;
  44814. /**
  44815. * Not implemented.
  44816. * @inheritDoc
  44817. */
  44818. ol.format.OSMXML.prototype.writeFeatureNode = function(feature, opt_options) {};
  44819. /**
  44820. * Not implemented.
  44821. * @inheritDoc
  44822. */
  44823. ol.format.OSMXML.prototype.writeFeaturesNode = function(features, opt_options) {};
  44824. /**
  44825. * Not implemented.
  44826. * @inheritDoc
  44827. */
  44828. ol.format.OSMXML.prototype.writeGeometryNode = function(geometry, opt_options) {};
  44829. goog.provide('ol.format.XLink');
  44830. /**
  44831. * @const
  44832. * @type {string}
  44833. */
  44834. ol.format.XLink.NAMESPACE_URI = 'http://www.w3.org/1999/xlink';
  44835. /**
  44836. * @param {Node} node Node.
  44837. * @return {boolean|undefined} Boolean.
  44838. */
  44839. ol.format.XLink.readHref = function(node) {
  44840. return node.getAttributeNS(ol.format.XLink.NAMESPACE_URI, 'href');
  44841. };
  44842. goog.provide('ol.format.XML');
  44843. goog.require('ol.xml');
  44844. /**
  44845. * @classdesc
  44846. * Generic format for reading non-feature XML data
  44847. *
  44848. * @constructor
  44849. * @abstract
  44850. * @struct
  44851. */
  44852. ol.format.XML = function() {
  44853. };
  44854. /**
  44855. * @param {Document|Node|string} source Source.
  44856. * @return {Object} The parsed result.
  44857. */
  44858. ol.format.XML.prototype.read = function(source) {
  44859. if (ol.xml.isDocument(source)) {
  44860. return this.readFromDocument(/** @type {Document} */ (source));
  44861. } else if (ol.xml.isNode(source)) {
  44862. return this.readFromNode(/** @type {Node} */ (source));
  44863. } else if (typeof source === 'string') {
  44864. var doc = ol.xml.parse(source);
  44865. return this.readFromDocument(doc);
  44866. } else {
  44867. return null;
  44868. }
  44869. };
  44870. /**
  44871. * @abstract
  44872. * @param {Document} doc Document.
  44873. * @return {Object} Object
  44874. */
  44875. ol.format.XML.prototype.readFromDocument = function(doc) {};
  44876. /**
  44877. * @abstract
  44878. * @param {Node} node Node.
  44879. * @return {Object} Object
  44880. */
  44881. ol.format.XML.prototype.readFromNode = function(node) {};
  44882. goog.provide('ol.format.OWS');
  44883. goog.require('ol');
  44884. goog.require('ol.format.XLink');
  44885. goog.require('ol.format.XML');
  44886. goog.require('ol.format.XSD');
  44887. goog.require('ol.xml');
  44888. /**
  44889. * @constructor
  44890. * @extends {ol.format.XML}
  44891. */
  44892. ol.format.OWS = function() {
  44893. ol.format.XML.call(this);
  44894. };
  44895. ol.inherits(ol.format.OWS, ol.format.XML);
  44896. /**
  44897. * @inheritDoc
  44898. */
  44899. ol.format.OWS.prototype.readFromDocument = function(doc) {
  44900. for (var n = doc.firstChild; n; n = n.nextSibling) {
  44901. if (n.nodeType == Node.ELEMENT_NODE) {
  44902. return this.readFromNode(n);
  44903. }
  44904. }
  44905. return null;
  44906. };
  44907. /**
  44908. * @inheritDoc
  44909. */
  44910. ol.format.OWS.prototype.readFromNode = function(node) {
  44911. var owsObject = ol.xml.pushParseAndPop({},
  44912. ol.format.OWS.PARSERS_, node, []);
  44913. return owsObject ? owsObject : null;
  44914. };
  44915. /**
  44916. * @param {Node} node Node.
  44917. * @param {Array.<*>} objectStack Object stack.
  44918. * @private
  44919. * @return {Object|undefined} The address.
  44920. */
  44921. ol.format.OWS.readAddress_ = function(node, objectStack) {
  44922. return ol.xml.pushParseAndPop({},
  44923. ol.format.OWS.ADDRESS_PARSERS_, node, objectStack);
  44924. };
  44925. /**
  44926. * @param {Node} node Node.
  44927. * @param {Array.<*>} objectStack Object stack.
  44928. * @private
  44929. * @return {Object|undefined} The values.
  44930. */
  44931. ol.format.OWS.readAllowedValues_ = function(node, objectStack) {
  44932. return ol.xml.pushParseAndPop({},
  44933. ol.format.OWS.ALLOWED_VALUES_PARSERS_, node, objectStack);
  44934. };
  44935. /**
  44936. * @param {Node} node Node.
  44937. * @param {Array.<*>} objectStack Object stack.
  44938. * @private
  44939. * @return {Object|undefined} The constraint.
  44940. */
  44941. ol.format.OWS.readConstraint_ = function(node, objectStack) {
  44942. var name = node.getAttribute('name');
  44943. if (!name) {
  44944. return undefined;
  44945. }
  44946. return ol.xml.pushParseAndPop({'name': name},
  44947. ol.format.OWS.CONSTRAINT_PARSERS_, node,
  44948. objectStack);
  44949. };
  44950. /**
  44951. * @param {Node} node Node.
  44952. * @param {Array.<*>} objectStack Object stack.
  44953. * @private
  44954. * @return {Object|undefined} The contact info.
  44955. */
  44956. ol.format.OWS.readContactInfo_ = function(node, objectStack) {
  44957. return ol.xml.pushParseAndPop({},
  44958. ol.format.OWS.CONTACT_INFO_PARSERS_, node, objectStack);
  44959. };
  44960. /**
  44961. * @param {Node} node Node.
  44962. * @param {Array.<*>} objectStack Object stack.
  44963. * @private
  44964. * @return {Object|undefined} The DCP.
  44965. */
  44966. ol.format.OWS.readDcp_ = function(node, objectStack) {
  44967. return ol.xml.pushParseAndPop({},
  44968. ol.format.OWS.DCP_PARSERS_, node, objectStack);
  44969. };
  44970. /**
  44971. * @param {Node} node Node.
  44972. * @param {Array.<*>} objectStack Object stack.
  44973. * @private
  44974. * @return {Object|undefined} The GET object.
  44975. */
  44976. ol.format.OWS.readGet_ = function(node, objectStack) {
  44977. var href = ol.format.XLink.readHref(node);
  44978. if (!href) {
  44979. return undefined;
  44980. }
  44981. return ol.xml.pushParseAndPop({'href': href},
  44982. ol.format.OWS.REQUEST_METHOD_PARSERS_, node, objectStack);
  44983. };
  44984. /**
  44985. * @param {Node} node Node.
  44986. * @param {Array.<*>} objectStack Object stack.
  44987. * @private
  44988. * @return {Object|undefined} The HTTP object.
  44989. */
  44990. ol.format.OWS.readHttp_ = function(node, objectStack) {
  44991. return ol.xml.pushParseAndPop({}, ol.format.OWS.HTTP_PARSERS_,
  44992. node, objectStack);
  44993. };
  44994. /**
  44995. * @param {Node} node Node.
  44996. * @param {Array.<*>} objectStack Object stack.
  44997. * @private
  44998. * @return {Object|undefined} The operation.
  44999. */
  45000. ol.format.OWS.readOperation_ = function(node, objectStack) {
  45001. var name = node.getAttribute('name');
  45002. var value = ol.xml.pushParseAndPop({},
  45003. ol.format.OWS.OPERATION_PARSERS_, node, objectStack);
  45004. if (!value) {
  45005. return undefined;
  45006. }
  45007. var object = /** @type {Object} */
  45008. (objectStack[objectStack.length - 1]);
  45009. object[name] = value;
  45010. };
  45011. /**
  45012. * @param {Node} node Node.
  45013. * @param {Array.<*>} objectStack Object stack.
  45014. * @private
  45015. * @return {Object|undefined} The operations metadata.
  45016. */
  45017. ol.format.OWS.readOperationsMetadata_ = function(node,
  45018. objectStack) {
  45019. return ol.xml.pushParseAndPop({},
  45020. ol.format.OWS.OPERATIONS_METADATA_PARSERS_, node,
  45021. objectStack);
  45022. };
  45023. /**
  45024. * @param {Node} node Node.
  45025. * @param {Array.<*>} objectStack Object stack.
  45026. * @private
  45027. * @return {Object|undefined} The phone.
  45028. */
  45029. ol.format.OWS.readPhone_ = function(node, objectStack) {
  45030. return ol.xml.pushParseAndPop({},
  45031. ol.format.OWS.PHONE_PARSERS_, node, objectStack);
  45032. };
  45033. /**
  45034. * @param {Node} node Node.
  45035. * @param {Array.<*>} objectStack Object stack.
  45036. * @private
  45037. * @return {Object|undefined} The service identification.
  45038. */
  45039. ol.format.OWS.readServiceIdentification_ = function(node,
  45040. objectStack) {
  45041. return ol.xml.pushParseAndPop(
  45042. {}, ol.format.OWS.SERVICE_IDENTIFICATION_PARSERS_, node,
  45043. objectStack);
  45044. };
  45045. /**
  45046. * @param {Node} node Node.
  45047. * @param {Array.<*>} objectStack Object stack.
  45048. * @private
  45049. * @return {Object|undefined} The service contact.
  45050. */
  45051. ol.format.OWS.readServiceContact_ = function(node, objectStack) {
  45052. return ol.xml.pushParseAndPop(
  45053. {}, ol.format.OWS.SERVICE_CONTACT_PARSERS_, node,
  45054. objectStack);
  45055. };
  45056. /**
  45057. * @param {Node} node Node.
  45058. * @param {Array.<*>} objectStack Object stack.
  45059. * @private
  45060. * @return {Object|undefined} The service provider.
  45061. */
  45062. ol.format.OWS.readServiceProvider_ = function(node, objectStack) {
  45063. return ol.xml.pushParseAndPop(
  45064. {}, ol.format.OWS.SERVICE_PROVIDER_PARSERS_, node,
  45065. objectStack);
  45066. };
  45067. /**
  45068. * @param {Node} node Node.
  45069. * @param {Array.<*>} objectStack Object stack.
  45070. * @private
  45071. * @return {string|undefined} The value.
  45072. */
  45073. ol.format.OWS.readValue_ = function(node, objectStack) {
  45074. return ol.format.XSD.readString(node);
  45075. };
  45076. /**
  45077. * @const
  45078. * @type {Array.<string>}
  45079. * @private
  45080. */
  45081. ol.format.OWS.NAMESPACE_URIS_ = [
  45082. null,
  45083. 'http://www.opengis.net/ows/1.1'
  45084. ];
  45085. /**
  45086. * @const
  45087. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45088. * @private
  45089. */
  45090. ol.format.OWS.PARSERS_ = ol.xml.makeStructureNS(
  45091. ol.format.OWS.NAMESPACE_URIS_, {
  45092. 'ServiceIdentification': ol.xml.makeObjectPropertySetter(
  45093. ol.format.OWS.readServiceIdentification_),
  45094. 'ServiceProvider': ol.xml.makeObjectPropertySetter(
  45095. ol.format.OWS.readServiceProvider_),
  45096. 'OperationsMetadata': ol.xml.makeObjectPropertySetter(
  45097. ol.format.OWS.readOperationsMetadata_)
  45098. });
  45099. /**
  45100. * @const
  45101. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45102. * @private
  45103. */
  45104. ol.format.OWS.ADDRESS_PARSERS_ = ol.xml.makeStructureNS(
  45105. ol.format.OWS.NAMESPACE_URIS_, {
  45106. 'DeliveryPoint': ol.xml.makeObjectPropertySetter(
  45107. ol.format.XSD.readString),
  45108. 'City': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45109. 'AdministrativeArea': ol.xml.makeObjectPropertySetter(
  45110. ol.format.XSD.readString),
  45111. 'PostalCode': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45112. 'Country': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45113. 'ElectronicMailAddress': ol.xml.makeObjectPropertySetter(
  45114. ol.format.XSD.readString)
  45115. });
  45116. /**
  45117. * @const
  45118. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45119. * @private
  45120. */
  45121. ol.format.OWS.ALLOWED_VALUES_PARSERS_ = ol.xml.makeStructureNS(
  45122. ol.format.OWS.NAMESPACE_URIS_, {
  45123. 'Value': ol.xml.makeObjectPropertyPusher(ol.format.OWS.readValue_)
  45124. });
  45125. /**
  45126. * @const
  45127. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45128. * @private
  45129. */
  45130. ol.format.OWS.CONSTRAINT_PARSERS_ = ol.xml.makeStructureNS(
  45131. ol.format.OWS.NAMESPACE_URIS_, {
  45132. 'AllowedValues': ol.xml.makeObjectPropertySetter(
  45133. ol.format.OWS.readAllowedValues_)
  45134. });
  45135. /**
  45136. * @const
  45137. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45138. * @private
  45139. */
  45140. ol.format.OWS.CONTACT_INFO_PARSERS_ = ol.xml.makeStructureNS(
  45141. ol.format.OWS.NAMESPACE_URIS_, {
  45142. 'Phone': ol.xml.makeObjectPropertySetter(ol.format.OWS.readPhone_),
  45143. 'Address': ol.xml.makeObjectPropertySetter(ol.format.OWS.readAddress_)
  45144. });
  45145. /**
  45146. * @const
  45147. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45148. * @private
  45149. */
  45150. ol.format.OWS.DCP_PARSERS_ = ol.xml.makeStructureNS(
  45151. ol.format.OWS.NAMESPACE_URIS_, {
  45152. 'HTTP': ol.xml.makeObjectPropertySetter(ol.format.OWS.readHttp_)
  45153. });
  45154. /**
  45155. * @const
  45156. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45157. * @private
  45158. */
  45159. ol.format.OWS.HTTP_PARSERS_ = ol.xml.makeStructureNS(
  45160. ol.format.OWS.NAMESPACE_URIS_, {
  45161. 'Get': ol.xml.makeObjectPropertyPusher(ol.format.OWS.readGet_),
  45162. 'Post': undefined // TODO
  45163. });
  45164. /**
  45165. * @const
  45166. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45167. * @private
  45168. */
  45169. ol.format.OWS.OPERATION_PARSERS_ = ol.xml.makeStructureNS(
  45170. ol.format.OWS.NAMESPACE_URIS_, {
  45171. 'DCP': ol.xml.makeObjectPropertySetter(ol.format.OWS.readDcp_)
  45172. });
  45173. /**
  45174. * @const
  45175. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45176. * @private
  45177. */
  45178. ol.format.OWS.OPERATIONS_METADATA_PARSERS_ = ol.xml.makeStructureNS(
  45179. ol.format.OWS.NAMESPACE_URIS_, {
  45180. 'Operation': ol.format.OWS.readOperation_
  45181. });
  45182. /**
  45183. * @const
  45184. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45185. * @private
  45186. */
  45187. ol.format.OWS.PHONE_PARSERS_ = ol.xml.makeStructureNS(
  45188. ol.format.OWS.NAMESPACE_URIS_, {
  45189. 'Voice': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45190. 'Facsimile': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
  45191. });
  45192. /**
  45193. * @const
  45194. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45195. * @private
  45196. */
  45197. ol.format.OWS.REQUEST_METHOD_PARSERS_ = ol.xml.makeStructureNS(
  45198. ol.format.OWS.NAMESPACE_URIS_, {
  45199. 'Constraint': ol.xml.makeObjectPropertyPusher(
  45200. ol.format.OWS.readConstraint_)
  45201. });
  45202. /**
  45203. * @const
  45204. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45205. * @private
  45206. */
  45207. ol.format.OWS.SERVICE_CONTACT_PARSERS_ =
  45208. ol.xml.makeStructureNS(
  45209. ol.format.OWS.NAMESPACE_URIS_, {
  45210. 'IndividualName': ol.xml.makeObjectPropertySetter(
  45211. ol.format.XSD.readString),
  45212. 'PositionName': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45213. 'ContactInfo': ol.xml.makeObjectPropertySetter(
  45214. ol.format.OWS.readContactInfo_)
  45215. });
  45216. /**
  45217. * @const
  45218. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45219. * @private
  45220. */
  45221. ol.format.OWS.SERVICE_IDENTIFICATION_PARSERS_ =
  45222. ol.xml.makeStructureNS(
  45223. ol.format.OWS.NAMESPACE_URIS_, {
  45224. 'Abstract': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45225. 'AccessConstraints': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45226. 'Fees': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45227. 'Title': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45228. 'ServiceTypeVersion': ol.xml.makeObjectPropertySetter(
  45229. ol.format.XSD.readString),
  45230. 'ServiceType': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
  45231. });
  45232. /**
  45233. * @const
  45234. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  45235. * @private
  45236. */
  45237. ol.format.OWS.SERVICE_PROVIDER_PARSERS_ =
  45238. ol.xml.makeStructureNS(
  45239. ol.format.OWS.NAMESPACE_URIS_, {
  45240. 'ProviderName': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  45241. 'ProviderSite': ol.xml.makeObjectPropertySetter(ol.format.XLink.readHref),
  45242. 'ServiceContact': ol.xml.makeObjectPropertySetter(
  45243. ol.format.OWS.readServiceContact_)
  45244. });
  45245. goog.provide('ol.geom.flat.flip');
  45246. /**
  45247. * @param {Array.<number>} flatCoordinates Flat coordinates.
  45248. * @param {number} offset Offset.
  45249. * @param {number} end End.
  45250. * @param {number} stride Stride.
  45251. * @param {Array.<number>=} opt_dest Destination.
  45252. * @param {number=} opt_destOffset Destination offset.
  45253. * @return {Array.<number>} Flat coordinates.
  45254. */
  45255. ol.geom.flat.flip.flipXY = function(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) {
  45256. var dest, destOffset;
  45257. if (opt_dest !== undefined) {
  45258. dest = opt_dest;
  45259. destOffset = opt_destOffset !== undefined ? opt_destOffset : 0;
  45260. } else {
  45261. dest = [];
  45262. destOffset = 0;
  45263. }
  45264. var j = offset;
  45265. while (j < end) {
  45266. var x = flatCoordinates[j++];
  45267. dest[destOffset++] = flatCoordinates[j++];
  45268. dest[destOffset++] = x;
  45269. for (var k = 2; k < stride; ++k) {
  45270. dest[destOffset++] = flatCoordinates[j++];
  45271. }
  45272. }
  45273. dest.length = destOffset;
  45274. return dest;
  45275. };
  45276. goog.provide('ol.format.Polyline');
  45277. goog.require('ol');
  45278. goog.require('ol.asserts');
  45279. goog.require('ol.Feature');
  45280. goog.require('ol.format.Feature');
  45281. goog.require('ol.format.TextFeature');
  45282. goog.require('ol.geom.GeometryLayout');
  45283. goog.require('ol.geom.LineString');
  45284. goog.require('ol.geom.SimpleGeometry');
  45285. goog.require('ol.geom.flat.flip');
  45286. goog.require('ol.geom.flat.inflate');
  45287. goog.require('ol.proj');
  45288. /**
  45289. * @classdesc
  45290. * Feature format for reading and writing data in the Encoded
  45291. * Polyline Algorithm Format.
  45292. *
  45293. * @constructor
  45294. * @extends {ol.format.TextFeature}
  45295. * @param {olx.format.PolylineOptions=} opt_options
  45296. * Optional configuration object.
  45297. * @api
  45298. */
  45299. ol.format.Polyline = function(opt_options) {
  45300. var options = opt_options ? opt_options : {};
  45301. ol.format.TextFeature.call(this);
  45302. /**
  45303. * @inheritDoc
  45304. */
  45305. this.defaultDataProjection = ol.proj.get('EPSG:4326');
  45306. /**
  45307. * @private
  45308. * @type {number}
  45309. */
  45310. this.factor_ = options.factor ? options.factor : 1e5;
  45311. /**
  45312. * @private
  45313. * @type {ol.geom.GeometryLayout}
  45314. */
  45315. this.geometryLayout_ = options.geometryLayout ?
  45316. options.geometryLayout : ol.geom.GeometryLayout.XY;
  45317. };
  45318. ol.inherits(ol.format.Polyline, ol.format.TextFeature);
  45319. /**
  45320. * Encode a list of n-dimensional points and return an encoded string
  45321. *
  45322. * Attention: This function will modify the passed array!
  45323. *
  45324. * @param {Array.<number>} numbers A list of n-dimensional points.
  45325. * @param {number} stride The number of dimension of the points in the list.
  45326. * @param {number=} opt_factor The factor by which the numbers will be
  45327. * multiplied. The remaining decimal places will get rounded away.
  45328. * Default is `1e5`.
  45329. * @return {string} The encoded string.
  45330. * @api
  45331. */
  45332. ol.format.Polyline.encodeDeltas = function(numbers, stride, opt_factor) {
  45333. var factor = opt_factor ? opt_factor : 1e5;
  45334. var d;
  45335. var lastNumbers = new Array(stride);
  45336. for (d = 0; d < stride; ++d) {
  45337. lastNumbers[d] = 0;
  45338. }
  45339. var i, ii;
  45340. for (i = 0, ii = numbers.length; i < ii;) {
  45341. for (d = 0; d < stride; ++d, ++i) {
  45342. var num = numbers[i];
  45343. var delta = num - lastNumbers[d];
  45344. lastNumbers[d] = num;
  45345. numbers[i] = delta;
  45346. }
  45347. }
  45348. return ol.format.Polyline.encodeFloats(numbers, factor);
  45349. };
  45350. /**
  45351. * Decode a list of n-dimensional points from an encoded string
  45352. *
  45353. * @param {string} encoded An encoded string.
  45354. * @param {number} stride The number of dimension of the points in the
  45355. * encoded string.
  45356. * @param {number=} opt_factor The factor by which the resulting numbers will
  45357. * be divided. Default is `1e5`.
  45358. * @return {Array.<number>} A list of n-dimensional points.
  45359. * @api
  45360. */
  45361. ol.format.Polyline.decodeDeltas = function(encoded, stride, opt_factor) {
  45362. var factor = opt_factor ? opt_factor : 1e5;
  45363. var d;
  45364. /** @type {Array.<number>} */
  45365. var lastNumbers = new Array(stride);
  45366. for (d = 0; d < stride; ++d) {
  45367. lastNumbers[d] = 0;
  45368. }
  45369. var numbers = ol.format.Polyline.decodeFloats(encoded, factor);
  45370. var i, ii;
  45371. for (i = 0, ii = numbers.length; i < ii;) {
  45372. for (d = 0; d < stride; ++d, ++i) {
  45373. lastNumbers[d] += numbers[i];
  45374. numbers[i] = lastNumbers[d];
  45375. }
  45376. }
  45377. return numbers;
  45378. };
  45379. /**
  45380. * Encode a list of floating point numbers and return an encoded string
  45381. *
  45382. * Attention: This function will modify the passed array!
  45383. *
  45384. * @param {Array.<number>} numbers A list of floating point numbers.
  45385. * @param {number=} opt_factor The factor by which the numbers will be
  45386. * multiplied. The remaining decimal places will get rounded away.
  45387. * Default is `1e5`.
  45388. * @return {string} The encoded string.
  45389. * @api
  45390. */
  45391. ol.format.Polyline.encodeFloats = function(numbers, opt_factor) {
  45392. var factor = opt_factor ? opt_factor : 1e5;
  45393. var i, ii;
  45394. for (i = 0, ii = numbers.length; i < ii; ++i) {
  45395. numbers[i] = Math.round(numbers[i] * factor);
  45396. }
  45397. return ol.format.Polyline.encodeSignedIntegers(numbers);
  45398. };
  45399. /**
  45400. * Decode a list of floating point numbers from an encoded string
  45401. *
  45402. * @param {string} encoded An encoded string.
  45403. * @param {number=} opt_factor The factor by which the result will be divided.
  45404. * Default is `1e5`.
  45405. * @return {Array.<number>} A list of floating point numbers.
  45406. * @api
  45407. */
  45408. ol.format.Polyline.decodeFloats = function(encoded, opt_factor) {
  45409. var factor = opt_factor ? opt_factor : 1e5;
  45410. var numbers = ol.format.Polyline.decodeSignedIntegers(encoded);
  45411. var i, ii;
  45412. for (i = 0, ii = numbers.length; i < ii; ++i) {
  45413. numbers[i] /= factor;
  45414. }
  45415. return numbers;
  45416. };
  45417. /**
  45418. * Encode a list of signed integers and return an encoded string
  45419. *
  45420. * Attention: This function will modify the passed array!
  45421. *
  45422. * @param {Array.<number>} numbers A list of signed integers.
  45423. * @return {string} The encoded string.
  45424. */
  45425. ol.format.Polyline.encodeSignedIntegers = function(numbers) {
  45426. var i, ii;
  45427. for (i = 0, ii = numbers.length; i < ii; ++i) {
  45428. var num = numbers[i];
  45429. numbers[i] = (num < 0) ? ~(num << 1) : (num << 1);
  45430. }
  45431. return ol.format.Polyline.encodeUnsignedIntegers(numbers);
  45432. };
  45433. /**
  45434. * Decode a list of signed integers from an encoded string
  45435. *
  45436. * @param {string} encoded An encoded string.
  45437. * @return {Array.<number>} A list of signed integers.
  45438. */
  45439. ol.format.Polyline.decodeSignedIntegers = function(encoded) {
  45440. var numbers = ol.format.Polyline.decodeUnsignedIntegers(encoded);
  45441. var i, ii;
  45442. for (i = 0, ii = numbers.length; i < ii; ++i) {
  45443. var num = numbers[i];
  45444. numbers[i] = (num & 1) ? ~(num >> 1) : (num >> 1);
  45445. }
  45446. return numbers;
  45447. };
  45448. /**
  45449. * Encode a list of unsigned integers and return an encoded string
  45450. *
  45451. * @param {Array.<number>} numbers A list of unsigned integers.
  45452. * @return {string} The encoded string.
  45453. */
  45454. ol.format.Polyline.encodeUnsignedIntegers = function(numbers) {
  45455. var encoded = '';
  45456. var i, ii;
  45457. for (i = 0, ii = numbers.length; i < ii; ++i) {
  45458. encoded += ol.format.Polyline.encodeUnsignedInteger(numbers[i]);
  45459. }
  45460. return encoded;
  45461. };
  45462. /**
  45463. * Decode a list of unsigned integers from an encoded string
  45464. *
  45465. * @param {string} encoded An encoded string.
  45466. * @return {Array.<number>} A list of unsigned integers.
  45467. */
  45468. ol.format.Polyline.decodeUnsignedIntegers = function(encoded) {
  45469. var numbers = [];
  45470. var current = 0;
  45471. var shift = 0;
  45472. var i, ii;
  45473. for (i = 0, ii = encoded.length; i < ii; ++i) {
  45474. var b = encoded.charCodeAt(i) - 63;
  45475. current |= (b & 0x1f) << shift;
  45476. if (b < 0x20) {
  45477. numbers.push(current);
  45478. current = 0;
  45479. shift = 0;
  45480. } else {
  45481. shift += 5;
  45482. }
  45483. }
  45484. return numbers;
  45485. };
  45486. /**
  45487. * Encode one single unsigned integer and return an encoded string
  45488. *
  45489. * @param {number} num Unsigned integer that should be encoded.
  45490. * @return {string} The encoded string.
  45491. */
  45492. ol.format.Polyline.encodeUnsignedInteger = function(num) {
  45493. var value, encoded = '';
  45494. while (num >= 0x20) {
  45495. value = (0x20 | (num & 0x1f)) + 63;
  45496. encoded += String.fromCharCode(value);
  45497. num >>= 5;
  45498. }
  45499. value = num + 63;
  45500. encoded += String.fromCharCode(value);
  45501. return encoded;
  45502. };
  45503. /**
  45504. * Read the feature from the Polyline source. The coordinates are assumed to be
  45505. * in two dimensions and in latitude, longitude order.
  45506. *
  45507. * @function
  45508. * @param {Document|Node|Object|string} source Source.
  45509. * @param {olx.format.ReadOptions=} opt_options Read options.
  45510. * @return {ol.Feature} Feature.
  45511. * @api
  45512. */
  45513. ol.format.Polyline.prototype.readFeature;
  45514. /**
  45515. * @inheritDoc
  45516. */
  45517. ol.format.Polyline.prototype.readFeatureFromText = function(text, opt_options) {
  45518. var geometry = this.readGeometryFromText(text, opt_options);
  45519. return new ol.Feature(geometry);
  45520. };
  45521. /**
  45522. * Read the feature from the source. As Polyline sources contain a single
  45523. * feature, this will return the feature in an array.
  45524. *
  45525. * @function
  45526. * @param {Document|Node|Object|string} source Source.
  45527. * @param {olx.format.ReadOptions=} opt_options Read options.
  45528. * @return {Array.<ol.Feature>} Features.
  45529. * @api
  45530. */
  45531. ol.format.Polyline.prototype.readFeatures;
  45532. /**
  45533. * @inheritDoc
  45534. */
  45535. ol.format.Polyline.prototype.readFeaturesFromText = function(text, opt_options) {
  45536. var feature = this.readFeatureFromText(text, opt_options);
  45537. return [feature];
  45538. };
  45539. /**
  45540. * Read the geometry from the source.
  45541. *
  45542. * @function
  45543. * @param {Document|Node|Object|string} source Source.
  45544. * @param {olx.format.ReadOptions=} opt_options Read options.
  45545. * @return {ol.geom.Geometry} Geometry.
  45546. * @api
  45547. */
  45548. ol.format.Polyline.prototype.readGeometry;
  45549. /**
  45550. * @inheritDoc
  45551. */
  45552. ol.format.Polyline.prototype.readGeometryFromText = function(text, opt_options) {
  45553. var stride = ol.geom.SimpleGeometry.getStrideForLayout(this.geometryLayout_);
  45554. var flatCoordinates = ol.format.Polyline.decodeDeltas(
  45555. text, stride, this.factor_);
  45556. ol.geom.flat.flip.flipXY(
  45557. flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
  45558. var coordinates = ol.geom.flat.inflate.coordinates(
  45559. flatCoordinates, 0, flatCoordinates.length, stride);
  45560. return /** @type {ol.geom.Geometry} */ (
  45561. ol.format.Feature.transformWithOptions(
  45562. new ol.geom.LineString(coordinates, this.geometryLayout_), false,
  45563. this.adaptOptions(opt_options)));
  45564. };
  45565. /**
  45566. * Read the projection from a Polyline source.
  45567. *
  45568. * @function
  45569. * @param {Document|Node|Object|string} source Source.
  45570. * @return {ol.proj.Projection} Projection.
  45571. * @api
  45572. */
  45573. ol.format.Polyline.prototype.readProjection;
  45574. /**
  45575. * @inheritDoc
  45576. */
  45577. ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) {
  45578. var geometry = feature.getGeometry();
  45579. if (geometry) {
  45580. return this.writeGeometryText(geometry, opt_options);
  45581. } else {
  45582. ol.asserts.assert(false, 40); // Expected `feature` to have a geometry
  45583. return '';
  45584. }
  45585. };
  45586. /**
  45587. * @inheritDoc
  45588. */
  45589. ol.format.Polyline.prototype.writeFeaturesText = function(features, opt_options) {
  45590. return this.writeFeatureText(features[0], opt_options);
  45591. };
  45592. /**
  45593. * Write a single geometry in Polyline format.
  45594. *
  45595. * @function
  45596. * @param {ol.geom.Geometry} geometry Geometry.
  45597. * @param {olx.format.WriteOptions=} opt_options Write options.
  45598. * @return {string} Geometry.
  45599. * @api
  45600. */
  45601. ol.format.Polyline.prototype.writeGeometry;
  45602. /**
  45603. * @inheritDoc
  45604. */
  45605. ol.format.Polyline.prototype.writeGeometryText = function(geometry, opt_options) {
  45606. geometry = /** @type {ol.geom.LineString} */
  45607. (ol.format.Feature.transformWithOptions(
  45608. geometry, true, this.adaptOptions(opt_options)));
  45609. var flatCoordinates = geometry.getFlatCoordinates();
  45610. var stride = geometry.getStride();
  45611. ol.geom.flat.flip.flipXY(
  45612. flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
  45613. return ol.format.Polyline.encodeDeltas(flatCoordinates, stride, this.factor_);
  45614. };
  45615. goog.provide('ol.format.TopoJSON');
  45616. goog.require('ol');
  45617. goog.require('ol.Feature');
  45618. goog.require('ol.format.Feature');
  45619. goog.require('ol.format.JSONFeature');
  45620. goog.require('ol.geom.LineString');
  45621. goog.require('ol.geom.MultiLineString');
  45622. goog.require('ol.geom.MultiPoint');
  45623. goog.require('ol.geom.MultiPolygon');
  45624. goog.require('ol.geom.Point');
  45625. goog.require('ol.geom.Polygon');
  45626. goog.require('ol.proj');
  45627. /**
  45628. * @classdesc
  45629. * Feature format for reading data in the TopoJSON format.
  45630. *
  45631. * @constructor
  45632. * @extends {ol.format.JSONFeature}
  45633. * @param {olx.format.TopoJSONOptions=} opt_options Options.
  45634. * @api
  45635. */
  45636. ol.format.TopoJSON = function(opt_options) {
  45637. var options = opt_options ? opt_options : {};
  45638. ol.format.JSONFeature.call(this);
  45639. /**
  45640. * @private
  45641. * @type {string|undefined}
  45642. */
  45643. this.layerName_ = options.layerName;
  45644. /**
  45645. * @private
  45646. * @type {Array.<string>}
  45647. */
  45648. this.layers_ = options.layers ? options.layers : null;
  45649. /**
  45650. * @inheritDoc
  45651. */
  45652. this.defaultDataProjection = ol.proj.get(
  45653. options.defaultDataProjection ?
  45654. options.defaultDataProjection : 'EPSG:4326');
  45655. };
  45656. ol.inherits(ol.format.TopoJSON, ol.format.JSONFeature);
  45657. /**
  45658. * Concatenate arcs into a coordinate array.
  45659. * @param {Array.<number>} indices Indices of arcs to concatenate. Negative
  45660. * values indicate arcs need to be reversed.
  45661. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs (already
  45662. * transformed).
  45663. * @return {Array.<ol.Coordinate>} Coordinates array.
  45664. * @private
  45665. */
  45666. ol.format.TopoJSON.concatenateArcs_ = function(indices, arcs) {
  45667. /** @type {Array.<ol.Coordinate>} */
  45668. var coordinates = [];
  45669. var index, arc;
  45670. var i, ii;
  45671. var j, jj;
  45672. for (i = 0, ii = indices.length; i < ii; ++i) {
  45673. index = indices[i];
  45674. if (i > 0) {
  45675. // splicing together arcs, discard last point
  45676. coordinates.pop();
  45677. }
  45678. if (index >= 0) {
  45679. // forward arc
  45680. arc = arcs[index];
  45681. } else {
  45682. // reverse arc
  45683. arc = arcs[~index].slice().reverse();
  45684. }
  45685. coordinates.push.apply(coordinates, arc);
  45686. }
  45687. // provide fresh copies of coordinate arrays
  45688. for (j = 0, jj = coordinates.length; j < jj; ++j) {
  45689. coordinates[j] = coordinates[j].slice();
  45690. }
  45691. return coordinates;
  45692. };
  45693. /**
  45694. * Create a point from a TopoJSON geometry object.
  45695. *
  45696. * @param {TopoJSONGeometry} object TopoJSON object.
  45697. * @param {Array.<number>} scale Scale for each dimension.
  45698. * @param {Array.<number>} translate Translation for each dimension.
  45699. * @return {ol.geom.Point} Geometry.
  45700. * @private
  45701. */
  45702. ol.format.TopoJSON.readPointGeometry_ = function(object, scale, translate) {
  45703. var coordinates = object.coordinates;
  45704. if (scale && translate) {
  45705. ol.format.TopoJSON.transformVertex_(coordinates, scale, translate);
  45706. }
  45707. return new ol.geom.Point(coordinates);
  45708. };
  45709. /**
  45710. * Create a multi-point from a TopoJSON geometry object.
  45711. *
  45712. * @param {TopoJSONGeometry} object TopoJSON object.
  45713. * @param {Array.<number>} scale Scale for each dimension.
  45714. * @param {Array.<number>} translate Translation for each dimension.
  45715. * @return {ol.geom.MultiPoint} Geometry.
  45716. * @private
  45717. */
  45718. ol.format.TopoJSON.readMultiPointGeometry_ = function(object, scale,
  45719. translate) {
  45720. var coordinates = object.coordinates;
  45721. var i, ii;
  45722. if (scale && translate) {
  45723. for (i = 0, ii = coordinates.length; i < ii; ++i) {
  45724. ol.format.TopoJSON.transformVertex_(coordinates[i], scale, translate);
  45725. }
  45726. }
  45727. return new ol.geom.MultiPoint(coordinates);
  45728. };
  45729. /**
  45730. * Create a linestring from a TopoJSON geometry object.
  45731. *
  45732. * @param {TopoJSONGeometry} object TopoJSON object.
  45733. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45734. * @return {ol.geom.LineString} Geometry.
  45735. * @private
  45736. */
  45737. ol.format.TopoJSON.readLineStringGeometry_ = function(object, arcs) {
  45738. var coordinates = ol.format.TopoJSON.concatenateArcs_(object.arcs, arcs);
  45739. return new ol.geom.LineString(coordinates);
  45740. };
  45741. /**
  45742. * Create a multi-linestring from a TopoJSON geometry object.
  45743. *
  45744. * @param {TopoJSONGeometry} object TopoJSON object.
  45745. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45746. * @return {ol.geom.MultiLineString} Geometry.
  45747. * @private
  45748. */
  45749. ol.format.TopoJSON.readMultiLineStringGeometry_ = function(object, arcs) {
  45750. var coordinates = [];
  45751. var i, ii;
  45752. for (i = 0, ii = object.arcs.length; i < ii; ++i) {
  45753. coordinates[i] = ol.format.TopoJSON.concatenateArcs_(object.arcs[i], arcs);
  45754. }
  45755. return new ol.geom.MultiLineString(coordinates);
  45756. };
  45757. /**
  45758. * Create a polygon from a TopoJSON geometry object.
  45759. *
  45760. * @param {TopoJSONGeometry} object TopoJSON object.
  45761. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45762. * @return {ol.geom.Polygon} Geometry.
  45763. * @private
  45764. */
  45765. ol.format.TopoJSON.readPolygonGeometry_ = function(object, arcs) {
  45766. var coordinates = [];
  45767. var i, ii;
  45768. for (i = 0, ii = object.arcs.length; i < ii; ++i) {
  45769. coordinates[i] = ol.format.TopoJSON.concatenateArcs_(object.arcs[i], arcs);
  45770. }
  45771. return new ol.geom.Polygon(coordinates);
  45772. };
  45773. /**
  45774. * Create a multi-polygon from a TopoJSON geometry object.
  45775. *
  45776. * @param {TopoJSONGeometry} object TopoJSON object.
  45777. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45778. * @return {ol.geom.MultiPolygon} Geometry.
  45779. * @private
  45780. */
  45781. ol.format.TopoJSON.readMultiPolygonGeometry_ = function(object, arcs) {
  45782. var coordinates = [];
  45783. var polyArray, ringCoords, j, jj;
  45784. var i, ii;
  45785. for (i = 0, ii = object.arcs.length; i < ii; ++i) {
  45786. // for each polygon
  45787. polyArray = object.arcs[i];
  45788. ringCoords = [];
  45789. for (j = 0, jj = polyArray.length; j < jj; ++j) {
  45790. // for each ring
  45791. ringCoords[j] = ol.format.TopoJSON.concatenateArcs_(polyArray[j], arcs);
  45792. }
  45793. coordinates[i] = ringCoords;
  45794. }
  45795. return new ol.geom.MultiPolygon(coordinates);
  45796. };
  45797. /**
  45798. * Create features from a TopoJSON GeometryCollection object.
  45799. *
  45800. * @param {TopoJSONGeometryCollection} collection TopoJSON Geometry
  45801. * object.
  45802. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45803. * @param {Array.<number>} scale Scale for each dimension.
  45804. * @param {Array.<number>} translate Translation for each dimension.
  45805. * @param {string|undefined} property Property to set the `GeometryCollection`'s parent
  45806. * object to.
  45807. * @param {string} name Name of the `Topology`'s child object.
  45808. * @param {olx.format.ReadOptions=} opt_options Read options.
  45809. * @return {Array.<ol.Feature>} Array of features.
  45810. * @private
  45811. */
  45812. ol.format.TopoJSON.readFeaturesFromGeometryCollection_ = function(
  45813. collection, arcs, scale, translate, property, name, opt_options) {
  45814. var geometries = collection.geometries;
  45815. var features = [];
  45816. var i, ii;
  45817. for (i = 0, ii = geometries.length; i < ii; ++i) {
  45818. features[i] = ol.format.TopoJSON.readFeatureFromGeometry_(
  45819. geometries[i], arcs, scale, translate, property, name, opt_options);
  45820. }
  45821. return features;
  45822. };
  45823. /**
  45824. * Create a feature from a TopoJSON geometry object.
  45825. *
  45826. * @param {TopoJSONGeometry} object TopoJSON geometry object.
  45827. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45828. * @param {Array.<number>} scale Scale for each dimension.
  45829. * @param {Array.<number>} translate Translation for each dimension.
  45830. * @param {string|undefined} property Property to set the `GeometryCollection`'s parent
  45831. * object to.
  45832. * @param {string} name Name of the `Topology`'s child object.
  45833. * @param {olx.format.ReadOptions=} opt_options Read options.
  45834. * @return {ol.Feature} Feature.
  45835. * @private
  45836. */
  45837. ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs,
  45838. scale, translate, property, name, opt_options) {
  45839. var geometry;
  45840. var type = object.type;
  45841. var geometryReader = ol.format.TopoJSON.GEOMETRY_READERS_[type];
  45842. if ((type === 'Point') || (type === 'MultiPoint')) {
  45843. geometry = geometryReader(object, scale, translate);
  45844. } else {
  45845. geometry = geometryReader(object, arcs);
  45846. }
  45847. var feature = new ol.Feature();
  45848. feature.setGeometry(/** @type {ol.geom.Geometry} */ (
  45849. ol.format.Feature.transformWithOptions(geometry, false, opt_options)));
  45850. if (object.id !== undefined) {
  45851. feature.setId(object.id);
  45852. }
  45853. var properties = object.properties;
  45854. if (property) {
  45855. if (!properties) {
  45856. properties = {};
  45857. }
  45858. properties[property] = name;
  45859. }
  45860. if (properties) {
  45861. feature.setProperties(properties);
  45862. }
  45863. return feature;
  45864. };
  45865. /**
  45866. * Read all features from a TopoJSON source.
  45867. *
  45868. * @function
  45869. * @param {Document|Node|Object|string} source Source.
  45870. * @return {Array.<ol.Feature>} Features.
  45871. * @api
  45872. */
  45873. ol.format.TopoJSON.prototype.readFeatures;
  45874. /**
  45875. * @inheritDoc
  45876. */
  45877. ol.format.TopoJSON.prototype.readFeaturesFromObject = function(
  45878. object, opt_options) {
  45879. if (object.type == 'Topology') {
  45880. var topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
  45881. var transform, scale = null, translate = null;
  45882. if (topoJSONTopology.transform) {
  45883. transform = topoJSONTopology.transform;
  45884. scale = transform.scale;
  45885. translate = transform.translate;
  45886. }
  45887. var arcs = topoJSONTopology.arcs;
  45888. if (transform) {
  45889. ol.format.TopoJSON.transformArcs_(arcs, scale, translate);
  45890. }
  45891. /** @type {Array.<ol.Feature>} */
  45892. var features = [];
  45893. var topoJSONFeatures = topoJSONTopology.objects;
  45894. var property = this.layerName_;
  45895. var objectName, feature;
  45896. for (objectName in topoJSONFeatures) {
  45897. if (this.layers_ && this.layers_.indexOf(objectName) == -1) {
  45898. continue;
  45899. }
  45900. if (topoJSONFeatures[objectName].type === 'GeometryCollection') {
  45901. feature = /** @type {TopoJSONGeometryCollection} */
  45902. (topoJSONFeatures[objectName]);
  45903. features.push.apply(features,
  45904. ol.format.TopoJSON.readFeaturesFromGeometryCollection_(
  45905. feature, arcs, scale, translate, property, objectName, opt_options));
  45906. } else {
  45907. feature = /** @type {TopoJSONGeometry} */
  45908. (topoJSONFeatures[objectName]);
  45909. features.push(ol.format.TopoJSON.readFeatureFromGeometry_(
  45910. feature, arcs, scale, translate, property, objectName, opt_options));
  45911. }
  45912. }
  45913. return features;
  45914. } else {
  45915. return [];
  45916. }
  45917. };
  45918. /**
  45919. * Apply a linear transform to array of arcs. The provided array of arcs is
  45920. * modified in place.
  45921. *
  45922. * @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs.
  45923. * @param {Array.<number>} scale Scale for each dimension.
  45924. * @param {Array.<number>} translate Translation for each dimension.
  45925. * @private
  45926. */
  45927. ol.format.TopoJSON.transformArcs_ = function(arcs, scale, translate) {
  45928. var i, ii;
  45929. for (i = 0, ii = arcs.length; i < ii; ++i) {
  45930. ol.format.TopoJSON.transformArc_(arcs[i], scale, translate);
  45931. }
  45932. };
  45933. /**
  45934. * Apply a linear transform to an arc. The provided arc is modified in place.
  45935. *
  45936. * @param {Array.<ol.Coordinate>} arc Arc.
  45937. * @param {Array.<number>} scale Scale for each dimension.
  45938. * @param {Array.<number>} translate Translation for each dimension.
  45939. * @private
  45940. */
  45941. ol.format.TopoJSON.transformArc_ = function(arc, scale, translate) {
  45942. var x = 0;
  45943. var y = 0;
  45944. var vertex;
  45945. var i, ii;
  45946. for (i = 0, ii = arc.length; i < ii; ++i) {
  45947. vertex = arc[i];
  45948. x += vertex[0];
  45949. y += vertex[1];
  45950. vertex[0] = x;
  45951. vertex[1] = y;
  45952. ol.format.TopoJSON.transformVertex_(vertex, scale, translate);
  45953. }
  45954. };
  45955. /**
  45956. * Apply a linear transform to a vertex. The provided vertex is modified in
  45957. * place.
  45958. *
  45959. * @param {ol.Coordinate} vertex Vertex.
  45960. * @param {Array.<number>} scale Scale for each dimension.
  45961. * @param {Array.<number>} translate Translation for each dimension.
  45962. * @private
  45963. */
  45964. ol.format.TopoJSON.transformVertex_ = function(vertex, scale, translate) {
  45965. vertex[0] = vertex[0] * scale[0] + translate[0];
  45966. vertex[1] = vertex[1] * scale[1] + translate[1];
  45967. };
  45968. /**
  45969. * Read the projection from a TopoJSON source.
  45970. *
  45971. * @param {Document|Node|Object|string} object Source.
  45972. * @return {ol.proj.Projection} Projection.
  45973. * @override
  45974. * @api
  45975. */
  45976. ol.format.TopoJSON.prototype.readProjection;
  45977. /**
  45978. * @inheritDoc
  45979. */
  45980. ol.format.TopoJSON.prototype.readProjectionFromObject = function(object) {
  45981. return this.defaultDataProjection;
  45982. };
  45983. /**
  45984. * @const
  45985. * @private
  45986. * @type {Object.<string, function(TopoJSONGeometry, Array, ...Array): ol.geom.Geometry>}
  45987. */
  45988. ol.format.TopoJSON.GEOMETRY_READERS_ = {
  45989. 'Point': ol.format.TopoJSON.readPointGeometry_,
  45990. 'LineString': ol.format.TopoJSON.readLineStringGeometry_,
  45991. 'Polygon': ol.format.TopoJSON.readPolygonGeometry_,
  45992. 'MultiPoint': ol.format.TopoJSON.readMultiPointGeometry_,
  45993. 'MultiLineString': ol.format.TopoJSON.readMultiLineStringGeometry_,
  45994. 'MultiPolygon': ol.format.TopoJSON.readMultiPolygonGeometry_
  45995. };
  45996. /**
  45997. * Not implemented.
  45998. * @inheritDoc
  45999. */
  46000. ol.format.TopoJSON.prototype.writeFeatureObject = function(feature, opt_options) {};
  46001. /**
  46002. * Not implemented.
  46003. * @inheritDoc
  46004. */
  46005. ol.format.TopoJSON.prototype.writeFeaturesObject = function(features, opt_options) {};
  46006. /**
  46007. * Not implemented.
  46008. * @inheritDoc
  46009. */
  46010. ol.format.TopoJSON.prototype.writeGeometryObject = function(geometry, opt_options) {};
  46011. /**
  46012. * Not implemented.
  46013. * @override
  46014. */
  46015. ol.format.TopoJSON.prototype.readGeometryFromObject = function() {};
  46016. /**
  46017. * Not implemented.
  46018. * @override
  46019. */
  46020. ol.format.TopoJSON.prototype.readFeatureFromObject = function() {};
  46021. goog.provide('ol.format.WFS');
  46022. goog.require('ol');
  46023. goog.require('ol.asserts');
  46024. goog.require('ol.format.GML2');
  46025. goog.require('ol.format.GML3');
  46026. goog.require('ol.format.GMLBase');
  46027. goog.require('ol.format.filter');
  46028. goog.require('ol.format.XMLFeature');
  46029. goog.require('ol.format.XSD');
  46030. goog.require('ol.geom.Geometry');
  46031. goog.require('ol.obj');
  46032. goog.require('ol.proj');
  46033. goog.require('ol.xml');
  46034. /**
  46035. * @classdesc
  46036. * Feature format for reading and writing data in the WFS format.
  46037. * By default, supports WFS version 1.1.0. You can pass a GML format
  46038. * as option if you want to read a WFS that contains GML2 (WFS 1.0.0).
  46039. * Also see {@link ol.format.GMLBase} which is used by this format.
  46040. *
  46041. * @constructor
  46042. * @param {olx.format.WFSOptions=} opt_options
  46043. * Optional configuration object.
  46044. * @extends {ol.format.XMLFeature}
  46045. * @api
  46046. */
  46047. ol.format.WFS = function(opt_options) {
  46048. var options = opt_options ? opt_options : {};
  46049. /**
  46050. * @private
  46051. * @type {Array.<string>|string|undefined}
  46052. */
  46053. this.featureType_ = options.featureType;
  46054. /**
  46055. * @private
  46056. * @type {Object.<string, string>|string|undefined}
  46057. */
  46058. this.featureNS_ = options.featureNS;
  46059. /**
  46060. * @private
  46061. * @type {ol.format.GMLBase}
  46062. */
  46063. this.gmlFormat_ = options.gmlFormat ?
  46064. options.gmlFormat : new ol.format.GML3();
  46065. /**
  46066. * @private
  46067. * @type {string}
  46068. */
  46069. this.schemaLocation_ = options.schemaLocation ?
  46070. options.schemaLocation :
  46071. ol.format.WFS.SCHEMA_LOCATIONS[ol.format.WFS.DEFAULT_VERSION];
  46072. ol.format.XMLFeature.call(this);
  46073. };
  46074. ol.inherits(ol.format.WFS, ol.format.XMLFeature);
  46075. /**
  46076. * @const
  46077. * @type {string}
  46078. */
  46079. ol.format.WFS.FEATURE_PREFIX = 'feature';
  46080. /**
  46081. * @const
  46082. * @type {string}
  46083. */
  46084. ol.format.WFS.XMLNS = 'http://www.w3.org/2000/xmlns/';
  46085. /**
  46086. * @const
  46087. * @type {string}
  46088. */
  46089. ol.format.WFS.OGCNS = 'http://www.opengis.net/ogc';
  46090. /**
  46091. * @const
  46092. * @type {string}
  46093. */
  46094. ol.format.WFS.WFSNS = 'http://www.opengis.net/wfs';
  46095. /**
  46096. * @const
  46097. * @type {string}
  46098. */
  46099. ol.format.WFS.FESNS = 'http://www.opengis.net/fes';
  46100. /**
  46101. * @const
  46102. * @type {Object.<string, string>}
  46103. */
  46104. ol.format.WFS.SCHEMA_LOCATIONS = {
  46105. '1.1.0': 'http://www.opengis.net/wfs ' +
  46106. 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
  46107. '1.0.0': 'http://www.opengis.net/wfs ' +
  46108. 'http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'
  46109. };
  46110. /**
  46111. * @const
  46112. * @type {string}
  46113. */
  46114. ol.format.WFS.DEFAULT_VERSION = '1.1.0';
  46115. /**
  46116. * @return {Array.<string>|string|undefined} featureType
  46117. */
  46118. ol.format.WFS.prototype.getFeatureType = function() {
  46119. return this.featureType_;
  46120. };
  46121. /**
  46122. * @param {Array.<string>|string|undefined} featureType Feature type(s) to parse.
  46123. */
  46124. ol.format.WFS.prototype.setFeatureType = function(featureType) {
  46125. this.featureType_ = featureType;
  46126. };
  46127. /**
  46128. * Read all features from a WFS FeatureCollection.
  46129. *
  46130. * @function
  46131. * @param {Document|Node|Object|string} source Source.
  46132. * @param {olx.format.ReadOptions=} opt_options Read options.
  46133. * @return {Array.<ol.Feature>} Features.
  46134. * @api
  46135. */
  46136. ol.format.WFS.prototype.readFeatures;
  46137. /**
  46138. * @inheritDoc
  46139. */
  46140. ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
  46141. var context = /** @type {ol.XmlNodeStackItem} */ ({
  46142. 'featureType': this.featureType_,
  46143. 'featureNS': this.featureNS_
  46144. });
  46145. ol.obj.assign(context, this.getReadOptions(node,
  46146. opt_options ? opt_options : {}));
  46147. var objectStack = [context];
  46148. this.gmlFormat_.FEATURE_COLLECTION_PARSERS[ol.format.GMLBase.GMLNS][
  46149. 'featureMember'] =
  46150. ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readFeaturesInternal);
  46151. var features = ol.xml.pushParseAndPop([],
  46152. this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
  46153. objectStack, this.gmlFormat_);
  46154. if (!features) {
  46155. features = [];
  46156. }
  46157. return features;
  46158. };
  46159. /**
  46160. * Read transaction response of the source.
  46161. *
  46162. * @param {Document|Node|Object|string} source Source.
  46163. * @return {ol.WFSTransactionResponse|undefined} Transaction response.
  46164. * @api
  46165. */
  46166. ol.format.WFS.prototype.readTransactionResponse = function(source) {
  46167. if (ol.xml.isDocument(source)) {
  46168. return this.readTransactionResponseFromDocument(
  46169. /** @type {Document} */ (source));
  46170. } else if (ol.xml.isNode(source)) {
  46171. return this.readTransactionResponseFromNode(/** @type {Node} */ (source));
  46172. } else if (typeof source === 'string') {
  46173. var doc = ol.xml.parse(source);
  46174. return this.readTransactionResponseFromDocument(doc);
  46175. } else {
  46176. return undefined;
  46177. }
  46178. };
  46179. /**
  46180. * Read feature collection metadata of the source.
  46181. *
  46182. * @param {Document|Node|Object|string} source Source.
  46183. * @return {ol.WFSFeatureCollectionMetadata|undefined}
  46184. * FeatureCollection metadata.
  46185. * @api
  46186. */
  46187. ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) {
  46188. if (ol.xml.isDocument(source)) {
  46189. return this.readFeatureCollectionMetadataFromDocument(
  46190. /** @type {Document} */ (source));
  46191. } else if (ol.xml.isNode(source)) {
  46192. return this.readFeatureCollectionMetadataFromNode(
  46193. /** @type {Node} */ (source));
  46194. } else if (typeof source === 'string') {
  46195. var doc = ol.xml.parse(source);
  46196. return this.readFeatureCollectionMetadataFromDocument(doc);
  46197. } else {
  46198. return undefined;
  46199. }
  46200. };
  46201. /**
  46202. * @param {Document} doc Document.
  46203. * @return {ol.WFSFeatureCollectionMetadata|undefined}
  46204. * FeatureCollection metadata.
  46205. */
  46206. ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument = function(doc) {
  46207. for (var n = doc.firstChild; n; n = n.nextSibling) {
  46208. if (n.nodeType == Node.ELEMENT_NODE) {
  46209. return this.readFeatureCollectionMetadataFromNode(n);
  46210. }
  46211. }
  46212. return undefined;
  46213. };
  46214. /**
  46215. * @const
  46216. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  46217. * @private
  46218. */
  46219. ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = {
  46220. 'http://www.opengis.net/gml': {
  46221. 'boundedBy': ol.xml.makeObjectPropertySetter(
  46222. ol.format.GMLBase.prototype.readGeometryElement, 'bounds')
  46223. }
  46224. };
  46225. /**
  46226. * @param {Node} node Node.
  46227. * @return {ol.WFSFeatureCollectionMetadata|undefined}
  46228. * FeatureCollection metadata.
  46229. */
  46230. ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
  46231. var result = {};
  46232. var value = ol.format.XSD.readNonNegativeIntegerString(
  46233. node.getAttribute('numberOfFeatures'));
  46234. result['numberOfFeatures'] = value;
  46235. return ol.xml.pushParseAndPop(
  46236. /** @type {ol.WFSFeatureCollectionMetadata} */ (result),
  46237. ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, [], this.gmlFormat_);
  46238. };
  46239. /**
  46240. * @const
  46241. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  46242. * @private
  46243. */
  46244. ol.format.WFS.TRANSACTION_SUMMARY_PARSERS_ = {
  46245. 'http://www.opengis.net/wfs': {
  46246. 'totalInserted': ol.xml.makeObjectPropertySetter(
  46247. ol.format.XSD.readNonNegativeInteger),
  46248. 'totalUpdated': ol.xml.makeObjectPropertySetter(
  46249. ol.format.XSD.readNonNegativeInteger),
  46250. 'totalDeleted': ol.xml.makeObjectPropertySetter(
  46251. ol.format.XSD.readNonNegativeInteger)
  46252. }
  46253. };
  46254. /**
  46255. * @param {Node} node Node.
  46256. * @param {Array.<*>} objectStack Object stack.
  46257. * @return {Object|undefined} Transaction Summary.
  46258. * @private
  46259. */
  46260. ol.format.WFS.readTransactionSummary_ = function(node, objectStack) {
  46261. return ol.xml.pushParseAndPop(
  46262. {}, ol.format.WFS.TRANSACTION_SUMMARY_PARSERS_, node, objectStack);
  46263. };
  46264. /**
  46265. * @const
  46266. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  46267. * @private
  46268. */
  46269. ol.format.WFS.OGC_FID_PARSERS_ = {
  46270. 'http://www.opengis.net/ogc': {
  46271. 'FeatureId': ol.xml.makeArrayPusher(function(node, objectStack) {
  46272. return node.getAttribute('fid');
  46273. })
  46274. }
  46275. };
  46276. /**
  46277. * @param {Node} node Node.
  46278. * @param {Array.<*>} objectStack Object stack.
  46279. * @private
  46280. */
  46281. ol.format.WFS.fidParser_ = function(node, objectStack) {
  46282. ol.xml.parseNode(ol.format.WFS.OGC_FID_PARSERS_, node, objectStack);
  46283. };
  46284. /**
  46285. * @const
  46286. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  46287. * @private
  46288. */
  46289. ol.format.WFS.INSERT_RESULTS_PARSERS_ = {
  46290. 'http://www.opengis.net/wfs': {
  46291. 'Feature': ol.format.WFS.fidParser_
  46292. }
  46293. };
  46294. /**
  46295. * @param {Node} node Node.
  46296. * @param {Array.<*>} objectStack Object stack.
  46297. * @return {Array.<string>|undefined} Insert results.
  46298. * @private
  46299. */
  46300. ol.format.WFS.readInsertResults_ = function(node, objectStack) {
  46301. return ol.xml.pushParseAndPop(
  46302. [], ol.format.WFS.INSERT_RESULTS_PARSERS_, node, objectStack);
  46303. };
  46304. /**
  46305. * @const
  46306. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  46307. * @private
  46308. */
  46309. ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_ = {
  46310. 'http://www.opengis.net/wfs': {
  46311. 'TransactionSummary': ol.xml.makeObjectPropertySetter(
  46312. ol.format.WFS.readTransactionSummary_, 'transactionSummary'),
  46313. 'InsertResults': ol.xml.makeObjectPropertySetter(
  46314. ol.format.WFS.readInsertResults_, 'insertIds')
  46315. }
  46316. };
  46317. /**
  46318. * @param {Document} doc Document.
  46319. * @return {ol.WFSTransactionResponse|undefined} Transaction response.
  46320. */
  46321. ol.format.WFS.prototype.readTransactionResponseFromDocument = function(doc) {
  46322. for (var n = doc.firstChild; n; n = n.nextSibling) {
  46323. if (n.nodeType == Node.ELEMENT_NODE) {
  46324. return this.readTransactionResponseFromNode(n);
  46325. }
  46326. }
  46327. return undefined;
  46328. };
  46329. /**
  46330. * @param {Node} node Node.
  46331. * @return {ol.WFSTransactionResponse|undefined} Transaction response.
  46332. */
  46333. ol.format.WFS.prototype.readTransactionResponseFromNode = function(node) {
  46334. return ol.xml.pushParseAndPop(
  46335. /** @type {ol.WFSTransactionResponse} */({}),
  46336. ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_, node, []);
  46337. };
  46338. /**
  46339. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  46340. * @private
  46341. */
  46342. ol.format.WFS.QUERY_SERIALIZERS_ = {
  46343. 'http://www.opengis.net/wfs': {
  46344. 'PropertyName': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
  46345. }
  46346. };
  46347. /**
  46348. * @param {Node} node Node.
  46349. * @param {ol.Feature} feature Feature.
  46350. * @param {Array.<*>} objectStack Node stack.
  46351. * @private
  46352. */
  46353. ol.format.WFS.writeFeature_ = function(node, feature, objectStack) {
  46354. var context = objectStack[objectStack.length - 1];
  46355. var featureType = context['featureType'];
  46356. var featureNS = context['featureNS'];
  46357. var gmlVersion = context['gmlVersion'];
  46358. var child = ol.xml.createElementNS(featureNS, featureType);
  46359. node.appendChild(child);
  46360. if (gmlVersion === 2) {
  46361. ol.format.GML2.prototype.writeFeatureElement(child, feature, objectStack);
  46362. } else {
  46363. ol.format.GML3.prototype.writeFeatureElement(child, feature, objectStack);
  46364. }
  46365. };
  46366. /**
  46367. * @param {Node} node Node.
  46368. * @param {number|string} fid Feature identifier.
  46369. * @param {Array.<*>} objectStack Node stack.
  46370. * @private
  46371. */
  46372. ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) {
  46373. var filter = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'Filter');
  46374. var child = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'FeatureId');
  46375. filter.appendChild(child);
  46376. child.setAttribute('fid', fid);
  46377. node.appendChild(filter);
  46378. };
  46379. /**
  46380. * @param {string|undefined} featurePrefix The prefix of the feature.
  46381. * @param {string} featureType The type of the feature.
  46382. * @returns {string} The value of the typeName property.
  46383. * @private
  46384. */
  46385. ol.format.WFS.getTypeName_ = function(featurePrefix, featureType) {
  46386. featurePrefix = featurePrefix ? featurePrefix :
  46387. ol.format.WFS.FEATURE_PREFIX;
  46388. var prefix = featurePrefix + ':';
  46389. // The featureType already contains the prefix.
  46390. if (featureType.indexOf(prefix) === 0) {
  46391. return featureType;
  46392. } else {
  46393. return prefix + featureType;
  46394. }
  46395. };
  46396. /**
  46397. * @param {Node} node Node.
  46398. * @param {ol.Feature} feature Feature.
  46399. * @param {Array.<*>} objectStack Node stack.
  46400. * @private
  46401. */
  46402. ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
  46403. var context = objectStack[objectStack.length - 1];
  46404. ol.asserts.assert(feature.getId() !== undefined, 26); // Features must have an id set
  46405. var featureType = context['featureType'];
  46406. var featurePrefix = context['featurePrefix'];
  46407. var featureNS = context['featureNS'];
  46408. var typeName = ol.format.WFS.getTypeName_(featurePrefix, featureType);
  46409. node.setAttribute('typeName', typeName);
  46410. ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
  46411. featureNS);
  46412. var fid = feature.getId();
  46413. if (fid !== undefined) {
  46414. ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack);
  46415. }
  46416. };
  46417. /**
  46418. * @param {Node} node Node.
  46419. * @param {ol.Feature} feature Feature.
  46420. * @param {Array.<*>} objectStack Node stack.
  46421. * @private
  46422. */
  46423. ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
  46424. var context = objectStack[objectStack.length - 1];
  46425. ol.asserts.assert(feature.getId() !== undefined, 27); // Features must have an id set
  46426. var featureType = context['featureType'];
  46427. var featurePrefix = context['featurePrefix'];
  46428. var featureNS = context['featureNS'];
  46429. var typeName = ol.format.WFS.getTypeName_(featurePrefix, featureType);
  46430. var geometryName = feature.getGeometryName();
  46431. node.setAttribute('typeName', typeName);
  46432. ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
  46433. featureNS);
  46434. var fid = feature.getId();
  46435. if (fid !== undefined) {
  46436. var keys = feature.getKeys();
  46437. var values = [];
  46438. for (var i = 0, ii = keys.length; i < ii; i++) {
  46439. var value = feature.get(keys[i]);
  46440. if (value !== undefined) {
  46441. var name = keys[i];
  46442. if (value instanceof ol.geom.Geometry) {
  46443. name = geometryName;
  46444. }
  46445. values.push({name: name, value: value});
  46446. }
  46447. }
  46448. ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */ (
  46449. {'gmlVersion': context['gmlVersion'], node: node,
  46450. 'hasZ': context['hasZ'], 'srsName': context['srsName']}),
  46451. ol.format.WFS.TRANSACTION_SERIALIZERS_,
  46452. ol.xml.makeSimpleNodeFactory('Property'), values,
  46453. objectStack);
  46454. ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack);
  46455. }
  46456. };
  46457. /**
  46458. * @param {Node} node Node.
  46459. * @param {Object} pair Property name and value.
  46460. * @param {Array.<*>} objectStack Node stack.
  46461. * @private
  46462. */
  46463. ol.format.WFS.writeProperty_ = function(node, pair, objectStack) {
  46464. var name = ol.xml.createElementNS(ol.format.WFS.WFSNS, 'Name');
  46465. var context = objectStack[objectStack.length - 1];
  46466. var gmlVersion = context['gmlVersion'];
  46467. node.appendChild(name);
  46468. ol.format.XSD.writeStringTextNode(name, pair.name);
  46469. if (pair.value !== undefined && pair.value !== null) {
  46470. var value = ol.xml.createElementNS(ol.format.WFS.WFSNS, 'Value');
  46471. node.appendChild(value);
  46472. if (pair.value instanceof ol.geom.Geometry) {
  46473. if (gmlVersion === 2) {
  46474. ol.format.GML2.prototype.writeGeometryElement(value,
  46475. pair.value, objectStack);
  46476. } else {
  46477. ol.format.GML3.prototype.writeGeometryElement(value,
  46478. pair.value, objectStack);
  46479. }
  46480. } else {
  46481. ol.format.XSD.writeStringTextNode(value, pair.value);
  46482. }
  46483. }
  46484. };
  46485. /**
  46486. * @param {Node} node Node.
  46487. * @param {{vendorId: string, safeToIgnore: boolean, value: string}}
  46488. * nativeElement The native element.
  46489. * @param {Array.<*>} objectStack Node stack.
  46490. * @private
  46491. */
  46492. ol.format.WFS.writeNative_ = function(node, nativeElement, objectStack) {
  46493. if (nativeElement.vendorId) {
  46494. node.setAttribute('vendorId', nativeElement.vendorId);
  46495. }
  46496. if (nativeElement.safeToIgnore !== undefined) {
  46497. node.setAttribute('safeToIgnore', nativeElement.safeToIgnore);
  46498. }
  46499. if (nativeElement.value !== undefined) {
  46500. ol.format.XSD.writeStringTextNode(node, nativeElement.value);
  46501. }
  46502. };
  46503. /**
  46504. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  46505. * @private
  46506. */
  46507. ol.format.WFS.TRANSACTION_SERIALIZERS_ = {
  46508. 'http://www.opengis.net/wfs': {
  46509. 'Insert': ol.xml.makeChildAppender(ol.format.WFS.writeFeature_),
  46510. 'Update': ol.xml.makeChildAppender(ol.format.WFS.writeUpdate_),
  46511. 'Delete': ol.xml.makeChildAppender(ol.format.WFS.writeDelete_),
  46512. 'Property': ol.xml.makeChildAppender(ol.format.WFS.writeProperty_),
  46513. 'Native': ol.xml.makeChildAppender(ol.format.WFS.writeNative_)
  46514. }
  46515. };
  46516. /**
  46517. * @param {Node} node Node.
  46518. * @param {string} featureType Feature type.
  46519. * @param {Array.<*>} objectStack Node stack.
  46520. * @private
  46521. */
  46522. ol.format.WFS.writeQuery_ = function(node, featureType, objectStack) {
  46523. var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  46524. var featurePrefix = context['featurePrefix'];
  46525. var featureNS = context['featureNS'];
  46526. var propertyNames = context['propertyNames'];
  46527. var srsName = context['srsName'];
  46528. var typeName;
  46529. // If feature prefix is not defined, we must not use the default prefix.
  46530. if (featurePrefix) {
  46531. typeName = ol.format.WFS.getTypeName_(featurePrefix, featureType);
  46532. } else {
  46533. typeName = featureType;
  46534. }
  46535. node.setAttribute('typeName', typeName);
  46536. if (srsName) {
  46537. node.setAttribute('srsName', srsName);
  46538. }
  46539. if (featureNS) {
  46540. ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
  46541. featureNS);
  46542. }
  46543. var item = /** @type {ol.XmlNodeStackItem} */ (ol.obj.assign({}, context));
  46544. item.node = node;
  46545. ol.xml.pushSerializeAndPop(item,
  46546. ol.format.WFS.QUERY_SERIALIZERS_,
  46547. ol.xml.makeSimpleNodeFactory('PropertyName'), propertyNames,
  46548. objectStack);
  46549. var filter = context['filter'];
  46550. if (filter) {
  46551. var child = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'Filter');
  46552. node.appendChild(child);
  46553. ol.format.WFS.writeFilterCondition_(child, filter, objectStack);
  46554. }
  46555. };
  46556. /**
  46557. * @param {Node} node Node.
  46558. * @param {ol.format.filter.Filter} filter Filter.
  46559. * @param {Array.<*>} objectStack Node stack.
  46560. * @private
  46561. */
  46562. ol.format.WFS.writeFilterCondition_ = function(node, filter, objectStack) {
  46563. /** @type {ol.XmlNodeStackItem} */
  46564. var item = {node: node};
  46565. ol.xml.pushSerializeAndPop(item,
  46566. ol.format.WFS.GETFEATURE_SERIALIZERS_,
  46567. ol.xml.makeSimpleNodeFactory(filter.getTagName()),
  46568. [filter], objectStack);
  46569. };
  46570. /**
  46571. * @param {Node} node Node.
  46572. * @param {ol.format.filter.Bbox} filter Filter.
  46573. * @param {Array.<*>} objectStack Node stack.
  46574. * @private
  46575. */
  46576. ol.format.WFS.writeBboxFilter_ = function(node, filter, objectStack) {
  46577. var context = objectStack[objectStack.length - 1];
  46578. context['srsName'] = filter.srsName;
  46579. ol.format.WFS.writeOgcPropertyName_(node, filter.geometryName);
  46580. ol.format.GML3.prototype.writeGeometryElement(node, filter.extent, objectStack);
  46581. };
  46582. /**
  46583. * @param {Node} node Node.
  46584. * @param {ol.format.filter.Contains} filter Filter.
  46585. * @param {Array.<*>} objectStack Node stack.
  46586. * @private
  46587. */
  46588. ol.format.WFS.writeContainsFilter_ = function(node, filter, objectStack) {
  46589. var context = objectStack[objectStack.length - 1];
  46590. context['srsName'] = filter.srsName;
  46591. ol.format.WFS.writeOgcPropertyName_(node, filter.geometryName);
  46592. ol.format.GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
  46593. };
  46594. /**
  46595. * @param {Node} node Node.
  46596. * @param {ol.format.filter.Intersects} filter Filter.
  46597. * @param {Array.<*>} objectStack Node stack.
  46598. * @private
  46599. */
  46600. ol.format.WFS.writeIntersectsFilter_ = function(node, filter, objectStack) {
  46601. var context = objectStack[objectStack.length - 1];
  46602. context['srsName'] = filter.srsName;
  46603. ol.format.WFS.writeOgcPropertyName_(node, filter.geometryName);
  46604. ol.format.GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
  46605. };
  46606. /**
  46607. * @param {Node} node Node.
  46608. * @param {ol.format.filter.Within} filter Filter.
  46609. * @param {Array.<*>} objectStack Node stack.
  46610. * @private
  46611. */
  46612. ol.format.WFS.writeWithinFilter_ = function(node, filter, objectStack) {
  46613. var context = objectStack[objectStack.length - 1];
  46614. context['srsName'] = filter.srsName;
  46615. ol.format.WFS.writeOgcPropertyName_(node, filter.geometryName);
  46616. ol.format.GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
  46617. };
  46618. /**
  46619. * @param {Node} node Node.
  46620. * @param {ol.format.filter.During} filter Filter.
  46621. * @param {Array.<*>} objectStack Node stack.
  46622. * @private
  46623. */
  46624. ol.format.WFS.writeDuringFilter_ = function(node, filter, objectStack) {
  46625. var valueReference = ol.xml.createElementNS(ol.format.WFS.FESNS, 'ValueReference');
  46626. ol.format.XSD.writeStringTextNode(valueReference, filter.propertyName);
  46627. node.appendChild(valueReference);
  46628. var timePeriod = ol.xml.createElementNS(ol.format.GMLBase.GMLNS, 'TimePeriod');
  46629. node.appendChild(timePeriod);
  46630. var begin = ol.xml.createElementNS(ol.format.GMLBase.GMLNS, 'begin');
  46631. timePeriod.appendChild(begin);
  46632. ol.format.WFS.writeTimeInstant_(begin, filter.begin);
  46633. var end = ol.xml.createElementNS(ol.format.GMLBase.GMLNS, 'end');
  46634. timePeriod.appendChild(end);
  46635. ol.format.WFS.writeTimeInstant_(end, filter.end);
  46636. };
  46637. /**
  46638. * @param {Node} node Node.
  46639. * @param {ol.format.filter.LogicalNary} filter Filter.
  46640. * @param {Array.<*>} objectStack Node stack.
  46641. * @private
  46642. */
  46643. ol.format.WFS.writeLogicalFilter_ = function(node, filter, objectStack) {
  46644. /** @type {ol.XmlNodeStackItem} */
  46645. var item = {node: node};
  46646. var conditions = filter.conditions;
  46647. for (var i = 0, ii = conditions.length; i < ii; ++i) {
  46648. var condition = conditions[i];
  46649. ol.xml.pushSerializeAndPop(item,
  46650. ol.format.WFS.GETFEATURE_SERIALIZERS_,
  46651. ol.xml.makeSimpleNodeFactory(condition.getTagName()),
  46652. [condition], objectStack);
  46653. }
  46654. };
  46655. /**
  46656. * @param {Node} node Node.
  46657. * @param {ol.format.filter.Not} filter Filter.
  46658. * @param {Array.<*>} objectStack Node stack.
  46659. * @private
  46660. */
  46661. ol.format.WFS.writeNotFilter_ = function(node, filter, objectStack) {
  46662. /** @type {ol.XmlNodeStackItem} */
  46663. var item = {node: node};
  46664. var condition = filter.condition;
  46665. ol.xml.pushSerializeAndPop(item,
  46666. ol.format.WFS.GETFEATURE_SERIALIZERS_,
  46667. ol.xml.makeSimpleNodeFactory(condition.getTagName()),
  46668. [condition], objectStack);
  46669. };
  46670. /**
  46671. * @param {Node} node Node.
  46672. * @param {ol.format.filter.ComparisonBinary} filter Filter.
  46673. * @param {Array.<*>} objectStack Node stack.
  46674. * @private
  46675. */
  46676. ol.format.WFS.writeComparisonFilter_ = function(node, filter, objectStack) {
  46677. if (filter.matchCase !== undefined) {
  46678. node.setAttribute('matchCase', filter.matchCase.toString());
  46679. }
  46680. ol.format.WFS.writeOgcPropertyName_(node, filter.propertyName);
  46681. ol.format.WFS.writeOgcLiteral_(node, '' + filter.expression);
  46682. };
  46683. /**
  46684. * @param {Node} node Node.
  46685. * @param {ol.format.filter.IsNull} filter Filter.
  46686. * @param {Array.<*>} objectStack Node stack.
  46687. * @private
  46688. */
  46689. ol.format.WFS.writeIsNullFilter_ = function(node, filter, objectStack) {
  46690. ol.format.WFS.writeOgcPropertyName_(node, filter.propertyName);
  46691. };
  46692. /**
  46693. * @param {Node} node Node.
  46694. * @param {ol.format.filter.IsBetween} filter Filter.
  46695. * @param {Array.<*>} objectStack Node stack.
  46696. * @private
  46697. */
  46698. ol.format.WFS.writeIsBetweenFilter_ = function(node, filter, objectStack) {
  46699. ol.format.WFS.writeOgcPropertyName_(node, filter.propertyName);
  46700. var lowerBoundary = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'LowerBoundary');
  46701. node.appendChild(lowerBoundary);
  46702. ol.format.WFS.writeOgcLiteral_(lowerBoundary, '' + filter.lowerBoundary);
  46703. var upperBoundary = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'UpperBoundary');
  46704. node.appendChild(upperBoundary);
  46705. ol.format.WFS.writeOgcLiteral_(upperBoundary, '' + filter.upperBoundary);
  46706. };
  46707. /**
  46708. * @param {Node} node Node.
  46709. * @param {ol.format.filter.IsLike} filter Filter.
  46710. * @param {Array.<*>} objectStack Node stack.
  46711. * @private
  46712. */
  46713. ol.format.WFS.writeIsLikeFilter_ = function(node, filter, objectStack) {
  46714. node.setAttribute('wildCard', filter.wildCard);
  46715. node.setAttribute('singleChar', filter.singleChar);
  46716. node.setAttribute('escapeChar', filter.escapeChar);
  46717. if (filter.matchCase !== undefined) {
  46718. node.setAttribute('matchCase', filter.matchCase.toString());
  46719. }
  46720. ol.format.WFS.writeOgcPropertyName_(node, filter.propertyName);
  46721. ol.format.WFS.writeOgcLiteral_(node, '' + filter.pattern);
  46722. };
  46723. /**
  46724. * @param {string} tagName Tag name.
  46725. * @param {Node} node Node.
  46726. * @param {string} value Value.
  46727. * @private
  46728. */
  46729. ol.format.WFS.writeOgcExpression_ = function(tagName, node, value) {
  46730. var property = ol.xml.createElementNS(ol.format.WFS.OGCNS, tagName);
  46731. ol.format.XSD.writeStringTextNode(property, value);
  46732. node.appendChild(property);
  46733. };
  46734. /**
  46735. * @param {Node} node Node.
  46736. * @param {string} value PropertyName value.
  46737. * @private
  46738. */
  46739. ol.format.WFS.writeOgcPropertyName_ = function(node, value) {
  46740. ol.format.WFS.writeOgcExpression_('PropertyName', node, value);
  46741. };
  46742. /**
  46743. * @param {Node} node Node.
  46744. * @param {string} value PropertyName value.
  46745. * @private
  46746. */
  46747. ol.format.WFS.writeOgcLiteral_ = function(node, value) {
  46748. ol.format.WFS.writeOgcExpression_('Literal', node, value);
  46749. };
  46750. /**
  46751. * @param {Node} node Node.
  46752. * @param {string} time PropertyName value.
  46753. * @private
  46754. */
  46755. ol.format.WFS.writeTimeInstant_ = function(node, time) {
  46756. var timeInstant = ol.xml.createElementNS(ol.format.GMLBase.GMLNS, 'TimeInstant');
  46757. node.appendChild(timeInstant);
  46758. var timePosition = ol.xml.createElementNS(ol.format.GMLBase.GMLNS, 'timePosition');
  46759. timeInstant.appendChild(timePosition);
  46760. ol.format.XSD.writeStringTextNode(timePosition, time);
  46761. };
  46762. /**
  46763. * @type {Object.<string, Object.<string, ol.XmlSerializer>>}
  46764. * @private
  46765. */
  46766. ol.format.WFS.GETFEATURE_SERIALIZERS_ = {
  46767. 'http://www.opengis.net/wfs': {
  46768. 'Query': ol.xml.makeChildAppender(ol.format.WFS.writeQuery_)
  46769. },
  46770. 'http://www.opengis.net/ogc': {
  46771. 'During': ol.xml.makeChildAppender(ol.format.WFS.writeDuringFilter_),
  46772. 'And': ol.xml.makeChildAppender(ol.format.WFS.writeLogicalFilter_),
  46773. 'Or': ol.xml.makeChildAppender(ol.format.WFS.writeLogicalFilter_),
  46774. 'Not': ol.xml.makeChildAppender(ol.format.WFS.writeNotFilter_),
  46775. 'BBOX': ol.xml.makeChildAppender(ol.format.WFS.writeBboxFilter_),
  46776. 'Contains': ol.xml.makeChildAppender(ol.format.WFS.writeContainsFilter_),
  46777. 'Intersects': ol.xml.makeChildAppender(ol.format.WFS.writeIntersectsFilter_),
  46778. 'Within': ol.xml.makeChildAppender(ol.format.WFS.writeWithinFilter_),
  46779. 'PropertyIsEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
  46780. 'PropertyIsNotEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
  46781. 'PropertyIsLessThan': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
  46782. 'PropertyIsLessThanOrEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
  46783. 'PropertyIsGreaterThan': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
  46784. 'PropertyIsGreaterThanOrEqualTo': ol.xml.makeChildAppender(ol.format.WFS.writeComparisonFilter_),
  46785. 'PropertyIsNull': ol.xml.makeChildAppender(ol.format.WFS.writeIsNullFilter_),
  46786. 'PropertyIsBetween': ol.xml.makeChildAppender(ol.format.WFS.writeIsBetweenFilter_),
  46787. 'PropertyIsLike': ol.xml.makeChildAppender(ol.format.WFS.writeIsLikeFilter_)
  46788. }
  46789. };
  46790. /**
  46791. * Encode filter as WFS `Filter` and return the Node.
  46792. *
  46793. * @param {ol.format.filter.Filter} filter Filter.
  46794. * @return {Node} Result.
  46795. * @api
  46796. */
  46797. ol.format.WFS.writeFilter = function(filter) {
  46798. var child = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'Filter');
  46799. ol.format.WFS.writeFilterCondition_(child, filter, []);
  46800. return child;
  46801. };
  46802. /**
  46803. * @param {Node} node Node.
  46804. * @param {Array.<string>} featureTypes Feature types.
  46805. * @param {Array.<*>} objectStack Node stack.
  46806. * @private
  46807. */
  46808. ol.format.WFS.writeGetFeature_ = function(node, featureTypes, objectStack) {
  46809. var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
  46810. var item = /** @type {ol.XmlNodeStackItem} */ (ol.obj.assign({}, context));
  46811. item.node = node;
  46812. ol.xml.pushSerializeAndPop(item,
  46813. ol.format.WFS.GETFEATURE_SERIALIZERS_,
  46814. ol.xml.makeSimpleNodeFactory('Query'), featureTypes,
  46815. objectStack);
  46816. };
  46817. /**
  46818. * Encode format as WFS `GetFeature` and return the Node.
  46819. *
  46820. * @param {olx.format.WFSWriteGetFeatureOptions} options Options.
  46821. * @return {Node} Result.
  46822. * @api
  46823. */
  46824. ol.format.WFS.prototype.writeGetFeature = function(options) {
  46825. var node = ol.xml.createElementNS(ol.format.WFS.WFSNS, 'GetFeature');
  46826. node.setAttribute('service', 'WFS');
  46827. node.setAttribute('version', '1.1.0');
  46828. var filter;
  46829. if (options) {
  46830. if (options.handle) {
  46831. node.setAttribute('handle', options.handle);
  46832. }
  46833. if (options.outputFormat) {
  46834. node.setAttribute('outputFormat', options.outputFormat);
  46835. }
  46836. if (options.maxFeatures !== undefined) {
  46837. node.setAttribute('maxFeatures', options.maxFeatures);
  46838. }
  46839. if (options.resultType) {
  46840. node.setAttribute('resultType', options.resultType);
  46841. }
  46842. if (options.startIndex !== undefined) {
  46843. node.setAttribute('startIndex', options.startIndex);
  46844. }
  46845. if (options.count !== undefined) {
  46846. node.setAttribute('count', options.count);
  46847. }
  46848. filter = options.filter;
  46849. if (options.bbox) {
  46850. ol.asserts.assert(options.geometryName,
  46851. 12); // `options.geometryName` must also be provided when `options.bbox` is set
  46852. var bbox = ol.format.filter.bbox(
  46853. /** @type {string} */ (options.geometryName), options.bbox, options.srsName);
  46854. if (filter) {
  46855. // if bbox and filter are both set, combine the two into a single filter
  46856. filter = ol.format.filter.and(filter, bbox);
  46857. } else {
  46858. filter = bbox;
  46859. }
  46860. }
  46861. }
  46862. ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
  46863. 'xsi:schemaLocation', this.schemaLocation_);
  46864. /** @type {ol.XmlNodeStackItem} */
  46865. var context = {
  46866. node: node,
  46867. 'srsName': options.srsName,
  46868. 'featureNS': options.featureNS ? options.featureNS : this.featureNS_,
  46869. 'featurePrefix': options.featurePrefix,
  46870. 'geometryName': options.geometryName,
  46871. 'filter': filter,
  46872. 'propertyNames': options.propertyNames ? options.propertyNames : []
  46873. };
  46874. ol.asserts.assert(Array.isArray(options.featureTypes),
  46875. 11); // `options.featureTypes` should be an Array
  46876. ol.format.WFS.writeGetFeature_(node, /** @type {!Array.<string>} */ (options.featureTypes), [context]);
  46877. return node;
  46878. };
  46879. /**
  46880. * Encode format as WFS `Transaction` and return the Node.
  46881. *
  46882. * @param {Array.<ol.Feature>} inserts The features to insert.
  46883. * @param {Array.<ol.Feature>} updates The features to update.
  46884. * @param {Array.<ol.Feature>} deletes The features to delete.
  46885. * @param {olx.format.WFSWriteTransactionOptions} options Write options.
  46886. * @return {Node} Result.
  46887. * @api
  46888. */
  46889. ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
  46890. options) {
  46891. var objectStack = [];
  46892. var node = ol.xml.createElementNS(ol.format.WFS.WFSNS, 'Transaction');
  46893. var version = options.version ?
  46894. options.version : ol.format.WFS.DEFAULT_VERSION;
  46895. var gmlVersion = version === '1.0.0' ? 2 : 3;
  46896. node.setAttribute('service', 'WFS');
  46897. node.setAttribute('version', version);
  46898. var baseObj;
  46899. /** @type {ol.XmlNodeStackItem} */
  46900. var obj;
  46901. if (options) {
  46902. baseObj = options.gmlOptions ? options.gmlOptions : {};
  46903. if (options.handle) {
  46904. node.setAttribute('handle', options.handle);
  46905. }
  46906. }
  46907. var schemaLocation = ol.format.WFS.SCHEMA_LOCATIONS[version];
  46908. ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
  46909. 'xsi:schemaLocation', schemaLocation);
  46910. var featurePrefix = options.featurePrefix ? options.featurePrefix : ol.format.WFS.FEATURE_PREFIX;
  46911. if (inserts) {
  46912. obj = {node: node, 'featureNS': options.featureNS,
  46913. 'featureType': options.featureType, 'featurePrefix': featurePrefix,
  46914. 'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName};
  46915. ol.obj.assign(obj, baseObj);
  46916. ol.xml.pushSerializeAndPop(obj,
  46917. ol.format.WFS.TRANSACTION_SERIALIZERS_,
  46918. ol.xml.makeSimpleNodeFactory('Insert'), inserts,
  46919. objectStack);
  46920. }
  46921. if (updates) {
  46922. obj = {node: node, 'featureNS': options.featureNS,
  46923. 'featureType': options.featureType, 'featurePrefix': featurePrefix,
  46924. 'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName};
  46925. ol.obj.assign(obj, baseObj);
  46926. ol.xml.pushSerializeAndPop(obj,
  46927. ol.format.WFS.TRANSACTION_SERIALIZERS_,
  46928. ol.xml.makeSimpleNodeFactory('Update'), updates,
  46929. objectStack);
  46930. }
  46931. if (deletes) {
  46932. ol.xml.pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
  46933. 'featureType': options.featureType, 'featurePrefix': featurePrefix,
  46934. 'gmlVersion': gmlVersion, 'srsName': options.srsName},
  46935. ol.format.WFS.TRANSACTION_SERIALIZERS_,
  46936. ol.xml.makeSimpleNodeFactory('Delete'), deletes,
  46937. objectStack);
  46938. }
  46939. if (options.nativeElements) {
  46940. ol.xml.pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
  46941. 'featureType': options.featureType, 'featurePrefix': featurePrefix,
  46942. 'gmlVersion': gmlVersion, 'srsName': options.srsName},
  46943. ol.format.WFS.TRANSACTION_SERIALIZERS_,
  46944. ol.xml.makeSimpleNodeFactory('Native'), options.nativeElements,
  46945. objectStack);
  46946. }
  46947. return node;
  46948. };
  46949. /**
  46950. * Read the projection from a WFS source.
  46951. *
  46952. * @function
  46953. * @param {Document|Node|Object|string} source Source.
  46954. * @return {?ol.proj.Projection} Projection.
  46955. * @api
  46956. */
  46957. ol.format.WFS.prototype.readProjection;
  46958. /**
  46959. * @inheritDoc
  46960. */
  46961. ol.format.WFS.prototype.readProjectionFromDocument = function(doc) {
  46962. for (var n = doc.firstChild; n; n = n.nextSibling) {
  46963. if (n.nodeType == Node.ELEMENT_NODE) {
  46964. return this.readProjectionFromNode(n);
  46965. }
  46966. }
  46967. return null;
  46968. };
  46969. /**
  46970. * @inheritDoc
  46971. */
  46972. ol.format.WFS.prototype.readProjectionFromNode = function(node) {
  46973. if (node.firstElementChild &&
  46974. node.firstElementChild.firstElementChild) {
  46975. node = node.firstElementChild.firstElementChild;
  46976. for (var n = node.firstElementChild; n; n = n.nextElementSibling) {
  46977. if (!(n.childNodes.length === 0 ||
  46978. (n.childNodes.length === 1 &&
  46979. n.firstChild.nodeType === 3))) {
  46980. var objectStack = [{}];
  46981. this.gmlFormat_.readGeometryElement(n, objectStack);
  46982. return ol.proj.get(objectStack.pop().srsName);
  46983. }
  46984. }
  46985. }
  46986. return null;
  46987. };
  46988. goog.provide('ol.format.WKT');
  46989. goog.require('ol');
  46990. goog.require('ol.Feature');
  46991. goog.require('ol.format.Feature');
  46992. goog.require('ol.format.TextFeature');
  46993. goog.require('ol.geom.GeometryCollection');
  46994. goog.require('ol.geom.GeometryType');
  46995. goog.require('ol.geom.GeometryLayout');
  46996. goog.require('ol.geom.LineString');
  46997. goog.require('ol.geom.MultiLineString');
  46998. goog.require('ol.geom.MultiPoint');
  46999. goog.require('ol.geom.MultiPolygon');
  47000. goog.require('ol.geom.Point');
  47001. goog.require('ol.geom.Polygon');
  47002. goog.require('ol.geom.SimpleGeometry');
  47003. /**
  47004. * @classdesc
  47005. * Geometry format for reading and writing data in the `WellKnownText` (WKT)
  47006. * format.
  47007. *
  47008. * @constructor
  47009. * @extends {ol.format.TextFeature}
  47010. * @param {olx.format.WKTOptions=} opt_options Options.
  47011. * @api
  47012. */
  47013. ol.format.WKT = function(opt_options) {
  47014. var options = opt_options ? opt_options : {};
  47015. ol.format.TextFeature.call(this);
  47016. /**
  47017. * Split GeometryCollection into multiple features.
  47018. * @type {boolean}
  47019. * @private
  47020. */
  47021. this.splitCollection_ = options.splitCollection !== undefined ?
  47022. options.splitCollection : false;
  47023. };
  47024. ol.inherits(ol.format.WKT, ol.format.TextFeature);
  47025. /**
  47026. * @const
  47027. * @type {string}
  47028. */
  47029. ol.format.WKT.EMPTY = 'EMPTY';
  47030. /**
  47031. * @const
  47032. * @type {string}
  47033. */
  47034. ol.format.WKT.Z = 'Z';
  47035. /**
  47036. * @const
  47037. * @type {string}
  47038. */
  47039. ol.format.WKT.M = 'M';
  47040. /**
  47041. * @const
  47042. * @type {string}
  47043. */
  47044. ol.format.WKT.ZM = 'ZM';
  47045. /**
  47046. * @param {ol.geom.Point} geom Point geometry.
  47047. * @return {string} Coordinates part of Point as WKT.
  47048. * @private
  47049. */
  47050. ol.format.WKT.encodePointGeometry_ = function(geom) {
  47051. var coordinates = geom.getCoordinates();
  47052. if (coordinates.length === 0) {
  47053. return '';
  47054. }
  47055. return coordinates.join(' ');
  47056. };
  47057. /**
  47058. * @param {ol.geom.MultiPoint} geom MultiPoint geometry.
  47059. * @return {string} Coordinates part of MultiPoint as WKT.
  47060. * @private
  47061. */
  47062. ol.format.WKT.encodeMultiPointGeometry_ = function(geom) {
  47063. var array = [];
  47064. var components = geom.getPoints();
  47065. for (var i = 0, ii = components.length; i < ii; ++i) {
  47066. array.push('(' + ol.format.WKT.encodePointGeometry_(components[i]) + ')');
  47067. }
  47068. return array.join(',');
  47069. };
  47070. /**
  47071. * @param {ol.geom.GeometryCollection} geom GeometryCollection geometry.
  47072. * @return {string} Coordinates part of GeometryCollection as WKT.
  47073. * @private
  47074. */
  47075. ol.format.WKT.encodeGeometryCollectionGeometry_ = function(geom) {
  47076. var array = [];
  47077. var geoms = geom.getGeometries();
  47078. for (var i = 0, ii = geoms.length; i < ii; ++i) {
  47079. array.push(ol.format.WKT.encode_(geoms[i]));
  47080. }
  47081. return array.join(',');
  47082. };
  47083. /**
  47084. * @param {ol.geom.LineString|ol.geom.LinearRing} geom LineString geometry.
  47085. * @return {string} Coordinates part of LineString as WKT.
  47086. * @private
  47087. */
  47088. ol.format.WKT.encodeLineStringGeometry_ = function(geom) {
  47089. var coordinates = geom.getCoordinates();
  47090. var array = [];
  47091. for (var i = 0, ii = coordinates.length; i < ii; ++i) {
  47092. array.push(coordinates[i].join(' '));
  47093. }
  47094. return array.join(',');
  47095. };
  47096. /**
  47097. * @param {ol.geom.MultiLineString} geom MultiLineString geometry.
  47098. * @return {string} Coordinates part of MultiLineString as WKT.
  47099. * @private
  47100. */
  47101. ol.format.WKT.encodeMultiLineStringGeometry_ = function(geom) {
  47102. var array = [];
  47103. var components = geom.getLineStrings();
  47104. for (var i = 0, ii = components.length; i < ii; ++i) {
  47105. array.push('(' + ol.format.WKT.encodeLineStringGeometry_(
  47106. components[i]) + ')');
  47107. }
  47108. return array.join(',');
  47109. };
  47110. /**
  47111. * @param {ol.geom.Polygon} geom Polygon geometry.
  47112. * @return {string} Coordinates part of Polygon as WKT.
  47113. * @private
  47114. */
  47115. ol.format.WKT.encodePolygonGeometry_ = function(geom) {
  47116. var array = [];
  47117. var rings = geom.getLinearRings();
  47118. for (var i = 0, ii = rings.length; i < ii; ++i) {
  47119. array.push('(' + ol.format.WKT.encodeLineStringGeometry_(
  47120. rings[i]) + ')');
  47121. }
  47122. return array.join(',');
  47123. };
  47124. /**
  47125. * @param {ol.geom.MultiPolygon} geom MultiPolygon geometry.
  47126. * @return {string} Coordinates part of MultiPolygon as WKT.
  47127. * @private
  47128. */
  47129. ol.format.WKT.encodeMultiPolygonGeometry_ = function(geom) {
  47130. var array = [];
  47131. var components = geom.getPolygons();
  47132. for (var i = 0, ii = components.length; i < ii; ++i) {
  47133. array.push('(' + ol.format.WKT.encodePolygonGeometry_(
  47134. components[i]) + ')');
  47135. }
  47136. return array.join(',');
  47137. };
  47138. /**
  47139. * @param {ol.geom.SimpleGeometry} geom SimpleGeometry geometry.
  47140. * @return {string} Potential dimensional information for WKT type.
  47141. * @private
  47142. */
  47143. ol.format.WKT.encodeGeometryLayout_ = function(geom) {
  47144. var layout = geom.getLayout();
  47145. var dimInfo = '';
  47146. if (layout === ol.geom.GeometryLayout.XYZ || layout === ol.geom.GeometryLayout.XYZM) {
  47147. dimInfo += ol.format.WKT.Z;
  47148. }
  47149. if (layout === ol.geom.GeometryLayout.XYM || layout === ol.geom.GeometryLayout.XYZM) {
  47150. dimInfo += ol.format.WKT.M;
  47151. }
  47152. return dimInfo;
  47153. };
  47154. /**
  47155. * Encode a geometry as WKT.
  47156. * @param {ol.geom.Geometry} geom The geometry to encode.
  47157. * @return {string} WKT string for the geometry.
  47158. * @private
  47159. */
  47160. ol.format.WKT.encode_ = function(geom) {
  47161. var type = geom.getType();
  47162. var geometryEncoder = ol.format.WKT.GeometryEncoder_[type];
  47163. var enc = geometryEncoder(geom);
  47164. type = type.toUpperCase();
  47165. if (geom instanceof ol.geom.SimpleGeometry) {
  47166. var dimInfo = ol.format.WKT.encodeGeometryLayout_(geom);
  47167. if (dimInfo.length > 0) {
  47168. type += ' ' + dimInfo;
  47169. }
  47170. }
  47171. if (enc.length === 0) {
  47172. return type + ' ' + ol.format.WKT.EMPTY;
  47173. }
  47174. return type + '(' + enc + ')';
  47175. };
  47176. /**
  47177. * @const
  47178. * @type {Object.<string, function(ol.geom.Geometry): string>}
  47179. * @private
  47180. */
  47181. ol.format.WKT.GeometryEncoder_ = {
  47182. 'Point': ol.format.WKT.encodePointGeometry_,
  47183. 'LineString': ol.format.WKT.encodeLineStringGeometry_,
  47184. 'Polygon': ol.format.WKT.encodePolygonGeometry_,
  47185. 'MultiPoint': ol.format.WKT.encodeMultiPointGeometry_,
  47186. 'MultiLineString': ol.format.WKT.encodeMultiLineStringGeometry_,
  47187. 'MultiPolygon': ol.format.WKT.encodeMultiPolygonGeometry_,
  47188. 'GeometryCollection': ol.format.WKT.encodeGeometryCollectionGeometry_
  47189. };
  47190. /**
  47191. * Parse a WKT string.
  47192. * @param {string} wkt WKT string.
  47193. * @return {ol.geom.Geometry|undefined}
  47194. * The geometry created.
  47195. * @private
  47196. */
  47197. ol.format.WKT.prototype.parse_ = function(wkt) {
  47198. var lexer = new ol.format.WKT.Lexer(wkt);
  47199. var parser = new ol.format.WKT.Parser(lexer);
  47200. return parser.parse();
  47201. };
  47202. /**
  47203. * Read a feature from a WKT source.
  47204. *
  47205. * @function
  47206. * @param {Document|Node|Object|string} source Source.
  47207. * @param {olx.format.ReadOptions=} opt_options Read options.
  47208. * @return {ol.Feature} Feature.
  47209. * @api
  47210. */
  47211. ol.format.WKT.prototype.readFeature;
  47212. /**
  47213. * @inheritDoc
  47214. */
  47215. ol.format.WKT.prototype.readFeatureFromText = function(text, opt_options) {
  47216. var geom = this.readGeometryFromText(text, opt_options);
  47217. if (geom) {
  47218. var feature = new ol.Feature();
  47219. feature.setGeometry(geom);
  47220. return feature;
  47221. }
  47222. return null;
  47223. };
  47224. /**
  47225. * Read all features from a WKT source.
  47226. *
  47227. * @function
  47228. * @param {Document|Node|Object|string} source Source.
  47229. * @param {olx.format.ReadOptions=} opt_options Read options.
  47230. * @return {Array.<ol.Feature>} Features.
  47231. * @api
  47232. */
  47233. ol.format.WKT.prototype.readFeatures;
  47234. /**
  47235. * @inheritDoc
  47236. */
  47237. ol.format.WKT.prototype.readFeaturesFromText = function(text, opt_options) {
  47238. var geometries = [];
  47239. var geometry = this.readGeometryFromText(text, opt_options);
  47240. if (this.splitCollection_ &&
  47241. geometry.getType() == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
  47242. geometries = (/** @type {ol.geom.GeometryCollection} */ (geometry))
  47243. .getGeometriesArray();
  47244. } else {
  47245. geometries = [geometry];
  47246. }
  47247. var feature, features = [];
  47248. for (var i = 0, ii = geometries.length; i < ii; ++i) {
  47249. feature = new ol.Feature();
  47250. feature.setGeometry(geometries[i]);
  47251. features.push(feature);
  47252. }
  47253. return features;
  47254. };
  47255. /**
  47256. * Read a single geometry from a WKT source.
  47257. *
  47258. * @function
  47259. * @param {Document|Node|Object|string} source Source.
  47260. * @param {olx.format.ReadOptions=} opt_options Read options.
  47261. * @return {ol.geom.Geometry} Geometry.
  47262. * @api
  47263. */
  47264. ol.format.WKT.prototype.readGeometry;
  47265. /**
  47266. * @inheritDoc
  47267. */
  47268. ol.format.WKT.prototype.readGeometryFromText = function(text, opt_options) {
  47269. var geometry = this.parse_(text);
  47270. if (geometry) {
  47271. return /** @type {ol.geom.Geometry} */ (
  47272. ol.format.Feature.transformWithOptions(geometry, false, opt_options));
  47273. } else {
  47274. return null;
  47275. }
  47276. };
  47277. /**
  47278. * Encode a feature as a WKT string.
  47279. *
  47280. * @function
  47281. * @param {ol.Feature} feature Feature.
  47282. * @param {olx.format.WriteOptions=} opt_options Write options.
  47283. * @return {string} WKT string.
  47284. * @api
  47285. */
  47286. ol.format.WKT.prototype.writeFeature;
  47287. /**
  47288. * @inheritDoc
  47289. */
  47290. ol.format.WKT.prototype.writeFeatureText = function(feature, opt_options) {
  47291. var geometry = feature.getGeometry();
  47292. if (geometry) {
  47293. return this.writeGeometryText(geometry, opt_options);
  47294. }
  47295. return '';
  47296. };
  47297. /**
  47298. * Encode an array of features as a WKT string.
  47299. *
  47300. * @function
  47301. * @param {Array.<ol.Feature>} features Features.
  47302. * @param {olx.format.WriteOptions=} opt_options Write options.
  47303. * @return {string} WKT string.
  47304. * @api
  47305. */
  47306. ol.format.WKT.prototype.writeFeatures;
  47307. /**
  47308. * @inheritDoc
  47309. */
  47310. ol.format.WKT.prototype.writeFeaturesText = function(features, opt_options) {
  47311. if (features.length == 1) {
  47312. return this.writeFeatureText(features[0], opt_options);
  47313. }
  47314. var geometries = [];
  47315. for (var i = 0, ii = features.length; i < ii; ++i) {
  47316. geometries.push(features[i].getGeometry());
  47317. }
  47318. var collection = new ol.geom.GeometryCollection(geometries);
  47319. return this.writeGeometryText(collection, opt_options);
  47320. };
  47321. /**
  47322. * Write a single geometry as a WKT string.
  47323. *
  47324. * @function
  47325. * @param {ol.geom.Geometry} geometry Geometry.
  47326. * @param {olx.format.WriteOptions=} opt_options Write options.
  47327. * @return {string} WKT string.
  47328. * @api
  47329. */
  47330. ol.format.WKT.prototype.writeGeometry;
  47331. /**
  47332. * @inheritDoc
  47333. */
  47334. ol.format.WKT.prototype.writeGeometryText = function(geometry, opt_options) {
  47335. return ol.format.WKT.encode_(/** @type {ol.geom.Geometry} */ (
  47336. ol.format.Feature.transformWithOptions(geometry, true, opt_options)));
  47337. };
  47338. /**
  47339. * @const
  47340. * @enum {number}
  47341. * @private
  47342. */
  47343. ol.format.WKT.TokenType_ = {
  47344. TEXT: 1,
  47345. LEFT_PAREN: 2,
  47346. RIGHT_PAREN: 3,
  47347. NUMBER: 4,
  47348. COMMA: 5,
  47349. EOF: 6
  47350. };
  47351. /**
  47352. * Class to tokenize a WKT string.
  47353. * @param {string} wkt WKT string.
  47354. * @constructor
  47355. * @protected
  47356. */
  47357. ol.format.WKT.Lexer = function(wkt) {
  47358. /**
  47359. * @type {string}
  47360. */
  47361. this.wkt = wkt;
  47362. /**
  47363. * @type {number}
  47364. * @private
  47365. */
  47366. this.index_ = -1;
  47367. };
  47368. /**
  47369. * @param {string} c Character.
  47370. * @return {boolean} Whether the character is alphabetic.
  47371. * @private
  47372. */
  47373. ol.format.WKT.Lexer.prototype.isAlpha_ = function(c) {
  47374. return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z';
  47375. };
  47376. /**
  47377. * @param {string} c Character.
  47378. * @param {boolean=} opt_decimal Whether the string number
  47379. * contains a dot, i.e. is a decimal number.
  47380. * @return {boolean} Whether the character is numeric.
  47381. * @private
  47382. */
  47383. ol.format.WKT.Lexer.prototype.isNumeric_ = function(c, opt_decimal) {
  47384. var decimal = opt_decimal !== undefined ? opt_decimal : false;
  47385. return c >= '0' && c <= '9' || c == '.' && !decimal;
  47386. };
  47387. /**
  47388. * @param {string} c Character.
  47389. * @return {boolean} Whether the character is whitespace.
  47390. * @private
  47391. */
  47392. ol.format.WKT.Lexer.prototype.isWhiteSpace_ = function(c) {
  47393. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  47394. };
  47395. /**
  47396. * @return {string} Next string character.
  47397. * @private
  47398. */
  47399. ol.format.WKT.Lexer.prototype.nextChar_ = function() {
  47400. return this.wkt.charAt(++this.index_);
  47401. };
  47402. /**
  47403. * Fetch and return the next token.
  47404. * @return {!ol.WKTToken} Next string token.
  47405. */
  47406. ol.format.WKT.Lexer.prototype.nextToken = function() {
  47407. var c = this.nextChar_();
  47408. var token = {position: this.index_, value: c};
  47409. if (c == '(') {
  47410. token.type = ol.format.WKT.TokenType_.LEFT_PAREN;
  47411. } else if (c == ',') {
  47412. token.type = ol.format.WKT.TokenType_.COMMA;
  47413. } else if (c == ')') {
  47414. token.type = ol.format.WKT.TokenType_.RIGHT_PAREN;
  47415. } else if (this.isNumeric_(c) || c == '-') {
  47416. token.type = ol.format.WKT.TokenType_.NUMBER;
  47417. token.value = this.readNumber_();
  47418. } else if (this.isAlpha_(c)) {
  47419. token.type = ol.format.WKT.TokenType_.TEXT;
  47420. token.value = this.readText_();
  47421. } else if (this.isWhiteSpace_(c)) {
  47422. return this.nextToken();
  47423. } else if (c === '') {
  47424. token.type = ol.format.WKT.TokenType_.EOF;
  47425. } else {
  47426. throw new Error('Unexpected character: ' + c);
  47427. }
  47428. return token;
  47429. };
  47430. /**
  47431. * @return {number} Numeric token value.
  47432. * @private
  47433. */
  47434. ol.format.WKT.Lexer.prototype.readNumber_ = function() {
  47435. var c, index = this.index_;
  47436. var decimal = false;
  47437. var scientificNotation = false;
  47438. do {
  47439. if (c == '.') {
  47440. decimal = true;
  47441. } else if (c == 'e' || c == 'E') {
  47442. scientificNotation = true;
  47443. }
  47444. c = this.nextChar_();
  47445. } while (
  47446. this.isNumeric_(c, decimal) ||
  47447. // if we haven't detected a scientific number before, 'e' or 'E'
  47448. // hint that we should continue to read
  47449. !scientificNotation && (c == 'e' || c == 'E') ||
  47450. // once we know that we have a scientific number, both '-' and '+'
  47451. // are allowed
  47452. scientificNotation && (c == '-' || c == '+')
  47453. );
  47454. return parseFloat(this.wkt.substring(index, this.index_--));
  47455. };
  47456. /**
  47457. * @return {string} String token value.
  47458. * @private
  47459. */
  47460. ol.format.WKT.Lexer.prototype.readText_ = function() {
  47461. var c, index = this.index_;
  47462. do {
  47463. c = this.nextChar_();
  47464. } while (this.isAlpha_(c));
  47465. return this.wkt.substring(index, this.index_--).toUpperCase();
  47466. };
  47467. /**
  47468. * Class to parse the tokens from the WKT string.
  47469. * @param {ol.format.WKT.Lexer} lexer The lexer.
  47470. * @constructor
  47471. * @protected
  47472. */
  47473. ol.format.WKT.Parser = function(lexer) {
  47474. /**
  47475. * @type {ol.format.WKT.Lexer}
  47476. * @private
  47477. */
  47478. this.lexer_ = lexer;
  47479. /**
  47480. * @type {ol.WKTToken}
  47481. * @private
  47482. */
  47483. this.token_;
  47484. /**
  47485. * @type {ol.geom.GeometryLayout}
  47486. * @private
  47487. */
  47488. this.layout_ = ol.geom.GeometryLayout.XY;
  47489. };
  47490. /**
  47491. * Fetch the next token form the lexer and replace the active token.
  47492. * @private
  47493. */
  47494. ol.format.WKT.Parser.prototype.consume_ = function() {
  47495. this.token_ = this.lexer_.nextToken();
  47496. };
  47497. /**
  47498. * Tests if the given type matches the type of the current token.
  47499. * @param {ol.format.WKT.TokenType_} type Token type.
  47500. * @return {boolean} Whether the token matches the given type.
  47501. */
  47502. ol.format.WKT.Parser.prototype.isTokenType = function(type) {
  47503. var isMatch = this.token_.type == type;
  47504. return isMatch;
  47505. };
  47506. /**
  47507. * If the given type matches the current token, consume it.
  47508. * @param {ol.format.WKT.TokenType_} type Token type.
  47509. * @return {boolean} Whether the token matches the given type.
  47510. */
  47511. ol.format.WKT.Parser.prototype.match = function(type) {
  47512. var isMatch = this.isTokenType(type);
  47513. if (isMatch) {
  47514. this.consume_();
  47515. }
  47516. return isMatch;
  47517. };
  47518. /**
  47519. * Try to parse the tokens provided by the lexer.
  47520. * @return {ol.geom.Geometry} The geometry.
  47521. */
  47522. ol.format.WKT.Parser.prototype.parse = function() {
  47523. this.consume_();
  47524. var geometry = this.parseGeometry_();
  47525. return geometry;
  47526. };
  47527. /**
  47528. * Try to parse the dimensional info.
  47529. * @return {ol.geom.GeometryLayout} The layout.
  47530. * @private
  47531. */
  47532. ol.format.WKT.Parser.prototype.parseGeometryLayout_ = function() {
  47533. var layout = ol.geom.GeometryLayout.XY;
  47534. var dimToken = this.token_;
  47535. if (this.isTokenType(ol.format.WKT.TokenType_.TEXT)) {
  47536. var dimInfo = dimToken.value;
  47537. if (dimInfo === ol.format.WKT.Z) {
  47538. layout = ol.geom.GeometryLayout.XYZ;
  47539. } else if (dimInfo === ol.format.WKT.M) {
  47540. layout = ol.geom.GeometryLayout.XYM;
  47541. } else if (dimInfo === ol.format.WKT.ZM) {
  47542. layout = ol.geom.GeometryLayout.XYZM;
  47543. }
  47544. if (layout !== ol.geom.GeometryLayout.XY) {
  47545. this.consume_();
  47546. }
  47547. }
  47548. return layout;
  47549. };
  47550. /**
  47551. * @return {!ol.geom.Geometry} The geometry.
  47552. * @private
  47553. */
  47554. ol.format.WKT.Parser.prototype.parseGeometry_ = function() {
  47555. var token = this.token_;
  47556. if (this.match(ol.format.WKT.TokenType_.TEXT)) {
  47557. var geomType = token.value;
  47558. this.layout_ = this.parseGeometryLayout_();
  47559. if (geomType == ol.geom.GeometryType.GEOMETRY_COLLECTION.toUpperCase()) {
  47560. var geometries = this.parseGeometryCollectionText_();
  47561. return new ol.geom.GeometryCollection(geometries);
  47562. } else {
  47563. var parser = ol.format.WKT.Parser.GeometryParser_[geomType];
  47564. var ctor = ol.format.WKT.Parser.GeometryConstructor_[geomType];
  47565. if (!parser || !ctor) {
  47566. throw new Error('Invalid geometry type: ' + geomType);
  47567. }
  47568. var coordinates = parser.call(this);
  47569. return new ctor(coordinates, this.layout_);
  47570. }
  47571. }
  47572. throw new Error(this.formatErrorMessage_());
  47573. };
  47574. /**
  47575. * @return {!Array.<ol.geom.Geometry>} A collection of geometries.
  47576. * @private
  47577. */
  47578. ol.format.WKT.Parser.prototype.parseGeometryCollectionText_ = function() {
  47579. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47580. var geometries = [];
  47581. do {
  47582. geometries.push(this.parseGeometry_());
  47583. } while (this.match(ol.format.WKT.TokenType_.COMMA));
  47584. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47585. return geometries;
  47586. }
  47587. } else if (this.isEmptyGeometry_()) {
  47588. return [];
  47589. }
  47590. throw new Error(this.formatErrorMessage_());
  47591. };
  47592. /**
  47593. * @return {Array.<number>} All values in a point.
  47594. * @private
  47595. */
  47596. ol.format.WKT.Parser.prototype.parsePointText_ = function() {
  47597. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47598. var coordinates = this.parsePoint_();
  47599. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47600. return coordinates;
  47601. }
  47602. } else if (this.isEmptyGeometry_()) {
  47603. return null;
  47604. }
  47605. throw new Error(this.formatErrorMessage_());
  47606. };
  47607. /**
  47608. * @return {!Array.<!Array.<number>>} All points in a linestring.
  47609. * @private
  47610. */
  47611. ol.format.WKT.Parser.prototype.parseLineStringText_ = function() {
  47612. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47613. var coordinates = this.parsePointList_();
  47614. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47615. return coordinates;
  47616. }
  47617. } else if (this.isEmptyGeometry_()) {
  47618. return [];
  47619. }
  47620. throw new Error(this.formatErrorMessage_());
  47621. };
  47622. /**
  47623. * @return {!Array.<!Array.<number>>} All points in a polygon.
  47624. * @private
  47625. */
  47626. ol.format.WKT.Parser.prototype.parsePolygonText_ = function() {
  47627. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47628. var coordinates = this.parseLineStringTextList_();
  47629. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47630. return coordinates;
  47631. }
  47632. } else if (this.isEmptyGeometry_()) {
  47633. return [];
  47634. }
  47635. throw new Error(this.formatErrorMessage_());
  47636. };
  47637. /**
  47638. * @return {!Array.<!Array.<number>>} All points in a multipoint.
  47639. * @private
  47640. */
  47641. ol.format.WKT.Parser.prototype.parseMultiPointText_ = function() {
  47642. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47643. var coordinates;
  47644. if (this.token_.type == ol.format.WKT.TokenType_.LEFT_PAREN) {
  47645. coordinates = this.parsePointTextList_();
  47646. } else {
  47647. coordinates = this.parsePointList_();
  47648. }
  47649. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47650. return coordinates;
  47651. }
  47652. } else if (this.isEmptyGeometry_()) {
  47653. return [];
  47654. }
  47655. throw new Error(this.formatErrorMessage_());
  47656. };
  47657. /**
  47658. * @return {!Array.<!Array.<number>>} All linestring points
  47659. * in a multilinestring.
  47660. * @private
  47661. */
  47662. ol.format.WKT.Parser.prototype.parseMultiLineStringText_ = function() {
  47663. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47664. var coordinates = this.parseLineStringTextList_();
  47665. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47666. return coordinates;
  47667. }
  47668. } else if (this.isEmptyGeometry_()) {
  47669. return [];
  47670. }
  47671. throw new Error(this.formatErrorMessage_());
  47672. };
  47673. /**
  47674. * @return {!Array.<!Array.<number>>} All polygon points in a multipolygon.
  47675. * @private
  47676. */
  47677. ol.format.WKT.Parser.prototype.parseMultiPolygonText_ = function() {
  47678. if (this.match(ol.format.WKT.TokenType_.LEFT_PAREN)) {
  47679. var coordinates = this.parsePolygonTextList_();
  47680. if (this.match(ol.format.WKT.TokenType_.RIGHT_PAREN)) {
  47681. return coordinates;
  47682. }
  47683. } else if (this.isEmptyGeometry_()) {
  47684. return [];
  47685. }
  47686. throw new Error(this.formatErrorMessage_());
  47687. };
  47688. /**
  47689. * @return {!Array.<number>} A point.
  47690. * @private
  47691. */
  47692. ol.format.WKT.Parser.prototype.parsePoint_ = function() {
  47693. var coordinates = [];
  47694. var dimensions = this.layout_.length;
  47695. for (var i = 0; i < dimensions; ++i) {
  47696. var token = this.token_;
  47697. if (this.match(ol.format.WKT.TokenType_.NUMBER)) {
  47698. coordinates.push(token.value);
  47699. } else {
  47700. break;
  47701. }
  47702. }
  47703. if (coordinates.length == dimensions) {
  47704. return coordinates;
  47705. }
  47706. throw new Error(this.formatErrorMessage_());
  47707. };
  47708. /**
  47709. * @return {!Array.<!Array.<number>>} An array of points.
  47710. * @private
  47711. */
  47712. ol.format.WKT.Parser.prototype.parsePointList_ = function() {
  47713. var coordinates = [this.parsePoint_()];
  47714. while (this.match(ol.format.WKT.TokenType_.COMMA)) {
  47715. coordinates.push(this.parsePoint_());
  47716. }
  47717. return coordinates;
  47718. };
  47719. /**
  47720. * @return {!Array.<!Array.<number>>} An array of points.
  47721. * @private
  47722. */
  47723. ol.format.WKT.Parser.prototype.parsePointTextList_ = function() {
  47724. var coordinates = [this.parsePointText_()];
  47725. while (this.match(ol.format.WKT.TokenType_.COMMA)) {
  47726. coordinates.push(this.parsePointText_());
  47727. }
  47728. return coordinates;
  47729. };
  47730. /**
  47731. * @return {!Array.<!Array.<number>>} An array of points.
  47732. * @private
  47733. */
  47734. ol.format.WKT.Parser.prototype.parseLineStringTextList_ = function() {
  47735. var coordinates = [this.parseLineStringText_()];
  47736. while (this.match(ol.format.WKT.TokenType_.COMMA)) {
  47737. coordinates.push(this.parseLineStringText_());
  47738. }
  47739. return coordinates;
  47740. };
  47741. /**
  47742. * @return {!Array.<!Array.<number>>} An array of points.
  47743. * @private
  47744. */
  47745. ol.format.WKT.Parser.prototype.parsePolygonTextList_ = function() {
  47746. var coordinates = [this.parsePolygonText_()];
  47747. while (this.match(ol.format.WKT.TokenType_.COMMA)) {
  47748. coordinates.push(this.parsePolygonText_());
  47749. }
  47750. return coordinates;
  47751. };
  47752. /**
  47753. * @return {boolean} Whether the token implies an empty geometry.
  47754. * @private
  47755. */
  47756. ol.format.WKT.Parser.prototype.isEmptyGeometry_ = function() {
  47757. var isEmpty = this.isTokenType(ol.format.WKT.TokenType_.TEXT) &&
  47758. this.token_.value == ol.format.WKT.EMPTY;
  47759. if (isEmpty) {
  47760. this.consume_();
  47761. }
  47762. return isEmpty;
  47763. };
  47764. /**
  47765. * Create an error message for an unexpected token error.
  47766. * @return {string} Error message.
  47767. * @private
  47768. */
  47769. ol.format.WKT.Parser.prototype.formatErrorMessage_ = function() {
  47770. return 'Unexpected `' + this.token_.value + '` at position ' +
  47771. this.token_.position + ' in `' + this.lexer_.wkt + '`';
  47772. };
  47773. /**
  47774. * @enum {function (new:ol.geom.Geometry, Array, ol.geom.GeometryLayout)}
  47775. * @private
  47776. */
  47777. ol.format.WKT.Parser.GeometryConstructor_ = {
  47778. 'POINT': ol.geom.Point,
  47779. 'LINESTRING': ol.geom.LineString,
  47780. 'POLYGON': ol.geom.Polygon,
  47781. 'MULTIPOINT': ol.geom.MultiPoint,
  47782. 'MULTILINESTRING': ol.geom.MultiLineString,
  47783. 'MULTIPOLYGON': ol.geom.MultiPolygon
  47784. };
  47785. /**
  47786. * @enum {(function(): Array)}
  47787. * @private
  47788. */
  47789. ol.format.WKT.Parser.GeometryParser_ = {
  47790. 'POINT': ol.format.WKT.Parser.prototype.parsePointText_,
  47791. 'LINESTRING': ol.format.WKT.Parser.prototype.parseLineStringText_,
  47792. 'POLYGON': ol.format.WKT.Parser.prototype.parsePolygonText_,
  47793. 'MULTIPOINT': ol.format.WKT.Parser.prototype.parseMultiPointText_,
  47794. 'MULTILINESTRING': ol.format.WKT.Parser.prototype.parseMultiLineStringText_,
  47795. 'MULTIPOLYGON': ol.format.WKT.Parser.prototype.parseMultiPolygonText_
  47796. };
  47797. goog.provide('ol.format.WMSCapabilities');
  47798. goog.require('ol');
  47799. goog.require('ol.format.XLink');
  47800. goog.require('ol.format.XML');
  47801. goog.require('ol.format.XSD');
  47802. goog.require('ol.xml');
  47803. /**
  47804. * @classdesc
  47805. * Format for reading WMS capabilities data
  47806. *
  47807. * @constructor
  47808. * @extends {ol.format.XML}
  47809. * @api
  47810. */
  47811. ol.format.WMSCapabilities = function() {
  47812. ol.format.XML.call(this);
  47813. /**
  47814. * @type {string|undefined}
  47815. */
  47816. this.version = undefined;
  47817. };
  47818. ol.inherits(ol.format.WMSCapabilities, ol.format.XML);
  47819. /**
  47820. * Read a WMS capabilities document.
  47821. *
  47822. * @function
  47823. * @param {Document|Node|string} source The XML source.
  47824. * @return {Object} An object representing the WMS capabilities.
  47825. * @api
  47826. */
  47827. ol.format.WMSCapabilities.prototype.read;
  47828. /**
  47829. * @inheritDoc
  47830. */
  47831. ol.format.WMSCapabilities.prototype.readFromDocument = function(doc) {
  47832. for (var n = doc.firstChild; n; n = n.nextSibling) {
  47833. if (n.nodeType == Node.ELEMENT_NODE) {
  47834. return this.readFromNode(n);
  47835. }
  47836. }
  47837. return null;
  47838. };
  47839. /**
  47840. * @inheritDoc
  47841. */
  47842. ol.format.WMSCapabilities.prototype.readFromNode = function(node) {
  47843. this.version = node.getAttribute('version').trim();
  47844. var wmsCapabilityObject = ol.xml.pushParseAndPop({
  47845. 'version': this.version
  47846. }, ol.format.WMSCapabilities.PARSERS_, node, []);
  47847. return wmsCapabilityObject ? wmsCapabilityObject : null;
  47848. };
  47849. /**
  47850. * @private
  47851. * @param {Node} node Node.
  47852. * @param {Array.<*>} objectStack Object stack.
  47853. * @return {Object|undefined} Attribution object.
  47854. */
  47855. ol.format.WMSCapabilities.readAttribution_ = function(node, objectStack) {
  47856. return ol.xml.pushParseAndPop(
  47857. {}, ol.format.WMSCapabilities.ATTRIBUTION_PARSERS_, node, objectStack);
  47858. };
  47859. /**
  47860. * @private
  47861. * @param {Node} node Node.
  47862. * @param {Array.<*>} objectStack Object stack.
  47863. * @return {Object} Bounding box object.
  47864. */
  47865. ol.format.WMSCapabilities.readBoundingBox_ = function(node, objectStack) {
  47866. var extent = [
  47867. ol.format.XSD.readDecimalString(node.getAttribute('minx')),
  47868. ol.format.XSD.readDecimalString(node.getAttribute('miny')),
  47869. ol.format.XSD.readDecimalString(node.getAttribute('maxx')),
  47870. ol.format.XSD.readDecimalString(node.getAttribute('maxy'))
  47871. ];
  47872. var resolutions = [
  47873. ol.format.XSD.readDecimalString(node.getAttribute('resx')),
  47874. ol.format.XSD.readDecimalString(node.getAttribute('resy'))
  47875. ];
  47876. return {
  47877. 'crs': node.getAttribute('CRS'),
  47878. 'extent': extent,
  47879. 'res': resolutions
  47880. };
  47881. };
  47882. /**
  47883. * @private
  47884. * @param {Node} node Node.
  47885. * @param {Array.<*>} objectStack Object stack.
  47886. * @return {ol.Extent|undefined} Bounding box object.
  47887. */
  47888. ol.format.WMSCapabilities.readEXGeographicBoundingBox_ = function(node, objectStack) {
  47889. var geographicBoundingBox = ol.xml.pushParseAndPop(
  47890. {},
  47891. ol.format.WMSCapabilities.EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS_,
  47892. node, objectStack);
  47893. if (!geographicBoundingBox) {
  47894. return undefined;
  47895. }
  47896. var westBoundLongitude = /** @type {number|undefined} */
  47897. (geographicBoundingBox['westBoundLongitude']);
  47898. var southBoundLatitude = /** @type {number|undefined} */
  47899. (geographicBoundingBox['southBoundLatitude']);
  47900. var eastBoundLongitude = /** @type {number|undefined} */
  47901. (geographicBoundingBox['eastBoundLongitude']);
  47902. var northBoundLatitude = /** @type {number|undefined} */
  47903. (geographicBoundingBox['northBoundLatitude']);
  47904. if (westBoundLongitude === undefined || southBoundLatitude === undefined ||
  47905. eastBoundLongitude === undefined || northBoundLatitude === undefined) {
  47906. return undefined;
  47907. }
  47908. return [
  47909. westBoundLongitude, southBoundLatitude,
  47910. eastBoundLongitude, northBoundLatitude
  47911. ];
  47912. };
  47913. /**
  47914. * @param {Node} node Node.
  47915. * @param {Array.<*>} objectStack Object stack.
  47916. * @private
  47917. * @return {Object|undefined} Capability object.
  47918. */
  47919. ol.format.WMSCapabilities.readCapability_ = function(node, objectStack) {
  47920. return ol.xml.pushParseAndPop(
  47921. {}, ol.format.WMSCapabilities.CAPABILITY_PARSERS_, node, objectStack);
  47922. };
  47923. /**
  47924. * @param {Node} node Node.
  47925. * @param {Array.<*>} objectStack Object stack.
  47926. * @private
  47927. * @return {Object|undefined} Service object.
  47928. */
  47929. ol.format.WMSCapabilities.readService_ = function(node, objectStack) {
  47930. return ol.xml.pushParseAndPop(
  47931. {}, ol.format.WMSCapabilities.SERVICE_PARSERS_, node, objectStack);
  47932. };
  47933. /**
  47934. * @param {Node} node Node.
  47935. * @param {Array.<*>} objectStack Object stack.
  47936. * @private
  47937. * @return {Object|undefined} Contact information object.
  47938. */
  47939. ol.format.WMSCapabilities.readContactInformation_ = function(node, objectStack) {
  47940. return ol.xml.pushParseAndPop(
  47941. {}, ol.format.WMSCapabilities.CONTACT_INFORMATION_PARSERS_,
  47942. node, objectStack);
  47943. };
  47944. /**
  47945. * @param {Node} node Node.
  47946. * @param {Array.<*>} objectStack Object stack.
  47947. * @private
  47948. * @return {Object|undefined} Contact person object.
  47949. */
  47950. ol.format.WMSCapabilities.readContactPersonPrimary_ = function(node, objectStack) {
  47951. return ol.xml.pushParseAndPop(
  47952. {}, ol.format.WMSCapabilities.CONTACT_PERSON_PARSERS_,
  47953. node, objectStack);
  47954. };
  47955. /**
  47956. * @param {Node} node Node.
  47957. * @param {Array.<*>} objectStack Object stack.
  47958. * @private
  47959. * @return {Object|undefined} Contact address object.
  47960. */
  47961. ol.format.WMSCapabilities.readContactAddress_ = function(node, objectStack) {
  47962. return ol.xml.pushParseAndPop(
  47963. {}, ol.format.WMSCapabilities.CONTACT_ADDRESS_PARSERS_,
  47964. node, objectStack);
  47965. };
  47966. /**
  47967. * @param {Node} node Node.
  47968. * @param {Array.<*>} objectStack Object stack.
  47969. * @private
  47970. * @return {Array.<string>|undefined} Format array.
  47971. */
  47972. ol.format.WMSCapabilities.readException_ = function(node, objectStack) {
  47973. return ol.xml.pushParseAndPop(
  47974. [], ol.format.WMSCapabilities.EXCEPTION_PARSERS_, node, objectStack);
  47975. };
  47976. /**
  47977. * @param {Node} node Node.
  47978. * @param {Array.<*>} objectStack Object stack.
  47979. * @private
  47980. * @return {Object|undefined} Layer object.
  47981. */
  47982. ol.format.WMSCapabilities.readCapabilityLayer_ = function(node, objectStack) {
  47983. return ol.xml.pushParseAndPop(
  47984. {}, ol.format.WMSCapabilities.LAYER_PARSERS_, node, objectStack);
  47985. };
  47986. /**
  47987. * @private
  47988. * @param {Node} node Node.
  47989. * @param {Array.<*>} objectStack Object stack.
  47990. * @return {Object|undefined} Layer object.
  47991. */
  47992. ol.format.WMSCapabilities.readLayer_ = function(node, objectStack) {
  47993. var parentLayerObject = /** @type {Object.<string,*>} */
  47994. (objectStack[objectStack.length - 1]);
  47995. var layerObject = ol.xml.pushParseAndPop(
  47996. {}, ol.format.WMSCapabilities.LAYER_PARSERS_, node, objectStack);
  47997. if (!layerObject) {
  47998. return undefined;
  47999. }
  48000. var queryable =
  48001. ol.format.XSD.readBooleanString(node.getAttribute('queryable'));
  48002. if (queryable === undefined) {
  48003. queryable = parentLayerObject['queryable'];
  48004. }
  48005. layerObject['queryable'] = queryable !== undefined ? queryable : false;
  48006. var cascaded = ol.format.XSD.readNonNegativeIntegerString(
  48007. node.getAttribute('cascaded'));
  48008. if (cascaded === undefined) {
  48009. cascaded = parentLayerObject['cascaded'];
  48010. }
  48011. layerObject['cascaded'] = cascaded;
  48012. var opaque = ol.format.XSD.readBooleanString(node.getAttribute('opaque'));
  48013. if (opaque === undefined) {
  48014. opaque = parentLayerObject['opaque'];
  48015. }
  48016. layerObject['opaque'] = opaque !== undefined ? opaque : false;
  48017. var noSubsets =
  48018. ol.format.XSD.readBooleanString(node.getAttribute('noSubsets'));
  48019. if (noSubsets === undefined) {
  48020. noSubsets = parentLayerObject['noSubsets'];
  48021. }
  48022. layerObject['noSubsets'] = noSubsets !== undefined ? noSubsets : false;
  48023. var fixedWidth =
  48024. ol.format.XSD.readDecimalString(node.getAttribute('fixedWidth'));
  48025. if (!fixedWidth) {
  48026. fixedWidth = parentLayerObject['fixedWidth'];
  48027. }
  48028. layerObject['fixedWidth'] = fixedWidth;
  48029. var fixedHeight =
  48030. ol.format.XSD.readDecimalString(node.getAttribute('fixedHeight'));
  48031. if (!fixedHeight) {
  48032. fixedHeight = parentLayerObject['fixedHeight'];
  48033. }
  48034. layerObject['fixedHeight'] = fixedHeight;
  48035. // See 7.2.4.8
  48036. var addKeys = ['Style', 'CRS', 'AuthorityURL'];
  48037. addKeys.forEach(function(key) {
  48038. if (key in parentLayerObject) {
  48039. var childValue = layerObject[key] || [];
  48040. layerObject[key] = childValue.concat(parentLayerObject[key]);
  48041. }
  48042. });
  48043. var replaceKeys = ['EX_GeographicBoundingBox', 'BoundingBox', 'Dimension',
  48044. 'Attribution', 'MinScaleDenominator', 'MaxScaleDenominator'];
  48045. replaceKeys.forEach(function(key) {
  48046. if (!(key in layerObject)) {
  48047. var parentValue = parentLayerObject[key];
  48048. layerObject[key] = parentValue;
  48049. }
  48050. });
  48051. return layerObject;
  48052. };
  48053. /**
  48054. * @private
  48055. * @param {Node} node Node.
  48056. * @param {Array.<*>} objectStack Object stack.
  48057. * @return {Object} Dimension object.
  48058. */
  48059. ol.format.WMSCapabilities.readDimension_ = function(node, objectStack) {
  48060. var dimensionObject = {
  48061. 'name': node.getAttribute('name'),
  48062. 'units': node.getAttribute('units'),
  48063. 'unitSymbol': node.getAttribute('unitSymbol'),
  48064. 'default': node.getAttribute('default'),
  48065. 'multipleValues': ol.format.XSD.readBooleanString(
  48066. node.getAttribute('multipleValues')),
  48067. 'nearestValue': ol.format.XSD.readBooleanString(
  48068. node.getAttribute('nearestValue')),
  48069. 'current': ol.format.XSD.readBooleanString(node.getAttribute('current')),
  48070. 'values': ol.format.XSD.readString(node)
  48071. };
  48072. return dimensionObject;
  48073. };
  48074. /**
  48075. * @private
  48076. * @param {Node} node Node.
  48077. * @param {Array.<*>} objectStack Object stack.
  48078. * @return {Object|undefined} Online resource object.
  48079. */
  48080. ol.format.WMSCapabilities.readFormatOnlineresource_ = function(node, objectStack) {
  48081. return ol.xml.pushParseAndPop(
  48082. {}, ol.format.WMSCapabilities.FORMAT_ONLINERESOURCE_PARSERS_,
  48083. node, objectStack);
  48084. };
  48085. /**
  48086. * @private
  48087. * @param {Node} node Node.
  48088. * @param {Array.<*>} objectStack Object stack.
  48089. * @return {Object|undefined} Request object.
  48090. */
  48091. ol.format.WMSCapabilities.readRequest_ = function(node, objectStack) {
  48092. return ol.xml.pushParseAndPop(
  48093. {}, ol.format.WMSCapabilities.REQUEST_PARSERS_, node, objectStack);
  48094. };
  48095. /**
  48096. * @private
  48097. * @param {Node} node Node.
  48098. * @param {Array.<*>} objectStack Object stack.
  48099. * @return {Object|undefined} DCP type object.
  48100. */
  48101. ol.format.WMSCapabilities.readDCPType_ = function(node, objectStack) {
  48102. return ol.xml.pushParseAndPop(
  48103. {}, ol.format.WMSCapabilities.DCPTYPE_PARSERS_, node, objectStack);
  48104. };
  48105. /**
  48106. * @private
  48107. * @param {Node} node Node.
  48108. * @param {Array.<*>} objectStack Object stack.
  48109. * @return {Object|undefined} HTTP object.
  48110. */
  48111. ol.format.WMSCapabilities.readHTTP_ = function(node, objectStack) {
  48112. return ol.xml.pushParseAndPop(
  48113. {}, ol.format.WMSCapabilities.HTTP_PARSERS_, node, objectStack);
  48114. };
  48115. /**
  48116. * @private
  48117. * @param {Node} node Node.
  48118. * @param {Array.<*>} objectStack Object stack.
  48119. * @return {Object|undefined} Operation type object.
  48120. */
  48121. ol.format.WMSCapabilities.readOperationType_ = function(node, objectStack) {
  48122. return ol.xml.pushParseAndPop(
  48123. {}, ol.format.WMSCapabilities.OPERATIONTYPE_PARSERS_, node, objectStack);
  48124. };
  48125. /**
  48126. * @private
  48127. * @param {Node} node Node.
  48128. * @param {Array.<*>} objectStack Object stack.
  48129. * @return {Object|undefined} Online resource object.
  48130. */
  48131. ol.format.WMSCapabilities.readSizedFormatOnlineresource_ = function(node, objectStack) {
  48132. var formatOnlineresource =
  48133. ol.format.WMSCapabilities.readFormatOnlineresource_(node, objectStack);
  48134. if (formatOnlineresource) {
  48135. var size = [
  48136. ol.format.XSD.readNonNegativeIntegerString(node.getAttribute('width')),
  48137. ol.format.XSD.readNonNegativeIntegerString(node.getAttribute('height'))
  48138. ];
  48139. formatOnlineresource['size'] = size;
  48140. return formatOnlineresource;
  48141. }
  48142. return undefined;
  48143. };
  48144. /**
  48145. * @private
  48146. * @param {Node} node Node.
  48147. * @param {Array.<*>} objectStack Object stack.
  48148. * @return {Object|undefined} Authority URL object.
  48149. */
  48150. ol.format.WMSCapabilities.readAuthorityURL_ = function(node, objectStack) {
  48151. var authorityObject =
  48152. ol.format.WMSCapabilities.readFormatOnlineresource_(node, objectStack);
  48153. if (authorityObject) {
  48154. authorityObject['name'] = node.getAttribute('name');
  48155. return authorityObject;
  48156. }
  48157. return undefined;
  48158. };
  48159. /**
  48160. * @private
  48161. * @param {Node} node Node.
  48162. * @param {Array.<*>} objectStack Object stack.
  48163. * @return {Object|undefined} Metadata URL object.
  48164. */
  48165. ol.format.WMSCapabilities.readMetadataURL_ = function(node, objectStack) {
  48166. var metadataObject =
  48167. ol.format.WMSCapabilities.readFormatOnlineresource_(node, objectStack);
  48168. if (metadataObject) {
  48169. metadataObject['type'] = node.getAttribute('type');
  48170. return metadataObject;
  48171. }
  48172. return undefined;
  48173. };
  48174. /**
  48175. * @private
  48176. * @param {Node} node Node.
  48177. * @param {Array.<*>} objectStack Object stack.
  48178. * @return {Object|undefined} Style object.
  48179. */
  48180. ol.format.WMSCapabilities.readStyle_ = function(node, objectStack) {
  48181. return ol.xml.pushParseAndPop(
  48182. {}, ol.format.WMSCapabilities.STYLE_PARSERS_, node, objectStack);
  48183. };
  48184. /**
  48185. * @private
  48186. * @param {Node} node Node.
  48187. * @param {Array.<*>} objectStack Object stack.
  48188. * @return {Array.<string>|undefined} Keyword list.
  48189. */
  48190. ol.format.WMSCapabilities.readKeywordList_ = function(node, objectStack) {
  48191. return ol.xml.pushParseAndPop(
  48192. [], ol.format.WMSCapabilities.KEYWORDLIST_PARSERS_, node, objectStack);
  48193. };
  48194. /**
  48195. * @const
  48196. * @private
  48197. * @type {Array.<string>}
  48198. */
  48199. ol.format.WMSCapabilities.NAMESPACE_URIS_ = [
  48200. null,
  48201. 'http://www.opengis.net/wms'
  48202. ];
  48203. /**
  48204. * @const
  48205. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48206. * @private
  48207. */
  48208. ol.format.WMSCapabilities.PARSERS_ = ol.xml.makeStructureNS(
  48209. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48210. 'Service': ol.xml.makeObjectPropertySetter(
  48211. ol.format.WMSCapabilities.readService_),
  48212. 'Capability': ol.xml.makeObjectPropertySetter(
  48213. ol.format.WMSCapabilities.readCapability_)
  48214. });
  48215. /**
  48216. * @const
  48217. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48218. * @private
  48219. */
  48220. ol.format.WMSCapabilities.CAPABILITY_PARSERS_ = ol.xml.makeStructureNS(
  48221. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48222. 'Request': ol.xml.makeObjectPropertySetter(
  48223. ol.format.WMSCapabilities.readRequest_),
  48224. 'Exception': ol.xml.makeObjectPropertySetter(
  48225. ol.format.WMSCapabilities.readException_),
  48226. 'Layer': ol.xml.makeObjectPropertySetter(
  48227. ol.format.WMSCapabilities.readCapabilityLayer_)
  48228. });
  48229. /**
  48230. * @const
  48231. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48232. * @private
  48233. */
  48234. ol.format.WMSCapabilities.SERVICE_PARSERS_ = ol.xml.makeStructureNS(
  48235. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48236. 'Name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48237. 'Title': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48238. 'Abstract': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48239. 'KeywordList': ol.xml.makeObjectPropertySetter(
  48240. ol.format.WMSCapabilities.readKeywordList_),
  48241. 'OnlineResource': ol.xml.makeObjectPropertySetter(
  48242. ol.format.XLink.readHref),
  48243. 'ContactInformation': ol.xml.makeObjectPropertySetter(
  48244. ol.format.WMSCapabilities.readContactInformation_),
  48245. 'Fees': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48246. 'AccessConstraints': ol.xml.makeObjectPropertySetter(
  48247. ol.format.XSD.readString),
  48248. 'LayerLimit': ol.xml.makeObjectPropertySetter(
  48249. ol.format.XSD.readNonNegativeInteger),
  48250. 'MaxWidth': ol.xml.makeObjectPropertySetter(
  48251. ol.format.XSD.readNonNegativeInteger),
  48252. 'MaxHeight': ol.xml.makeObjectPropertySetter(
  48253. ol.format.XSD.readNonNegativeInteger)
  48254. });
  48255. /**
  48256. * @const
  48257. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48258. * @private
  48259. */
  48260. ol.format.WMSCapabilities.CONTACT_INFORMATION_PARSERS_ = ol.xml.makeStructureNS(
  48261. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48262. 'ContactPersonPrimary': ol.xml.makeObjectPropertySetter(
  48263. ol.format.WMSCapabilities.readContactPersonPrimary_),
  48264. 'ContactPosition': ol.xml.makeObjectPropertySetter(
  48265. ol.format.XSD.readString),
  48266. 'ContactAddress': ol.xml.makeObjectPropertySetter(
  48267. ol.format.WMSCapabilities.readContactAddress_),
  48268. 'ContactVoiceTelephone': ol.xml.makeObjectPropertySetter(
  48269. ol.format.XSD.readString),
  48270. 'ContactFacsimileTelephone': ol.xml.makeObjectPropertySetter(
  48271. ol.format.XSD.readString),
  48272. 'ContactElectronicMailAddress': ol.xml.makeObjectPropertySetter(
  48273. ol.format.XSD.readString)
  48274. });
  48275. /**
  48276. * @const
  48277. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48278. * @private
  48279. */
  48280. ol.format.WMSCapabilities.CONTACT_PERSON_PARSERS_ = ol.xml.makeStructureNS(
  48281. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48282. 'ContactPerson': ol.xml.makeObjectPropertySetter(
  48283. ol.format.XSD.readString),
  48284. 'ContactOrganization': ol.xml.makeObjectPropertySetter(
  48285. ol.format.XSD.readString)
  48286. });
  48287. /**
  48288. * @const
  48289. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48290. * @private
  48291. */
  48292. ol.format.WMSCapabilities.CONTACT_ADDRESS_PARSERS_ = ol.xml.makeStructureNS(
  48293. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48294. 'AddressType': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48295. 'Address': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48296. 'City': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48297. 'StateOrProvince': ol.xml.makeObjectPropertySetter(
  48298. ol.format.XSD.readString),
  48299. 'PostCode': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48300. 'Country': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString)
  48301. });
  48302. /**
  48303. * @const
  48304. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48305. * @private
  48306. */
  48307. ol.format.WMSCapabilities.EXCEPTION_PARSERS_ = ol.xml.makeStructureNS(
  48308. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48309. 'Format': ol.xml.makeArrayPusher(ol.format.XSD.readString)
  48310. });
  48311. /**
  48312. * @const
  48313. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48314. * @private
  48315. */
  48316. ol.format.WMSCapabilities.LAYER_PARSERS_ = ol.xml.makeStructureNS(
  48317. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48318. 'Name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48319. 'Title': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48320. 'Abstract': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48321. 'KeywordList': ol.xml.makeObjectPropertySetter(
  48322. ol.format.WMSCapabilities.readKeywordList_),
  48323. 'CRS': ol.xml.makeObjectPropertyPusher(ol.format.XSD.readString),
  48324. 'EX_GeographicBoundingBox': ol.xml.makeObjectPropertySetter(
  48325. ol.format.WMSCapabilities.readEXGeographicBoundingBox_),
  48326. 'BoundingBox': ol.xml.makeObjectPropertyPusher(
  48327. ol.format.WMSCapabilities.readBoundingBox_),
  48328. 'Dimension': ol.xml.makeObjectPropertyPusher(
  48329. ol.format.WMSCapabilities.readDimension_),
  48330. 'Attribution': ol.xml.makeObjectPropertySetter(
  48331. ol.format.WMSCapabilities.readAttribution_),
  48332. 'AuthorityURL': ol.xml.makeObjectPropertyPusher(
  48333. ol.format.WMSCapabilities.readAuthorityURL_),
  48334. 'Identifier': ol.xml.makeObjectPropertyPusher(ol.format.XSD.readString),
  48335. 'MetadataURL': ol.xml.makeObjectPropertyPusher(
  48336. ol.format.WMSCapabilities.readMetadataURL_),
  48337. 'DataURL': ol.xml.makeObjectPropertyPusher(
  48338. ol.format.WMSCapabilities.readFormatOnlineresource_),
  48339. 'FeatureListURL': ol.xml.makeObjectPropertyPusher(
  48340. ol.format.WMSCapabilities.readFormatOnlineresource_),
  48341. 'Style': ol.xml.makeObjectPropertyPusher(
  48342. ol.format.WMSCapabilities.readStyle_),
  48343. 'MinScaleDenominator': ol.xml.makeObjectPropertySetter(
  48344. ol.format.XSD.readDecimal),
  48345. 'MaxScaleDenominator': ol.xml.makeObjectPropertySetter(
  48346. ol.format.XSD.readDecimal),
  48347. 'Layer': ol.xml.makeObjectPropertyPusher(
  48348. ol.format.WMSCapabilities.readLayer_)
  48349. });
  48350. /**
  48351. * @const
  48352. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48353. * @private
  48354. */
  48355. ol.format.WMSCapabilities.ATTRIBUTION_PARSERS_ = ol.xml.makeStructureNS(
  48356. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48357. 'Title': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48358. 'OnlineResource': ol.xml.makeObjectPropertySetter(
  48359. ol.format.XLink.readHref),
  48360. 'LogoURL': ol.xml.makeObjectPropertySetter(
  48361. ol.format.WMSCapabilities.readSizedFormatOnlineresource_)
  48362. });
  48363. /**
  48364. * @const
  48365. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48366. * @private
  48367. */
  48368. ol.format.WMSCapabilities.EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS_ =
  48369. ol.xml.makeStructureNS(ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48370. 'westBoundLongitude': ol.xml.makeObjectPropertySetter(
  48371. ol.format.XSD.readDecimal),
  48372. 'eastBoundLongitude': ol.xml.makeObjectPropertySetter(
  48373. ol.format.XSD.readDecimal),
  48374. 'southBoundLatitude': ol.xml.makeObjectPropertySetter(
  48375. ol.format.XSD.readDecimal),
  48376. 'northBoundLatitude': ol.xml.makeObjectPropertySetter(
  48377. ol.format.XSD.readDecimal)
  48378. });
  48379. /**
  48380. * @const
  48381. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48382. * @private
  48383. */
  48384. ol.format.WMSCapabilities.REQUEST_PARSERS_ = ol.xml.makeStructureNS(
  48385. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48386. 'GetCapabilities': ol.xml.makeObjectPropertySetter(
  48387. ol.format.WMSCapabilities.readOperationType_),
  48388. 'GetMap': ol.xml.makeObjectPropertySetter(
  48389. ol.format.WMSCapabilities.readOperationType_),
  48390. 'GetFeatureInfo': ol.xml.makeObjectPropertySetter(
  48391. ol.format.WMSCapabilities.readOperationType_)
  48392. });
  48393. /**
  48394. * @const
  48395. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48396. * @private
  48397. */
  48398. ol.format.WMSCapabilities.OPERATIONTYPE_PARSERS_ = ol.xml.makeStructureNS(
  48399. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48400. 'Format': ol.xml.makeObjectPropertyPusher(ol.format.XSD.readString),
  48401. 'DCPType': ol.xml.makeObjectPropertyPusher(
  48402. ol.format.WMSCapabilities.readDCPType_)
  48403. });
  48404. /**
  48405. * @const
  48406. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48407. * @private
  48408. */
  48409. ol.format.WMSCapabilities.DCPTYPE_PARSERS_ = ol.xml.makeStructureNS(
  48410. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48411. 'HTTP': ol.xml.makeObjectPropertySetter(
  48412. ol.format.WMSCapabilities.readHTTP_)
  48413. });
  48414. /**
  48415. * @const
  48416. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48417. * @private
  48418. */
  48419. ol.format.WMSCapabilities.HTTP_PARSERS_ = ol.xml.makeStructureNS(
  48420. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48421. 'Get': ol.xml.makeObjectPropertySetter(
  48422. ol.format.WMSCapabilities.readFormatOnlineresource_),
  48423. 'Post': ol.xml.makeObjectPropertySetter(
  48424. ol.format.WMSCapabilities.readFormatOnlineresource_)
  48425. });
  48426. /**
  48427. * @const
  48428. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48429. * @private
  48430. */
  48431. ol.format.WMSCapabilities.STYLE_PARSERS_ = ol.xml.makeStructureNS(
  48432. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48433. 'Name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48434. 'Title': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48435. 'Abstract': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48436. 'LegendURL': ol.xml.makeObjectPropertyPusher(
  48437. ol.format.WMSCapabilities.readSizedFormatOnlineresource_),
  48438. 'StyleSheetURL': ol.xml.makeObjectPropertySetter(
  48439. ol.format.WMSCapabilities.readFormatOnlineresource_),
  48440. 'StyleURL': ol.xml.makeObjectPropertySetter(
  48441. ol.format.WMSCapabilities.readFormatOnlineresource_)
  48442. });
  48443. /**
  48444. * @const
  48445. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48446. * @private
  48447. */
  48448. ol.format.WMSCapabilities.FORMAT_ONLINERESOURCE_PARSERS_ =
  48449. ol.xml.makeStructureNS(ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48450. 'Format': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString),
  48451. 'OnlineResource': ol.xml.makeObjectPropertySetter(
  48452. ol.format.XLink.readHref)
  48453. });
  48454. /**
  48455. * @const
  48456. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48457. * @private
  48458. */
  48459. ol.format.WMSCapabilities.KEYWORDLIST_PARSERS_ = ol.xml.makeStructureNS(
  48460. ol.format.WMSCapabilities.NAMESPACE_URIS_, {
  48461. 'Keyword': ol.xml.makeArrayPusher(ol.format.XSD.readString)
  48462. });
  48463. goog.provide('ol.format.WMSGetFeatureInfo');
  48464. goog.require('ol');
  48465. goog.require('ol.array');
  48466. goog.require('ol.format.GML2');
  48467. goog.require('ol.format.XMLFeature');
  48468. goog.require('ol.obj');
  48469. goog.require('ol.xml');
  48470. /**
  48471. * @classdesc
  48472. * Format for reading WMSGetFeatureInfo format. It uses
  48473. * {@link ol.format.GML2} to read features.
  48474. *
  48475. * @constructor
  48476. * @extends {ol.format.XMLFeature}
  48477. * @param {olx.format.WMSGetFeatureInfoOptions=} opt_options Options.
  48478. * @api
  48479. */
  48480. ol.format.WMSGetFeatureInfo = function(opt_options) {
  48481. var options = opt_options ? opt_options : {};
  48482. /**
  48483. * @private
  48484. * @type {string}
  48485. */
  48486. this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver';
  48487. /**
  48488. * @private
  48489. * @type {ol.format.GML2}
  48490. */
  48491. this.gmlFormat_ = new ol.format.GML2();
  48492. /**
  48493. * @private
  48494. * @type {Array.<string>}
  48495. */
  48496. this.layers_ = options.layers ? options.layers : null;
  48497. ol.format.XMLFeature.call(this);
  48498. };
  48499. ol.inherits(ol.format.WMSGetFeatureInfo, ol.format.XMLFeature);
  48500. /**
  48501. * @const
  48502. * @type {string}
  48503. * @private
  48504. */
  48505. ol.format.WMSGetFeatureInfo.featureIdentifier_ = '_feature';
  48506. /**
  48507. * @const
  48508. * @type {string}
  48509. * @private
  48510. */
  48511. ol.format.WMSGetFeatureInfo.layerIdentifier_ = '_layer';
  48512. /**
  48513. * @return {Array.<string>} layers
  48514. */
  48515. ol.format.WMSGetFeatureInfo.prototype.getLayers = function() {
  48516. return this.layers_;
  48517. };
  48518. /**
  48519. * @param {Array.<string>} layers Layers to parse.
  48520. */
  48521. ol.format.WMSGetFeatureInfo.prototype.setLayers = function(layers) {
  48522. this.layers_ = layers;
  48523. };
  48524. /**
  48525. * @param {Node} node Node.
  48526. * @param {Array.<*>} objectStack Object stack.
  48527. * @return {Array.<ol.Feature>} Features.
  48528. * @private
  48529. */
  48530. ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
  48531. node.setAttribute('namespaceURI', this.featureNS_);
  48532. var localName = node.localName;
  48533. /** @type {Array.<ol.Feature>} */
  48534. var features = [];
  48535. if (node.childNodes.length === 0) {
  48536. return features;
  48537. }
  48538. if (localName == 'msGMLOutput') {
  48539. for (var i = 0, ii = node.childNodes.length; i < ii; i++) {
  48540. var layer = node.childNodes[i];
  48541. if (layer.nodeType !== Node.ELEMENT_NODE) {
  48542. continue;
  48543. }
  48544. var context = objectStack[0];
  48545. var toRemove = ol.format.WMSGetFeatureInfo.layerIdentifier_;
  48546. var layerName = layer.localName.replace(toRemove, '');
  48547. if (this.layers_ && !ol.array.includes(this.layers_, layerName)) {
  48548. continue;
  48549. }
  48550. var featureType = layerName +
  48551. ol.format.WMSGetFeatureInfo.featureIdentifier_;
  48552. context['featureType'] = featureType;
  48553. context['featureNS'] = this.featureNS_;
  48554. var parsers = {};
  48555. parsers[featureType] = ol.xml.makeArrayPusher(
  48556. this.gmlFormat_.readFeatureElement, this.gmlFormat_);
  48557. var parsersNS = ol.xml.makeStructureNS(
  48558. [context['featureNS'], null], parsers);
  48559. layer.setAttribute('namespaceURI', this.featureNS_);
  48560. var layerFeatures = ol.xml.pushParseAndPop(
  48561. [], parsersNS, layer, objectStack, this.gmlFormat_);
  48562. if (layerFeatures) {
  48563. ol.array.extend(features, layerFeatures);
  48564. }
  48565. }
  48566. }
  48567. if (localName == 'FeatureCollection') {
  48568. var gmlFeatures = ol.xml.pushParseAndPop([],
  48569. this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
  48570. [{}], this.gmlFormat_);
  48571. if (gmlFeatures) {
  48572. features = gmlFeatures;
  48573. }
  48574. }
  48575. return features;
  48576. };
  48577. /**
  48578. * Read all features from a WMSGetFeatureInfo response.
  48579. *
  48580. * @function
  48581. * @param {Document|Node|Object|string} source Source.
  48582. * @param {olx.format.ReadOptions=} opt_options Options.
  48583. * @return {Array.<ol.Feature>} Features.
  48584. * @api
  48585. */
  48586. ol.format.WMSGetFeatureInfo.prototype.readFeatures;
  48587. /**
  48588. * @inheritDoc
  48589. */
  48590. ol.format.WMSGetFeatureInfo.prototype.readFeaturesFromNode = function(node, opt_options) {
  48591. var options = {};
  48592. if (opt_options) {
  48593. ol.obj.assign(options, this.getReadOptions(node, opt_options));
  48594. }
  48595. return this.readFeatures_(node, [options]);
  48596. };
  48597. /**
  48598. * Not implemented.
  48599. * @inheritDoc
  48600. */
  48601. ol.format.WMSGetFeatureInfo.prototype.writeFeatureNode = function(feature, opt_options) {};
  48602. /**
  48603. * Not implemented.
  48604. * @inheritDoc
  48605. */
  48606. ol.format.WMSGetFeatureInfo.prototype.writeFeaturesNode = function(features, opt_options) {};
  48607. /**
  48608. * Not implemented.
  48609. * @inheritDoc
  48610. */
  48611. ol.format.WMSGetFeatureInfo.prototype.writeGeometryNode = function(geometry, opt_options) {};
  48612. goog.provide('ol.format.WMTSCapabilities');
  48613. goog.require('ol');
  48614. goog.require('ol.extent');
  48615. goog.require('ol.format.OWS');
  48616. goog.require('ol.format.XLink');
  48617. goog.require('ol.format.XML');
  48618. goog.require('ol.format.XSD');
  48619. goog.require('ol.xml');
  48620. /**
  48621. * @classdesc
  48622. * Format for reading WMTS capabilities data.
  48623. *
  48624. * @constructor
  48625. * @extends {ol.format.XML}
  48626. * @api
  48627. */
  48628. ol.format.WMTSCapabilities = function() {
  48629. ol.format.XML.call(this);
  48630. /**
  48631. * @type {ol.format.OWS}
  48632. * @private
  48633. */
  48634. this.owsParser_ = new ol.format.OWS();
  48635. };
  48636. ol.inherits(ol.format.WMTSCapabilities, ol.format.XML);
  48637. /**
  48638. * Read a WMTS capabilities document.
  48639. *
  48640. * @function
  48641. * @param {Document|Node|string} source The XML source.
  48642. * @return {Object} An object representing the WMTS capabilities.
  48643. * @api
  48644. */
  48645. ol.format.WMTSCapabilities.prototype.read;
  48646. /**
  48647. * @inheritDoc
  48648. */
  48649. ol.format.WMTSCapabilities.prototype.readFromDocument = function(doc) {
  48650. for (var n = doc.firstChild; n; n = n.nextSibling) {
  48651. if (n.nodeType == Node.ELEMENT_NODE) {
  48652. return this.readFromNode(n);
  48653. }
  48654. }
  48655. return null;
  48656. };
  48657. /**
  48658. * @inheritDoc
  48659. */
  48660. ol.format.WMTSCapabilities.prototype.readFromNode = function(node) {
  48661. var version = node.getAttribute('version').trim();
  48662. var WMTSCapabilityObject = this.owsParser_.readFromNode(node);
  48663. if (!WMTSCapabilityObject) {
  48664. return null;
  48665. }
  48666. WMTSCapabilityObject['version'] = version;
  48667. WMTSCapabilityObject = ol.xml.pushParseAndPop(WMTSCapabilityObject,
  48668. ol.format.WMTSCapabilities.PARSERS_, node, []);
  48669. return WMTSCapabilityObject ? WMTSCapabilityObject : null;
  48670. };
  48671. /**
  48672. * @private
  48673. * @param {Node} node Node.
  48674. * @param {Array.<*>} objectStack Object stack.
  48675. * @return {Object|undefined} Attribution object.
  48676. */
  48677. ol.format.WMTSCapabilities.readContents_ = function(node, objectStack) {
  48678. return ol.xml.pushParseAndPop({},
  48679. ol.format.WMTSCapabilities.CONTENTS_PARSERS_, node, objectStack);
  48680. };
  48681. /**
  48682. * @private
  48683. * @param {Node} node Node.
  48684. * @param {Array.<*>} objectStack Object stack.
  48685. * @return {Object|undefined} Layers object.
  48686. */
  48687. ol.format.WMTSCapabilities.readLayer_ = function(node, objectStack) {
  48688. return ol.xml.pushParseAndPop({},
  48689. ol.format.WMTSCapabilities.LAYER_PARSERS_, node, objectStack);
  48690. };
  48691. /**
  48692. * @private
  48693. * @param {Node} node Node.
  48694. * @param {Array.<*>} objectStack Object stack.
  48695. * @return {Object|undefined} Tile Matrix Set object.
  48696. */
  48697. ol.format.WMTSCapabilities.readTileMatrixSet_ = function(node, objectStack) {
  48698. return ol.xml.pushParseAndPop({},
  48699. ol.format.WMTSCapabilities.TMS_PARSERS_, node, objectStack);
  48700. };
  48701. /**
  48702. * @private
  48703. * @param {Node} node Node.
  48704. * @param {Array.<*>} objectStack Object stack.
  48705. * @return {Object|undefined} Style object.
  48706. */
  48707. ol.format.WMTSCapabilities.readStyle_ = function(node, objectStack) {
  48708. var style = ol.xml.pushParseAndPop({},
  48709. ol.format.WMTSCapabilities.STYLE_PARSERS_, node, objectStack);
  48710. if (!style) {
  48711. return undefined;
  48712. }
  48713. var isDefault = node.getAttribute('isDefault') === 'true';
  48714. style['isDefault'] = isDefault;
  48715. return style;
  48716. };
  48717. /**
  48718. * @private
  48719. * @param {Node} node Node.
  48720. * @param {Array.<*>} objectStack Object stack.
  48721. * @return {Object|undefined} Tile Matrix Set Link object.
  48722. */
  48723. ol.format.WMTSCapabilities.readTileMatrixSetLink_ = function(node,
  48724. objectStack) {
  48725. return ol.xml.pushParseAndPop({},
  48726. ol.format.WMTSCapabilities.TMS_LINKS_PARSERS_, node, objectStack);
  48727. };
  48728. /**
  48729. * @private
  48730. * @param {Node} node Node.
  48731. * @param {Array.<*>} objectStack Object stack.
  48732. * @return {Object|undefined} Dimension object.
  48733. */
  48734. ol.format.WMTSCapabilities.readDimensions_ = function(node, objectStack) {
  48735. return ol.xml.pushParseAndPop({},
  48736. ol.format.WMTSCapabilities.DIMENSION_PARSERS_, node, objectStack);
  48737. };
  48738. /**
  48739. * @private
  48740. * @param {Node} node Node.
  48741. * @param {Array.<*>} objectStack Object stack.
  48742. * @return {Object|undefined} Resource URL object.
  48743. */
  48744. ol.format.WMTSCapabilities.readResourceUrl_ = function(node, objectStack) {
  48745. var format = node.getAttribute('format');
  48746. var template = node.getAttribute('template');
  48747. var resourceType = node.getAttribute('resourceType');
  48748. var resource = {};
  48749. if (format) {
  48750. resource['format'] = format;
  48751. }
  48752. if (template) {
  48753. resource['template'] = template;
  48754. }
  48755. if (resourceType) {
  48756. resource['resourceType'] = resourceType;
  48757. }
  48758. return resource;
  48759. };
  48760. /**
  48761. * @private
  48762. * @param {Node} node Node.
  48763. * @param {Array.<*>} objectStack Object stack.
  48764. * @return {Object|undefined} WGS84 BBox object.
  48765. */
  48766. ol.format.WMTSCapabilities.readWgs84BoundingBox_ = function(node, objectStack) {
  48767. var coordinates = ol.xml.pushParseAndPop([],
  48768. ol.format.WMTSCapabilities.WGS84_BBOX_READERS_, node, objectStack);
  48769. if (coordinates.length != 2) {
  48770. return undefined;
  48771. }
  48772. return ol.extent.boundingExtent(coordinates);
  48773. };
  48774. /**
  48775. * @private
  48776. * @param {Node} node Node.
  48777. * @param {Array.<*>} objectStack Object stack.
  48778. * @return {Object|undefined} Legend object.
  48779. */
  48780. ol.format.WMTSCapabilities.readLegendUrl_ = function(node, objectStack) {
  48781. var legend = {};
  48782. legend['format'] = node.getAttribute('format');
  48783. legend['href'] = ol.format.XLink.readHref(node);
  48784. return legend;
  48785. };
  48786. /**
  48787. * @private
  48788. * @param {Node} node Node.
  48789. * @param {Array.<*>} objectStack Object stack.
  48790. * @return {Object|undefined} Coordinates object.
  48791. */
  48792. ol.format.WMTSCapabilities.readCoordinates_ = function(node, objectStack) {
  48793. var coordinates = ol.format.XSD.readString(node).split(' ');
  48794. if (!coordinates || coordinates.length != 2) {
  48795. return undefined;
  48796. }
  48797. var x = +coordinates[0];
  48798. var y = +coordinates[1];
  48799. if (isNaN(x) || isNaN(y)) {
  48800. return undefined;
  48801. }
  48802. return [x, y];
  48803. };
  48804. /**
  48805. * @private
  48806. * @param {Node} node Node.
  48807. * @param {Array.<*>} objectStack Object stack.
  48808. * @return {Object|undefined} TileMatrix object.
  48809. */
  48810. ol.format.WMTSCapabilities.readTileMatrix_ = function(node, objectStack) {
  48811. return ol.xml.pushParseAndPop({},
  48812. ol.format.WMTSCapabilities.TM_PARSERS_, node, objectStack);
  48813. };
  48814. /**
  48815. * @private
  48816. * @param {Node} node Node.
  48817. * @param {Array.<*>} objectStack Object stack.
  48818. * @return {Object|undefined} TileMatrixSetLimits Object.
  48819. */
  48820. ol.format.WMTSCapabilities.readTileMatrixLimitsList_ = function(node,
  48821. objectStack) {
  48822. return ol.xml.pushParseAndPop([],
  48823. ol.format.WMTSCapabilities.TMS_LIMITS_LIST_PARSERS_, node,
  48824. objectStack);
  48825. };
  48826. /**
  48827. * @private
  48828. * @param {Node} node Node.
  48829. * @param {Array.<*>} objectStack Object stack.
  48830. * @return {Object|undefined} TileMatrixLimits Array.
  48831. */
  48832. ol.format.WMTSCapabilities.readTileMatrixLimits_ = function(node, objectStack) {
  48833. return ol.xml.pushParseAndPop({},
  48834. ol.format.WMTSCapabilities.TMS_LIMITS_PARSERS_, node, objectStack);
  48835. };
  48836. /**
  48837. * @const
  48838. * @private
  48839. * @type {Array.<string>}
  48840. */
  48841. ol.format.WMTSCapabilities.NAMESPACE_URIS_ = [
  48842. null,
  48843. 'http://www.opengis.net/wmts/1.0'
  48844. ];
  48845. /**
  48846. * @const
  48847. * @private
  48848. * @type {Array.<string>}
  48849. */
  48850. ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_ = [
  48851. null,
  48852. 'http://www.opengis.net/ows/1.1'
  48853. ];
  48854. /**
  48855. * @const
  48856. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48857. * @private
  48858. */
  48859. ol.format.WMTSCapabilities.PARSERS_ = ol.xml.makeStructureNS(
  48860. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48861. 'Contents': ol.xml.makeObjectPropertySetter(
  48862. ol.format.WMTSCapabilities.readContents_)
  48863. });
  48864. /**
  48865. * @const
  48866. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48867. * @private
  48868. */
  48869. ol.format.WMTSCapabilities.CONTENTS_PARSERS_ = ol.xml.makeStructureNS(
  48870. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48871. 'Layer': ol.xml.makeObjectPropertyPusher(
  48872. ol.format.WMTSCapabilities.readLayer_),
  48873. 'TileMatrixSet': ol.xml.makeObjectPropertyPusher(
  48874. ol.format.WMTSCapabilities.readTileMatrixSet_)
  48875. });
  48876. /**
  48877. * @const
  48878. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48879. * @private
  48880. */
  48881. ol.format.WMTSCapabilities.LAYER_PARSERS_ = ol.xml.makeStructureNS(
  48882. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48883. 'Style': ol.xml.makeObjectPropertyPusher(
  48884. ol.format.WMTSCapabilities.readStyle_),
  48885. 'Format': ol.xml.makeObjectPropertyPusher(
  48886. ol.format.XSD.readString),
  48887. 'TileMatrixSetLink': ol.xml.makeObjectPropertyPusher(
  48888. ol.format.WMTSCapabilities.readTileMatrixSetLink_),
  48889. 'Dimension': ol.xml.makeObjectPropertyPusher(
  48890. ol.format.WMTSCapabilities.readDimensions_),
  48891. 'ResourceURL': ol.xml.makeObjectPropertyPusher(
  48892. ol.format.WMTSCapabilities.readResourceUrl_)
  48893. }, ol.xml.makeStructureNS(ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_, {
  48894. 'Title': ol.xml.makeObjectPropertySetter(
  48895. ol.format.XSD.readString),
  48896. 'Abstract': ol.xml.makeObjectPropertySetter(
  48897. ol.format.XSD.readString),
  48898. 'WGS84BoundingBox': ol.xml.makeObjectPropertySetter(
  48899. ol.format.WMTSCapabilities.readWgs84BoundingBox_),
  48900. 'Identifier': ol.xml.makeObjectPropertySetter(
  48901. ol.format.XSD.readString)
  48902. }));
  48903. /**
  48904. * @const
  48905. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48906. * @private
  48907. */
  48908. ol.format.WMTSCapabilities.STYLE_PARSERS_ = ol.xml.makeStructureNS(
  48909. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48910. 'LegendURL': ol.xml.makeObjectPropertyPusher(
  48911. ol.format.WMTSCapabilities.readLegendUrl_)
  48912. }, ol.xml.makeStructureNS(ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_, {
  48913. 'Title': ol.xml.makeObjectPropertySetter(
  48914. ol.format.XSD.readString),
  48915. 'Identifier': ol.xml.makeObjectPropertySetter(
  48916. ol.format.XSD.readString)
  48917. }));
  48918. /**
  48919. * @const
  48920. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48921. * @private
  48922. */
  48923. ol.format.WMTSCapabilities.TMS_LINKS_PARSERS_ = ol.xml.makeStructureNS(
  48924. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48925. 'TileMatrixSet': ol.xml.makeObjectPropertySetter(
  48926. ol.format.XSD.readString),
  48927. 'TileMatrixSetLimits': ol.xml.makeObjectPropertySetter(
  48928. ol.format.WMTSCapabilities.readTileMatrixLimitsList_)
  48929. });
  48930. /**
  48931. * @const
  48932. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48933. * @private
  48934. */
  48935. ol.format.WMTSCapabilities.TMS_LIMITS_LIST_PARSERS_ = ol.xml.makeStructureNS(
  48936. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48937. 'TileMatrixLimits': ol.xml.makeArrayPusher(
  48938. ol.format.WMTSCapabilities.readTileMatrixLimits_)
  48939. });
  48940. /**
  48941. * @const
  48942. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48943. * @private
  48944. */
  48945. ol.format.WMTSCapabilities.TMS_LIMITS_PARSERS_ = ol.xml.makeStructureNS(
  48946. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48947. 'TileMatrix': ol.xml.makeObjectPropertySetter(
  48948. ol.format.XSD.readString),
  48949. 'MinTileRow': ol.xml.makeObjectPropertySetter(
  48950. ol.format.XSD.readNonNegativeInteger),
  48951. 'MaxTileRow': ol.xml.makeObjectPropertySetter(
  48952. ol.format.XSD.readNonNegativeInteger),
  48953. 'MinTileCol': ol.xml.makeObjectPropertySetter(
  48954. ol.format.XSD.readNonNegativeInteger),
  48955. 'MaxTileCol': ol.xml.makeObjectPropertySetter(
  48956. ol.format.XSD.readNonNegativeInteger)
  48957. });
  48958. /**
  48959. * @const
  48960. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48961. * @private
  48962. */
  48963. ol.format.WMTSCapabilities.DIMENSION_PARSERS_ = ol.xml.makeStructureNS(
  48964. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48965. 'Default': ol.xml.makeObjectPropertySetter(
  48966. ol.format.XSD.readString),
  48967. 'Value': ol.xml.makeObjectPropertyPusher(
  48968. ol.format.XSD.readString)
  48969. }, ol.xml.makeStructureNS(ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_, {
  48970. 'Identifier': ol.xml.makeObjectPropertySetter(
  48971. ol.format.XSD.readString)
  48972. }));
  48973. /**
  48974. * @const
  48975. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48976. * @private
  48977. */
  48978. ol.format.WMTSCapabilities.WGS84_BBOX_READERS_ = ol.xml.makeStructureNS(
  48979. ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_, {
  48980. 'LowerCorner': ol.xml.makeArrayPusher(
  48981. ol.format.WMTSCapabilities.readCoordinates_),
  48982. 'UpperCorner': ol.xml.makeArrayPusher(
  48983. ol.format.WMTSCapabilities.readCoordinates_)
  48984. });
  48985. /**
  48986. * @const
  48987. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  48988. * @private
  48989. */
  48990. ol.format.WMTSCapabilities.TMS_PARSERS_ = ol.xml.makeStructureNS(
  48991. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  48992. 'WellKnownScaleSet': ol.xml.makeObjectPropertySetter(
  48993. ol.format.XSD.readString),
  48994. 'TileMatrix': ol.xml.makeObjectPropertyPusher(
  48995. ol.format.WMTSCapabilities.readTileMatrix_)
  48996. }, ol.xml.makeStructureNS(ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_, {
  48997. 'SupportedCRS': ol.xml.makeObjectPropertySetter(
  48998. ol.format.XSD.readString),
  48999. 'Identifier': ol.xml.makeObjectPropertySetter(
  49000. ol.format.XSD.readString)
  49001. }));
  49002. /**
  49003. * @const
  49004. * @type {Object.<string, Object.<string, ol.XmlParser>>}
  49005. * @private
  49006. */
  49007. ol.format.WMTSCapabilities.TM_PARSERS_ = ol.xml.makeStructureNS(
  49008. ol.format.WMTSCapabilities.NAMESPACE_URIS_, {
  49009. 'TopLeftCorner': ol.xml.makeObjectPropertySetter(
  49010. ol.format.WMTSCapabilities.readCoordinates_),
  49011. 'ScaleDenominator': ol.xml.makeObjectPropertySetter(
  49012. ol.format.XSD.readDecimal),
  49013. 'TileWidth': ol.xml.makeObjectPropertySetter(
  49014. ol.format.XSD.readNonNegativeInteger),
  49015. 'TileHeight': ol.xml.makeObjectPropertySetter(
  49016. ol.format.XSD.readNonNegativeInteger),
  49017. 'MatrixWidth': ol.xml.makeObjectPropertySetter(
  49018. ol.format.XSD.readNonNegativeInteger),
  49019. 'MatrixHeight': ol.xml.makeObjectPropertySetter(
  49020. ol.format.XSD.readNonNegativeInteger)
  49021. }, ol.xml.makeStructureNS(ol.format.WMTSCapabilities.OWS_NAMESPACE_URIS_, {
  49022. 'Identifier': ol.xml.makeObjectPropertySetter(
  49023. ol.format.XSD.readString)
  49024. }));
  49025. goog.provide('ol.GeolocationProperty');
  49026. /**
  49027. * @enum {string}
  49028. */
  49029. ol.GeolocationProperty = {
  49030. ACCURACY: 'accuracy',
  49031. ACCURACY_GEOMETRY: 'accuracyGeometry',
  49032. ALTITUDE: 'altitude',
  49033. ALTITUDE_ACCURACY: 'altitudeAccuracy',
  49034. HEADING: 'heading',
  49035. POSITION: 'position',
  49036. PROJECTION: 'projection',
  49037. SPEED: 'speed',
  49038. TRACKING: 'tracking',
  49039. TRACKING_OPTIONS: 'trackingOptions'
  49040. };
  49041. // FIXME handle geolocation not supported
  49042. goog.provide('ol.Geolocation');
  49043. goog.require('ol');
  49044. goog.require('ol.GeolocationProperty');
  49045. goog.require('ol.Object');
  49046. goog.require('ol.Sphere');
  49047. goog.require('ol.events');
  49048. goog.require('ol.events.EventType');
  49049. goog.require('ol.geom.Polygon');
  49050. goog.require('ol.has');
  49051. goog.require('ol.math');
  49052. goog.require('ol.proj');
  49053. goog.require('ol.proj.EPSG4326');
  49054. /**
  49055. * @classdesc
  49056. * Helper class for providing HTML5 Geolocation capabilities.
  49057. * The [Geolocation API](http://www.w3.org/TR/geolocation-API/)
  49058. * is used to locate a user's position.
  49059. *
  49060. * To get notified of position changes, register a listener for the generic
  49061. * `change` event on your instance of `ol.Geolocation`.
  49062. *
  49063. * Example:
  49064. *
  49065. * var geolocation = new ol.Geolocation({
  49066. * // take the projection to use from the map's view
  49067. * projection: view.getProjection()
  49068. * });
  49069. * // listen to changes in position
  49070. * geolocation.on('change', function(evt) {
  49071. * window.console.log(geolocation.getPosition());
  49072. * });
  49073. *
  49074. * @fires error
  49075. * @constructor
  49076. * @extends {ol.Object}
  49077. * @param {olx.GeolocationOptions=} opt_options Options.
  49078. * @api
  49079. */
  49080. ol.Geolocation = function(opt_options) {
  49081. ol.Object.call(this);
  49082. var options = opt_options || {};
  49083. /**
  49084. * The unprojected (EPSG:4326) device position.
  49085. * @private
  49086. * @type {ol.Coordinate}
  49087. */
  49088. this.position_ = null;
  49089. /**
  49090. * @private
  49091. * @type {ol.TransformFunction}
  49092. */
  49093. this.transform_ = ol.proj.identityTransform;
  49094. /**
  49095. * @private
  49096. * @type {ol.Sphere}
  49097. */
  49098. this.sphere_ = new ol.Sphere(ol.proj.EPSG4326.RADIUS);
  49099. /**
  49100. * @private
  49101. * @type {number|undefined}
  49102. */
  49103. this.watchId_ = undefined;
  49104. ol.events.listen(
  49105. this, ol.Object.getChangeEventType(ol.GeolocationProperty.PROJECTION),
  49106. this.handleProjectionChanged_, this);
  49107. ol.events.listen(
  49108. this, ol.Object.getChangeEventType(ol.GeolocationProperty.TRACKING),
  49109. this.handleTrackingChanged_, this);
  49110. if (options.projection !== undefined) {
  49111. this.setProjection(options.projection);
  49112. }
  49113. if (options.trackingOptions !== undefined) {
  49114. this.setTrackingOptions(options.trackingOptions);
  49115. }
  49116. this.setTracking(options.tracking !== undefined ? options.tracking : false);
  49117. };
  49118. ol.inherits(ol.Geolocation, ol.Object);
  49119. /**
  49120. * @inheritDoc
  49121. */
  49122. ol.Geolocation.prototype.disposeInternal = function() {
  49123. this.setTracking(false);
  49124. ol.Object.prototype.disposeInternal.call(this);
  49125. };
  49126. /**
  49127. * @private
  49128. */
  49129. ol.Geolocation.prototype.handleProjectionChanged_ = function() {
  49130. var projection = this.getProjection();
  49131. if (projection) {
  49132. this.transform_ = ol.proj.getTransformFromProjections(
  49133. ol.proj.get('EPSG:4326'), projection);
  49134. if (this.position_) {
  49135. this.set(
  49136. ol.GeolocationProperty.POSITION, this.transform_(this.position_));
  49137. }
  49138. }
  49139. };
  49140. /**
  49141. * @private
  49142. */
  49143. ol.Geolocation.prototype.handleTrackingChanged_ = function() {
  49144. if (ol.has.GEOLOCATION) {
  49145. var tracking = this.getTracking();
  49146. if (tracking && this.watchId_ === undefined) {
  49147. this.watchId_ = navigator.geolocation.watchPosition(
  49148. this.positionChange_.bind(this),
  49149. this.positionError_.bind(this),
  49150. this.getTrackingOptions());
  49151. } else if (!tracking && this.watchId_ !== undefined) {
  49152. navigator.geolocation.clearWatch(this.watchId_);
  49153. this.watchId_ = undefined;
  49154. }
  49155. }
  49156. };
  49157. /**
  49158. * @private
  49159. * @param {GeolocationPosition} position position event.
  49160. */
  49161. ol.Geolocation.prototype.positionChange_ = function(position) {
  49162. var coords = position.coords;
  49163. this.set(ol.GeolocationProperty.ACCURACY, coords.accuracy);
  49164. this.set(ol.GeolocationProperty.ALTITUDE,
  49165. coords.altitude === null ? undefined : coords.altitude);
  49166. this.set(ol.GeolocationProperty.ALTITUDE_ACCURACY,
  49167. coords.altitudeAccuracy === null ?
  49168. undefined : coords.altitudeAccuracy);
  49169. this.set(ol.GeolocationProperty.HEADING, coords.heading === null ?
  49170. undefined : ol.math.toRadians(coords.heading));
  49171. if (!this.position_) {
  49172. this.position_ = [coords.longitude, coords.latitude];
  49173. } else {
  49174. this.position_[0] = coords.longitude;
  49175. this.position_[1] = coords.latitude;
  49176. }
  49177. var projectedPosition = this.transform_(this.position_);
  49178. this.set(ol.GeolocationProperty.POSITION, projectedPosition);
  49179. this.set(ol.GeolocationProperty.SPEED,
  49180. coords.speed === null ? undefined : coords.speed);
  49181. var geometry = ol.geom.Polygon.circular(
  49182. this.sphere_, this.position_, coords.accuracy);
  49183. geometry.applyTransform(this.transform_);
  49184. this.set(ol.GeolocationProperty.ACCURACY_GEOMETRY, geometry);
  49185. this.changed();
  49186. };
  49187. /**
  49188. * Triggered when the Geolocation returns an error.
  49189. * @event error
  49190. * @api
  49191. */
  49192. /**
  49193. * @private
  49194. * @param {GeolocationPositionError} error error object.
  49195. */
  49196. ol.Geolocation.prototype.positionError_ = function(error) {
  49197. error.type = ol.events.EventType.ERROR;
  49198. this.setTracking(false);
  49199. this.dispatchEvent(/** @type {{type: string, target: undefined}} */ (error));
  49200. };
  49201. /**
  49202. * Get the accuracy of the position in meters.
  49203. * @return {number|undefined} The accuracy of the position measurement in
  49204. * meters.
  49205. * @observable
  49206. * @api
  49207. */
  49208. ol.Geolocation.prototype.getAccuracy = function() {
  49209. return /** @type {number|undefined} */ (
  49210. this.get(ol.GeolocationProperty.ACCURACY));
  49211. };
  49212. /**
  49213. * Get a geometry of the position accuracy.
  49214. * @return {?ol.geom.Polygon} A geometry of the position accuracy.
  49215. * @observable
  49216. * @api
  49217. */
  49218. ol.Geolocation.prototype.getAccuracyGeometry = function() {
  49219. return /** @type {?ol.geom.Polygon} */ (
  49220. this.get(ol.GeolocationProperty.ACCURACY_GEOMETRY) || null);
  49221. };
  49222. /**
  49223. * Get the altitude associated with the position.
  49224. * @return {number|undefined} The altitude of the position in meters above mean
  49225. * sea level.
  49226. * @observable
  49227. * @api
  49228. */
  49229. ol.Geolocation.prototype.getAltitude = function() {
  49230. return /** @type {number|undefined} */ (
  49231. this.get(ol.GeolocationProperty.ALTITUDE));
  49232. };
  49233. /**
  49234. * Get the altitude accuracy of the position.
  49235. * @return {number|undefined} The accuracy of the altitude measurement in
  49236. * meters.
  49237. * @observable
  49238. * @api
  49239. */
  49240. ol.Geolocation.prototype.getAltitudeAccuracy = function() {
  49241. return /** @type {number|undefined} */ (
  49242. this.get(ol.GeolocationProperty.ALTITUDE_ACCURACY));
  49243. };
  49244. /**
  49245. * Get the heading as radians clockwise from North.
  49246. * @return {number|undefined} The heading of the device in radians from north.
  49247. * @observable
  49248. * @api
  49249. */
  49250. ol.Geolocation.prototype.getHeading = function() {
  49251. return /** @type {number|undefined} */ (
  49252. this.get(ol.GeolocationProperty.HEADING));
  49253. };
  49254. /**
  49255. * Get the position of the device.
  49256. * @return {ol.Coordinate|undefined} The current position of the device reported
  49257. * in the current projection.
  49258. * @observable
  49259. * @api
  49260. */
  49261. ol.Geolocation.prototype.getPosition = function() {
  49262. return /** @type {ol.Coordinate|undefined} */ (
  49263. this.get(ol.GeolocationProperty.POSITION));
  49264. };
  49265. /**
  49266. * Get the projection associated with the position.
  49267. * @return {ol.proj.Projection|undefined} The projection the position is
  49268. * reported in.
  49269. * @observable
  49270. * @api
  49271. */
  49272. ol.Geolocation.prototype.getProjection = function() {
  49273. return /** @type {ol.proj.Projection|undefined} */ (
  49274. this.get(ol.GeolocationProperty.PROJECTION));
  49275. };
  49276. /**
  49277. * Get the speed in meters per second.
  49278. * @return {number|undefined} The instantaneous speed of the device in meters
  49279. * per second.
  49280. * @observable
  49281. * @api
  49282. */
  49283. ol.Geolocation.prototype.getSpeed = function() {
  49284. return /** @type {number|undefined} */ (
  49285. this.get(ol.GeolocationProperty.SPEED));
  49286. };
  49287. /**
  49288. * Determine if the device location is being tracked.
  49289. * @return {boolean} The device location is being tracked.
  49290. * @observable
  49291. * @api
  49292. */
  49293. ol.Geolocation.prototype.getTracking = function() {
  49294. return /** @type {boolean} */ (
  49295. this.get(ol.GeolocationProperty.TRACKING));
  49296. };
  49297. /**
  49298. * Get the tracking options.
  49299. * @see http://www.w3.org/TR/geolocation-API/#position-options
  49300. * @return {GeolocationPositionOptions|undefined} PositionOptions as defined by
  49301. * the [HTML5 Geolocation spec
  49302. * ](http://www.w3.org/TR/geolocation-API/#position_options_interface).
  49303. * @observable
  49304. * @api
  49305. */
  49306. ol.Geolocation.prototype.getTrackingOptions = function() {
  49307. return /** @type {GeolocationPositionOptions|undefined} */ (
  49308. this.get(ol.GeolocationProperty.TRACKING_OPTIONS));
  49309. };
  49310. /**
  49311. * Set the projection to use for transforming the coordinates.
  49312. * @param {ol.ProjectionLike} projection The projection the position is
  49313. * reported in.
  49314. * @observable
  49315. * @api
  49316. */
  49317. ol.Geolocation.prototype.setProjection = function(projection) {
  49318. this.set(ol.GeolocationProperty.PROJECTION, ol.proj.get(projection));
  49319. };
  49320. /**
  49321. * Enable or disable tracking.
  49322. * @param {boolean} tracking Enable tracking.
  49323. * @observable
  49324. * @api
  49325. */
  49326. ol.Geolocation.prototype.setTracking = function(tracking) {
  49327. this.set(ol.GeolocationProperty.TRACKING, tracking);
  49328. };
  49329. /**
  49330. * Set the tracking options.
  49331. * @see http://www.w3.org/TR/geolocation-API/#position-options
  49332. * @param {GeolocationPositionOptions} options PositionOptions as defined by the
  49333. * [HTML5 Geolocation spec
  49334. * ](http://www.w3.org/TR/geolocation-API/#position_options_interface).
  49335. * @observable
  49336. * @api
  49337. */
  49338. ol.Geolocation.prototype.setTrackingOptions = function(options) {
  49339. this.set(ol.GeolocationProperty.TRACKING_OPTIONS, options);
  49340. };
  49341. goog.provide('ol.geom.Circle');
  49342. goog.require('ol');
  49343. goog.require('ol.extent');
  49344. goog.require('ol.geom.GeometryLayout');
  49345. goog.require('ol.geom.GeometryType');
  49346. goog.require('ol.geom.SimpleGeometry');
  49347. goog.require('ol.geom.flat.deflate');
  49348. /**
  49349. * @classdesc
  49350. * Circle geometry.
  49351. *
  49352. * @constructor
  49353. * @extends {ol.geom.SimpleGeometry}
  49354. * @param {ol.Coordinate} center Center.
  49355. * @param {number=} opt_radius Radius.
  49356. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  49357. * @api
  49358. */
  49359. ol.geom.Circle = function(center, opt_radius, opt_layout) {
  49360. ol.geom.SimpleGeometry.call(this);
  49361. var radius = opt_radius ? opt_radius : 0;
  49362. this.setCenterAndRadius(center, radius, opt_layout);
  49363. };
  49364. ol.inherits(ol.geom.Circle, ol.geom.SimpleGeometry);
  49365. /**
  49366. * Make a complete copy of the geometry.
  49367. * @return {!ol.geom.Circle} Clone.
  49368. * @override
  49369. * @api
  49370. */
  49371. ol.geom.Circle.prototype.clone = function() {
  49372. var circle = new ol.geom.Circle(null);
  49373. circle.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
  49374. return circle;
  49375. };
  49376. /**
  49377. * @inheritDoc
  49378. */
  49379. ol.geom.Circle.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
  49380. var flatCoordinates = this.flatCoordinates;
  49381. var dx = x - flatCoordinates[0];
  49382. var dy = y - flatCoordinates[1];
  49383. var squaredDistance = dx * dx + dy * dy;
  49384. if (squaredDistance < minSquaredDistance) {
  49385. var i;
  49386. if (squaredDistance === 0) {
  49387. for (i = 0; i < this.stride; ++i) {
  49388. closestPoint[i] = flatCoordinates[i];
  49389. }
  49390. } else {
  49391. var delta = this.getRadius() / Math.sqrt(squaredDistance);
  49392. closestPoint[0] = flatCoordinates[0] + delta * dx;
  49393. closestPoint[1] = flatCoordinates[1] + delta * dy;
  49394. for (i = 2; i < this.stride; ++i) {
  49395. closestPoint[i] = flatCoordinates[i];
  49396. }
  49397. }
  49398. closestPoint.length = this.stride;
  49399. return squaredDistance;
  49400. } else {
  49401. return minSquaredDistance;
  49402. }
  49403. };
  49404. /**
  49405. * @inheritDoc
  49406. */
  49407. ol.geom.Circle.prototype.containsXY = function(x, y) {
  49408. var flatCoordinates = this.flatCoordinates;
  49409. var dx = x - flatCoordinates[0];
  49410. var dy = y - flatCoordinates[1];
  49411. return dx * dx + dy * dy <= this.getRadiusSquared_();
  49412. };
  49413. /**
  49414. * Return the center of the circle as {@link ol.Coordinate coordinate}.
  49415. * @return {ol.Coordinate} Center.
  49416. * @api
  49417. */
  49418. ol.geom.Circle.prototype.getCenter = function() {
  49419. return this.flatCoordinates.slice(0, this.stride);
  49420. };
  49421. /**
  49422. * @inheritDoc
  49423. */
  49424. ol.geom.Circle.prototype.computeExtent = function(extent) {
  49425. var flatCoordinates = this.flatCoordinates;
  49426. var radius = flatCoordinates[this.stride] - flatCoordinates[0];
  49427. return ol.extent.createOrUpdate(
  49428. flatCoordinates[0] - radius, flatCoordinates[1] - radius,
  49429. flatCoordinates[0] + radius, flatCoordinates[1] + radius,
  49430. extent);
  49431. };
  49432. /**
  49433. * Return the radius of the circle.
  49434. * @return {number} Radius.
  49435. * @api
  49436. */
  49437. ol.geom.Circle.prototype.getRadius = function() {
  49438. return Math.sqrt(this.getRadiusSquared_());
  49439. };
  49440. /**
  49441. * @private
  49442. * @return {number} Radius squared.
  49443. */
  49444. ol.geom.Circle.prototype.getRadiusSquared_ = function() {
  49445. var dx = this.flatCoordinates[this.stride] - this.flatCoordinates[0];
  49446. var dy = this.flatCoordinates[this.stride + 1] - this.flatCoordinates[1];
  49447. return dx * dx + dy * dy;
  49448. };
  49449. /**
  49450. * @inheritDoc
  49451. * @api
  49452. */
  49453. ol.geom.Circle.prototype.getType = function() {
  49454. return ol.geom.GeometryType.CIRCLE;
  49455. };
  49456. /**
  49457. * @inheritDoc
  49458. * @api
  49459. */
  49460. ol.geom.Circle.prototype.intersectsExtent = function(extent) {
  49461. var circleExtent = this.getExtent();
  49462. if (ol.extent.intersects(extent, circleExtent)) {
  49463. var center = this.getCenter();
  49464. if (extent[0] <= center[0] && extent[2] >= center[0]) {
  49465. return true;
  49466. }
  49467. if (extent[1] <= center[1] && extent[3] >= center[1]) {
  49468. return true;
  49469. }
  49470. return ol.extent.forEachCorner(extent, this.intersectsCoordinate, this);
  49471. }
  49472. return false;
  49473. };
  49474. /**
  49475. * Set the center of the circle as {@link ol.Coordinate coordinate}.
  49476. * @param {ol.Coordinate} center Center.
  49477. * @api
  49478. */
  49479. ol.geom.Circle.prototype.setCenter = function(center) {
  49480. var stride = this.stride;
  49481. var radius = this.flatCoordinates[stride] - this.flatCoordinates[0];
  49482. var flatCoordinates = center.slice();
  49483. flatCoordinates[stride] = flatCoordinates[0] + radius;
  49484. var i;
  49485. for (i = 1; i < stride; ++i) {
  49486. flatCoordinates[stride + i] = center[i];
  49487. }
  49488. this.setFlatCoordinates(this.layout, flatCoordinates);
  49489. };
  49490. /**
  49491. * Set the center (as {@link ol.Coordinate coordinate}) and the radius (as
  49492. * number) of the circle.
  49493. * @param {ol.Coordinate} center Center.
  49494. * @param {number} radius Radius.
  49495. * @param {ol.geom.GeometryLayout=} opt_layout Layout.
  49496. * @api
  49497. */
  49498. ol.geom.Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) {
  49499. if (!center) {
  49500. this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null);
  49501. } else {
  49502. this.setLayout(opt_layout, center, 0);
  49503. if (!this.flatCoordinates) {
  49504. this.flatCoordinates = [];
  49505. }
  49506. /** @type {Array.<number>} */
  49507. var flatCoordinates = this.flatCoordinates;
  49508. var offset = ol.geom.flat.deflate.coordinate(
  49509. flatCoordinates, 0, center, this.stride);
  49510. flatCoordinates[offset++] = flatCoordinates[0] + radius;
  49511. var i, ii;
  49512. for (i = 1, ii = this.stride; i < ii; ++i) {
  49513. flatCoordinates[offset++] = flatCoordinates[i];
  49514. }
  49515. flatCoordinates.length = offset;
  49516. this.changed();
  49517. }
  49518. };
  49519. /**
  49520. * @inheritDoc
  49521. */
  49522. ol.geom.Circle.prototype.getCoordinates = function() {};
  49523. /**
  49524. * @inheritDoc
  49525. */
  49526. ol.geom.Circle.prototype.setCoordinates = function(coordinates, opt_layout) {};
  49527. /**
  49528. * @param {ol.geom.GeometryLayout} layout Layout.
  49529. * @param {Array.<number>} flatCoordinates Flat coordinates.
  49530. */
  49531. ol.geom.Circle.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
  49532. this.setFlatCoordinatesInternal(layout, flatCoordinates);
  49533. this.changed();
  49534. };
  49535. /**
  49536. * Set the radius of the circle. The radius is in the units of the projection.
  49537. * @param {number} radius Radius.
  49538. * @api
  49539. */
  49540. ol.geom.Circle.prototype.setRadius = function(radius) {
  49541. this.flatCoordinates[this.stride] = this.flatCoordinates[0] + radius;
  49542. this.changed();
  49543. };
  49544. /**
  49545. * Transform each coordinate of the circle from one coordinate reference system
  49546. * to another. The geometry is modified in place.
  49547. * If you do not want the geometry modified in place, first clone() it and
  49548. * then use this function on the clone.
  49549. *
  49550. * Internally a circle is currently represented by two points: the center of
  49551. * the circle `[cx, cy]`, and the point to the right of the circle
  49552. * `[cx + r, cy]`. This `transform` function just transforms these two points.
  49553. * So the resulting geometry is also a circle, and that circle does not
  49554. * correspond to the shape that would be obtained by transforming every point
  49555. * of the original circle.
  49556. *
  49557. * @param {ol.ProjectionLike} source The current projection. Can be a
  49558. * string identifier or a {@link ol.proj.Projection} object.
  49559. * @param {ol.ProjectionLike} destination The desired projection. Can be a
  49560. * string identifier or a {@link ol.proj.Projection} object.
  49561. * @return {ol.geom.Circle} This geometry. Note that original geometry is
  49562. * modified in place.
  49563. * @function
  49564. * @api
  49565. */
  49566. ol.geom.Circle.prototype.transform;
  49567. goog.provide('ol.geom.flat.geodesic');
  49568. goog.require('ol.math');
  49569. goog.require('ol.proj');
  49570. /**
  49571. * @private
  49572. * @param {function(number): ol.Coordinate} interpolate Interpolate function.
  49573. * @param {ol.TransformFunction} transform Transform from longitude/latitude to
  49574. * projected coordinates.
  49575. * @param {number} squaredTolerance Squared tolerance.
  49576. * @return {Array.<number>} Flat coordinates.
  49577. */
  49578. ol.geom.flat.geodesic.line_ = function(interpolate, transform, squaredTolerance) {
  49579. // FIXME reduce garbage generation
  49580. // FIXME optimize stack operations
  49581. /** @type {Array.<number>} */
  49582. var flatCoordinates = [];
  49583. var geoA = interpolate(0);
  49584. var geoB = interpolate(1);
  49585. var a = transform(geoA);
  49586. var b = transform(geoB);
  49587. /** @type {Array.<ol.Coordinate>} */
  49588. var geoStack = [geoB, geoA];
  49589. /** @type {Array.<ol.Coordinate>} */
  49590. var stack = [b, a];
  49591. /** @type {Array.<number>} */
  49592. var fractionStack = [1, 0];
  49593. /** @type {Object.<string, boolean>} */
  49594. var fractions = {};
  49595. var maxIterations = 1e5;
  49596. var geoM, m, fracA, fracB, fracM, key;
  49597. while (--maxIterations > 0 && fractionStack.length > 0) {
  49598. // Pop the a coordinate off the stack
  49599. fracA = fractionStack.pop();
  49600. geoA = geoStack.pop();
  49601. a = stack.pop();
  49602. // Add the a coordinate if it has not been added yet
  49603. key = fracA.toString();
  49604. if (!(key in fractions)) {
  49605. flatCoordinates.push(a[0], a[1]);
  49606. fractions[key] = true;
  49607. }
  49608. // Pop the b coordinate off the stack
  49609. fracB = fractionStack.pop();
  49610. geoB = geoStack.pop();
  49611. b = stack.pop();
  49612. // Find the m point between the a and b coordinates
  49613. fracM = (fracA + fracB) / 2;
  49614. geoM = interpolate(fracM);
  49615. m = transform(geoM);
  49616. if (ol.math.squaredSegmentDistance(m[0], m[1], a[0], a[1],
  49617. b[0], b[1]) < squaredTolerance) {
  49618. // If the m point is sufficiently close to the straight line, then we
  49619. // discard it. Just use the b coordinate and move on to the next line
  49620. // segment.
  49621. flatCoordinates.push(b[0], b[1]);
  49622. key = fracB.toString();
  49623. fractions[key] = true;
  49624. } else {
  49625. // Otherwise, we need to subdivide the current line segment. Split it
  49626. // into two and push the two line segments onto the stack.
  49627. fractionStack.push(fracB, fracM, fracM, fracA);
  49628. stack.push(b, m, m, a);
  49629. geoStack.push(geoB, geoM, geoM, geoA);
  49630. }
  49631. }
  49632. return flatCoordinates;
  49633. };
  49634. /**
  49635. * Generate a great-circle arcs between two lat/lon points.
  49636. * @param {number} lon1 Longitude 1 in degrees.
  49637. * @param {number} lat1 Latitude 1 in degrees.
  49638. * @param {number} lon2 Longitude 2 in degrees.
  49639. * @param {number} lat2 Latitude 2 in degrees.
  49640. * @param {ol.proj.Projection} projection Projection.
  49641. * @param {number} squaredTolerance Squared tolerance.
  49642. * @return {Array.<number>} Flat coordinates.
  49643. */
  49644. ol.geom.flat.geodesic.greatCircleArc = function(
  49645. lon1, lat1, lon2, lat2, projection, squaredTolerance) {
  49646. var geoProjection = ol.proj.get('EPSG:4326');
  49647. var cosLat1 = Math.cos(ol.math.toRadians(lat1));
  49648. var sinLat1 = Math.sin(ol.math.toRadians(lat1));
  49649. var cosLat2 = Math.cos(ol.math.toRadians(lat2));
  49650. var sinLat2 = Math.sin(ol.math.toRadians(lat2));
  49651. var cosDeltaLon = Math.cos(ol.math.toRadians(lon2 - lon1));
  49652. var sinDeltaLon = Math.sin(ol.math.toRadians(lon2 - lon1));
  49653. var d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon;
  49654. return ol.geom.flat.geodesic.line_(
  49655. /**
  49656. * @param {number} frac Fraction.
  49657. * @return {ol.Coordinate} Coordinate.
  49658. */
  49659. function(frac) {
  49660. if (1 <= d) {
  49661. return [lon2, lat2];
  49662. }
  49663. var D = frac * Math.acos(d);
  49664. var cosD = Math.cos(D);
  49665. var sinD = Math.sin(D);
  49666. var y = sinDeltaLon * cosLat2;
  49667. var x = cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosDeltaLon;
  49668. var theta = Math.atan2(y, x);
  49669. var lat = Math.asin(sinLat1 * cosD + cosLat1 * sinD * Math.cos(theta));
  49670. var lon = ol.math.toRadians(lon1) +
  49671. Math.atan2(Math.sin(theta) * sinD * cosLat1,
  49672. cosD - sinLat1 * Math.sin(lat));
  49673. return [ol.math.toDegrees(lon), ol.math.toDegrees(lat)];
  49674. }, ol.proj.getTransform(geoProjection, projection), squaredTolerance);
  49675. };
  49676. /**
  49677. * Generate a meridian (line at constant longitude).
  49678. * @param {number} lon Longitude.
  49679. * @param {number} lat1 Latitude 1.
  49680. * @param {number} lat2 Latitude 2.
  49681. * @param {ol.proj.Projection} projection Projection.
  49682. * @param {number} squaredTolerance Squared tolerance.
  49683. * @return {Array.<number>} Flat coordinates.
  49684. */
  49685. ol.geom.flat.geodesic.meridian = function(lon, lat1, lat2, projection, squaredTolerance) {
  49686. var epsg4326Projection = ol.proj.get('EPSG:4326');
  49687. return ol.geom.flat.geodesic.line_(
  49688. /**
  49689. * @param {number} frac Fraction.
  49690. * @return {ol.Coordinate} Coordinate.
  49691. */
  49692. function(frac) {
  49693. return [lon, lat1 + ((lat2 - lat1) * frac)];
  49694. },
  49695. ol.proj.getTransform(epsg4326Projection, projection), squaredTolerance);
  49696. };
  49697. /**
  49698. * Generate a parallel (line at constant latitude).
  49699. * @param {number} lat Latitude.
  49700. * @param {number} lon1 Longitude 1.
  49701. * @param {number} lon2 Longitude 2.
  49702. * @param {ol.proj.Projection} projection Projection.
  49703. * @param {number} squaredTolerance Squared tolerance.
  49704. * @return {Array.<number>} Flat coordinates.
  49705. */
  49706. ol.geom.flat.geodesic.parallel = function(lat, lon1, lon2, projection, squaredTolerance) {
  49707. var epsg4326Projection = ol.proj.get('EPSG:4326');
  49708. return ol.geom.flat.geodesic.line_(
  49709. /**
  49710. * @param {number} frac Fraction.
  49711. * @return {ol.Coordinate} Coordinate.
  49712. */
  49713. function(frac) {
  49714. return [lon1 + ((lon2 - lon1) * frac), lat];
  49715. },
  49716. ol.proj.getTransform(epsg4326Projection, projection), squaredTolerance);
  49717. };
  49718. goog.provide('ol.geom.flat.topology');
  49719. goog.require('ol.geom.flat.area');
  49720. /**
  49721. * Check if the linestring is a boundary.
  49722. * @param {Array.<number>} flatCoordinates Flat coordinates.
  49723. * @param {number} offset Offset.
  49724. * @param {number} end End.
  49725. * @param {number} stride Stride.
  49726. * @return {boolean} The linestring is a boundary.
  49727. */
  49728. ol.geom.flat.topology.lineStringIsClosed = function(flatCoordinates, offset, end, stride) {
  49729. var lastCoord = end - stride;
  49730. if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
  49731. flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
  49732. return !!ol.geom.flat.area.linearRing(flatCoordinates, offset, end, stride);
  49733. }
  49734. return false;
  49735. };
  49736. goog.provide('ol.Graticule');
  49737. goog.require('ol.coordinate');
  49738. goog.require('ol.extent');
  49739. goog.require('ol.geom.GeometryLayout');
  49740. goog.require('ol.geom.LineString');
  49741. goog.require('ol.geom.Point');
  49742. goog.require('ol.geom.flat.geodesic');
  49743. goog.require('ol.math');
  49744. goog.require('ol.proj');
  49745. goog.require('ol.render.EventType');
  49746. goog.require('ol.style.Fill');
  49747. goog.require('ol.style.Stroke');
  49748. goog.require('ol.style.Text');
  49749. /**
  49750. * Render a grid for a coordinate system on a map.
  49751. * @constructor
  49752. * @param {olx.GraticuleOptions=} opt_options Options.
  49753. * @api
  49754. */
  49755. ol.Graticule = function(opt_options) {
  49756. var options = opt_options || {};
  49757. /**
  49758. * @type {ol.PluggableMap}
  49759. * @private
  49760. */
  49761. this.map_ = null;
  49762. /**
  49763. * @type {ol.proj.Projection}
  49764. * @private
  49765. */
  49766. this.projection_ = null;
  49767. /**
  49768. * @type {number}
  49769. * @private
  49770. */
  49771. this.maxLat_ = Infinity;
  49772. /**
  49773. * @type {number}
  49774. * @private
  49775. */
  49776. this.maxLon_ = Infinity;
  49777. /**
  49778. * @type {number}
  49779. * @private
  49780. */
  49781. this.minLat_ = -Infinity;
  49782. /**
  49783. * @type {number}
  49784. * @private
  49785. */
  49786. this.minLon_ = -Infinity;
  49787. /**
  49788. * @type {number}
  49789. * @private
  49790. */
  49791. this.maxLatP_ = Infinity;
  49792. /**
  49793. * @type {number}
  49794. * @private
  49795. */
  49796. this.maxLonP_ = Infinity;
  49797. /**
  49798. * @type {number}
  49799. * @private
  49800. */
  49801. this.minLatP_ = -Infinity;
  49802. /**
  49803. * @type {number}
  49804. * @private
  49805. */
  49806. this.minLonP_ = -Infinity;
  49807. /**
  49808. * @type {number}
  49809. * @private
  49810. */
  49811. this.targetSize_ = options.targetSize !== undefined ?
  49812. options.targetSize : 100;
  49813. /**
  49814. * @type {number}
  49815. * @private
  49816. */
  49817. this.maxLines_ = options.maxLines !== undefined ? options.maxLines : 100;
  49818. /**
  49819. * @type {Array.<ol.geom.LineString>}
  49820. * @private
  49821. */
  49822. this.meridians_ = [];
  49823. /**
  49824. * @type {Array.<ol.geom.LineString>}
  49825. * @private
  49826. */
  49827. this.parallels_ = [];
  49828. /**
  49829. * @type {ol.style.Stroke}
  49830. * @private
  49831. */
  49832. this.strokeStyle_ = options.strokeStyle !== undefined ?
  49833. options.strokeStyle : ol.Graticule.DEFAULT_STROKE_STYLE_;
  49834. /**
  49835. * @type {ol.TransformFunction|undefined}
  49836. * @private
  49837. */
  49838. this.fromLonLatTransform_ = undefined;
  49839. /**
  49840. * @type {ol.TransformFunction|undefined}
  49841. * @private
  49842. */
  49843. this.toLonLatTransform_ = undefined;
  49844. /**
  49845. * @type {ol.Coordinate}
  49846. * @private
  49847. */
  49848. this.projectionCenterLonLat_ = null;
  49849. /**
  49850. * @type {Array.<ol.GraticuleLabelDataType>}
  49851. * @private
  49852. */
  49853. this.meridiansLabels_ = null;
  49854. /**
  49855. * @type {Array.<ol.GraticuleLabelDataType>}
  49856. * @private
  49857. */
  49858. this.parallelsLabels_ = null;
  49859. if (options.showLabels == true) {
  49860. var degreesToString = ol.coordinate.degreesToStringHDMS;
  49861. /**
  49862. * @type {null|function(number):string}
  49863. * @private
  49864. */
  49865. this.lonLabelFormatter_ = options.lonLabelFormatter == undefined ?
  49866. degreesToString.bind(this, 'EW') : options.lonLabelFormatter;
  49867. /**
  49868. * @type {function(number):string}
  49869. * @private
  49870. */
  49871. this.latLabelFormatter_ = options.latLabelFormatter == undefined ?
  49872. degreesToString.bind(this, 'NS') : options.latLabelFormatter;
  49873. /**
  49874. * Longitude label position in fractions (0..1) of view extent. 0 means
  49875. * bottom, 1 means top.
  49876. * @type {number}
  49877. * @private
  49878. */
  49879. this.lonLabelPosition_ = options.lonLabelPosition == undefined ? 0 :
  49880. options.lonLabelPosition;
  49881. /**
  49882. * Latitude Label position in fractions (0..1) of view extent. 0 means left, 1
  49883. * means right.
  49884. * @type {number}
  49885. * @private
  49886. */
  49887. this.latLabelPosition_ = options.latLabelPosition == undefined ? 1 :
  49888. options.latLabelPosition;
  49889. /**
  49890. * @type {ol.style.Text}
  49891. * @private
  49892. */
  49893. this.lonLabelStyle_ = options.lonLabelStyle !== undefined ? options.lonLabelStyle :
  49894. new ol.style.Text({
  49895. font: '12px Calibri,sans-serif',
  49896. textBaseline: 'bottom',
  49897. fill: new ol.style.Fill({
  49898. color: 'rgba(0,0,0,1)'
  49899. }),
  49900. stroke: new ol.style.Stroke({
  49901. color: 'rgba(255,255,255,1)',
  49902. width: 3
  49903. })
  49904. });
  49905. /**
  49906. * @type {ol.style.Text}
  49907. * @private
  49908. */
  49909. this.latLabelStyle_ = options.latLabelStyle !== undefined ? options.latLabelStyle :
  49910. new ol.style.Text({
  49911. font: '12px Calibri,sans-serif',
  49912. textAlign: 'end',
  49913. fill: new ol.style.Fill({
  49914. color: 'rgba(0,0,0,1)'
  49915. }),
  49916. stroke: new ol.style.Stroke({
  49917. color: 'rgba(255,255,255,1)',
  49918. width: 3
  49919. })
  49920. });
  49921. this.meridiansLabels_ = [];
  49922. this.parallelsLabels_ = [];
  49923. }
  49924. this.setMap(options.map !== undefined ? options.map : null);
  49925. };
  49926. /**
  49927. * @type {ol.style.Stroke}
  49928. * @private
  49929. * @const
  49930. */
  49931. ol.Graticule.DEFAULT_STROKE_STYLE_ = new ol.style.Stroke({
  49932. color: 'rgba(0,0,0,0.2)'
  49933. });
  49934. /**
  49935. * TODO can be configurable
  49936. * @type {Array.<number>}
  49937. * @private
  49938. */
  49939. ol.Graticule.intervals_ = [90, 45, 30, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05,
  49940. 0.01, 0.005, 0.002, 0.001];
  49941. /**
  49942. * @param {number} lon Longitude.
  49943. * @param {number} minLat Minimal latitude.
  49944. * @param {number} maxLat Maximal latitude.
  49945. * @param {number} squaredTolerance Squared tolerance.
  49946. * @param {ol.Extent} extent Extent.
  49947. * @param {number} index Index.
  49948. * @return {number} Index.
  49949. * @private
  49950. */
  49951. ol.Graticule.prototype.addMeridian_ = function(lon, minLat, maxLat, squaredTolerance, extent, index) {
  49952. var lineString = this.getMeridian_(lon, minLat, maxLat,
  49953. squaredTolerance, index);
  49954. if (ol.extent.intersects(lineString.getExtent(), extent)) {
  49955. if (this.meridiansLabels_) {
  49956. var textPoint = this.getMeridianPoint_(lineString, extent, index);
  49957. this.meridiansLabels_[index] = {
  49958. geom: textPoint,
  49959. text: this.lonLabelFormatter_(lon)
  49960. };
  49961. }
  49962. this.meridians_[index++] = lineString;
  49963. }
  49964. return index;
  49965. };
  49966. /**
  49967. * @param {ol.geom.LineString} lineString Meridian
  49968. * @param {ol.Extent} extent Extent.
  49969. * @param {number} index Index.
  49970. * @return {ol.geom.Point} Meridian point.
  49971. * @private
  49972. */
  49973. ol.Graticule.prototype.getMeridianPoint_ = function(lineString, extent, index) {
  49974. var flatCoordinates = lineString.getFlatCoordinates();
  49975. var clampedBottom = Math.max(extent[1], flatCoordinates[1]);
  49976. var clampedTop = Math.min(extent[3], flatCoordinates[flatCoordinates.length - 1]);
  49977. var lat = ol.math.clamp(
  49978. extent[1] + Math.abs(extent[1] - extent[3]) * this.lonLabelPosition_,
  49979. clampedBottom, clampedTop);
  49980. var coordinate = [flatCoordinates[0], lat];
  49981. var point = this.meridiansLabels_[index] !== undefined ?
  49982. this.meridiansLabels_[index].geom : new ol.geom.Point(null);
  49983. point.setCoordinates(coordinate);
  49984. return point;
  49985. };
  49986. /**
  49987. * @param {number} lat Latitude.
  49988. * @param {number} minLon Minimal longitude.
  49989. * @param {number} maxLon Maximal longitude.
  49990. * @param {number} squaredTolerance Squared tolerance.
  49991. * @param {ol.Extent} extent Extent.
  49992. * @param {number} index Index.
  49993. * @return {number} Index.
  49994. * @private
  49995. */
  49996. ol.Graticule.prototype.addParallel_ = function(lat, minLon, maxLon, squaredTolerance, extent, index) {
  49997. var lineString = this.getParallel_(lat, minLon, maxLon, squaredTolerance,
  49998. index);
  49999. if (ol.extent.intersects(lineString.getExtent(), extent)) {
  50000. if (this.parallelsLabels_) {
  50001. var textPoint = this.getParallelPoint_(lineString, extent, index);
  50002. this.parallelsLabels_[index] = {
  50003. geom: textPoint,
  50004. text: this.latLabelFormatter_(lat)
  50005. };
  50006. }
  50007. this.parallels_[index++] = lineString;
  50008. }
  50009. return index;
  50010. };
  50011. /**
  50012. * @param {ol.geom.LineString} lineString Parallels.
  50013. * @param {ol.Extent} extent Extent.
  50014. * @param {number} index Index.
  50015. * @return {ol.geom.Point} Parallel point.
  50016. * @private
  50017. */
  50018. ol.Graticule.prototype.getParallelPoint_ = function(lineString, extent, index) {
  50019. var flatCoordinates = lineString.getFlatCoordinates();
  50020. var clampedLeft = Math.max(extent[0], flatCoordinates[0]);
  50021. var clampedRight = Math.min(extent[2], flatCoordinates[flatCoordinates.length - 2]);
  50022. var lon = ol.math.clamp(
  50023. extent[0] + Math.abs(extent[0] - extent[2]) * this.latLabelPosition_,
  50024. clampedLeft, clampedRight);
  50025. var coordinate = [lon, flatCoordinates[1]];
  50026. var point = this.parallelsLabels_[index] !== undefined ?
  50027. this.parallelsLabels_[index].geom : new ol.geom.Point(null);
  50028. point.setCoordinates(coordinate);
  50029. return point;
  50030. };
  50031. /**
  50032. * @param {ol.Extent} extent Extent.
  50033. * @param {ol.Coordinate} center Center.
  50034. * @param {number} resolution Resolution.
  50035. * @param {number} squaredTolerance Squared tolerance.
  50036. * @private
  50037. */
  50038. ol.Graticule.prototype.createGraticule_ = function(extent, center, resolution, squaredTolerance) {
  50039. var interval = this.getInterval_(resolution);
  50040. if (interval == -1) {
  50041. this.meridians_.length = this.parallels_.length = 0;
  50042. if (this.meridiansLabels_) {
  50043. this.meridiansLabels_.length = 0;
  50044. }
  50045. if (this.parallelsLabels_) {
  50046. this.parallelsLabels_.length = 0;
  50047. }
  50048. return;
  50049. }
  50050. var centerLonLat = this.toLonLatTransform_(center);
  50051. var centerLon = centerLonLat[0];
  50052. var centerLat = centerLonLat[1];
  50053. var maxLines = this.maxLines_;
  50054. var cnt, idx, lat, lon;
  50055. var validExtent = [
  50056. Math.max(extent[0], this.minLonP_),
  50057. Math.max(extent[1], this.minLatP_),
  50058. Math.min(extent[2], this.maxLonP_),
  50059. Math.min(extent[3], this.maxLatP_)
  50060. ];
  50061. validExtent = ol.proj.transformExtent(validExtent, this.projection_,
  50062. 'EPSG:4326');
  50063. var maxLat = validExtent[3];
  50064. var maxLon = validExtent[2];
  50065. var minLat = validExtent[1];
  50066. var minLon = validExtent[0];
  50067. // Create meridians
  50068. centerLon = Math.floor(centerLon / interval) * interval;
  50069. lon = ol.math.clamp(centerLon, this.minLon_, this.maxLon_);
  50070. idx = this.addMeridian_(lon, minLat, maxLat, squaredTolerance, extent, 0);
  50071. cnt = 0;
  50072. while (lon != this.minLon_ && cnt++ < maxLines) {
  50073. lon = Math.max(lon - interval, this.minLon_);
  50074. idx = this.addMeridian_(lon, minLat, maxLat, squaredTolerance, extent, idx);
  50075. }
  50076. lon = ol.math.clamp(centerLon, this.minLon_, this.maxLon_);
  50077. cnt = 0;
  50078. while (lon != this.maxLon_ && cnt++ < maxLines) {
  50079. lon = Math.min(lon + interval, this.maxLon_);
  50080. idx = this.addMeridian_(lon, minLat, maxLat, squaredTolerance, extent, idx);
  50081. }
  50082. this.meridians_.length = idx;
  50083. if (this.meridiansLabels_) {
  50084. this.meridiansLabels_.length = idx;
  50085. }
  50086. // Create parallels
  50087. centerLat = Math.floor(centerLat / interval) * interval;
  50088. lat = ol.math.clamp(centerLat, this.minLat_, this.maxLat_);
  50089. idx = this.addParallel_(lat, minLon, maxLon, squaredTolerance, extent, 0);
  50090. cnt = 0;
  50091. while (lat != this.minLat_ && cnt++ < maxLines) {
  50092. lat = Math.max(lat - interval, this.minLat_);
  50093. idx = this.addParallel_(lat, minLon, maxLon, squaredTolerance, extent, idx);
  50094. }
  50095. lat = ol.math.clamp(centerLat, this.minLat_, this.maxLat_);
  50096. cnt = 0;
  50097. while (lat != this.maxLat_ && cnt++ < maxLines) {
  50098. lat = Math.min(lat + interval, this.maxLat_);
  50099. idx = this.addParallel_(lat, minLon, maxLon, squaredTolerance, extent, idx);
  50100. }
  50101. this.parallels_.length = idx;
  50102. if (this.parallelsLabels_) {
  50103. this.parallelsLabels_.length = idx;
  50104. }
  50105. };
  50106. /**
  50107. * @param {number} resolution Resolution.
  50108. * @return {number} The interval in degrees.
  50109. * @private
  50110. */
  50111. ol.Graticule.prototype.getInterval_ = function(resolution) {
  50112. var centerLon = this.projectionCenterLonLat_[0];
  50113. var centerLat = this.projectionCenterLonLat_[1];
  50114. var interval = -1;
  50115. var i, ii, delta, dist;
  50116. var target = Math.pow(this.targetSize_ * resolution, 2);
  50117. /** @type {Array.<number>} **/
  50118. var p1 = [];
  50119. /** @type {Array.<number>} **/
  50120. var p2 = [];
  50121. for (i = 0, ii = ol.Graticule.intervals_.length; i < ii; ++i) {
  50122. delta = ol.Graticule.intervals_[i] / 2;
  50123. p1[0] = centerLon - delta;
  50124. p1[1] = centerLat - delta;
  50125. p2[0] = centerLon + delta;
  50126. p2[1] = centerLat + delta;
  50127. this.fromLonLatTransform_(p1, p1);
  50128. this.fromLonLatTransform_(p2, p2);
  50129. dist = Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2);
  50130. if (dist <= target) {
  50131. break;
  50132. }
  50133. interval = ol.Graticule.intervals_[i];
  50134. }
  50135. return interval;
  50136. };
  50137. /**
  50138. * Get the map associated with this graticule.
  50139. * @return {ol.PluggableMap} The map.
  50140. * @api
  50141. */
  50142. ol.Graticule.prototype.getMap = function() {
  50143. return this.map_;
  50144. };
  50145. /**
  50146. * @param {number} lon Longitude.
  50147. * @param {number} minLat Minimal latitude.
  50148. * @param {number} maxLat Maximal latitude.
  50149. * @param {number} squaredTolerance Squared tolerance.
  50150. * @return {ol.geom.LineString} The meridian line string.
  50151. * @param {number} index Index.
  50152. * @private
  50153. */
  50154. ol.Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat,
  50155. squaredTolerance, index) {
  50156. var flatCoordinates = ol.geom.flat.geodesic.meridian(lon,
  50157. minLat, maxLat, this.projection_, squaredTolerance);
  50158. var lineString = this.meridians_[index] !== undefined ?
  50159. this.meridians_[index] : new ol.geom.LineString(null);
  50160. lineString.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates);
  50161. return lineString;
  50162. };
  50163. /**
  50164. * Get the list of meridians. Meridians are lines of equal longitude.
  50165. * @return {Array.<ol.geom.LineString>} The meridians.
  50166. * @api
  50167. */
  50168. ol.Graticule.prototype.getMeridians = function() {
  50169. return this.meridians_;
  50170. };
  50171. /**
  50172. * @param {number} lat Latitude.
  50173. * @param {number} minLon Minimal longitude.
  50174. * @param {number} maxLon Maximal longitude.
  50175. * @param {number} squaredTolerance Squared tolerance.
  50176. * @return {ol.geom.LineString} The parallel line string.
  50177. * @param {number} index Index.
  50178. * @private
  50179. */
  50180. ol.Graticule.prototype.getParallel_ = function(lat, minLon, maxLon,
  50181. squaredTolerance, index) {
  50182. var flatCoordinates = ol.geom.flat.geodesic.parallel(lat,
  50183. minLon, maxLon, this.projection_, squaredTolerance);
  50184. var lineString = this.parallels_[index] !== undefined ?
  50185. this.parallels_[index] : new ol.geom.LineString(null);
  50186. lineString.setFlatCoordinates(ol.geom.GeometryLayout.XY, flatCoordinates);
  50187. return lineString;
  50188. };
  50189. /**
  50190. * Get the list of parallels. Parallels are lines of equal latitude.
  50191. * @return {Array.<ol.geom.LineString>} The parallels.
  50192. * @api
  50193. */
  50194. ol.Graticule.prototype.getParallels = function() {
  50195. return this.parallels_;
  50196. };
  50197. /**
  50198. * @param {ol.render.Event} e Event.
  50199. * @private
  50200. */
  50201. ol.Graticule.prototype.handlePostCompose_ = function(e) {
  50202. var vectorContext = e.vectorContext;
  50203. var frameState = e.frameState;
  50204. var extent = frameState.extent;
  50205. var viewState = frameState.viewState;
  50206. var center = viewState.center;
  50207. var projection = viewState.projection;
  50208. var resolution = viewState.resolution;
  50209. var pixelRatio = frameState.pixelRatio;
  50210. var squaredTolerance =
  50211. resolution * resolution / (4 * pixelRatio * pixelRatio);
  50212. var updateProjectionInfo = !this.projection_ ||
  50213. !ol.proj.equivalent(this.projection_, projection);
  50214. if (updateProjectionInfo) {
  50215. this.updateProjectionInfo_(projection);
  50216. }
  50217. this.createGraticule_(extent, center, resolution, squaredTolerance);
  50218. // Draw the lines
  50219. vectorContext.setFillStrokeStyle(null, this.strokeStyle_);
  50220. var i, l, line;
  50221. for (i = 0, l = this.meridians_.length; i < l; ++i) {
  50222. line = this.meridians_[i];
  50223. vectorContext.drawGeometry(line);
  50224. }
  50225. for (i = 0, l = this.parallels_.length; i < l; ++i) {
  50226. line = this.parallels_[i];
  50227. vectorContext.drawGeometry(line);
  50228. }
  50229. var labelData;
  50230. if (this.meridiansLabels_) {
  50231. for (i = 0, l = this.meridiansLabels_.length; i < l; ++i) {
  50232. labelData = this.meridiansLabels_[i];
  50233. this.lonLabelStyle_.setText(labelData.text);
  50234. vectorContext.setTextStyle(this.lonLabelStyle_);
  50235. vectorContext.drawGeometry(labelData.geom);
  50236. }
  50237. }
  50238. if (this.parallelsLabels_) {
  50239. for (i = 0, l = this.parallelsLabels_.length; i < l; ++i) {
  50240. labelData = this.parallelsLabels_[i];
  50241. this.latLabelStyle_.setText(labelData.text);
  50242. vectorContext.setTextStyle(this.latLabelStyle_);
  50243. vectorContext.drawGeometry(labelData.geom);
  50244. }
  50245. }
  50246. };
  50247. /**
  50248. * @param {ol.proj.Projection} projection Projection.
  50249. * @private
  50250. */
  50251. ol.Graticule.prototype.updateProjectionInfo_ = function(projection) {
  50252. var epsg4326Projection = ol.proj.get('EPSG:4326');
  50253. var extent = projection.getExtent();
  50254. var worldExtent = projection.getWorldExtent();
  50255. var worldExtentP = ol.proj.transformExtent(worldExtent,
  50256. epsg4326Projection, projection);
  50257. var maxLat = worldExtent[3];
  50258. var maxLon = worldExtent[2];
  50259. var minLat = worldExtent[1];
  50260. var minLon = worldExtent[0];
  50261. var maxLatP = worldExtentP[3];
  50262. var maxLonP = worldExtentP[2];
  50263. var minLatP = worldExtentP[1];
  50264. var minLonP = worldExtentP[0];
  50265. this.maxLat_ = maxLat;
  50266. this.maxLon_ = maxLon;
  50267. this.minLat_ = minLat;
  50268. this.minLon_ = minLon;
  50269. this.maxLatP_ = maxLatP;
  50270. this.maxLonP_ = maxLonP;
  50271. this.minLatP_ = minLatP;
  50272. this.minLonP_ = minLonP;
  50273. this.fromLonLatTransform_ = ol.proj.getTransform(
  50274. epsg4326Projection, projection);
  50275. this.toLonLatTransform_ = ol.proj.getTransform(
  50276. projection, epsg4326Projection);
  50277. this.projectionCenterLonLat_ = this.toLonLatTransform_(
  50278. ol.extent.getCenter(extent));
  50279. this.projection_ = projection;
  50280. };
  50281. /**
  50282. * Set the map for this graticule. The graticule will be rendered on the
  50283. * provided map.
  50284. * @param {ol.PluggableMap} map Map.
  50285. * @api
  50286. */
  50287. ol.Graticule.prototype.setMap = function(map) {
  50288. if (this.map_) {
  50289. this.map_.un(ol.render.EventType.POSTCOMPOSE,
  50290. this.handlePostCompose_, this);
  50291. this.map_.render();
  50292. }
  50293. if (map) {
  50294. map.on(ol.render.EventType.POSTCOMPOSE,
  50295. this.handlePostCompose_, this);
  50296. map.render();
  50297. }
  50298. this.map_ = map;
  50299. };
  50300. goog.provide('ol.Image');
  50301. goog.require('ol');
  50302. goog.require('ol.ImageBase');
  50303. goog.require('ol.ImageState');
  50304. goog.require('ol.events');
  50305. goog.require('ol.events.EventType');
  50306. goog.require('ol.extent');
  50307. /**
  50308. * @constructor
  50309. * @extends {ol.ImageBase}
  50310. * @param {ol.Extent} extent Extent.
  50311. * @param {number|undefined} resolution Resolution.
  50312. * @param {number} pixelRatio Pixel ratio.
  50313. * @param {string} src Image source URI.
  50314. * @param {?string} crossOrigin Cross origin.
  50315. * @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
  50316. */
  50317. ol.Image = function(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) {
  50318. ol.ImageBase.call(this, extent, resolution, pixelRatio, ol.ImageState.IDLE);
  50319. /**
  50320. * @private
  50321. * @type {string}
  50322. */
  50323. this.src_ = src;
  50324. /**
  50325. * @private
  50326. * @type {HTMLCanvasElement|Image|HTMLVideoElement}
  50327. */
  50328. this.image_ = new Image();
  50329. if (crossOrigin !== null) {
  50330. this.image_.crossOrigin = crossOrigin;
  50331. }
  50332. /**
  50333. * @private
  50334. * @type {Array.<ol.EventsKey>}
  50335. */
  50336. this.imageListenerKeys_ = null;
  50337. /**
  50338. * @protected
  50339. * @type {ol.ImageState}
  50340. */
  50341. this.state = ol.ImageState.IDLE;
  50342. /**
  50343. * @private
  50344. * @type {ol.ImageLoadFunctionType}
  50345. */
  50346. this.imageLoadFunction_ = imageLoadFunction;
  50347. };
  50348. ol.inherits(ol.Image, ol.ImageBase);
  50349. /**
  50350. * @inheritDoc
  50351. * @api
  50352. */
  50353. ol.Image.prototype.getImage = function() {
  50354. return this.image_;
  50355. };
  50356. /**
  50357. * Tracks loading or read errors.
  50358. *
  50359. * @private
  50360. */
  50361. ol.Image.prototype.handleImageError_ = function() {
  50362. this.state = ol.ImageState.ERROR;
  50363. this.unlistenImage_();
  50364. this.changed();
  50365. };
  50366. /**
  50367. * Tracks successful image load.
  50368. *
  50369. * @private
  50370. */
  50371. ol.Image.prototype.handleImageLoad_ = function() {
  50372. if (this.resolution === undefined) {
  50373. this.resolution = ol.extent.getHeight(this.extent) / this.image_.height;
  50374. }
  50375. this.state = ol.ImageState.LOADED;
  50376. this.unlistenImage_();
  50377. this.changed();
  50378. };
  50379. /**
  50380. * Load the image or retry if loading previously failed.
  50381. * Loading is taken care of by the tile queue, and calling this method is
  50382. * only needed for preloading or for reloading in case of an error.
  50383. * @override
  50384. * @api
  50385. */
  50386. ol.Image.prototype.load = function() {
  50387. if (this.state == ol.ImageState.IDLE || this.state == ol.ImageState.ERROR) {
  50388. this.state = ol.ImageState.LOADING;
  50389. this.changed();
  50390. this.imageListenerKeys_ = [
  50391. ol.events.listenOnce(this.image_, ol.events.EventType.ERROR,
  50392. this.handleImageError_, this),
  50393. ol.events.listenOnce(this.image_, ol.events.EventType.LOAD,
  50394. this.handleImageLoad_, this)
  50395. ];
  50396. this.imageLoadFunction_(this, this.src_);
  50397. }
  50398. };
  50399. /**
  50400. * @param {HTMLCanvasElement|Image|HTMLVideoElement} image Image.
  50401. */
  50402. ol.Image.prototype.setImage = function(image) {
  50403. this.image_ = image;
  50404. };
  50405. /**
  50406. * Discards event handlers which listen for load completion or errors.
  50407. *
  50408. * @private
  50409. */
  50410. ol.Image.prototype.unlistenImage_ = function() {
  50411. this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
  50412. this.imageListenerKeys_ = null;
  50413. };
  50414. goog.provide('ol.Tile');
  50415. goog.require('ol');
  50416. goog.require('ol.TileState');
  50417. goog.require('ol.easing');
  50418. goog.require('ol.events.EventTarget');
  50419. goog.require('ol.events.EventType');
  50420. /**
  50421. * @classdesc
  50422. * Base class for tiles.
  50423. *
  50424. * @constructor
  50425. * @abstract
  50426. * @extends {ol.events.EventTarget}
  50427. * @param {ol.TileCoord} tileCoord Tile coordinate.
  50428. * @param {ol.TileState} state State.
  50429. * @param {olx.TileOptions=} opt_options Tile options.
  50430. */
  50431. ol.Tile = function(tileCoord, state, opt_options) {
  50432. ol.events.EventTarget.call(this);
  50433. var options = opt_options ? opt_options : {};
  50434. /**
  50435. * @type {ol.TileCoord}
  50436. */
  50437. this.tileCoord = tileCoord;
  50438. /**
  50439. * @protected
  50440. * @type {ol.TileState}
  50441. */
  50442. this.state = state;
  50443. /**
  50444. * An "interim" tile for this tile. The interim tile may be used while this
  50445. * one is loading, for "smooth" transitions when changing params/dimensions
  50446. * on the source.
  50447. * @type {ol.Tile}
  50448. */
  50449. this.interimTile = null;
  50450. /**
  50451. * A key assigned to the tile. This is used by the tile source to determine
  50452. * if this tile can effectively be used, or if a new tile should be created
  50453. * and this one be used as an interim tile for this new tile.
  50454. * @type {string}
  50455. */
  50456. this.key = '';
  50457. /**
  50458. * The duration for the opacity transition.
  50459. * @type {number}
  50460. */
  50461. this.transition_ = options.transition === undefined ?
  50462. 250 : options.transition;
  50463. /**
  50464. * Lookup of start times for rendering transitions. If the start time is
  50465. * equal to -1, the transition is complete.
  50466. * @type {Object.<number, number>}
  50467. */
  50468. this.transitionStarts_ = {};
  50469. };
  50470. ol.inherits(ol.Tile, ol.events.EventTarget);
  50471. /**
  50472. * @protected
  50473. */
  50474. ol.Tile.prototype.changed = function() {
  50475. this.dispatchEvent(ol.events.EventType.CHANGE);
  50476. };
  50477. /**
  50478. * @return {string} Key.
  50479. */
  50480. ol.Tile.prototype.getKey = function() {
  50481. return this.key + '/' + this.tileCoord;
  50482. };
  50483. /**
  50484. * Get the interim tile most suitable for rendering using the chain of interim
  50485. * tiles. This corresponds to the most recent tile that has been loaded, if no
  50486. * such tile exists, the original tile is returned.
  50487. * @return {!ol.Tile} Best tile for rendering.
  50488. */
  50489. ol.Tile.prototype.getInterimTile = function() {
  50490. if (!this.interimTile) {
  50491. //empty chain
  50492. return this;
  50493. }
  50494. var tile = this.interimTile;
  50495. // find the first loaded tile and return it. Since the chain is sorted in
  50496. // decreasing order of creation time, there is no need to search the remainder
  50497. // of the list (all those tiles correspond to older requests and will be
  50498. // cleaned up by refreshInterimChain)
  50499. do {
  50500. if (tile.getState() == ol.TileState.LOADED) {
  50501. return tile;
  50502. }
  50503. tile = tile.interimTile;
  50504. } while (tile);
  50505. // we can not find a better tile
  50506. return this;
  50507. };
  50508. /**
  50509. * Goes through the chain of interim tiles and discards sections of the chain
  50510. * that are no longer relevant.
  50511. */
  50512. ol.Tile.prototype.refreshInterimChain = function() {
  50513. if (!this.interimTile) {
  50514. return;
  50515. }
  50516. var tile = this.interimTile;
  50517. var prev = this;
  50518. do {
  50519. if (tile.getState() == ol.TileState.LOADED) {
  50520. //we have a loaded tile, we can discard the rest of the list
  50521. //we would could abort any LOADING tile request
  50522. //older than this tile (i.e. any LOADING tile following this entry in the chain)
  50523. tile.interimTile = null;
  50524. break;
  50525. } else if (tile.getState() == ol.TileState.LOADING) {
  50526. //keep this LOADING tile any loaded tiles later in the chain are
  50527. //older than this tile, so we're still interested in the request
  50528. prev = tile;
  50529. } else if (tile.getState() == ol.TileState.IDLE) {
  50530. //the head of the list is the most current tile, we don't need
  50531. //to start any other requests for this chain
  50532. prev.interimTile = tile.interimTile;
  50533. } else {
  50534. prev = tile;
  50535. }
  50536. tile = prev.interimTile;
  50537. } while (tile);
  50538. };
  50539. /**
  50540. * Get the tile coordinate for this tile.
  50541. * @return {ol.TileCoord} The tile coordinate.
  50542. * @api
  50543. */
  50544. ol.Tile.prototype.getTileCoord = function() {
  50545. return this.tileCoord;
  50546. };
  50547. /**
  50548. * @return {ol.TileState} State.
  50549. */
  50550. ol.Tile.prototype.getState = function() {
  50551. return this.state;
  50552. };
  50553. /**
  50554. * @param {ol.TileState} state State.
  50555. */
  50556. ol.Tile.prototype.setState = function(state) {
  50557. this.state = state;
  50558. this.changed();
  50559. };
  50560. /**
  50561. * Load the image or retry if loading previously failed.
  50562. * Loading is taken care of by the tile queue, and calling this method is
  50563. * only needed for preloading or for reloading in case of an error.
  50564. * @abstract
  50565. * @api
  50566. */
  50567. ol.Tile.prototype.load = function() {};
  50568. /**
  50569. * Get the alpha value for rendering.
  50570. * @param {number} id An id for the renderer.
  50571. * @param {number} time The render frame time.
  50572. * @return {number} A number between 0 and 1.
  50573. */
  50574. ol.Tile.prototype.getAlpha = function(id, time) {
  50575. if (!this.transition_) {
  50576. return 1;
  50577. }
  50578. var start = this.transitionStarts_[id];
  50579. if (!start) {
  50580. start = time;
  50581. this.transitionStarts_[id] = start;
  50582. } else if (start === -1) {
  50583. return 1;
  50584. }
  50585. var delta = time - start + (1000 / 60); // avoid rendering at 0
  50586. if (delta >= this.transition_) {
  50587. return 1;
  50588. }
  50589. return ol.easing.easeIn(delta / this.transition_);
  50590. };
  50591. /**
  50592. * Determine if a tile is in an alpha transition. A tile is considered in
  50593. * transition if tile.getAlpha() has not yet been called or has been called
  50594. * and returned 1.
  50595. * @param {number} id An id for the renderer.
  50596. * @return {boolean} The tile is in transition.
  50597. */
  50598. ol.Tile.prototype.inTransition = function(id) {
  50599. if (!this.transition_) {
  50600. return false;
  50601. }
  50602. return this.transitionStarts_[id] !== -1;
  50603. };
  50604. /**
  50605. * Mark a transition as complete.
  50606. * @param {number} id An id for the renderer.
  50607. */
  50608. ol.Tile.prototype.endTransition = function(id) {
  50609. if (this.transition_) {
  50610. this.transitionStarts_[id] = -1;
  50611. }
  50612. };
  50613. goog.provide('ol.ImageTile');
  50614. goog.require('ol');
  50615. goog.require('ol.Tile');
  50616. goog.require('ol.TileState');
  50617. goog.require('ol.dom');
  50618. goog.require('ol.events');
  50619. goog.require('ol.events.EventType');
  50620. /**
  50621. * @constructor
  50622. * @extends {ol.Tile}
  50623. * @param {ol.TileCoord} tileCoord Tile coordinate.
  50624. * @param {ol.TileState} state State.
  50625. * @param {string} src Image source URI.
  50626. * @param {?string} crossOrigin Cross origin.
  50627. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
  50628. * @param {olx.TileOptions=} opt_options Tile options.
  50629. */
  50630. ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
  50631. ol.Tile.call(this, tileCoord, state, opt_options);
  50632. /**
  50633. * @private
  50634. * @type {?string}
  50635. */
  50636. this.crossOrigin_ = crossOrigin;
  50637. /**
  50638. * Image URI
  50639. *
  50640. * @private
  50641. * @type {string}
  50642. */
  50643. this.src_ = src;
  50644. /**
  50645. * @private
  50646. * @type {Image|HTMLCanvasElement}
  50647. */
  50648. this.image_ = new Image();
  50649. if (crossOrigin !== null) {
  50650. this.image_.crossOrigin = crossOrigin;
  50651. }
  50652. /**
  50653. * @private
  50654. * @type {Array.<ol.EventsKey>}
  50655. */
  50656. this.imageListenerKeys_ = null;
  50657. /**
  50658. * @private
  50659. * @type {ol.TileLoadFunctionType}
  50660. */
  50661. this.tileLoadFunction_ = tileLoadFunction;
  50662. };
  50663. ol.inherits(ol.ImageTile, ol.Tile);
  50664. /**
  50665. * @inheritDoc
  50666. */
  50667. ol.ImageTile.prototype.disposeInternal = function() {
  50668. if (this.state == ol.TileState.LOADING) {
  50669. this.unlistenImage_();
  50670. this.image_ = ol.ImageTile.getBlankImage();
  50671. }
  50672. if (this.interimTile) {
  50673. this.interimTile.dispose();
  50674. }
  50675. this.state = ol.TileState.ABORT;
  50676. this.changed();
  50677. ol.Tile.prototype.disposeInternal.call(this);
  50678. };
  50679. /**
  50680. * Get the HTML image element for this tile (may be a Canvas, Image, or Video).
  50681. * @return {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} Image.
  50682. * @api
  50683. */
  50684. ol.ImageTile.prototype.getImage = function() {
  50685. return this.image_;
  50686. };
  50687. /**
  50688. * @inheritDoc
  50689. */
  50690. ol.ImageTile.prototype.getKey = function() {
  50691. return this.src_;
  50692. };
  50693. /**
  50694. * Tracks loading or read errors.
  50695. *
  50696. * @private
  50697. */
  50698. ol.ImageTile.prototype.handleImageError_ = function() {
  50699. this.state = ol.TileState.ERROR;
  50700. this.unlistenImage_();
  50701. this.image_ = ol.ImageTile.getBlankImage();
  50702. this.changed();
  50703. };
  50704. /**
  50705. * Tracks successful image load.
  50706. *
  50707. * @private
  50708. */
  50709. ol.ImageTile.prototype.handleImageLoad_ = function() {
  50710. if (this.image_.naturalWidth && this.image_.naturalHeight) {
  50711. this.state = ol.TileState.LOADED;
  50712. } else {
  50713. this.state = ol.TileState.EMPTY;
  50714. }
  50715. this.unlistenImage_();
  50716. this.changed();
  50717. };
  50718. /**
  50719. * @inheritDoc
  50720. * @api
  50721. */
  50722. ol.ImageTile.prototype.load = function() {
  50723. if (this.state == ol.TileState.ERROR) {
  50724. this.state = ol.TileState.IDLE;
  50725. this.image_ = new Image();
  50726. if (this.crossOrigin_ !== null) {
  50727. this.image_.crossOrigin = this.crossOrigin_;
  50728. }
  50729. }
  50730. if (this.state == ol.TileState.IDLE) {
  50731. this.state = ol.TileState.LOADING;
  50732. this.changed();
  50733. this.imageListenerKeys_ = [
  50734. ol.events.listenOnce(this.image_, ol.events.EventType.ERROR,
  50735. this.handleImageError_, this),
  50736. ol.events.listenOnce(this.image_, ol.events.EventType.LOAD,
  50737. this.handleImageLoad_, this)
  50738. ];
  50739. this.tileLoadFunction_(this, this.src_);
  50740. }
  50741. };
  50742. /**
  50743. * Discards event handlers which listen for load completion or errors.
  50744. *
  50745. * @private
  50746. */
  50747. ol.ImageTile.prototype.unlistenImage_ = function() {
  50748. this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
  50749. this.imageListenerKeys_ = null;
  50750. };
  50751. /**
  50752. * Get a 1-pixel blank image.
  50753. * @return {HTMLCanvasElement} Blank image.
  50754. */
  50755. ol.ImageTile.getBlankImage = function() {
  50756. var ctx = ol.dom.createCanvasContext2D(1, 1);
  50757. ctx.fillStyle = 'rgba(0,0,0,0)';
  50758. ctx.fillRect(0, 0, 1, 1);
  50759. return ctx.canvas;
  50760. };
  50761. // FIXME should handle all geo-referenced data, not just vector data
  50762. goog.provide('ol.interaction.DragAndDrop');
  50763. goog.require('ol');
  50764. goog.require('ol.functions');
  50765. goog.require('ol.events');
  50766. goog.require('ol.events.Event');
  50767. goog.require('ol.events.EventType');
  50768. goog.require('ol.interaction.Interaction');
  50769. goog.require('ol.proj');
  50770. /**
  50771. * @classdesc
  50772. * Handles input of vector data by drag and drop.
  50773. *
  50774. * @constructor
  50775. * @extends {ol.interaction.Interaction}
  50776. * @fires ol.interaction.DragAndDrop.Event
  50777. * @param {olx.interaction.DragAndDropOptions=} opt_options Options.
  50778. * @api
  50779. */
  50780. ol.interaction.DragAndDrop = function(opt_options) {
  50781. var options = opt_options ? opt_options : {};
  50782. ol.interaction.Interaction.call(this, {
  50783. handleEvent: ol.interaction.DragAndDrop.handleEvent
  50784. });
  50785. /**
  50786. * @private
  50787. * @type {Array.<function(new: ol.format.Feature)>}
  50788. */
  50789. this.formatConstructors_ = options.formatConstructors ?
  50790. options.formatConstructors : [];
  50791. /**
  50792. * @private
  50793. * @type {ol.proj.Projection}
  50794. */
  50795. this.projection_ = options.projection ?
  50796. ol.proj.get(options.projection) : null;
  50797. /**
  50798. * @private
  50799. * @type {Array.<ol.EventsKey>}
  50800. */
  50801. this.dropListenKeys_ = null;
  50802. /**
  50803. * @private
  50804. * @type {ol.source.Vector}
  50805. */
  50806. this.source_ = options.source || null;
  50807. /**
  50808. * @private
  50809. * @type {Element}
  50810. */
  50811. this.target = options.target ? options.target : null;
  50812. };
  50813. ol.inherits(ol.interaction.DragAndDrop, ol.interaction.Interaction);
  50814. /**
  50815. * @param {Event} event Event.
  50816. * @this {ol.interaction.DragAndDrop}
  50817. * @private
  50818. */
  50819. ol.interaction.DragAndDrop.handleDrop_ = function(event) {
  50820. var files = event.dataTransfer.files;
  50821. var i, ii, file;
  50822. for (i = 0, ii = files.length; i < ii; ++i) {
  50823. file = files.item(i);
  50824. var reader = new FileReader();
  50825. reader.addEventListener(ol.events.EventType.LOAD,
  50826. this.handleResult_.bind(this, file));
  50827. reader.readAsText(file);
  50828. }
  50829. };
  50830. /**
  50831. * @param {Event} event Event.
  50832. * @private
  50833. */
  50834. ol.interaction.DragAndDrop.handleStop_ = function(event) {
  50835. event.stopPropagation();
  50836. event.preventDefault();
  50837. event.dataTransfer.dropEffect = 'copy';
  50838. };
  50839. /**
  50840. * @param {File} file File.
  50841. * @param {Event} event Load event.
  50842. * @private
  50843. */
  50844. ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, event) {
  50845. var result = event.target.result;
  50846. var map = this.getMap();
  50847. var projection = this.projection_;
  50848. if (!projection) {
  50849. var view = map.getView();
  50850. projection = view.getProjection();
  50851. }
  50852. var formatConstructors = this.formatConstructors_;
  50853. var features = [];
  50854. var i, ii;
  50855. for (i = 0, ii = formatConstructors.length; i < ii; ++i) {
  50856. /**
  50857. * Avoid "cannot instantiate abstract class" error.
  50858. * @type {Function}
  50859. */
  50860. var formatConstructor = formatConstructors[i];
  50861. /**
  50862. * @type {ol.format.Feature}
  50863. */
  50864. var format = new formatConstructor();
  50865. features = this.tryReadFeatures_(format, result, {
  50866. featureProjection: projection
  50867. });
  50868. if (features && features.length > 0) {
  50869. break;
  50870. }
  50871. }
  50872. if (this.source_) {
  50873. this.source_.clear();
  50874. this.source_.addFeatures(features);
  50875. }
  50876. this.dispatchEvent(
  50877. new ol.interaction.DragAndDrop.Event(
  50878. ol.interaction.DragAndDrop.EventType_.ADD_FEATURES, file,
  50879. features, projection));
  50880. };
  50881. /**
  50882. * Handles the {@link ol.MapBrowserEvent map browser event} unconditionally and
  50883. * neither prevents the browser default nor stops event propagation.
  50884. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  50885. * @return {boolean} `false` to stop event propagation.
  50886. * @this {ol.interaction.DragAndDrop}
  50887. * @api
  50888. */
  50889. ol.interaction.DragAndDrop.handleEvent = ol.functions.TRUE;
  50890. /**
  50891. * @private
  50892. */
  50893. ol.interaction.DragAndDrop.prototype.registerListeners_ = function() {
  50894. var map = this.getMap();
  50895. if (map) {
  50896. var dropArea = this.target ? this.target : map.getViewport();
  50897. this.dropListenKeys_ = [
  50898. ol.events.listen(dropArea, ol.events.EventType.DROP,
  50899. ol.interaction.DragAndDrop.handleDrop_, this),
  50900. ol.events.listen(dropArea, ol.events.EventType.DRAGENTER,
  50901. ol.interaction.DragAndDrop.handleStop_, this),
  50902. ol.events.listen(dropArea, ol.events.EventType.DRAGOVER,
  50903. ol.interaction.DragAndDrop.handleStop_, this),
  50904. ol.events.listen(dropArea, ol.events.EventType.DROP,
  50905. ol.interaction.DragAndDrop.handleStop_, this)
  50906. ];
  50907. }
  50908. };
  50909. /**
  50910. * @inheritDoc
  50911. */
  50912. ol.interaction.DragAndDrop.prototype.setActive = function(active) {
  50913. ol.interaction.Interaction.prototype.setActive.call(this, active);
  50914. if (active) {
  50915. this.registerListeners_();
  50916. } else {
  50917. this.unregisterListeners_();
  50918. }
  50919. };
  50920. /**
  50921. * @inheritDoc
  50922. */
  50923. ol.interaction.DragAndDrop.prototype.setMap = function(map) {
  50924. this.unregisterListeners_();
  50925. ol.interaction.Interaction.prototype.setMap.call(this, map);
  50926. if (this.getActive()) {
  50927. this.registerListeners_();
  50928. }
  50929. };
  50930. /**
  50931. * @param {ol.format.Feature} format Format.
  50932. * @param {string} text Text.
  50933. * @param {olx.format.ReadOptions} options Read options.
  50934. * @private
  50935. * @return {Array.<ol.Feature>} Features.
  50936. */
  50937. ol.interaction.DragAndDrop.prototype.tryReadFeatures_ = function(format, text, options) {
  50938. try {
  50939. return format.readFeatures(text, options);
  50940. } catch (e) {
  50941. return null;
  50942. }
  50943. };
  50944. /**
  50945. * @private
  50946. */
  50947. ol.interaction.DragAndDrop.prototype.unregisterListeners_ = function() {
  50948. if (this.dropListenKeys_) {
  50949. this.dropListenKeys_.forEach(ol.events.unlistenByKey);
  50950. this.dropListenKeys_ = null;
  50951. }
  50952. };
  50953. /**
  50954. * @enum {string}
  50955. * @private
  50956. */
  50957. ol.interaction.DragAndDrop.EventType_ = {
  50958. /**
  50959. * Triggered when features are added
  50960. * @event ol.interaction.DragAndDrop.Event#addfeatures
  50961. * @api
  50962. */
  50963. ADD_FEATURES: 'addfeatures'
  50964. };
  50965. /**
  50966. * @classdesc
  50967. * Events emitted by {@link ol.interaction.DragAndDrop} instances are instances
  50968. * of this type.
  50969. *
  50970. * @constructor
  50971. * @extends {ol.events.Event}
  50972. * @implements {oli.interaction.DragAndDropEvent}
  50973. * @param {ol.interaction.DragAndDrop.EventType_} type Type.
  50974. * @param {File} file File.
  50975. * @param {Array.<ol.Feature>=} opt_features Features.
  50976. * @param {ol.proj.Projection=} opt_projection Projection.
  50977. */
  50978. ol.interaction.DragAndDrop.Event = function(type, file, opt_features, opt_projection) {
  50979. ol.events.Event.call(this, type);
  50980. /**
  50981. * The features parsed from dropped data.
  50982. * @type {Array.<ol.Feature>|undefined}
  50983. * @api
  50984. */
  50985. this.features = opt_features;
  50986. /**
  50987. * The dropped file.
  50988. * @type {File}
  50989. * @api
  50990. */
  50991. this.file = file;
  50992. /**
  50993. * The feature projection.
  50994. * @type {ol.proj.Projection|undefined}
  50995. * @api
  50996. */
  50997. this.projection = opt_projection;
  50998. };
  50999. ol.inherits(ol.interaction.DragAndDrop.Event, ol.events.Event);
  51000. goog.provide('ol.interaction.DragRotateAndZoom');
  51001. goog.require('ol');
  51002. goog.require('ol.RotationConstraint');
  51003. goog.require('ol.ViewHint');
  51004. goog.require('ol.events.condition');
  51005. goog.require('ol.interaction.Interaction');
  51006. goog.require('ol.interaction.Pointer');
  51007. /**
  51008. * @classdesc
  51009. * Allows the user to zoom and rotate the map by clicking and dragging
  51010. * on the map. By default, this interaction is limited to when the shift
  51011. * key is held down.
  51012. *
  51013. * This interaction is only supported for mouse devices.
  51014. *
  51015. * And this interaction is not included in the default interactions.
  51016. *
  51017. * @constructor
  51018. * @extends {ol.interaction.Pointer}
  51019. * @param {olx.interaction.DragRotateAndZoomOptions=} opt_options Options.
  51020. * @api
  51021. */
  51022. ol.interaction.DragRotateAndZoom = function(opt_options) {
  51023. var options = opt_options ? opt_options : {};
  51024. ol.interaction.Pointer.call(this, {
  51025. handleDownEvent: ol.interaction.DragRotateAndZoom.handleDownEvent_,
  51026. handleDragEvent: ol.interaction.DragRotateAndZoom.handleDragEvent_,
  51027. handleUpEvent: ol.interaction.DragRotateAndZoom.handleUpEvent_
  51028. });
  51029. /**
  51030. * @private
  51031. * @type {ol.EventsConditionType}
  51032. */
  51033. this.condition_ = options.condition ?
  51034. options.condition : ol.events.condition.shiftKeyOnly;
  51035. /**
  51036. * @private
  51037. * @type {number|undefined}
  51038. */
  51039. this.lastAngle_ = undefined;
  51040. /**
  51041. * @private
  51042. * @type {number|undefined}
  51043. */
  51044. this.lastMagnitude_ = undefined;
  51045. /**
  51046. * @private
  51047. * @type {number}
  51048. */
  51049. this.lastScaleDelta_ = 0;
  51050. /**
  51051. * @private
  51052. * @type {number}
  51053. */
  51054. this.duration_ = options.duration !== undefined ? options.duration : 400;
  51055. };
  51056. ol.inherits(ol.interaction.DragRotateAndZoom, ol.interaction.Pointer);
  51057. /**
  51058. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  51059. * @this {ol.interaction.DragRotateAndZoom}
  51060. * @private
  51061. */
  51062. ol.interaction.DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) {
  51063. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  51064. return;
  51065. }
  51066. var map = mapBrowserEvent.map;
  51067. var size = map.getSize();
  51068. var offset = mapBrowserEvent.pixel;
  51069. var deltaX = offset[0] - size[0] / 2;
  51070. var deltaY = size[1] / 2 - offset[1];
  51071. var theta = Math.atan2(deltaY, deltaX);
  51072. var magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
  51073. var view = map.getView();
  51074. if (view.getConstraints().rotation !== ol.RotationConstraint.disable && this.lastAngle_ !== undefined) {
  51075. var angleDelta = theta - this.lastAngle_;
  51076. ol.interaction.Interaction.rotateWithoutConstraints(
  51077. view, view.getRotation() - angleDelta);
  51078. }
  51079. this.lastAngle_ = theta;
  51080. if (this.lastMagnitude_ !== undefined) {
  51081. var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
  51082. ol.interaction.Interaction.zoomWithoutConstraints(view, resolution);
  51083. }
  51084. if (this.lastMagnitude_ !== undefined) {
  51085. this.lastScaleDelta_ = this.lastMagnitude_ / magnitude;
  51086. }
  51087. this.lastMagnitude_ = magnitude;
  51088. };
  51089. /**
  51090. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  51091. * @return {boolean} Stop drag sequence?
  51092. * @this {ol.interaction.DragRotateAndZoom}
  51093. * @private
  51094. */
  51095. ol.interaction.DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) {
  51096. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  51097. return true;
  51098. }
  51099. var map = mapBrowserEvent.map;
  51100. var view = map.getView();
  51101. view.setHint(ol.ViewHint.INTERACTING, -1);
  51102. var direction = this.lastScaleDelta_ - 1;
  51103. ol.interaction.Interaction.rotate(view, view.getRotation());
  51104. ol.interaction.Interaction.zoom(view, view.getResolution(),
  51105. undefined, this.duration_, direction);
  51106. this.lastScaleDelta_ = 0;
  51107. return false;
  51108. };
  51109. /**
  51110. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  51111. * @return {boolean} Start drag sequence?
  51112. * @this {ol.interaction.DragRotateAndZoom}
  51113. * @private
  51114. */
  51115. ol.interaction.DragRotateAndZoom.handleDownEvent_ = function(mapBrowserEvent) {
  51116. if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
  51117. return false;
  51118. }
  51119. if (this.condition_(mapBrowserEvent)) {
  51120. mapBrowserEvent.map.getView().setHint(ol.ViewHint.INTERACTING, 1);
  51121. this.lastAngle_ = undefined;
  51122. this.lastMagnitude_ = undefined;
  51123. return true;
  51124. } else {
  51125. return false;
  51126. }
  51127. };
  51128. goog.provide('ol.interaction.DrawEventType');
  51129. /**
  51130. * @enum {string}
  51131. */
  51132. ol.interaction.DrawEventType = {
  51133. /**
  51134. * Triggered upon feature draw start
  51135. * @event ol.interaction.Draw.Event#drawstart
  51136. * @api
  51137. */
  51138. DRAWSTART: 'drawstart',
  51139. /**
  51140. * Triggered upon feature draw end
  51141. * @event ol.interaction.Draw.Event#drawend
  51142. * @api
  51143. */
  51144. DRAWEND: 'drawend'
  51145. };
  51146. goog.provide('ol.layer.Vector');
  51147. goog.require('ol');
  51148. goog.require('ol.LayerType');
  51149. goog.require('ol.layer.Layer');
  51150. goog.require('ol.layer.VectorRenderType');
  51151. goog.require('ol.obj');
  51152. goog.require('ol.style.Style');
  51153. /**
  51154. * @classdesc
  51155. * Vector data that is rendered client-side.
  51156. * Note that any property set in the options is set as a {@link ol.Object}
  51157. * property on the layer object; for example, setting `title: 'My Title'` in the
  51158. * options means that `title` is observable, and has get/set accessors.
  51159. *
  51160. * @constructor
  51161. * @extends {ol.layer.Layer}
  51162. * @fires ol.render.Event
  51163. * @param {olx.layer.VectorOptions=} opt_options Options.
  51164. * @api
  51165. */
  51166. ol.layer.Vector = function(opt_options) {
  51167. var options = opt_options ?
  51168. opt_options : /** @type {olx.layer.VectorOptions} */ ({});
  51169. var baseOptions = ol.obj.assign({}, options);
  51170. delete baseOptions.style;
  51171. delete baseOptions.renderBuffer;
  51172. delete baseOptions.updateWhileAnimating;
  51173. delete baseOptions.updateWhileInteracting;
  51174. ol.layer.Layer.call(this, /** @type {olx.layer.LayerOptions} */ (baseOptions));
  51175. /**
  51176. * @private
  51177. * @type {boolean}
  51178. */
  51179. this.declutter_ = options.declutter !== undefined ? options.declutter : false;
  51180. /**
  51181. * @type {number}
  51182. * @private
  51183. */
  51184. this.renderBuffer_ = options.renderBuffer !== undefined ?
  51185. options.renderBuffer : 100;
  51186. /**
  51187. * User provided style.
  51188. * @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
  51189. * @private
  51190. */
  51191. this.style_ = null;
  51192. /**
  51193. * Style function for use within the library.
  51194. * @type {ol.StyleFunction|undefined}
  51195. * @private
  51196. */
  51197. this.styleFunction_ = undefined;
  51198. this.setStyle(options.style);
  51199. /**
  51200. * @type {boolean}
  51201. * @private
  51202. */
  51203. this.updateWhileAnimating_ = options.updateWhileAnimating !== undefined ?
  51204. options.updateWhileAnimating : false;
  51205. /**
  51206. * @type {boolean}
  51207. * @private
  51208. */
  51209. this.updateWhileInteracting_ = options.updateWhileInteracting !== undefined ?
  51210. options.updateWhileInteracting : false;
  51211. /**
  51212. * @private
  51213. * @type {ol.layer.VectorTileRenderType|string}
  51214. */
  51215. this.renderMode_ = options.renderMode || ol.layer.VectorRenderType.VECTOR;
  51216. /**
  51217. * The layer type.
  51218. * @protected
  51219. * @type {ol.LayerType}
  51220. */
  51221. this.type = ol.LayerType.VECTOR;
  51222. };
  51223. ol.inherits(ol.layer.Vector, ol.layer.Layer);
  51224. /**
  51225. * @return {boolean} Declutter.
  51226. */
  51227. ol.layer.Vector.prototype.getDeclutter = function() {
  51228. return this.declutter_;
  51229. };
  51230. /**
  51231. * @param {boolean} declutter Declutter.
  51232. */
  51233. ol.layer.Vector.prototype.setDeclutter = function(declutter) {
  51234. this.declutter_ = declutter;
  51235. };
  51236. /**
  51237. * @return {number|undefined} Render buffer.
  51238. */
  51239. ol.layer.Vector.prototype.getRenderBuffer = function() {
  51240. return this.renderBuffer_;
  51241. };
  51242. /**
  51243. * @return {function(ol.Feature, ol.Feature): number|null|undefined} Render
  51244. * order.
  51245. */
  51246. ol.layer.Vector.prototype.getRenderOrder = function() {
  51247. return /** @type {ol.RenderOrderFunction|null|undefined} */ (
  51248. this.get(ol.layer.Vector.Property_.RENDER_ORDER));
  51249. };
  51250. /**
  51251. * Return the associated {@link ol.source.Vector vectorsource} of the layer.
  51252. * @function
  51253. * @return {ol.source.Vector} Source.
  51254. * @api
  51255. */
  51256. ol.layer.Vector.prototype.getSource;
  51257. /**
  51258. * Get the style for features. This returns whatever was passed to the `style`
  51259. * option at construction or to the `setStyle` method.
  51260. * @return {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
  51261. * Layer style.
  51262. * @api
  51263. */
  51264. ol.layer.Vector.prototype.getStyle = function() {
  51265. return this.style_;
  51266. };
  51267. /**
  51268. * Get the style function.
  51269. * @return {ol.StyleFunction|undefined} Layer style function.
  51270. * @api
  51271. */
  51272. ol.layer.Vector.prototype.getStyleFunction = function() {
  51273. return this.styleFunction_;
  51274. };
  51275. /**
  51276. * @return {boolean} Whether the rendered layer should be updated while
  51277. * animating.
  51278. */
  51279. ol.layer.Vector.prototype.getUpdateWhileAnimating = function() {
  51280. return this.updateWhileAnimating_;
  51281. };
  51282. /**
  51283. * @return {boolean} Whether the rendered layer should be updated while
  51284. * interacting.
  51285. */
  51286. ol.layer.Vector.prototype.getUpdateWhileInteracting = function() {
  51287. return this.updateWhileInteracting_;
  51288. };
  51289. /**
  51290. * @param {ol.RenderOrderFunction|null|undefined} renderOrder
  51291. * Render order.
  51292. */
  51293. ol.layer.Vector.prototype.setRenderOrder = function(renderOrder) {
  51294. this.set(ol.layer.Vector.Property_.RENDER_ORDER, renderOrder);
  51295. };
  51296. /**
  51297. * Set the style for features. This can be a single style object, an array
  51298. * of styles, or a function that takes a feature and resolution and returns
  51299. * an array of styles. If it is `undefined` the default style is used. If
  51300. * it is `null` the layer has no style (a `null` style), so only features
  51301. * that have their own styles will be rendered in the layer. See
  51302. * {@link ol.style} for information on the default style.
  51303. * @param {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|null|undefined}
  51304. * style Layer style.
  51305. * @api
  51306. */
  51307. ol.layer.Vector.prototype.setStyle = function(style) {
  51308. this.style_ = style !== undefined ? style : ol.style.Style.defaultFunction;
  51309. this.styleFunction_ = style === null ?
  51310. undefined : ol.style.Style.createFunction(this.style_);
  51311. this.changed();
  51312. };
  51313. /**
  51314. * @return {ol.layer.VectorRenderType|string} The render mode.
  51315. */
  51316. ol.layer.Vector.prototype.getRenderMode = function() {
  51317. return this.renderMode_;
  51318. };
  51319. /**
  51320. * @enum {string}
  51321. * @private
  51322. */
  51323. ol.layer.Vector.Property_ = {
  51324. RENDER_ORDER: 'renderOrder'
  51325. };
  51326. goog.provide('ol.loadingstrategy');
  51327. /**
  51328. * Strategy function for loading all features with a single request.
  51329. * @param {ol.Extent} extent Extent.
  51330. * @param {number} resolution Resolution.
  51331. * @return {Array.<ol.Extent>} Extents.
  51332. * @api
  51333. */
  51334. ol.loadingstrategy.all = function(extent, resolution) {
  51335. return [[-Infinity, -Infinity, Infinity, Infinity]];
  51336. };
  51337. /**
  51338. * Strategy function for loading features based on the view's extent and
  51339. * resolution.
  51340. * @param {ol.Extent} extent Extent.
  51341. * @param {number} resolution Resolution.
  51342. * @return {Array.<ol.Extent>} Extents.
  51343. * @api
  51344. */
  51345. ol.loadingstrategy.bbox = function(extent, resolution) {
  51346. return [extent];
  51347. };
  51348. /**
  51349. * Creates a strategy function for loading features based on a tile grid.
  51350. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
  51351. * @return {function(ol.Extent, number): Array.<ol.Extent>} Loading strategy.
  51352. * @api
  51353. */
  51354. ol.loadingstrategy.tile = function(tileGrid) {
  51355. return (
  51356. /**
  51357. * @param {ol.Extent} extent Extent.
  51358. * @param {number} resolution Resolution.
  51359. * @return {Array.<ol.Extent>} Extents.
  51360. */
  51361. function(extent, resolution) {
  51362. var z = tileGrid.getZForResolution(resolution);
  51363. var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
  51364. /** @type {Array.<ol.Extent>} */
  51365. var extents = [];
  51366. /** @type {ol.TileCoord} */
  51367. var tileCoord = [z, 0, 0];
  51368. for (tileCoord[1] = tileRange.minX; tileCoord[1] <= tileRange.maxX;
  51369. ++tileCoord[1]) {
  51370. for (tileCoord[2] = tileRange.minY; tileCoord[2] <= tileRange.maxY;
  51371. ++tileCoord[2]) {
  51372. extents.push(tileGrid.getTileCoordExtent(tileCoord));
  51373. }
  51374. }
  51375. return extents;
  51376. });
  51377. };
  51378. goog.provide('ol.source.Source');
  51379. goog.require('ol');
  51380. goog.require('ol.Attribution');
  51381. goog.require('ol.Object');
  51382. goog.require('ol.proj');
  51383. goog.require('ol.source.State');
  51384. /**
  51385. * @classdesc
  51386. * Abstract base class; normally only used for creating subclasses and not
  51387. * instantiated in apps.
  51388. * Base class for {@link ol.layer.Layer} sources.
  51389. *
  51390. * A generic `change` event is triggered when the state of the source changes.
  51391. *
  51392. * @constructor
  51393. * @abstract
  51394. * @extends {ol.Object}
  51395. * @param {ol.SourceSourceOptions} options Source options.
  51396. * @api
  51397. */
  51398. ol.source.Source = function(options) {
  51399. ol.Object.call(this);
  51400. /**
  51401. * @private
  51402. * @type {ol.proj.Projection}
  51403. */
  51404. this.projection_ = ol.proj.get(options.projection);
  51405. /**
  51406. * @private
  51407. * @type {Array.<ol.Attribution>}
  51408. */
  51409. this.attributions_ = null;
  51410. /**
  51411. * @private
  51412. * @type {?ol.Attribution2}
  51413. */
  51414. this.attributions2_ = this.adaptAttributions_(options.attributions);
  51415. /**
  51416. * @private
  51417. * @type {string|olx.LogoOptions|undefined}
  51418. */
  51419. this.logo_ = options.logo;
  51420. /**
  51421. * @private
  51422. * @type {ol.source.State}
  51423. */
  51424. this.state_ = options.state !== undefined ?
  51425. options.state : ol.source.State.READY;
  51426. /**
  51427. * @private
  51428. * @type {boolean}
  51429. */
  51430. this.wrapX_ = options.wrapX !== undefined ? options.wrapX : false;
  51431. };
  51432. ol.inherits(ol.source.Source, ol.Object);
  51433. /**
  51434. * Turns the attributions option into an attributions function.
  51435. * @suppress {deprecated}
  51436. * @param {ol.AttributionLike|undefined} attributionLike The attribution option.
  51437. * @return {?ol.Attribution2} An attribution function (or null).
  51438. */
  51439. ol.source.Source.prototype.adaptAttributions_ = function(attributionLike) {
  51440. if (!attributionLike) {
  51441. return null;
  51442. }
  51443. if (attributionLike instanceof ol.Attribution) {
  51444. // TODO: remove attributions_ in next major release
  51445. this.attributions_ = [attributionLike];
  51446. return function(frameState) {
  51447. return [attributionLike.getHTML()];
  51448. };
  51449. }
  51450. if (Array.isArray(attributionLike)) {
  51451. if (attributionLike[0] instanceof ol.Attribution) {
  51452. // TODO: remove attributions_ in next major release
  51453. this.attributions_ = attributionLike;
  51454. var attributions = attributionLike.map(function(attribution) {
  51455. return attribution.getHTML();
  51456. });
  51457. return function(frameState) {
  51458. return attributions;
  51459. };
  51460. }
  51461. // TODO: remove attributions_ in next major release
  51462. this.attributions_ = attributionLike.map(function(attribution) {
  51463. return new ol.Attribution({html: attribution});
  51464. });
  51465. return function(frameState) {
  51466. return attributionLike;
  51467. };
  51468. }
  51469. if (typeof attributionLike === 'function') {
  51470. return attributionLike;
  51471. }
  51472. // TODO: remove attributions_ in next major release
  51473. this.attributions_ = [
  51474. new ol.Attribution({html: attributionLike})
  51475. ];
  51476. return function(frameState) {
  51477. return [attributionLike];
  51478. };
  51479. };
  51480. /**
  51481. * @param {ol.Coordinate} coordinate Coordinate.
  51482. * @param {number} resolution Resolution.
  51483. * @param {number} rotation Rotation.
  51484. * @param {number} hitTolerance Hit tolerance in pixels.
  51485. * @param {Object.<string, boolean>} skippedFeatureUids Skipped feature uids.
  51486. * @param {function((ol.Feature|ol.render.Feature)): T} callback Feature
  51487. * callback.
  51488. * @return {T|undefined} Callback result.
  51489. * @template T
  51490. */
  51491. ol.source.Source.prototype.forEachFeatureAtCoordinate = ol.nullFunction;
  51492. /**
  51493. * Get the attributions of the source.
  51494. * @return {Array.<ol.Attribution>} Attributions.
  51495. * @api
  51496. */
  51497. ol.source.Source.prototype.getAttributions = function() {
  51498. return this.attributions_;
  51499. };
  51500. /**
  51501. * Get the attribution function for the source.
  51502. * @return {?ol.Attribution2} Attribution function.
  51503. */
  51504. ol.source.Source.prototype.getAttributions2 = function() {
  51505. return this.attributions2_;
  51506. };
  51507. /**
  51508. * Get the logo of the source.
  51509. * @return {string|olx.LogoOptions|undefined} Logo.
  51510. * @api
  51511. */
  51512. ol.source.Source.prototype.getLogo = function() {
  51513. return this.logo_;
  51514. };
  51515. /**
  51516. * Get the projection of the source.
  51517. * @return {ol.proj.Projection} Projection.
  51518. * @api
  51519. */
  51520. ol.source.Source.prototype.getProjection = function() {
  51521. return this.projection_;
  51522. };
  51523. /**
  51524. * @abstract
  51525. * @return {Array.<number>|undefined} Resolutions.
  51526. */
  51527. ol.source.Source.prototype.getResolutions = function() {};
  51528. /**
  51529. * Get the state of the source, see {@link ol.source.State} for possible states.
  51530. * @return {ol.source.State} State.
  51531. * @api
  51532. */
  51533. ol.source.Source.prototype.getState = function() {
  51534. return this.state_;
  51535. };
  51536. /**
  51537. * @return {boolean|undefined} Wrap X.
  51538. */
  51539. ol.source.Source.prototype.getWrapX = function() {
  51540. return this.wrapX_;
  51541. };
  51542. /**
  51543. * Refreshes the source and finally dispatches a 'change' event.
  51544. * @api
  51545. */
  51546. ol.source.Source.prototype.refresh = function() {
  51547. this.changed();
  51548. };
  51549. /**
  51550. * Set the attributions of the source.
  51551. * @param {ol.AttributionLike|undefined} attributions Attributions.
  51552. * Can be passed as `string`, `Array<string>`, `{@link ol.Attribution2}`,
  51553. * or `undefined`.
  51554. * @api
  51555. */
  51556. ol.source.Source.prototype.setAttributions = function(attributions) {
  51557. this.attributions2_ = this.adaptAttributions_(attributions);
  51558. this.changed();
  51559. };
  51560. /**
  51561. * Set the logo of the source.
  51562. * @param {string|olx.LogoOptions|undefined} logo Logo.
  51563. */
  51564. ol.source.Source.prototype.setLogo = function(logo) {
  51565. this.logo_ = logo;
  51566. };
  51567. /**
  51568. * Set the state of the source.
  51569. * @param {ol.source.State} state State.
  51570. * @protected
  51571. */
  51572. ol.source.Source.prototype.setState = function(state) {
  51573. this.state_ = state;
  51574. this.changed();
  51575. };
  51576. goog.provide('ol.source.VectorEventType');
  51577. /**
  51578. * @enum {string}
  51579. */
  51580. ol.source.VectorEventType = {
  51581. /**
  51582. * Triggered when a feature is added to the source.
  51583. * @event ol.source.Vector.Event#addfeature
  51584. * @api
  51585. */
  51586. ADDFEATURE: 'addfeature',
  51587. /**
  51588. * Triggered when a feature is updated.
  51589. * @event ol.source.Vector.Event#changefeature
  51590. * @api
  51591. */
  51592. CHANGEFEATURE: 'changefeature',
  51593. /**
  51594. * Triggered when the clear method is called on the source.
  51595. * @event ol.source.Vector.Event#clear
  51596. * @api
  51597. */
  51598. CLEAR: 'clear',
  51599. /**
  51600. * Triggered when a feature is removed from the source.
  51601. * See {@link ol.source.Vector#clear source.clear()} for exceptions.
  51602. * @event ol.source.Vector.Event#removefeature
  51603. * @api
  51604. */
  51605. REMOVEFEATURE: 'removefeature'
  51606. };
  51607. goog.provide('ol.structs.RBush');
  51608. goog.require('ol');
  51609. goog.require('ol.ext.rbush');
  51610. goog.require('ol.extent');
  51611. goog.require('ol.obj');
  51612. /**
  51613. * Wrapper around the RBush by Vladimir Agafonkin.
  51614. *
  51615. * @constructor
  51616. * @param {number=} opt_maxEntries Max entries.
  51617. * @see https://github.com/mourner/rbush
  51618. * @struct
  51619. * @template T
  51620. */
  51621. ol.structs.RBush = function(opt_maxEntries) {
  51622. /**
  51623. * @private
  51624. */
  51625. this.rbush_ = ol.ext.rbush(opt_maxEntries);
  51626. /**
  51627. * A mapping between the objects added to this rbush wrapper
  51628. * and the objects that are actually added to the internal rbush.
  51629. * @private
  51630. * @type {Object.<number, ol.RBushEntry>}
  51631. */
  51632. this.items_ = {};
  51633. };
  51634. /**
  51635. * Insert a value into the RBush.
  51636. * @param {ol.Extent} extent Extent.
  51637. * @param {T} value Value.
  51638. */
  51639. ol.structs.RBush.prototype.insert = function(extent, value) {
  51640. /** @type {ol.RBushEntry} */
  51641. var item = {
  51642. minX: extent[0],
  51643. minY: extent[1],
  51644. maxX: extent[2],
  51645. maxY: extent[3],
  51646. value: value
  51647. };
  51648. this.rbush_.insert(item);
  51649. this.items_[ol.getUid(value)] = item;
  51650. };
  51651. /**
  51652. * Bulk-insert values into the RBush.
  51653. * @param {Array.<ol.Extent>} extents Extents.
  51654. * @param {Array.<T>} values Values.
  51655. */
  51656. ol.structs.RBush.prototype.load = function(extents, values) {
  51657. var items = new Array(values.length);
  51658. for (var i = 0, l = values.length; i < l; i++) {
  51659. var extent = extents[i];
  51660. var value = values[i];
  51661. /** @type {ol.RBushEntry} */
  51662. var item = {
  51663. minX: extent[0],
  51664. minY: extent[1],
  51665. maxX: extent[2],
  51666. maxY: extent[3],
  51667. value: value
  51668. };
  51669. items[i] = item;
  51670. this.items_[ol.getUid(value)] = item;
  51671. }
  51672. this.rbush_.load(items);
  51673. };
  51674. /**
  51675. * Remove a value from the RBush.
  51676. * @param {T} value Value.
  51677. * @return {boolean} Removed.
  51678. */
  51679. ol.structs.RBush.prototype.remove = function(value) {
  51680. var uid = ol.getUid(value);
  51681. // get the object in which the value was wrapped when adding to the
  51682. // internal rbush. then use that object to do the removal.
  51683. var item = this.items_[uid];
  51684. delete this.items_[uid];
  51685. return this.rbush_.remove(item) !== null;
  51686. };
  51687. /**
  51688. * Update the extent of a value in the RBush.
  51689. * @param {ol.Extent} extent Extent.
  51690. * @param {T} value Value.
  51691. */
  51692. ol.structs.RBush.prototype.update = function(extent, value) {
  51693. var item = this.items_[ol.getUid(value)];
  51694. var bbox = [item.minX, item.minY, item.maxX, item.maxY];
  51695. if (!ol.extent.equals(bbox, extent)) {
  51696. this.remove(value);
  51697. this.insert(extent, value);
  51698. }
  51699. };
  51700. /**
  51701. * Return all values in the RBush.
  51702. * @return {Array.<T>} All.
  51703. */
  51704. ol.structs.RBush.prototype.getAll = function() {
  51705. var items = this.rbush_.all();
  51706. return items.map(function(item) {
  51707. return item.value;
  51708. });
  51709. };
  51710. /**
  51711. * Return all values in the given extent.
  51712. * @param {ol.Extent} extent Extent.
  51713. * @return {Array.<T>} All in extent.
  51714. */
  51715. ol.structs.RBush.prototype.getInExtent = function(extent) {
  51716. /** @type {ol.RBushEntry} */
  51717. var bbox = {
  51718. minX: extent[0],
  51719. minY: extent[1],
  51720. maxX: extent[2],
  51721. maxY: extent[3]
  51722. };
  51723. var items = this.rbush_.search(bbox);
  51724. return items.map(function(item) {
  51725. return item.value;
  51726. });
  51727. };
  51728. /**
  51729. * Calls a callback function with each value in the tree.
  51730. * If the callback returns a truthy value, this value is returned without
  51731. * checking the rest of the tree.
  51732. * @param {function(this: S, T): *} callback Callback.
  51733. * @param {S=} opt_this The object to use as `this` in `callback`.
  51734. * @return {*} Callback return value.
  51735. * @template S
  51736. */
  51737. ol.structs.RBush.prototype.forEach = function(callback, opt_this) {
  51738. return this.forEach_(this.getAll(), callback, opt_this);
  51739. };
  51740. /**
  51741. * Calls a callback function with each value in the provided extent.
  51742. * @param {ol.Extent} extent Extent.
  51743. * @param {function(this: S, T): *} callback Callback.
  51744. * @param {S=} opt_this The object to use as `this` in `callback`.
  51745. * @return {*} Callback return value.
  51746. * @template S
  51747. */
  51748. ol.structs.RBush.prototype.forEachInExtent = function(extent, callback, opt_this) {
  51749. return this.forEach_(this.getInExtent(extent), callback, opt_this);
  51750. };
  51751. /**
  51752. * @param {Array.<T>} values Values.
  51753. * @param {function(this: S, T): *} callback Callback.
  51754. * @param {S=} opt_this The object to use as `this` in `callback`.
  51755. * @private
  51756. * @return {*} Callback return value.
  51757. * @template S
  51758. */
  51759. ol.structs.RBush.prototype.forEach_ = function(values, callback, opt_this) {
  51760. var result;
  51761. for (var i = 0, l = values.length; i < l; i++) {
  51762. result = callback.call(opt_this, values[i]);
  51763. if (result) {
  51764. return result;
  51765. }
  51766. }
  51767. return result;
  51768. };
  51769. /**
  51770. * @return {boolean} Is empty.
  51771. */
  51772. ol.structs.RBush.prototype.isEmpty = function() {
  51773. return ol.obj.isEmpty(this.items_);
  51774. };
  51775. /**
  51776. * Remove all values from the RBush.
  51777. */
  51778. ol.structs.RBush.prototype.clear = function() {
  51779. this.rbush_.clear();
  51780. this.items_ = {};
  51781. };
  51782. /**
  51783. * @param {ol.Extent=} opt_extent Extent.
  51784. * @return {ol.Extent} Extent.
  51785. */
  51786. ol.structs.RBush.prototype.getExtent = function(opt_extent) {
  51787. // FIXME add getExtent() to rbush
  51788. var data = this.rbush_.data;
  51789. return ol.extent.createOrUpdate(data.minX, data.minY, data.maxX, data.maxY, opt_extent);
  51790. };
  51791. /**
  51792. * @param {ol.structs.RBush} rbush R-Tree.
  51793. */
  51794. ol.structs.RBush.prototype.concat = function(rbush) {
  51795. this.rbush_.load(rbush.rbush_.all());
  51796. for (var i in rbush.items_) {
  51797. this.items_[i | 0] = rbush.items_[i | 0];
  51798. }
  51799. };
  51800. // FIXME bulk feature upload - suppress events
  51801. // FIXME make change-detection more refined (notably, geometry hint)
  51802. goog.provide('ol.source.Vector');
  51803. goog.require('ol');
  51804. goog.require('ol.Collection');
  51805. goog.require('ol.CollectionEventType');
  51806. goog.require('ol.ObjectEventType');
  51807. goog.require('ol.array');
  51808. goog.require('ol.asserts');
  51809. goog.require('ol.events');
  51810. goog.require('ol.events.Event');
  51811. goog.require('ol.events.EventType');
  51812. goog.require('ol.extent');
  51813. goog.require('ol.featureloader');
  51814. goog.require('ol.functions');
  51815. goog.require('ol.loadingstrategy');
  51816. goog.require('ol.obj');
  51817. goog.require('ol.source.Source');
  51818. goog.require('ol.source.State');
  51819. goog.require('ol.source.VectorEventType');
  51820. goog.require('ol.structs.RBush');
  51821. /**
  51822. * @classdesc
  51823. * Provides a source of features for vector layers. Vector features provided
  51824. * by this source are suitable for editing. See {@link ol.source.VectorTile} for
  51825. * vector data that is optimized for rendering.
  51826. *
  51827. * @constructor
  51828. * @extends {ol.source.Source}
  51829. * @fires ol.source.Vector.Event
  51830. * @param {olx.source.VectorOptions=} opt_options Vector source options.
  51831. * @api
  51832. */
  51833. ol.source.Vector = function(opt_options) {
  51834. var options = opt_options || {};
  51835. ol.source.Source.call(this, {
  51836. attributions: options.attributions,
  51837. logo: options.logo,
  51838. projection: undefined,
  51839. state: ol.source.State.READY,
  51840. wrapX: options.wrapX !== undefined ? options.wrapX : true
  51841. });
  51842. /**
  51843. * @private
  51844. * @type {ol.FeatureLoader}
  51845. */
  51846. this.loader_ = ol.nullFunction;
  51847. /**
  51848. * @private
  51849. * @type {ol.format.Feature|undefined}
  51850. */
  51851. this.format_ = options.format;
  51852. /**
  51853. * @private
  51854. * @type {boolean}
  51855. */
  51856. this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
  51857. /**
  51858. * @private
  51859. * @type {string|ol.FeatureUrlFunction|undefined}
  51860. */
  51861. this.url_ = options.url;
  51862. if (options.loader !== undefined) {
  51863. this.loader_ = options.loader;
  51864. } else if (this.url_ !== undefined) {
  51865. ol.asserts.assert(this.format_, 7); // `format` must be set when `url` is set
  51866. // create a XHR feature loader for "url" and "format"
  51867. this.loader_ = ol.featureloader.xhr(this.url_, /** @type {ol.format.Feature} */ (this.format_));
  51868. }
  51869. /**
  51870. * @private
  51871. * @type {ol.LoadingStrategy}
  51872. */
  51873. this.strategy_ = options.strategy !== undefined ? options.strategy :
  51874. ol.loadingstrategy.all;
  51875. var useSpatialIndex =
  51876. options.useSpatialIndex !== undefined ? options.useSpatialIndex : true;
  51877. /**
  51878. * @private
  51879. * @type {ol.structs.RBush.<ol.Feature>}
  51880. */
  51881. this.featuresRtree_ = useSpatialIndex ? new ol.structs.RBush() : null;
  51882. /**
  51883. * @private
  51884. * @type {ol.structs.RBush.<{extent: ol.Extent}>}
  51885. */
  51886. this.loadedExtentsRtree_ = new ol.structs.RBush();
  51887. /**
  51888. * @private
  51889. * @type {Object.<string, ol.Feature>}
  51890. */
  51891. this.nullGeometryFeatures_ = {};
  51892. /**
  51893. * A lookup of features by id (the return from feature.getId()).
  51894. * @private
  51895. * @type {Object.<string, ol.Feature>}
  51896. */
  51897. this.idIndex_ = {};
  51898. /**
  51899. * A lookup of features without id (keyed by ol.getUid(feature)).
  51900. * @private
  51901. * @type {Object.<string, ol.Feature>}
  51902. */
  51903. this.undefIdIndex_ = {};
  51904. /**
  51905. * @private
  51906. * @type {Object.<string, Array.<ol.EventsKey>>}
  51907. */
  51908. this.featureChangeKeys_ = {};
  51909. /**
  51910. * @private
  51911. * @type {ol.Collection.<ol.Feature>}
  51912. */
  51913. this.featuresCollection_ = null;
  51914. var collection, features;
  51915. if (options.features instanceof ol.Collection) {
  51916. collection = options.features;
  51917. features = collection.getArray();
  51918. } else if (Array.isArray(options.features)) {
  51919. features = options.features;
  51920. }
  51921. if (!useSpatialIndex && collection === undefined) {
  51922. collection = new ol.Collection(features);
  51923. }
  51924. if (features !== undefined) {
  51925. this.addFeaturesInternal(features);
  51926. }
  51927. if (collection !== undefined) {
  51928. this.bindFeaturesCollection_(collection);
  51929. }
  51930. };
  51931. ol.inherits(ol.source.Vector, ol.source.Source);
  51932. /**
  51933. * Add a single feature to the source. If you want to add a batch of features
  51934. * at once, call {@link ol.source.Vector#addFeatures source.addFeatures()}
  51935. * instead. A feature will not be added to the source if feature with
  51936. * the same id is already there. The reason for this behavior is to avoid
  51937. * feature duplication when using bbox or tile loading strategies.
  51938. * @param {ol.Feature} feature Feature to add.
  51939. * @api
  51940. */
  51941. ol.source.Vector.prototype.addFeature = function(feature) {
  51942. this.addFeatureInternal(feature);
  51943. this.changed();
  51944. };
  51945. /**
  51946. * Add a feature without firing a `change` event.
  51947. * @param {ol.Feature} feature Feature.
  51948. * @protected
  51949. */
  51950. ol.source.Vector.prototype.addFeatureInternal = function(feature) {
  51951. var featureKey = ol.getUid(feature).toString();
  51952. if (!this.addToIndex_(featureKey, feature)) {
  51953. return;
  51954. }
  51955. this.setupChangeEvents_(featureKey, feature);
  51956. var geometry = feature.getGeometry();
  51957. if (geometry) {
  51958. var extent = geometry.getExtent();
  51959. if (this.featuresRtree_) {
  51960. this.featuresRtree_.insert(extent, feature);
  51961. }
  51962. } else {
  51963. this.nullGeometryFeatures_[featureKey] = feature;
  51964. }
  51965. this.dispatchEvent(
  51966. new ol.source.Vector.Event(ol.source.VectorEventType.ADDFEATURE, feature));
  51967. };
  51968. /**
  51969. * @param {string} featureKey Unique identifier for the feature.
  51970. * @param {ol.Feature} feature The feature.
  51971. * @private
  51972. */
  51973. ol.source.Vector.prototype.setupChangeEvents_ = function(featureKey, feature) {
  51974. this.featureChangeKeys_[featureKey] = [
  51975. ol.events.listen(feature, ol.events.EventType.CHANGE,
  51976. this.handleFeatureChange_, this),
  51977. ol.events.listen(feature, ol.ObjectEventType.PROPERTYCHANGE,
  51978. this.handleFeatureChange_, this)
  51979. ];
  51980. };
  51981. /**
  51982. * @param {string} featureKey Unique identifier for the feature.
  51983. * @param {ol.Feature} feature The feature.
  51984. * @return {boolean} The feature is "valid", in the sense that it is also a
  51985. * candidate for insertion into the Rtree.
  51986. * @private
  51987. */
  51988. ol.source.Vector.prototype.addToIndex_ = function(featureKey, feature) {
  51989. var valid = true;
  51990. var id = feature.getId();
  51991. if (id !== undefined) {
  51992. if (!(id.toString() in this.idIndex_)) {
  51993. this.idIndex_[id.toString()] = feature;
  51994. } else {
  51995. valid = false;
  51996. }
  51997. } else {
  51998. ol.asserts.assert(!(featureKey in this.undefIdIndex_),
  51999. 30); // The passed `feature` was already added to the source
  52000. this.undefIdIndex_[featureKey] = feature;
  52001. }
  52002. return valid;
  52003. };
  52004. /**
  52005. * Add a batch of features to the source.
  52006. * @param {Array.<ol.Feature>} features Features to add.
  52007. * @api
  52008. */
  52009. ol.source.Vector.prototype.addFeatures = function(features) {
  52010. this.addFeaturesInternal(features);
  52011. this.changed();
  52012. };
  52013. /**
  52014. * Add features without firing a `change` event.
  52015. * @param {Array.<ol.Feature>} features Features.
  52016. * @protected
  52017. */
  52018. ol.source.Vector.prototype.addFeaturesInternal = function(features) {
  52019. var featureKey, i, length, feature;
  52020. var extents = [];
  52021. var newFeatures = [];
  52022. var geometryFeatures = [];
  52023. for (i = 0, length = features.length; i < length; i++) {
  52024. feature = features[i];
  52025. featureKey = ol.getUid(feature).toString();
  52026. if (this.addToIndex_(featureKey, feature)) {
  52027. newFeatures.push(feature);
  52028. }
  52029. }
  52030. for (i = 0, length = newFeatures.length; i < length; i++) {
  52031. feature = newFeatures[i];
  52032. featureKey = ol.getUid(feature).toString();
  52033. this.setupChangeEvents_(featureKey, feature);
  52034. var geometry = feature.getGeometry();
  52035. if (geometry) {
  52036. var extent = geometry.getExtent();
  52037. extents.push(extent);
  52038. geometryFeatures.push(feature);
  52039. } else {
  52040. this.nullGeometryFeatures_[featureKey] = feature;
  52041. }
  52042. }
  52043. if (this.featuresRtree_) {
  52044. this.featuresRtree_.load(extents, geometryFeatures);
  52045. }
  52046. for (i = 0, length = newFeatures.length; i < length; i++) {
  52047. this.dispatchEvent(new ol.source.Vector.Event(
  52048. ol.source.VectorEventType.ADDFEATURE, newFeatures[i]));
  52049. }
  52050. };
  52051. /**
  52052. * @param {!ol.Collection.<ol.Feature>} collection Collection.
  52053. * @private
  52054. */
  52055. ol.source.Vector.prototype.bindFeaturesCollection_ = function(collection) {
  52056. var modifyingCollection = false;
  52057. ol.events.listen(this, ol.source.VectorEventType.ADDFEATURE,
  52058. function(evt) {
  52059. if (!modifyingCollection) {
  52060. modifyingCollection = true;
  52061. collection.push(evt.feature);
  52062. modifyingCollection = false;
  52063. }
  52064. });
  52065. ol.events.listen(this, ol.source.VectorEventType.REMOVEFEATURE,
  52066. function(evt) {
  52067. if (!modifyingCollection) {
  52068. modifyingCollection = true;
  52069. collection.remove(evt.feature);
  52070. modifyingCollection = false;
  52071. }
  52072. });
  52073. ol.events.listen(collection, ol.CollectionEventType.ADD,
  52074. function(evt) {
  52075. if (!modifyingCollection) {
  52076. modifyingCollection = true;
  52077. this.addFeature(/** @type {ol.Feature} */ (evt.element));
  52078. modifyingCollection = false;
  52079. }
  52080. }, this);
  52081. ol.events.listen(collection, ol.CollectionEventType.REMOVE,
  52082. function(evt) {
  52083. if (!modifyingCollection) {
  52084. modifyingCollection = true;
  52085. this.removeFeature(/** @type {ol.Feature} */ (evt.element));
  52086. modifyingCollection = false;
  52087. }
  52088. }, this);
  52089. this.featuresCollection_ = collection;
  52090. };
  52091. /**
  52092. * Remove all features from the source.
  52093. * @param {boolean=} opt_fast Skip dispatching of {@link removefeature} events.
  52094. * @api
  52095. */
  52096. ol.source.Vector.prototype.clear = function(opt_fast) {
  52097. if (opt_fast) {
  52098. for (var featureId in this.featureChangeKeys_) {
  52099. var keys = this.featureChangeKeys_[featureId];
  52100. keys.forEach(ol.events.unlistenByKey);
  52101. }
  52102. if (!this.featuresCollection_) {
  52103. this.featureChangeKeys_ = {};
  52104. this.idIndex_ = {};
  52105. this.undefIdIndex_ = {};
  52106. }
  52107. } else {
  52108. if (this.featuresRtree_) {
  52109. this.featuresRtree_.forEach(this.removeFeatureInternal, this);
  52110. for (var id in this.nullGeometryFeatures_) {
  52111. this.removeFeatureInternal(this.nullGeometryFeatures_[id]);
  52112. }
  52113. }
  52114. }
  52115. if (this.featuresCollection_) {
  52116. this.featuresCollection_.clear();
  52117. }
  52118. if (this.featuresRtree_) {
  52119. this.featuresRtree_.clear();
  52120. }
  52121. this.loadedExtentsRtree_.clear();
  52122. this.nullGeometryFeatures_ = {};
  52123. var clearEvent = new ol.source.Vector.Event(ol.source.VectorEventType.CLEAR);
  52124. this.dispatchEvent(clearEvent);
  52125. this.changed();
  52126. };
  52127. /**
  52128. * Iterate through all features on the source, calling the provided callback
  52129. * with each one. If the callback returns any "truthy" value, iteration will
  52130. * stop and the function will return the same value.
  52131. *
  52132. * @param {function(this: T, ol.Feature): S} callback Called with each feature
  52133. * on the source. Return a truthy value to stop iteration.
  52134. * @param {T=} opt_this The object to use as `this` in the callback.
  52135. * @return {S|undefined} The return value from the last call to the callback.
  52136. * @template T,S
  52137. * @api
  52138. */
  52139. ol.source.Vector.prototype.forEachFeature = function(callback, opt_this) {
  52140. if (this.featuresRtree_) {
  52141. return this.featuresRtree_.forEach(callback, opt_this);
  52142. } else if (this.featuresCollection_) {
  52143. return this.featuresCollection_.forEach(callback, opt_this);
  52144. }
  52145. };
  52146. /**
  52147. * Iterate through all features whose geometries contain the provided
  52148. * coordinate, calling the callback with each feature. If the callback returns
  52149. * a "truthy" value, iteration will stop and the function will return the same
  52150. * value.
  52151. *
  52152. * @param {ol.Coordinate} coordinate Coordinate.
  52153. * @param {function(this: T, ol.Feature): S} callback Called with each feature
  52154. * whose goemetry contains the provided coordinate.
  52155. * @param {T=} opt_this The object to use as `this` in the callback.
  52156. * @return {S|undefined} The return value from the last call to the callback.
  52157. * @template T,S
  52158. */
  52159. ol.source.Vector.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, callback, opt_this) {
  52160. var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
  52161. return this.forEachFeatureInExtent(extent, function(feature) {
  52162. var geometry = feature.getGeometry();
  52163. if (geometry.intersectsCoordinate(coordinate)) {
  52164. return callback.call(opt_this, feature);
  52165. } else {
  52166. return undefined;
  52167. }
  52168. });
  52169. };
  52170. /**
  52171. * Iterate through all features whose bounding box intersects the provided
  52172. * extent (note that the feature's geometry may not intersect the extent),
  52173. * calling the callback with each feature. If the callback returns a "truthy"
  52174. * value, iteration will stop and the function will return the same value.
  52175. *
  52176. * If you are interested in features whose geometry intersects an extent, call
  52177. * the {@link ol.source.Vector#forEachFeatureIntersectingExtent
  52178. * source.forEachFeatureIntersectingExtent()} method instead.
  52179. *
  52180. * When `useSpatialIndex` is set to false, this method will loop through all
  52181. * features, equivalent to {@link ol.source.Vector#forEachFeature}.
  52182. *
  52183. * @param {ol.Extent} extent Extent.
  52184. * @param {function(this: T, ol.Feature): S} callback Called with each feature
  52185. * whose bounding box intersects the provided extent.
  52186. * @param {T=} opt_this The object to use as `this` in the callback.
  52187. * @return {S|undefined} The return value from the last call to the callback.
  52188. * @template T,S
  52189. * @api
  52190. */
  52191. ol.source.Vector.prototype.forEachFeatureInExtent = function(extent, callback, opt_this) {
  52192. if (this.featuresRtree_) {
  52193. return this.featuresRtree_.forEachInExtent(extent, callback, opt_this);
  52194. } else if (this.featuresCollection_) {
  52195. return this.featuresCollection_.forEach(callback, opt_this);
  52196. }
  52197. };
  52198. /**
  52199. * Iterate through all features whose geometry intersects the provided extent,
  52200. * calling the callback with each feature. If the callback returns a "truthy"
  52201. * value, iteration will stop and the function will return the same value.
  52202. *
  52203. * If you only want to test for bounding box intersection, call the
  52204. * {@link ol.source.Vector#forEachFeatureInExtent
  52205. * source.forEachFeatureInExtent()} method instead.
  52206. *
  52207. * @param {ol.Extent} extent Extent.
  52208. * @param {function(this: T, ol.Feature): S} callback Called with each feature
  52209. * whose geometry intersects the provided extent.
  52210. * @param {T=} opt_this The object to use as `this` in the callback.
  52211. * @return {S|undefined} The return value from the last call to the callback.
  52212. * @template T,S
  52213. * @api
  52214. */
  52215. ol.source.Vector.prototype.forEachFeatureIntersectingExtent = function(extent, callback, opt_this) {
  52216. return this.forEachFeatureInExtent(extent,
  52217. /**
  52218. * @param {ol.Feature} feature Feature.
  52219. * @return {S|undefined} The return value from the last call to the callback.
  52220. * @template S
  52221. */
  52222. function(feature) {
  52223. var geometry = feature.getGeometry();
  52224. if (geometry.intersectsExtent(extent)) {
  52225. var result = callback.call(opt_this, feature);
  52226. if (result) {
  52227. return result;
  52228. }
  52229. }
  52230. });
  52231. };
  52232. /**
  52233. * Get the features collection associated with this source. Will be `null`
  52234. * unless the source was configured with `useSpatialIndex` set to `false`, or
  52235. * with an {@link ol.Collection} as `features`.
  52236. * @return {ol.Collection.<ol.Feature>} The collection of features.
  52237. * @api
  52238. */
  52239. ol.source.Vector.prototype.getFeaturesCollection = function() {
  52240. return this.featuresCollection_;
  52241. };
  52242. /**
  52243. * Get all features on the source in random order.
  52244. * @return {Array.<ol.Feature>} Features.
  52245. * @api
  52246. */
  52247. ol.source.Vector.prototype.getFeatures = function() {
  52248. var features;
  52249. if (this.featuresCollection_) {
  52250. features = this.featuresCollection_.getArray();
  52251. } else if (this.featuresRtree_) {
  52252. features = this.featuresRtree_.getAll();
  52253. if (!ol.obj.isEmpty(this.nullGeometryFeatures_)) {
  52254. ol.array.extend(
  52255. features, ol.obj.getValues(this.nullGeometryFeatures_));
  52256. }
  52257. }
  52258. return /** @type {Array.<ol.Feature>} */ (features);
  52259. };
  52260. /**
  52261. * Get all features whose geometry intersects the provided coordinate.
  52262. * @param {ol.Coordinate} coordinate Coordinate.
  52263. * @return {Array.<ol.Feature>} Features.
  52264. * @api
  52265. */
  52266. ol.source.Vector.prototype.getFeaturesAtCoordinate = function(coordinate) {
  52267. var features = [];
  52268. this.forEachFeatureAtCoordinateDirect(coordinate, function(feature) {
  52269. features.push(feature);
  52270. });
  52271. return features;
  52272. };
  52273. /**
  52274. * Get all features in the provided extent. Note that this returns an array of
  52275. * all features intersecting the given extent in random order (so it may include
  52276. * features whose geometries do not intersect the extent).
  52277. *
  52278. * This method is not available when the source is configured with
  52279. * `useSpatialIndex` set to `false`.
  52280. * @param {ol.Extent} extent Extent.
  52281. * @return {Array.<ol.Feature>} Features.
  52282. * @api
  52283. */
  52284. ol.source.Vector.prototype.getFeaturesInExtent = function(extent) {
  52285. return this.featuresRtree_.getInExtent(extent);
  52286. };
  52287. /**
  52288. * Get the closest feature to the provided coordinate.
  52289. *
  52290. * This method is not available when the source is configured with
  52291. * `useSpatialIndex` set to `false`.
  52292. * @param {ol.Coordinate} coordinate Coordinate.
  52293. * @param {function(ol.Feature):boolean=} opt_filter Feature filter function.
  52294. * The filter function will receive one argument, the {@link ol.Feature feature}
  52295. * and it should return a boolean value. By default, no filtering is made.
  52296. * @return {ol.Feature} Closest feature.
  52297. * @api
  52298. */
  52299. ol.source.Vector.prototype.getClosestFeatureToCoordinate = function(coordinate, opt_filter) {
  52300. // Find the closest feature using branch and bound. We start searching an
  52301. // infinite extent, and find the distance from the first feature found. This
  52302. // becomes the closest feature. We then compute a smaller extent which any
  52303. // closer feature must intersect. We continue searching with this smaller
  52304. // extent, trying to find a closer feature. Every time we find a closer
  52305. // feature, we update the extent being searched so that any even closer
  52306. // feature must intersect it. We continue until we run out of features.
  52307. var x = coordinate[0];
  52308. var y = coordinate[1];
  52309. var closestFeature = null;
  52310. var closestPoint = [NaN, NaN];
  52311. var minSquaredDistance = Infinity;
  52312. var extent = [-Infinity, -Infinity, Infinity, Infinity];
  52313. var filter = opt_filter ? opt_filter : ol.functions.TRUE;
  52314. this.featuresRtree_.forEachInExtent(extent,
  52315. /**
  52316. * @param {ol.Feature} feature Feature.
  52317. */
  52318. function(feature) {
  52319. if (filter(feature)) {
  52320. var geometry = feature.getGeometry();
  52321. var previousMinSquaredDistance = minSquaredDistance;
  52322. minSquaredDistance = geometry.closestPointXY(
  52323. x, y, closestPoint, minSquaredDistance);
  52324. if (minSquaredDistance < previousMinSquaredDistance) {
  52325. closestFeature = feature;
  52326. // This is sneaky. Reduce the extent that it is currently being
  52327. // searched while the R-Tree traversal using this same extent object
  52328. // is still in progress. This is safe because the new extent is
  52329. // strictly contained by the old extent.
  52330. var minDistance = Math.sqrt(minSquaredDistance);
  52331. extent[0] = x - minDistance;
  52332. extent[1] = y - minDistance;
  52333. extent[2] = x + minDistance;
  52334. extent[3] = y + minDistance;
  52335. }
  52336. }
  52337. });
  52338. return closestFeature;
  52339. };
  52340. /**
  52341. * Get the extent of the features currently in the source.
  52342. *
  52343. * This method is not available when the source is configured with
  52344. * `useSpatialIndex` set to `false`.
  52345. * @param {ol.Extent=} opt_extent Destination extent. If provided, no new extent
  52346. * will be created. Instead, that extent's coordinates will be overwritten.
  52347. * @return {ol.Extent} Extent.
  52348. * @api
  52349. */
  52350. ol.source.Vector.prototype.getExtent = function(opt_extent) {
  52351. return this.featuresRtree_.getExtent(opt_extent);
  52352. };
  52353. /**
  52354. * Get a feature by its identifier (the value returned by feature.getId()).
  52355. * Note that the index treats string and numeric identifiers as the same. So
  52356. * `source.getFeatureById(2)` will return a feature with id `'2'` or `2`.
  52357. *
  52358. * @param {string|number} id Feature identifier.
  52359. * @return {ol.Feature} The feature (or `null` if not found).
  52360. * @api
  52361. */
  52362. ol.source.Vector.prototype.getFeatureById = function(id) {
  52363. var feature = this.idIndex_[id.toString()];
  52364. return feature !== undefined ? feature : null;
  52365. };
  52366. /**
  52367. * Get the format associated with this source.
  52368. *
  52369. * @return {ol.format.Feature|undefined} The feature format.
  52370. * @api
  52371. */
  52372. ol.source.Vector.prototype.getFormat = function() {
  52373. return this.format_;
  52374. };
  52375. /**
  52376. * @return {boolean} The source can have overlapping geometries.
  52377. */
  52378. ol.source.Vector.prototype.getOverlaps = function() {
  52379. return this.overlaps_;
  52380. };
  52381. /**
  52382. * @override
  52383. */
  52384. ol.source.Vector.prototype.getResolutions = function() {};
  52385. /**
  52386. * Get the url associated with this source.
  52387. *
  52388. * @return {string|ol.FeatureUrlFunction|undefined} The url.
  52389. * @api
  52390. */
  52391. ol.source.Vector.prototype.getUrl = function() {
  52392. return this.url_;
  52393. };
  52394. /**
  52395. * @param {ol.events.Event} event Event.
  52396. * @private
  52397. */
  52398. ol.source.Vector.prototype.handleFeatureChange_ = function(event) {
  52399. var feature = /** @type {ol.Feature} */ (event.target);
  52400. var featureKey = ol.getUid(feature).toString();
  52401. var geometry = feature.getGeometry();
  52402. if (!geometry) {
  52403. if (!(featureKey in this.nullGeometryFeatures_)) {
  52404. if (this.featuresRtree_) {
  52405. this.featuresRtree_.remove(feature);
  52406. }
  52407. this.nullGeometryFeatures_[featureKey] = feature;
  52408. }
  52409. } else {
  52410. var extent = geometry.getExtent();
  52411. if (featureKey in this.nullGeometryFeatures_) {
  52412. delete this.nullGeometryFeatures_[featureKey];
  52413. if (this.featuresRtree_) {
  52414. this.featuresRtree_.insert(extent, feature);
  52415. }
  52416. } else {
  52417. if (this.featuresRtree_) {
  52418. this.featuresRtree_.update(extent, feature);
  52419. }
  52420. }
  52421. }
  52422. var id = feature.getId();
  52423. if (id !== undefined) {
  52424. var sid = id.toString();
  52425. if (featureKey in this.undefIdIndex_) {
  52426. delete this.undefIdIndex_[featureKey];
  52427. this.idIndex_[sid] = feature;
  52428. } else {
  52429. if (this.idIndex_[sid] !== feature) {
  52430. this.removeFromIdIndex_(feature);
  52431. this.idIndex_[sid] = feature;
  52432. }
  52433. }
  52434. } else {
  52435. if (!(featureKey in this.undefIdIndex_)) {
  52436. this.removeFromIdIndex_(feature);
  52437. this.undefIdIndex_[featureKey] = feature;
  52438. }
  52439. }
  52440. this.changed();
  52441. this.dispatchEvent(new ol.source.Vector.Event(
  52442. ol.source.VectorEventType.CHANGEFEATURE, feature));
  52443. };
  52444. /**
  52445. * @return {boolean} Is empty.
  52446. */
  52447. ol.source.Vector.prototype.isEmpty = function() {
  52448. return this.featuresRtree_.isEmpty() &&
  52449. ol.obj.isEmpty(this.nullGeometryFeatures_);
  52450. };
  52451. /**
  52452. * @param {ol.Extent} extent Extent.
  52453. * @param {number} resolution Resolution.
  52454. * @param {ol.proj.Projection} projection Projection.
  52455. */
  52456. ol.source.Vector.prototype.loadFeatures = function(
  52457. extent, resolution, projection) {
  52458. var loadedExtentsRtree = this.loadedExtentsRtree_;
  52459. var extentsToLoad = this.strategy_(extent, resolution);
  52460. var i, ii;
  52461. for (i = 0, ii = extentsToLoad.length; i < ii; ++i) {
  52462. var extentToLoad = extentsToLoad[i];
  52463. var alreadyLoaded = loadedExtentsRtree.forEachInExtent(extentToLoad,
  52464. /**
  52465. * @param {{extent: ol.Extent}} object Object.
  52466. * @return {boolean} Contains.
  52467. */
  52468. function(object) {
  52469. return ol.extent.containsExtent(object.extent, extentToLoad);
  52470. });
  52471. if (!alreadyLoaded) {
  52472. this.loader_.call(this, extentToLoad, resolution, projection);
  52473. loadedExtentsRtree.insert(extentToLoad, {extent: extentToLoad.slice()});
  52474. }
  52475. }
  52476. };
  52477. /**
  52478. * Remove an extent from the list of loaded extents.
  52479. * @param {ol.Extent} extent Extent.
  52480. * @api
  52481. */
  52482. ol.source.Vector.prototype.removeLoadedExtent = function(extent) {
  52483. var loadedExtentsRtree = this.loadedExtentsRtree_;
  52484. var obj;
  52485. loadedExtentsRtree.forEachInExtent(extent, function(object) {
  52486. if (ol.extent.equals(object.extent, extent)) {
  52487. obj = object;
  52488. return true;
  52489. }
  52490. });
  52491. if (obj) {
  52492. loadedExtentsRtree.remove(obj);
  52493. }
  52494. };
  52495. /**
  52496. * Remove a single feature from the source. If you want to remove all features
  52497. * at once, use the {@link ol.source.Vector#clear source.clear()} method
  52498. * instead.
  52499. * @param {ol.Feature} feature Feature to remove.
  52500. * @api
  52501. */
  52502. ol.source.Vector.prototype.removeFeature = function(feature) {
  52503. var featureKey = ol.getUid(feature).toString();
  52504. if (featureKey in this.nullGeometryFeatures_) {
  52505. delete this.nullGeometryFeatures_[featureKey];
  52506. } else {
  52507. if (this.featuresRtree_) {
  52508. this.featuresRtree_.remove(feature);
  52509. }
  52510. }
  52511. this.removeFeatureInternal(feature);
  52512. this.changed();
  52513. };
  52514. /**
  52515. * Remove feature without firing a `change` event.
  52516. * @param {ol.Feature} feature Feature.
  52517. * @protected
  52518. */
  52519. ol.source.Vector.prototype.removeFeatureInternal = function(feature) {
  52520. var featureKey = ol.getUid(feature).toString();
  52521. this.featureChangeKeys_[featureKey].forEach(ol.events.unlistenByKey);
  52522. delete this.featureChangeKeys_[featureKey];
  52523. var id = feature.getId();
  52524. if (id !== undefined) {
  52525. delete this.idIndex_[id.toString()];
  52526. } else {
  52527. delete this.undefIdIndex_[featureKey];
  52528. }
  52529. this.dispatchEvent(new ol.source.Vector.Event(
  52530. ol.source.VectorEventType.REMOVEFEATURE, feature));
  52531. };
  52532. /**
  52533. * Remove a feature from the id index. Called internally when the feature id
  52534. * may have changed.
  52535. * @param {ol.Feature} feature The feature.
  52536. * @return {boolean} Removed the feature from the index.
  52537. * @private
  52538. */
  52539. ol.source.Vector.prototype.removeFromIdIndex_ = function(feature) {
  52540. var removed = false;
  52541. for (var id in this.idIndex_) {
  52542. if (this.idIndex_[id] === feature) {
  52543. delete this.idIndex_[id];
  52544. removed = true;
  52545. break;
  52546. }
  52547. }
  52548. return removed;
  52549. };
  52550. /**
  52551. * Set the new loader of the source. The next loadFeatures call will use the
  52552. * new loader.
  52553. * @param {ol.FeatureLoader} loader The loader to set.
  52554. * @api
  52555. */
  52556. ol.source.Vector.prototype.setLoader = function(loader) {
  52557. this.loader_ = loader;
  52558. };
  52559. /**
  52560. * @classdesc
  52561. * Events emitted by {@link ol.source.Vector} instances are instances of this
  52562. * type.
  52563. *
  52564. * @constructor
  52565. * @extends {ol.events.Event}
  52566. * @implements {oli.source.Vector.Event}
  52567. * @param {string} type Type.
  52568. * @param {ol.Feature=} opt_feature Feature.
  52569. */
  52570. ol.source.Vector.Event = function(type, opt_feature) {
  52571. ol.events.Event.call(this, type);
  52572. /**
  52573. * The feature being added or removed.
  52574. * @type {ol.Feature|undefined}
  52575. * @api
  52576. */
  52577. this.feature = opt_feature;
  52578. };
  52579. ol.inherits(ol.source.Vector.Event, ol.events.Event);
  52580. goog.provide('ol.interaction.Draw');
  52581. goog.require('ol');
  52582. goog.require('ol.Feature');
  52583. goog.require('ol.MapBrowserEventType');
  52584. goog.require('ol.Object');
  52585. goog.require('ol.coordinate');
  52586. goog.require('ol.events');
  52587. goog.require('ol.events.Event');
  52588. goog.require('ol.events.condition');
  52589. goog.require('ol.extent');
  52590. goog.require('ol.functions');
  52591. goog.require('ol.geom.Circle');
  52592. goog.require('ol.geom.GeometryType');
  52593. goog.require('ol.geom.LineString');
  52594. goog.require('ol.geom.MultiLineString');
  52595. goog.require('ol.geom.MultiPoint');
  52596. goog.require('ol.geom.MultiPolygon');
  52597. goog.require('ol.geom.Point');
  52598. goog.require('ol.geom.Polygon');
  52599. goog.require('ol.interaction.DrawEventType');
  52600. goog.require('ol.interaction.Pointer');
  52601. goog.require('ol.interaction.Property');
  52602. goog.require('ol.layer.Vector');
  52603. goog.require('ol.source.Vector');
  52604. goog.require('ol.style.Style');
  52605. /**
  52606. * @classdesc
  52607. * Interaction for drawing feature geometries.
  52608. *
  52609. * @constructor
  52610. * @extends {ol.interaction.Pointer}
  52611. * @fires ol.interaction.Draw.Event
  52612. * @param {olx.interaction.DrawOptions} options Options.
  52613. * @api
  52614. */
  52615. ol.interaction.Draw = function(options) {
  52616. ol.interaction.Pointer.call(this, {
  52617. handleDownEvent: ol.interaction.Draw.handleDownEvent_,
  52618. handleEvent: ol.interaction.Draw.handleEvent,
  52619. handleUpEvent: ol.interaction.Draw.handleUpEvent_
  52620. });
  52621. /**
  52622. * @type {boolean}
  52623. * @private
  52624. */
  52625. this.shouldHandle_ = false;
  52626. /**
  52627. * @type {ol.Pixel}
  52628. * @private
  52629. */
  52630. this.downPx_ = null;
  52631. /**
  52632. * @type {boolean}
  52633. * @private
  52634. */
  52635. this.freehand_ = false;
  52636. /**
  52637. * Target source for drawn features.
  52638. * @type {ol.source.Vector}
  52639. * @private
  52640. */
  52641. this.source_ = options.source ? options.source : null;
  52642. /**
  52643. * Target collection for drawn features.
  52644. * @type {ol.Collection.<ol.Feature>}
  52645. * @private
  52646. */
  52647. this.features_ = options.features ? options.features : null;
  52648. /**
  52649. * Pixel distance for snapping.
  52650. * @type {number}
  52651. * @private
  52652. */
  52653. this.snapTolerance_ = options.snapTolerance ? options.snapTolerance : 12;
  52654. /**
  52655. * Geometry type.
  52656. * @type {ol.geom.GeometryType}
  52657. * @private
  52658. */
  52659. this.type_ = /** @type {ol.geom.GeometryType} */ (options.type);
  52660. /**
  52661. * Drawing mode (derived from geometry type.
  52662. * @type {ol.interaction.Draw.Mode_}
  52663. * @private
  52664. */
  52665. this.mode_ = ol.interaction.Draw.getMode_(this.type_);
  52666. /**
  52667. * Stop click, singleclick, and doubleclick events from firing during drawing.
  52668. * Default is `false`.
  52669. * @type {boolean}
  52670. * @private
  52671. */
  52672. this.stopClick_ = !!options.stopClick;
  52673. /**
  52674. * The number of points that must be drawn before a polygon ring or line
  52675. * string can be finished. The default is 3 for polygon rings and 2 for
  52676. * line strings.
  52677. * @type {number}
  52678. * @private
  52679. */
  52680. this.minPoints_ = options.minPoints ?
  52681. options.minPoints :
  52682. (this.mode_ === ol.interaction.Draw.Mode_.POLYGON ? 3 : 2);
  52683. /**
  52684. * The number of points that can be drawn before a polygon ring or line string
  52685. * is finished. The default is no restriction.
  52686. * @type {number}
  52687. * @private
  52688. */
  52689. this.maxPoints_ = options.maxPoints ? options.maxPoints : Infinity;
  52690. /**
  52691. * A function to decide if a potential finish coordinate is permissible
  52692. * @private
  52693. * @type {ol.EventsConditionType}
  52694. */
  52695. this.finishCondition_ = options.finishCondition ? options.finishCondition : ol.functions.TRUE;
  52696. var geometryFunction = options.geometryFunction;
  52697. if (!geometryFunction) {
  52698. if (this.type_ === ol.geom.GeometryType.CIRCLE) {
  52699. /**
  52700. * @param {!Array.<ol.Coordinate>} coordinates
  52701. * The coordinates.
  52702. * @param {ol.geom.SimpleGeometry=} opt_geometry Optional geometry.
  52703. * @return {ol.geom.SimpleGeometry} A geometry.
  52704. */
  52705. geometryFunction = function(coordinates, opt_geometry) {
  52706. var circle = opt_geometry ? /** @type {ol.geom.Circle} */ (opt_geometry) :
  52707. new ol.geom.Circle([NaN, NaN]);
  52708. var squaredLength = ol.coordinate.squaredDistance(
  52709. coordinates[0], coordinates[1]);
  52710. circle.setCenterAndRadius(coordinates[0], Math.sqrt(squaredLength));
  52711. return circle;
  52712. };
  52713. } else {
  52714. var Constructor;
  52715. var mode = this.mode_;
  52716. if (mode === ol.interaction.Draw.Mode_.POINT) {
  52717. Constructor = ol.geom.Point;
  52718. } else if (mode === ol.interaction.Draw.Mode_.LINE_STRING) {
  52719. Constructor = ol.geom.LineString;
  52720. } else if (mode === ol.interaction.Draw.Mode_.POLYGON) {
  52721. Constructor = ol.geom.Polygon;
  52722. }
  52723. /**
  52724. * @param {!Array.<ol.Coordinate>} coordinates
  52725. * The coordinates.
  52726. * @param {ol.geom.SimpleGeometry=} opt_geometry Optional geometry.
  52727. * @return {ol.geom.SimpleGeometry} A geometry.
  52728. */
  52729. geometryFunction = function(coordinates, opt_geometry) {
  52730. var geometry = opt_geometry;
  52731. if (geometry) {
  52732. if (mode === ol.interaction.Draw.Mode_.POLYGON) {
  52733. if (coordinates[0].length) {
  52734. // Add a closing coordinate to match the first
  52735. geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
  52736. } else {
  52737. geometry.setCoordinates([]);
  52738. }
  52739. } else {
  52740. geometry.setCoordinates(coordinates);
  52741. }
  52742. } else {
  52743. geometry = new Constructor(coordinates);
  52744. }
  52745. return geometry;
  52746. };
  52747. }
  52748. }
  52749. /**
  52750. * @type {ol.DrawGeometryFunctionType}
  52751. * @private
  52752. */
  52753. this.geometryFunction_ = geometryFunction;
  52754. /**
  52755. * Finish coordinate for the feature (first point for polygons, last point for
  52756. * linestrings).
  52757. * @type {ol.Coordinate}
  52758. * @private
  52759. */
  52760. this.finishCoordinate_ = null;
  52761. /**
  52762. * Sketch feature.
  52763. * @type {ol.Feature}
  52764. * @private
  52765. */
  52766. this.sketchFeature_ = null;
  52767. /**
  52768. * Sketch point.
  52769. * @type {ol.Feature}
  52770. * @private
  52771. */
  52772. this.sketchPoint_ = null;
  52773. /**
  52774. * Sketch coordinates. Used when drawing a line or polygon.
  52775. * @type {ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>}
  52776. * @private
  52777. */
  52778. this.sketchCoords_ = null;
  52779. /**
  52780. * Sketch line. Used when drawing polygon.
  52781. * @type {ol.Feature}
  52782. * @private
  52783. */
  52784. this.sketchLine_ = null;
  52785. /**
  52786. * Sketch line coordinates. Used when drawing a polygon or circle.
  52787. * @type {Array.<ol.Coordinate>}
  52788. * @private
  52789. */
  52790. this.sketchLineCoords_ = null;
  52791. /**
  52792. * Squared tolerance for handling up events. If the squared distance
  52793. * between a down and up event is greater than this tolerance, up events
  52794. * will not be handled.
  52795. * @type {number}
  52796. * @private
  52797. */
  52798. this.squaredClickTolerance_ = options.clickTolerance ?
  52799. options.clickTolerance * options.clickTolerance : 36;
  52800. /**
  52801. * Draw overlay where our sketch features are drawn.
  52802. * @type {ol.layer.Vector}
  52803. * @private
  52804. */
  52805. this.overlay_ = new ol.layer.Vector({
  52806. source: new ol.source.Vector({
  52807. useSpatialIndex: false,
  52808. wrapX: options.wrapX ? options.wrapX : false
  52809. }),
  52810. style: options.style ? options.style :
  52811. ol.interaction.Draw.getDefaultStyleFunction()
  52812. });
  52813. /**
  52814. * Name of the geometry attribute for newly created features.
  52815. * @type {string|undefined}
  52816. * @private
  52817. */
  52818. this.geometryName_ = options.geometryName;
  52819. /**
  52820. * @private
  52821. * @type {ol.EventsConditionType}
  52822. */
  52823. this.condition_ = options.condition ?
  52824. options.condition : ol.events.condition.noModifierKeys;
  52825. /**
  52826. * @private
  52827. * @type {ol.EventsConditionType}
  52828. */
  52829. this.freehandCondition_;
  52830. if (options.freehand) {
  52831. this.freehandCondition_ = ol.events.condition.always;
  52832. } else {
  52833. this.freehandCondition_ = options.freehandCondition ?
  52834. options.freehandCondition : ol.events.condition.shiftKeyOnly;
  52835. }
  52836. ol.events.listen(this,
  52837. ol.Object.getChangeEventType(ol.interaction.Property.ACTIVE),
  52838. this.updateState_, this);
  52839. };
  52840. ol.inherits(ol.interaction.Draw, ol.interaction.Pointer);
  52841. /**
  52842. * @return {ol.StyleFunction} Styles.
  52843. */
  52844. ol.interaction.Draw.getDefaultStyleFunction = function() {
  52845. var styles = ol.style.Style.createDefaultEditing();
  52846. return function(feature, resolution) {
  52847. return styles[feature.getGeometry().getType()];
  52848. };
  52849. };
  52850. /**
  52851. * @inheritDoc
  52852. */
  52853. ol.interaction.Draw.prototype.setMap = function(map) {
  52854. ol.interaction.Pointer.prototype.setMap.call(this, map);
  52855. this.updateState_();
  52856. };
  52857. /**
  52858. * Handles the {@link ol.MapBrowserEvent map browser event} and may actually
  52859. * draw or finish the drawing.
  52860. * @param {ol.MapBrowserEvent} event Map browser event.
  52861. * @return {boolean} `false` to stop event propagation.
  52862. * @this {ol.interaction.Draw}
  52863. * @api
  52864. */
  52865. ol.interaction.Draw.handleEvent = function(event) {
  52866. this.freehand_ = this.mode_ !== ol.interaction.Draw.Mode_.POINT && this.freehandCondition_(event);
  52867. var pass = true;
  52868. if (this.freehand_ &&
  52869. event.type === ol.MapBrowserEventType.POINTERDRAG &&
  52870. this.sketchFeature_ !== null) {
  52871. this.addToDrawing_(event);
  52872. pass = false;
  52873. } else if (this.freehand_ &&
  52874. event.type === ol.MapBrowserEventType.POINTERDOWN) {
  52875. pass = false;
  52876. } else if (event.type === ol.MapBrowserEventType.POINTERMOVE) {
  52877. pass = this.handlePointerMove_(event);
  52878. } else if (event.type === ol.MapBrowserEventType.DBLCLICK) {
  52879. pass = false;
  52880. }
  52881. return ol.interaction.Pointer.handleEvent.call(this, event) && pass;
  52882. };
  52883. /**
  52884. * @param {ol.MapBrowserPointerEvent} event Event.
  52885. * @return {boolean} Start drag sequence?
  52886. * @this {ol.interaction.Draw}
  52887. * @private
  52888. */
  52889. ol.interaction.Draw.handleDownEvent_ = function(event) {
  52890. this.shouldHandle_ = !this.freehand_;
  52891. if (this.freehand_) {
  52892. this.downPx_ = event.pixel;
  52893. if (!this.finishCoordinate_) {
  52894. this.startDrawing_(event);
  52895. }
  52896. return true;
  52897. } else if (this.condition_(event)) {
  52898. this.downPx_ = event.pixel;
  52899. return true;
  52900. } else {
  52901. return false;
  52902. }
  52903. };
  52904. /**
  52905. * @param {ol.MapBrowserPointerEvent} event Event.
  52906. * @return {boolean} Stop drag sequence?
  52907. * @this {ol.interaction.Draw}
  52908. * @private
  52909. */
  52910. ol.interaction.Draw.handleUpEvent_ = function(event) {
  52911. var pass = true;
  52912. this.handlePointerMove_(event);
  52913. var circleMode = this.mode_ === ol.interaction.Draw.Mode_.CIRCLE;
  52914. if (this.shouldHandle_) {
  52915. if (!this.finishCoordinate_) {
  52916. this.startDrawing_(event);
  52917. if (this.mode_ === ol.interaction.Draw.Mode_.POINT) {
  52918. this.finishDrawing();
  52919. }
  52920. } else if (this.freehand_ || circleMode) {
  52921. this.finishDrawing();
  52922. } else if (this.atFinish_(event)) {
  52923. if (this.finishCondition_(event)) {
  52924. this.finishDrawing();
  52925. }
  52926. } else {
  52927. this.addToDrawing_(event);
  52928. }
  52929. pass = false;
  52930. } else if (this.freehand_) {
  52931. this.finishCoordinate_ = null;
  52932. this.abortDrawing_();
  52933. }
  52934. if (!pass && this.stopClick_) {
  52935. event.stopPropagation();
  52936. }
  52937. return pass;
  52938. };
  52939. /**
  52940. * Handle move events.
  52941. * @param {ol.MapBrowserEvent} event A move event.
  52942. * @return {boolean} Pass the event to other interactions.
  52943. * @private
  52944. */
  52945. ol.interaction.Draw.prototype.handlePointerMove_ = function(event) {
  52946. if (this.downPx_ &&
  52947. ((!this.freehand_ && this.shouldHandle_) ||
  52948. (this.freehand_ && !this.shouldHandle_))) {
  52949. var downPx = this.downPx_;
  52950. var clickPx = event.pixel;
  52951. var dx = downPx[0] - clickPx[0];
  52952. var dy = downPx[1] - clickPx[1];
  52953. var squaredDistance = dx * dx + dy * dy;
  52954. this.shouldHandle_ = this.freehand_ ?
  52955. squaredDistance > this.squaredClickTolerance_ :
  52956. squaredDistance <= this.squaredClickTolerance_;
  52957. }
  52958. if (this.finishCoordinate_) {
  52959. this.modifyDrawing_(event);
  52960. } else {
  52961. this.createOrUpdateSketchPoint_(event);
  52962. }
  52963. return true;
  52964. };
  52965. /**
  52966. * Determine if an event is within the snapping tolerance of the start coord.
  52967. * @param {ol.MapBrowserEvent} event Event.
  52968. * @return {boolean} The event is within the snapping tolerance of the start.
  52969. * @private
  52970. */
  52971. ol.interaction.Draw.prototype.atFinish_ = function(event) {
  52972. var at = false;
  52973. if (this.sketchFeature_) {
  52974. var potentiallyDone = false;
  52975. var potentiallyFinishCoordinates = [this.finishCoordinate_];
  52976. if (this.mode_ === ol.interaction.Draw.Mode_.LINE_STRING) {
  52977. potentiallyDone = this.sketchCoords_.length > this.minPoints_;
  52978. } else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
  52979. potentiallyDone = this.sketchCoords_[0].length >
  52980. this.minPoints_;
  52981. potentiallyFinishCoordinates = [this.sketchCoords_[0][0],
  52982. this.sketchCoords_[0][this.sketchCoords_[0].length - 2]];
  52983. }
  52984. if (potentiallyDone) {
  52985. var map = event.map;
  52986. for (var i = 0, ii = potentiallyFinishCoordinates.length; i < ii; i++) {
  52987. var finishCoordinate = potentiallyFinishCoordinates[i];
  52988. var finishPixel = map.getPixelFromCoordinate(finishCoordinate);
  52989. var pixel = event.pixel;
  52990. var dx = pixel[0] - finishPixel[0];
  52991. var dy = pixel[1] - finishPixel[1];
  52992. var snapTolerance = this.freehand_ ? 1 : this.snapTolerance_;
  52993. at = Math.sqrt(dx * dx + dy * dy) <= snapTolerance;
  52994. if (at) {
  52995. this.finishCoordinate_ = finishCoordinate;
  52996. break;
  52997. }
  52998. }
  52999. }
  53000. }
  53001. return at;
  53002. };
  53003. /**
  53004. * @param {ol.MapBrowserEvent} event Event.
  53005. * @private
  53006. */
  53007. ol.interaction.Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
  53008. var coordinates = event.coordinate.slice();
  53009. if (!this.sketchPoint_) {
  53010. this.sketchPoint_ = new ol.Feature(new ol.geom.Point(coordinates));
  53011. this.updateSketchFeatures_();
  53012. } else {
  53013. var sketchPointGeom = /** @type {ol.geom.Point} */ (this.sketchPoint_.getGeometry());
  53014. sketchPointGeom.setCoordinates(coordinates);
  53015. }
  53016. };
  53017. /**
  53018. * Start the drawing.
  53019. * @param {ol.MapBrowserEvent} event Event.
  53020. * @private
  53021. */
  53022. ol.interaction.Draw.prototype.startDrawing_ = function(event) {
  53023. var start = event.coordinate;
  53024. this.finishCoordinate_ = start;
  53025. if (this.mode_ === ol.interaction.Draw.Mode_.POINT) {
  53026. this.sketchCoords_ = start.slice();
  53027. } else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
  53028. this.sketchCoords_ = [[start.slice(), start.slice()]];
  53029. this.sketchLineCoords_ = this.sketchCoords_[0];
  53030. } else {
  53031. this.sketchCoords_ = [start.slice(), start.slice()];
  53032. if (this.mode_ === ol.interaction.Draw.Mode_.CIRCLE) {
  53033. this.sketchLineCoords_ = this.sketchCoords_;
  53034. }
  53035. }
  53036. if (this.sketchLineCoords_) {
  53037. this.sketchLine_ = new ol.Feature(
  53038. new ol.geom.LineString(this.sketchLineCoords_));
  53039. }
  53040. var geometry = this.geometryFunction_(this.sketchCoords_);
  53041. this.sketchFeature_ = new ol.Feature();
  53042. if (this.geometryName_) {
  53043. this.sketchFeature_.setGeometryName(this.geometryName_);
  53044. }
  53045. this.sketchFeature_.setGeometry(geometry);
  53046. this.updateSketchFeatures_();
  53047. this.dispatchEvent(new ol.interaction.Draw.Event(
  53048. ol.interaction.DrawEventType.DRAWSTART, this.sketchFeature_));
  53049. };
  53050. /**
  53051. * Modify the drawing.
  53052. * @param {ol.MapBrowserEvent} event Event.
  53053. * @private
  53054. */
  53055. ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
  53056. var coordinate = event.coordinate;
  53057. var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
  53058. var coordinates, last;
  53059. if (this.mode_ === ol.interaction.Draw.Mode_.POINT) {
  53060. last = this.sketchCoords_;
  53061. } else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
  53062. coordinates = this.sketchCoords_[0];
  53063. last = coordinates[coordinates.length - 1];
  53064. if (this.atFinish_(event)) {
  53065. // snap to finish
  53066. coordinate = this.finishCoordinate_.slice();
  53067. }
  53068. } else {
  53069. coordinates = this.sketchCoords_;
  53070. last = coordinates[coordinates.length - 1];
  53071. }
  53072. last[0] = coordinate[0];
  53073. last[1] = coordinate[1];
  53074. this.geometryFunction_(/** @type {!Array.<ol.Coordinate>} */ (this.sketchCoords_), geometry);
  53075. if (this.sketchPoint_) {
  53076. var sketchPointGeom = /** @type {ol.geom.Point} */ (this.sketchPoint_.getGeometry());
  53077. sketchPointGeom.setCoordinates(coordinate);
  53078. }
  53079. var sketchLineGeom;
  53080. if (geometry instanceof ol.geom.Polygon &&
  53081. this.mode_ !== ol.interaction.Draw.Mode_.POLYGON) {
  53082. if (!this.sketchLine_) {
  53083. this.sketchLine_ = new ol.Feature(new ol.geom.LineString(null));
  53084. }
  53085. var ring = geometry.getLinearRing(0);
  53086. sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
  53087. sketchLineGeom.setFlatCoordinates(
  53088. ring.getLayout(), ring.getFlatCoordinates());
  53089. } else if (this.sketchLineCoords_) {
  53090. sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
  53091. sketchLineGeom.setCoordinates(this.sketchLineCoords_);
  53092. }
  53093. this.updateSketchFeatures_();
  53094. };
  53095. /**
  53096. * Add a new coordinate to the drawing.
  53097. * @param {ol.MapBrowserEvent} event Event.
  53098. * @private
  53099. */
  53100. ol.interaction.Draw.prototype.addToDrawing_ = function(event) {
  53101. var coordinate = event.coordinate;
  53102. var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
  53103. var done;
  53104. var coordinates;
  53105. if (this.mode_ === ol.interaction.Draw.Mode_.LINE_STRING) {
  53106. this.finishCoordinate_ = coordinate.slice();
  53107. coordinates = this.sketchCoords_;
  53108. if (coordinates.length >= this.maxPoints_) {
  53109. if (this.freehand_) {
  53110. coordinates.pop();
  53111. } else {
  53112. done = true;
  53113. }
  53114. }
  53115. coordinates.push(coordinate.slice());
  53116. this.geometryFunction_(coordinates, geometry);
  53117. } else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
  53118. coordinates = this.sketchCoords_[0];
  53119. if (coordinates.length >= this.maxPoints_) {
  53120. if (this.freehand_) {
  53121. coordinates.pop();
  53122. } else {
  53123. done = true;
  53124. }
  53125. }
  53126. coordinates.push(coordinate.slice());
  53127. if (done) {
  53128. this.finishCoordinate_ = coordinates[0];
  53129. }
  53130. this.geometryFunction_(this.sketchCoords_, geometry);
  53131. }
  53132. this.updateSketchFeatures_();
  53133. if (done) {
  53134. this.finishDrawing();
  53135. }
  53136. };
  53137. /**
  53138. * Remove last point of the feature currently being drawn.
  53139. * @api
  53140. */
  53141. ol.interaction.Draw.prototype.removeLastPoint = function() {
  53142. if (!this.sketchFeature_) {
  53143. return;
  53144. }
  53145. var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
  53146. var coordinates, sketchLineGeom;
  53147. if (this.mode_ === ol.interaction.Draw.Mode_.LINE_STRING) {
  53148. coordinates = this.sketchCoords_;
  53149. coordinates.splice(-2, 1);
  53150. this.geometryFunction_(coordinates, geometry);
  53151. if (coordinates.length >= 2) {
  53152. this.finishCoordinate_ = coordinates[coordinates.length - 2].slice();
  53153. }
  53154. } else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
  53155. coordinates = this.sketchCoords_[0];
  53156. coordinates.splice(-2, 1);
  53157. sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
  53158. sketchLineGeom.setCoordinates(coordinates);
  53159. this.geometryFunction_(this.sketchCoords_, geometry);
  53160. }
  53161. if (coordinates.length === 0) {
  53162. this.finishCoordinate_ = null;
  53163. }
  53164. this.updateSketchFeatures_();
  53165. };
  53166. /**
  53167. * Stop drawing and add the sketch feature to the target layer.
  53168. * The {@link ol.interaction.DrawEventType.DRAWEND} event is dispatched before
  53169. * inserting the feature.
  53170. * @api
  53171. */
  53172. ol.interaction.Draw.prototype.finishDrawing = function() {
  53173. var sketchFeature = this.abortDrawing_();
  53174. var coordinates = this.sketchCoords_;
  53175. var geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry());
  53176. if (this.mode_ === ol.interaction.Draw.Mode_.LINE_STRING) {
  53177. // remove the redundant last point
  53178. coordinates.pop();
  53179. this.geometryFunction_(coordinates, geometry);
  53180. } else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
  53181. // remove the redundant last point in ring
  53182. coordinates[0].pop();
  53183. this.geometryFunction_(coordinates, geometry);
  53184. coordinates = geometry.getCoordinates();
  53185. }
  53186. // cast multi-part geometries
  53187. if (this.type_ === ol.geom.GeometryType.MULTI_POINT) {
  53188. sketchFeature.setGeometry(new ol.geom.MultiPoint([coordinates]));
  53189. } else if (this.type_ === ol.geom.GeometryType.MULTI_LINE_STRING) {
  53190. sketchFeature.setGeometry(new ol.geom.MultiLineString([coordinates]));
  53191. } else if (this.type_ === ol.geom.GeometryType.MULTI_POLYGON) {
  53192. sketchFeature.setGeometry(new ol.geom.MultiPolygon([coordinates]));
  53193. }
  53194. // First dispatch event to allow full set up of feature
  53195. this.dispatchEvent(new ol.interaction.Draw.Event(
  53196. ol.interaction.DrawEventType.DRAWEND, sketchFeature));
  53197. // Then insert feature
  53198. if (this.features_) {
  53199. this.features_.push(sketchFeature);
  53200. }
  53201. if (this.source_) {
  53202. this.source_.addFeature(sketchFeature);
  53203. }
  53204. };
  53205. /**
  53206. * Stop drawing without adding the sketch feature to the target layer.
  53207. * @return {ol.Feature} The sketch feature (or null if none).
  53208. * @private
  53209. */
  53210. ol.interaction.Draw.prototype.abortDrawing_ = function() {
  53211. this.finishCoordinate_ = null;
  53212. var sketchFeature = this.sketchFeature_;
  53213. if (sketchFeature) {
  53214. this.sketchFeature_ = null;
  53215. this.sketchPoint_ = null;
  53216. this.sketchLine_ = null;
  53217. this.overlay_.getSource().clear(true);
  53218. }
  53219. return sketchFeature;
  53220. };
  53221. /**
  53222. * Extend an existing geometry by adding additional points. This only works
  53223. * on features with `LineString` geometries, where the interaction will
  53224. * extend lines by adding points to the end of the coordinates array.
  53225. * @param {!ol.Feature} feature Feature to be extended.
  53226. * @api
  53227. */
  53228. ol.interaction.Draw.prototype.extend = function(feature) {
  53229. var geometry = feature.getGeometry();
  53230. var lineString = /** @type {ol.geom.LineString} */ (geometry);
  53231. this.sketchFeature_ = feature;
  53232. this.sketchCoords_ = lineString.getCoordinates();
  53233. var last = this.sketchCoords_[this.sketchCoords_.length - 1];
  53234. this.finishCoordinate_ = last.slice();
  53235. this.sketchCoords_.push(last.slice());
  53236. this.updateSketchFeatures_();
  53237. this.dispatchEvent(new ol.interaction.Draw.Event(
  53238. ol.interaction.DrawEventType.DRAWSTART, this.sketchFeature_));
  53239. };
  53240. /**
  53241. * @inheritDoc
  53242. */
  53243. ol.interaction.Draw.prototype.shouldStopEvent = ol.functions.FALSE;
  53244. /**
  53245. * Redraw the sketch features.
  53246. * @private
  53247. */
  53248. ol.interaction.Draw.prototype.updateSketchFeatures_ = function() {
  53249. var sketchFeatures = [];
  53250. if (this.sketchFeature_) {
  53251. sketchFeatures.push(this.sketchFeature_);
  53252. }
  53253. if (this.sketchLine_) {
  53254. sketchFeatures.push(this.sketchLine_);
  53255. }
  53256. if (this.sketchPoint_) {
  53257. sketchFeatures.push(this.sketchPoint_);
  53258. }
  53259. var overlaySource = this.overlay_.getSource();
  53260. overlaySource.clear(true);
  53261. overlaySource.addFeatures(sketchFeatures);
  53262. };
  53263. /**
  53264. * @private
  53265. */
  53266. ol.interaction.Draw.prototype.updateState_ = function() {
  53267. var map = this.getMap();
  53268. var active = this.getActive();
  53269. if (!map || !active) {
  53270. this.abortDrawing_();
  53271. }
  53272. this.overlay_.setMap(active ? map : null);
  53273. };
  53274. /**
  53275. * Create a `geometryFunction` for `type: 'Circle'` that will create a regular
  53276. * polygon with a user specified number of sides and start angle instead of an
  53277. * `ol.geom.Circle` geometry.
  53278. * @param {number=} opt_sides Number of sides of the regular polygon. Default is
  53279. * 32.
  53280. * @param {number=} opt_angle Angle of the first point in radians. 0 means East.
  53281. * Default is the angle defined by the heading from the center of the
  53282. * regular polygon to the current pointer position.
  53283. * @return {ol.DrawGeometryFunctionType} Function that draws a
  53284. * polygon.
  53285. * @api
  53286. */
  53287. ol.interaction.Draw.createRegularPolygon = function(opt_sides, opt_angle) {
  53288. return (
  53289. /**
  53290. * @param {ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>} coordinates
  53291. * @param {ol.geom.SimpleGeometry=} opt_geometry
  53292. * @return {ol.geom.SimpleGeometry}
  53293. */
  53294. function(coordinates, opt_geometry) {
  53295. var center = coordinates[0];
  53296. var end = coordinates[1];
  53297. var radius = Math.sqrt(
  53298. ol.coordinate.squaredDistance(center, end));
  53299. var geometry = opt_geometry ? /** @type {ol.geom.Polygon} */ (opt_geometry) :
  53300. ol.geom.Polygon.fromCircle(new ol.geom.Circle(center), opt_sides);
  53301. var angle = opt_angle ? opt_angle :
  53302. Math.atan((end[1] - center[1]) / (end[0] - center[0]));
  53303. ol.geom.Polygon.makeRegular(geometry, center, radius, angle);
  53304. return geometry;
  53305. }
  53306. );
  53307. };
  53308. /**
  53309. * Create a `geometryFunction` that will create a box-shaped polygon (aligned
  53310. * with the coordinate system axes). Use this with the draw interaction and
  53311. * `type: 'Circle'` to return a box instead of a circle geometry.
  53312. * @return {ol.DrawGeometryFunctionType} Function that draws a box-shaped polygon.
  53313. * @api
  53314. */
  53315. ol.interaction.Draw.createBox = function() {
  53316. return (
  53317. /**
  53318. * @param {Array.<ol.Coordinate>} coordinates
  53319. * @param {ol.geom.SimpleGeometry=} opt_geometry
  53320. * @return {ol.geom.SimpleGeometry}
  53321. */
  53322. function(coordinates, opt_geometry) {
  53323. var extent = ol.extent.boundingExtent(coordinates);
  53324. var geometry = opt_geometry || new ol.geom.Polygon(null);
  53325. geometry.setCoordinates([[
  53326. ol.extent.getBottomLeft(extent),
  53327. ol.extent.getBottomRight(extent),
  53328. ol.extent.getTopRight(extent),
  53329. ol.extent.getTopLeft(extent),
  53330. ol.extent.getBottomLeft(extent)
  53331. ]]);
  53332. return geometry;
  53333. }
  53334. );
  53335. };
  53336. /**
  53337. * Get the drawing mode. The mode for mult-part geometries is the same as for
  53338. * their single-part cousins.
  53339. * @param {ol.geom.GeometryType} type Geometry type.
  53340. * @return {ol.interaction.Draw.Mode_} Drawing mode.
  53341. * @private
  53342. */
  53343. ol.interaction.Draw.getMode_ = function(type) {
  53344. var mode;
  53345. if (type === ol.geom.GeometryType.POINT ||
  53346. type === ol.geom.GeometryType.MULTI_POINT) {
  53347. mode = ol.interaction.Draw.Mode_.POINT;
  53348. } else if (type === ol.geom.GeometryType.LINE_STRING ||
  53349. type === ol.geom.GeometryType.MULTI_LINE_STRING) {
  53350. mode = ol.interaction.Draw.Mode_.LINE_STRING;
  53351. } else if (type === ol.geom.GeometryType.POLYGON ||
  53352. type === ol.geom.GeometryType.MULTI_POLYGON) {
  53353. mode = ol.interaction.Draw.Mode_.POLYGON;
  53354. } else if (type === ol.geom.GeometryType.CIRCLE) {
  53355. mode = ol.interaction.Draw.Mode_.CIRCLE;
  53356. }
  53357. return /** @type {!ol.interaction.Draw.Mode_} */ (mode);
  53358. };
  53359. /**
  53360. * Draw mode. This collapses multi-part geometry types with their single-part
  53361. * cousins.
  53362. * @enum {string}
  53363. * @private
  53364. */
  53365. ol.interaction.Draw.Mode_ = {
  53366. POINT: 'Point',
  53367. LINE_STRING: 'LineString',
  53368. POLYGON: 'Polygon',
  53369. CIRCLE: 'Circle'
  53370. };
  53371. /**
  53372. * @classdesc
  53373. * Events emitted by {@link ol.interaction.Draw} instances are instances of
  53374. * this type.
  53375. *
  53376. * @constructor
  53377. * @extends {ol.events.Event}
  53378. * @implements {oli.DrawEvent}
  53379. * @param {ol.interaction.DrawEventType} type Type.
  53380. * @param {ol.Feature} feature The feature drawn.
  53381. */
  53382. ol.interaction.Draw.Event = function(type, feature) {
  53383. ol.events.Event.call(this, type);
  53384. /**
  53385. * The feature being drawn.
  53386. * @type {ol.Feature}
  53387. * @api
  53388. */
  53389. this.feature = feature;
  53390. };
  53391. ol.inherits(ol.interaction.Draw.Event, ol.events.Event);
  53392. goog.provide('ol.interaction.ExtentEventType');
  53393. /**
  53394. * @enum {string}
  53395. */
  53396. ol.interaction.ExtentEventType = {
  53397. /**
  53398. * Triggered after the extent is changed
  53399. * @event ol.interaction.Extent.Event#extentchanged
  53400. * @api
  53401. */
  53402. EXTENTCHANGED: 'extentchanged'
  53403. };
  53404. goog.provide('ol.interaction.Extent');
  53405. goog.require('ol');
  53406. goog.require('ol.Feature');
  53407. goog.require('ol.MapBrowserEventType');
  53408. goog.require('ol.MapBrowserPointerEvent');
  53409. goog.require('ol.coordinate');
  53410. goog.require('ol.events.Event');
  53411. goog.require('ol.extent');
  53412. goog.require('ol.geom.GeometryType');
  53413. goog.require('ol.geom.Point');
  53414. goog.require('ol.geom.Polygon');
  53415. goog.require('ol.interaction.ExtentEventType');
  53416. goog.require('ol.interaction.Pointer');
  53417. goog.require('ol.layer.Vector');
  53418. goog.require('ol.source.Vector');
  53419. goog.require('ol.style.Style');
  53420. /**
  53421. * @classdesc
  53422. * Allows the user to draw a vector box by clicking and dragging on the map.
  53423. * Once drawn, the vector box can be modified by dragging its vertices or edges.
  53424. * This interaction is only supported for mouse devices.
  53425. *
  53426. * @constructor
  53427. * @extends {ol.interaction.Pointer}
  53428. * @fires ol.interaction.Extent.Event
  53429. * @param {olx.interaction.ExtentOptions=} opt_options Options.
  53430. * @api
  53431. */
  53432. ol.interaction.Extent = function(opt_options) {
  53433. var options = opt_options || {};
  53434. /**
  53435. * Extent of the drawn box
  53436. * @type {ol.Extent}
  53437. * @private
  53438. */
  53439. this.extent_ = null;
  53440. /**
  53441. * Handler for pointer move events
  53442. * @type {function (ol.Coordinate): ol.Extent|null}
  53443. * @private
  53444. */
  53445. this.pointerHandler_ = null;
  53446. /**
  53447. * Pixel threshold to snap to extent
  53448. * @type {number}
  53449. * @private
  53450. */
  53451. this.pixelTolerance_ = options.pixelTolerance !== undefined ?
  53452. options.pixelTolerance : 10;
  53453. /**
  53454. * Is the pointer snapped to an extent vertex
  53455. * @type {boolean}
  53456. * @private
  53457. */
  53458. this.snappedToVertex_ = false;
  53459. /**
  53460. * Feature for displaying the visible extent
  53461. * @type {ol.Feature}
  53462. * @private
  53463. */
  53464. this.extentFeature_ = null;
  53465. /**
  53466. * Feature for displaying the visible pointer
  53467. * @type {ol.Feature}
  53468. * @private
  53469. */
  53470. this.vertexFeature_ = null;
  53471. if (!opt_options) {
  53472. opt_options = {};
  53473. }
  53474. /* Inherit ol.interaction.Pointer */
  53475. ol.interaction.Pointer.call(this, {
  53476. handleDownEvent: ol.interaction.Extent.handleDownEvent_,
  53477. handleDragEvent: ol.interaction.Extent.handleDragEvent_,
  53478. handleEvent: ol.interaction.Extent.handleEvent_,
  53479. handleUpEvent: ol.interaction.Extent.handleUpEvent_
  53480. });
  53481. /**
  53482. * Layer for the extentFeature
  53483. * @type {ol.layer.Vector}
  53484. * @private
  53485. */
  53486. this.extentOverlay_ = new ol.layer.Vector({
  53487. source: new ol.source.Vector({
  53488. useSpatialIndex: false,
  53489. wrapX: !!opt_options.wrapX
  53490. }),
  53491. style: opt_options.boxStyle ? opt_options.boxStyle : ol.interaction.Extent.getDefaultExtentStyleFunction_(),
  53492. updateWhileAnimating: true,
  53493. updateWhileInteracting: true
  53494. });
  53495. /**
  53496. * Layer for the vertexFeature
  53497. * @type {ol.layer.Vector}
  53498. * @private
  53499. */
  53500. this.vertexOverlay_ = new ol.layer.Vector({
  53501. source: new ol.source.Vector({
  53502. useSpatialIndex: false,
  53503. wrapX: !!opt_options.wrapX
  53504. }),
  53505. style: opt_options.pointerStyle ? opt_options.pointerStyle : ol.interaction.Extent.getDefaultPointerStyleFunction_(),
  53506. updateWhileAnimating: true,
  53507. updateWhileInteracting: true
  53508. });
  53509. if (opt_options.extent) {
  53510. this.setExtent(opt_options.extent);
  53511. }
  53512. };
  53513. ol.inherits(ol.interaction.Extent, ol.interaction.Pointer);
  53514. /**
  53515. * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
  53516. * @return {boolean} Propagate event?
  53517. * @this {ol.interaction.Extent}
  53518. * @private
  53519. */
  53520. ol.interaction.Extent.handleEvent_ = function(mapBrowserEvent) {
  53521. if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
  53522. return true;
  53523. }
  53524. //display pointer (if not dragging)
  53525. if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERMOVE && !this.handlingDownUpSequence) {
  53526. this.handlePointerMove_(mapBrowserEvent);
  53527. }
  53528. //call pointer to determine up/down/drag
  53529. ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent);
  53530. //return false to stop propagation
  53531. return false;
  53532. };
  53533. /**
  53534. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  53535. * @return {boolean} Event handled?
  53536. * @this {ol.interaction.Extent}
  53537. * @private
  53538. */
  53539. ol.interaction.Extent.handleDownEvent_ = function(mapBrowserEvent) {
  53540. var pixel = mapBrowserEvent.pixel;
  53541. var map = mapBrowserEvent.map;
  53542. var extent = this.getExtent();
  53543. var vertex = this.snapToVertex_(pixel, map);
  53544. //find the extent corner opposite the passed corner
  53545. var getOpposingPoint = function(point) {
  53546. var x_ = null;
  53547. var y_ = null;
  53548. if (point[0] == extent[0]) {
  53549. x_ = extent[2];
  53550. } else if (point[0] == extent[2]) {
  53551. x_ = extent[0];
  53552. }
  53553. if (point[1] == extent[1]) {
  53554. y_ = extent[3];
  53555. } else if (point[1] == extent[3]) {
  53556. y_ = extent[1];
  53557. }
  53558. if (x_ !== null && y_ !== null) {
  53559. return [x_, y_];
  53560. }
  53561. return null;
  53562. };
  53563. if (vertex && extent) {
  53564. var x = (vertex[0] == extent[0] || vertex[0] == extent[2]) ? vertex[0] : null;
  53565. var y = (vertex[1] == extent[1] || vertex[1] == extent[3]) ? vertex[1] : null;
  53566. //snap to point
  53567. if (x !== null && y !== null) {
  53568. this.pointerHandler_ = ol.interaction.Extent.getPointHandler_(getOpposingPoint(vertex));
  53569. //snap to edge
  53570. } else if (x !== null) {
  53571. this.pointerHandler_ = ol.interaction.Extent.getEdgeHandler_(
  53572. getOpposingPoint([x, extent[1]]),
  53573. getOpposingPoint([x, extent[3]])
  53574. );
  53575. } else if (y !== null) {
  53576. this.pointerHandler_ = ol.interaction.Extent.getEdgeHandler_(
  53577. getOpposingPoint([extent[0], y]),
  53578. getOpposingPoint([extent[2], y])
  53579. );
  53580. }
  53581. //no snap - new bbox
  53582. } else {
  53583. vertex = map.getCoordinateFromPixel(pixel);
  53584. this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]);
  53585. this.pointerHandler_ = ol.interaction.Extent.getPointHandler_(vertex);
  53586. }
  53587. return true; //event handled; start downup sequence
  53588. };
  53589. /**
  53590. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  53591. * @return {boolean} Event handled?
  53592. * @this {ol.interaction.Extent}
  53593. * @private
  53594. */
  53595. ol.interaction.Extent.handleDragEvent_ = function(mapBrowserEvent) {
  53596. if (this.pointerHandler_) {
  53597. var pixelCoordinate = mapBrowserEvent.coordinate;
  53598. this.setExtent(this.pointerHandler_(pixelCoordinate));
  53599. this.createOrUpdatePointerFeature_(pixelCoordinate);
  53600. }
  53601. return true;
  53602. };
  53603. /**
  53604. * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
  53605. * @return {boolean} Stop drag sequence?
  53606. * @this {ol.interaction.Extent}
  53607. * @private
  53608. */
  53609. ol.interaction.Extent.handleUpEvent_ = function(mapBrowserEvent) {
  53610. this.pointerHandler_ = null;
  53611. //If bbox is zero area, set to null;
  53612. var extent = this.getExtent();
  53613. if (!extent || ol.extent.getArea(extent) === 0) {
  53614. this.setExtent(null);
  53615. }
  53616. return false; //Stop handling downup sequence
  53617. };
  53618. /**
  53619. * Returns the default style for the drawn bbox
  53620. *
  53621. * @return {ol.StyleFunction} Default Extent style
  53622. * @private
  53623. */
  53624. ol.interaction.Extent.getDefaultExtentStyleFunction_ = function() {
  53625. var style = ol.style.Style.createDefaultEditing();
  53626. return function(feature, resolution) {
  53627. return style[ol.geom.GeometryType.POLYGON];
  53628. };
  53629. };
  53630. /**
  53631. * Returns the default style for the pointer
  53632. *
  53633. * @return {ol.StyleFunction} Default pointer style
  53634. * @private
  53635. */
  53636. ol.interaction.Extent.getDefaultPointerStyleFunction_ = function() {
  53637. var style = ol.style.Style.createDefaultEditing();
  53638. return function(feature, resolution) {
  53639. return style[ol.geom.GeometryType.POINT];
  53640. };
  53641. };
  53642. /**
  53643. * @param {ol.Coordinate} fixedPoint corner that will be unchanged in the new extent
  53644. * @returns {function (ol.Coordinate): ol.Extent} event handler
  53645. * @private
  53646. */
  53647. ol.interaction.Extent.getPointHandler_ = function(fixedPoint) {
  53648. return function(point) {
  53649. return ol.extent.boundingExtent([fixedPoint, point]);
  53650. };
  53651. };
  53652. /**
  53653. * @param {ol.Coordinate} fixedP1 first corner that will be unchanged in the new extent
  53654. * @param {ol.Coordinate} fixedP2 second corner that will be unchanged in the new extent
  53655. * @returns {function (ol.Coordinate): ol.Extent|null} event handler
  53656. * @private
  53657. */
  53658. ol.interaction.Extent.getEdgeHandler_ = function(fixedP1, fixedP2) {
  53659. if (fixedP1[0] == fixedP2[0]) {
  53660. return function(point) {
  53661. return ol.extent.boundingExtent([fixedP1, [point[0], fixedP2[1]]]);
  53662. };
  53663. } else if (fixedP1[1] == fixedP2[1]) {
  53664. return function(point) {
  53665. return ol.extent.boundingExtent([fixedP1, [fixedP2[0], point[1]]]);
  53666. };
  53667. } else {
  53668. return null;
  53669. }
  53670. };
  53671. /**
  53672. * @param {ol.Extent} extent extent
  53673. * @returns {Array<Array<ol.Coordinate>>} extent line segments
  53674. * @private
  53675. */
  53676. ol.interaction.Extent.getSegments_ = function(extent) {
  53677. return [
  53678. [[extent[0], extent[1]], [extent[0], extent[3]]],
  53679. [[extent[0], extent[3]], [extent[2], extent[3]]],
  53680. [[extent[2], extent[3]], [extent[2], extent[1]]],
  53681. [[extent[2], extent[1]], [extent[0], extent[1]]]
  53682. ];
  53683. };
  53684. /**
  53685. * @param {ol.Pixel} pixel cursor location
  53686. * @param {ol.PluggableMap} map map
  53687. * @returns {ol.Coordinate|null} snapped vertex on extent
  53688. * @private
  53689. */
  53690. ol.interaction.Extent.prototype.snapToVertex_ = function(pixel, map) {
  53691. var pixelCoordinate = map.getCoordinateFromPixel(pixel);
  53692. var sortByDistance = function(a, b) {
  53693. return ol.coordinate.squaredDistanceToSegment(pixelCoordinate, a) -
  53694. ol.coordinate.squaredDistanceToSegment(pixelCoordinate, b);
  53695. };
  53696. var extent = this.getExtent();
  53697. if (extent) {
  53698. //convert extents to line segments and find the segment closest to pixelCoordinate
  53699. var segments = ol.interaction.Extent.getSegments_(extent);
  53700. segments.sort(sortByDistance);
  53701. var closestSegment = segments[0];
  53702. var vertex = (ol.coordinate.closestOnSegment(pixelCoordinate,
  53703. closestSegment));
  53704. var vertexPixel = map.getPixelFromCoordinate(vertex);
  53705. //if the distance is within tolerance, snap to the segment
  53706. if (ol.coordinate.distance(pixel, vertexPixel) <= this.pixelTolerance_) {
  53707. //test if we should further snap to a vertex
  53708. var pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
  53709. var pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
  53710. var squaredDist1 = ol.coordinate.squaredDistance(vertexPixel, pixel1);
  53711. var squaredDist2 = ol.coordinate.squaredDistance(vertexPixel, pixel2);
  53712. var dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
  53713. this.snappedToVertex_ = dist <= this.pixelTolerance_;
  53714. if (this.snappedToVertex_) {
  53715. vertex = squaredDist1 > squaredDist2 ?
  53716. closestSegment[1] : closestSegment[0];
  53717. }
  53718. return vertex;
  53719. }
  53720. }
  53721. return null;
  53722. };
  53723. /**
  53724. * @param {ol.MapBrowserEvent} mapBrowserEvent pointer move event
  53725. * @private
  53726. */
  53727. ol.interaction.Extent.prototype.handlePointerMove_ = function(mapBrowserEvent) {
  53728. var pixel = mapBrowserEvent.pixel;
  53729. var map = mapBrowserEvent.map;
  53730. var vertex = this.snapToVertex_(pixel, map);
  53731. if (!vertex) {
  53732. vertex = map.getCoordinateFromPixel(pixel);
  53733. }
  53734. this.createOrUpdatePointerFeature_(vertex);
  53735. };
  53736. /**
  53737. * @param {ol.Extent} extent extent
  53738. * @returns {ol.Feature} extent as featrue
  53739. * @private
  53740. */
  53741. ol.interaction.Extent.prototype.createOrUpdateExtentFeature_ = function(extent) {
  53742. var extentFeature = this.extentFeature_;
  53743. if (!extentFeature) {
  53744. if (!extent) {
  53745. extentFeature = new ol.Feature({});
  53746. } else {
  53747. extentFeature = new ol.Feature(ol.geom.Polygon.fromExtent(extent));
  53748. }
  53749. this.extentFeature_ = extentFeature;
  53750. this.extentOverlay_.getSource().addFeature(extentFeature);
  53751. } else {
  53752. if (!extent) {
  53753. extentFeature.setGeometry(undefined);
  53754. } else {
  53755. extentFeature.setGeometry(ol.geom.Polygon.fromExtent(extent));
  53756. }
  53757. }
  53758. return extentFeature;
  53759. };
  53760. /**
  53761. * @param {ol.Coordinate} vertex location of feature
  53762. * @returns {ol.Feature} vertex as feature
  53763. * @private
  53764. */
  53765. ol.interaction.Extent.prototype.createOrUpdatePointerFeature_ = function(vertex) {
  53766. var vertexFeature = this.vertexFeature_;
  53767. if (!vertexFeature) {
  53768. vertexFeature = new ol.Feature(new ol.geom.Point(vertex));
  53769. this.vertexFeature_ = vertexFeature;
  53770. this.vertexOverlay_.getSource().addFeature(vertexFeature);
  53771. } else {
  53772. var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
  53773. geometry.setCoordinates(vertex);
  53774. }
  53775. return vertexFeature;
  53776. };
  53777. /**
  53778. * @inheritDoc
  53779. */
  53780. ol.interaction.Extent.prototype.setMap = function(map) {
  53781. this.extentOverlay_.setMap(map);
  53782. this.vertexOverlay_.setMap(map);
  53783. ol.interaction.Pointer.prototype.setMap.call(this, map);
  53784. };
  53785. /**
  53786. * Returns the current drawn extent in the view projection
  53787. *
  53788. * @return {ol.Extent} Drawn extent in the view projection.
  53789. * @api
  53790. */
  53791. ol.interaction.Extent.prototype.getExtent = function() {
  53792. return this.extent_;
  53793. };
  53794. /**
  53795. * Manually sets the drawn extent, using the view projection.
  53796. *
  53797. * @param {ol.Extent} extent Extent
  53798. * @api
  53799. */
  53800. ol.interaction.Extent.prototype.setExtent = function(extent) {
  53801. //Null extent means no bbox
  53802. this.extent_ = extent ? extent : null;
  53803. this.createOrUpdateExtentFeature_(extent);
  53804. this.dispatchEvent(new ol.interaction.Extent.Event(this.extent_));
  53805. };
  53806. /**
  53807. * @classdesc
  53808. * Events emitted by {@link ol.interaction.Extent} instances are instances of
  53809. * this type.
  53810. *
  53811. * @constructor
  53812. * @implements {oli.ExtentEvent}
  53813. * @param {ol.Extent} extent the new extent
  53814. * @extends {ol.events.Event}
  53815. */
  53816. ol.interaction.Extent.Event = function(extent) {
  53817. ol.events.Event.call(this, ol.interaction.ExtentEventType.EXTENTCHANGED);
  53818. /**
  53819. * The current extent.
  53820. * @type {ol.Extent}
  53821. * @api
  53822. */
  53823. this.extent = extent;
  53824. };
  53825. ol.inherits(ol.interaction.Extent.Event, ol.events.Event);
  53826. goog.provide('ol.interaction.ModifyEventType');
  53827. /**
  53828. * @enum {string}
  53829. */
  53830. ol.interaction.ModifyEventType = {
  53831. /**
  53832. * Triggered upon feature modification start
  53833. * @event ol.interaction.Modify.Event#modifystart
  53834. * @api
  53835. */
  53836. MODIFYSTART: 'modifystart',
  53837. /**
  53838. * Triggered upon feature modification end
  53839. * @event ol.interaction.Modify.Event#modifyend
  53840. * @api
  53841. */
  53842. MODIFYEND: 'modifyend'
  53843. };
  53844. goog.provide('ol.interaction.Modify');
  53845. goog.require('ol');
  53846. goog.require('ol.Collection');
  53847. goog.require('ol.CollectionEventType');
  53848. goog.require('ol.Feature');
  53849. goog.require('ol.MapBrowserEventType');
  53850. goog.require('ol.MapBrowserPointerEvent');
  53851. goog.require('ol.array');
  53852. goog.require('ol.coordinate');
  53853. goog.require('ol.events');
  53854. goog.require('ol.events.Event');
  53855. goog.require('ol.events.EventType');
  53856. goog.require('ol.events.condition');
  53857. goog.require('ol.extent');
  53858. goog.require('ol.geom.GeometryType');
  53859. goog.require('ol.geom.Point');
  53860. goog.require('ol.interaction.ModifyEventType');
  53861. goog.require('ol.interaction.Pointer');
  53862. goog.require('ol.layer.Vector');
  53863. goog.require('ol.source.Vector');
  53864. goog.require('ol.source.VectorEventType');
  53865. goog.require('ol.structs.RBush');
  53866. goog.require('ol.style.Style');
  53867. /**
  53868. * @classdesc
  53869. * Interaction for modifying feature geometries. To modify features that have
  53870. * been added to an existing source, construct the modify interaction with the
  53871. * `source` option. If you want to modify features in a collection (for example,
  53872. * the collection used by a select interaction), construct the interaction with
  53873. * the `features` option. The interaction must be constructed with either a
  53874. * `source` or `features` option.
  53875. *
  53876. * By default, the interaction will allow deletion of vertices when the `alt`
  53877. * key is pressed. To configure the interaction with a different condition
  53878. * for deletion, use the `deleteCondition` option.
  53879. *
  53880. * @constructor
  53881. * @extends {ol.interaction.Pointer}
  53882. * @param {olx.interaction.ModifyOptions} options Options.
  53883. * @fires ol.interaction.Modify.Event
  53884. * @api
  53885. */
  53886. ol.interaction.Modify = function(options) {
  53887. ol.interaction.Pointer.call(this, {
  53888. handleDownEvent: ol.interaction.Modify.handleDownEvent_,
  53889. handleDragEvent: ol.interaction.Modify.handleDragEvent_,
  53890. handleEvent: ol.interaction.Modify.handleEvent,
  53891. handleUpEvent: ol.interaction.Modify.handleUpEvent_
  53892. });
  53893. /**
  53894. * @private
  53895. * @type {ol.EventsConditionType}
  53896. */
  53897. this.condition_ = options.condition ?
  53898. options.condition : ol.events.condition.primaryAction;
  53899. /**
  53900. * @private
  53901. * @param {ol.MapBrowserEvent} mapBrowserEvent Browser event.
  53902. * @return {boolean} Combined condition result.
  53903. */
  53904. this.defaultDeleteCondition_ = function(mapBrowserEvent) {
  53905. return ol.events.condition.altKeyOnly(mapBrowserEvent) &&
  53906. ol.events.condition.singleClick(mapBrowserEvent);
  53907. };
  53908. /**
  53909. * @type {ol.EventsConditionType}
  53910. * @private
  53911. */
  53912. this.deleteCondition_ = options.deleteCondition ?
  53913. options.deleteCondition : this.defaultDeleteCondition_;
  53914. /**
  53915. * @type {ol.EventsConditionType}
  53916. * @private
  53917. */
  53918. this.insertVertexCondition_ = options.insertVertexCondition ?
  53919. options.insertVertexCondition : ol.events.condition.always;
  53920. /**
  53921. * Editing vertex.
  53922. * @type {ol.Feature}
  53923. * @private
  53924. */
  53925. this.vertexFeature_ = null;
  53926. /**
  53927. * Segments intersecting {@link this.vertexFeature_} by segment uid.
  53928. * @type {Object.<string, boolean>}
  53929. * @private
  53930. */
  53931. this.vertexSegments_ = null;
  53932. /**
  53933. * @type {ol.Pixel}
  53934. * @private
  53935. */
  53936. this.lastPixel_ = [0, 0];
  53937. /**
  53938. * Tracks if the next `singleclick` event should be ignored to prevent
  53939. * accidental deletion right after vertex creation.
  53940. * @type {boolean}
  53941. * @private
  53942. */
  53943. this.ignoreNextSingleClick_ = false;
  53944. /**
  53945. * @type {boolean}
  53946. * @private
  53947. */
  53948. this.modified_ = false;
  53949. /**
  53950. * Segment RTree for each layer
  53951. * @type {ol.structs.RBush.<ol.ModifySegmentDataType>}
  53952. * @private
  53953. */
  53954. this.rBush_ = new ol.structs.RBush();
  53955. /**
  53956. * @type {number}
  53957. * @private
  53958. */
  53959. this.pixelTolerance_ = options.pixelTolerance !== undefined ?
  53960. options.pixelTolerance : 10;
  53961. /**
  53962. * @type {boolean}
  53963. * @private
  53964. */
  53965. this.snappedToVertex_ = false;
  53966. /**
  53967. * Indicate whether the interaction is currently changing a feature's
  53968. * coordinates.
  53969. * @type {boolean}
  53970. * @private
  53971. */
  53972. this.changingFeature_ = false;
  53973. /**
  53974. * @type {Array}
  53975. * @private
  53976. */
  53977. this.dragSegments_ = [];
  53978. /**
  53979. * Draw overlay where sketch features are drawn.
  53980. * @type {ol.layer.Vector}
  53981. * @private
  53982. */
  53983. this.overlay_ = new ol.layer.Vector({
  53984. source: new ol.source.Vector({
  53985. useSpatialIndex: false,
  53986. wrapX: !!options.wrapX
  53987. }),
  53988. style: options.style ? options.style :
  53989. ol.interaction.Modify.getDefaultStyleFunction(),
  53990. updateWhileAnimating: true,
  53991. updateWhileInteracting: true
  53992. });
  53993. /**
  53994. * @const
  53995. * @private
  53996. * @type {Object.<string, function(ol.Feature, ol.geom.Geometry)>}
  53997. */
  53998. this.SEGMENT_WRITERS_ = {
  53999. 'Point': this.writePointGeometry_,
  54000. 'LineString': this.writeLineStringGeometry_,
  54001. 'LinearRing': this.writeLineStringGeometry_,
  54002. 'Polygon': this.writePolygonGeometry_,
  54003. 'MultiPoint': this.writeMultiPointGeometry_,
  54004. 'MultiLineString': this.writeMultiLineStringGeometry_,
  54005. 'MultiPolygon': this.writeMultiPolygonGeometry_,
  54006. 'Circle': this.writeCircleGeometry_,
  54007. 'GeometryCollection': this.writeGeometryCollectionGeometry_
  54008. };
  54009. /**
  54010. * @type {ol.source.Vector}
  54011. * @private
  54012. */
  54013. this.source_ = null;
  54014. var features;
  54015. if (options.source) {
  54016. this.source_ = options.source;
  54017. features = new ol.Collection(this.source_.getFeatures());
  54018. ol.events.listen(this.source_, ol.source.VectorEventType.ADDFEATURE,
  54019. this.handleSourceAdd_, this);
  54020. ol.events.listen(this.source_, ol.source.VectorEventType.REMOVEFEATURE,
  54021. this.handleSourceRemove_, this);
  54022. } else {
  54023. features = options.features;
  54024. }
  54025. if (!features) {
  54026. throw new Error('The modify interaction requires features or a source');
  54027. }
  54028. /**
  54029. * @type {ol.Collection.<ol.Feature>}
  54030. * @private
  54031. */
  54032. this.features_ = features;
  54033. this.features_.forEach(this.addFeature_, this);
  54034. ol.events.listen(this.features_, ol.CollectionEventType.ADD,
  54035. this.handleFeatureAdd_, this);
  54036. ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
  54037. this.handleFeatureRemove_, this);
  54038. /**
  54039. * @type {ol.MapBrowserPointerEvent}
  54040. * @private
  54041. */
  54042. this.lastPointerEvent_ = null;
  54043. };
  54044. ol.inherits(ol.interaction.Modify, ol.interaction.Pointer);
  54045. /**
  54046. * @define {number} The segment index assigned to a circle's center when
  54047. * breaking up a cicrle into ModifySegmentDataType segments.
  54048. */
  54049. ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX = 0;
  54050. /**
  54051. * @define {number} The segment index assigned to a circle's circumference when
  54052. * breaking up a circle into ModifySegmentDataType segments.
  54053. */
  54054. ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX = 1;
  54055. /**
  54056. * @param {ol.Feature} feature Feature.
  54057. * @private
  54058. */
  54059. ol.interaction.Modify.prototype.addFeature_ = function(feature) {
  54060. var geometry = feature.getGeometry();
  54061. if (geometry && geometry.getType() in this.SEGMENT_WRITERS_) {
  54062. this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry);
  54063. }
  54064. var map = this.getMap();
  54065. if (map && map.isRendered() && this.getActive()) {
  54066. this.handlePointerAtPixel_(this.lastPixel_, map);
  54067. }
  54068. ol.events.listen(feature, ol.events.EventType.CHANGE,
  54069. this.handleFeatureChange_, this);
  54070. };
  54071. /**
  54072. * @param {ol.MapBrowserPointerEvent} evt Map browser event
  54073. * @private
  54074. */
  54075. ol.interaction.Modify.prototype.willModifyFeatures_ = function(evt) {
  54076. if (!this.modified_) {
  54077. this.modified_ = true;
  54078. this.dispatchEvent(new ol.interaction.Modify.Event(
  54079. ol.interaction.ModifyEventType.MODIFYSTART, this.features_, evt));
  54080. }
  54081. };
  54082. /**
  54083. * @param {ol.Feature} feature Feature.
  54084. * @private
  54085. */
  54086. ol.interaction.Modify.prototype.removeFeature_ = function(feature) {
  54087. this.removeFeatureSegmentData_(feature);
  54088. // Remove the vertex feature if the collection of canditate features
  54089. // is empty.
  54090. if (this.vertexFeature_ && this.features_.getLength() === 0) {
  54091. this.overlay_.getSource().removeFeature(this.vertexFeature_);
  54092. this.vertexFeature_ = null;
  54093. }
  54094. ol.events.unlisten(feature, ol.events.EventType.CHANGE,
  54095. this.handleFeatureChange_, this);
  54096. };
  54097. /**
  54098. * @param {ol.Feature} feature Feature.
  54099. * @private
  54100. */
  54101. ol.interaction.Modify.prototype.removeFeatureSegmentData_ = function(feature) {
  54102. var rBush = this.rBush_;
  54103. var /** @type {Array.<ol.ModifySegmentDataType>} */ nodesToRemove = [];
  54104. rBush.forEach(
  54105. /**
  54106. * @param {ol.ModifySegmentDataType} node RTree node.
  54107. */
  54108. function(node) {
  54109. if (feature === node.feature) {
  54110. nodesToRemove.push(node);
  54111. }
  54112. });
  54113. for (var i = nodesToRemove.length - 1; i >= 0; --i) {
  54114. rBush.remove(nodesToRemove[i]);
  54115. }
  54116. };
  54117. /**
  54118. * @inheritDoc
  54119. */
  54120. ol.interaction.Modify.prototype.setActive = function(active) {
  54121. if (this.vertexFeature_ && !active) {
  54122. this.overlay_.getSource().removeFeature(this.vertexFeature_);
  54123. this.vertexFeature_ = null;
  54124. }
  54125. ol.interaction.Pointer.prototype.setActive.call(this, active);
  54126. };
  54127. /**
  54128. * @inheritDoc
  54129. */
  54130. ol.interaction.Modify.prototype.setMap = function(map) {
  54131. this.overlay_.setMap(map);
  54132. ol.interaction.Pointer.prototype.setMap.call(this, map);
  54133. };
  54134. /**
  54135. * @param {ol.source.Vector.Event} event Event.
  54136. * @private
  54137. */
  54138. ol.interaction.Modify.prototype.handleSourceAdd_ = function(event) {
  54139. if (event.feature) {
  54140. this.features_.push(event.feature);
  54141. }
  54142. };
  54143. /**
  54144. * @param {ol.source.Vector.Event} event Event.
  54145. * @private
  54146. */
  54147. ol.interaction.Modify.prototype.handleSourceRemove_ = function(event) {
  54148. if (event.feature) {
  54149. this.features_.remove(event.feature);
  54150. }
  54151. };
  54152. /**
  54153. * @param {ol.Collection.Event} evt Event.
  54154. * @private
  54155. */
  54156. ol.interaction.Modify.prototype.handleFeatureAdd_ = function(evt) {
  54157. this.addFeature_(/** @type {ol.Feature} */ (evt.element));
  54158. };
  54159. /**
  54160. * @param {ol.events.Event} evt Event.
  54161. * @private
  54162. */
  54163. ol.interaction.Modify.prototype.handleFeatureChange_ = function(evt) {
  54164. if (!this.changingFeature_) {
  54165. var feature = /** @type {ol.Feature} */ (evt.target);
  54166. this.removeFeature_(feature);
  54167. this.addFeature_(feature);
  54168. }
  54169. };
  54170. /**
  54171. * @param {ol.Collection.Event} evt Event.
  54172. * @private
  54173. */
  54174. ol.interaction.Modify.prototype.handleFeatureRemove_ = function(evt) {
  54175. var feature = /** @type {ol.Feature} */ (evt.element);
  54176. this.removeFeature_(feature);
  54177. };
  54178. /**
  54179. * @param {ol.Feature} feature Feature
  54180. * @param {ol.geom.Point} geometry Geometry.
  54181. * @private
  54182. */
  54183. ol.interaction.Modify.prototype.writePointGeometry_ = function(feature, geometry) {
  54184. var coordinates = geometry.getCoordinates();
  54185. var segmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54186. feature: feature,
  54187. geometry: geometry,
  54188. segment: [coordinates, coordinates]
  54189. });
  54190. this.rBush_.insert(geometry.getExtent(), segmentData);
  54191. };
  54192. /**
  54193. * @param {ol.Feature} feature Feature
  54194. * @param {ol.geom.MultiPoint} geometry Geometry.
  54195. * @private
  54196. */
  54197. ol.interaction.Modify.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
  54198. var points = geometry.getCoordinates();
  54199. var coordinates, i, ii, segmentData;
  54200. for (i = 0, ii = points.length; i < ii; ++i) {
  54201. coordinates = points[i];
  54202. segmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54203. feature: feature,
  54204. geometry: geometry,
  54205. depth: [i],
  54206. index: i,
  54207. segment: [coordinates, coordinates]
  54208. });
  54209. this.rBush_.insert(geometry.getExtent(), segmentData);
  54210. }
  54211. };
  54212. /**
  54213. * @param {ol.Feature} feature Feature
  54214. * @param {ol.geom.LineString} geometry Geometry.
  54215. * @private
  54216. */
  54217. ol.interaction.Modify.prototype.writeLineStringGeometry_ = function(feature, geometry) {
  54218. var coordinates = geometry.getCoordinates();
  54219. var i, ii, segment, segmentData;
  54220. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  54221. segment = coordinates.slice(i, i + 2);
  54222. segmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54223. feature: feature,
  54224. geometry: geometry,
  54225. index: i,
  54226. segment: segment
  54227. });
  54228. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  54229. }
  54230. };
  54231. /**
  54232. * @param {ol.Feature} feature Feature
  54233. * @param {ol.geom.MultiLineString} geometry Geometry.
  54234. * @private
  54235. */
  54236. ol.interaction.Modify.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
  54237. var lines = geometry.getCoordinates();
  54238. var coordinates, i, ii, j, jj, segment, segmentData;
  54239. for (j = 0, jj = lines.length; j < jj; ++j) {
  54240. coordinates = lines[j];
  54241. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  54242. segment = coordinates.slice(i, i + 2);
  54243. segmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54244. feature: feature,
  54245. geometry: geometry,
  54246. depth: [j],
  54247. index: i,
  54248. segment: segment
  54249. });
  54250. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  54251. }
  54252. }
  54253. };
  54254. /**
  54255. * @param {ol.Feature} feature Feature
  54256. * @param {ol.geom.Polygon} geometry Geometry.
  54257. * @private
  54258. */
  54259. ol.interaction.Modify.prototype.writePolygonGeometry_ = function(feature, geometry) {
  54260. var rings = geometry.getCoordinates();
  54261. var coordinates, i, ii, j, jj, segment, segmentData;
  54262. for (j = 0, jj = rings.length; j < jj; ++j) {
  54263. coordinates = rings[j];
  54264. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  54265. segment = coordinates.slice(i, i + 2);
  54266. segmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54267. feature: feature,
  54268. geometry: geometry,
  54269. depth: [j],
  54270. index: i,
  54271. segment: segment
  54272. });
  54273. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  54274. }
  54275. }
  54276. };
  54277. /**
  54278. * @param {ol.Feature} feature Feature
  54279. * @param {ol.geom.MultiPolygon} geometry Geometry.
  54280. * @private
  54281. */
  54282. ol.interaction.Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
  54283. var polygons = geometry.getCoordinates();
  54284. var coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
  54285. for (k = 0, kk = polygons.length; k < kk; ++k) {
  54286. rings = polygons[k];
  54287. for (j = 0, jj = rings.length; j < jj; ++j) {
  54288. coordinates = rings[j];
  54289. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  54290. segment = coordinates.slice(i, i + 2);
  54291. segmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54292. feature: feature,
  54293. geometry: geometry,
  54294. depth: [j, k],
  54295. index: i,
  54296. segment: segment
  54297. });
  54298. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  54299. }
  54300. }
  54301. }
  54302. };
  54303. /**
  54304. * We convert a circle into two segments. The segment at index
  54305. * {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX} is the
  54306. * circle's center (a point). The segment at index
  54307. * {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX} is
  54308. * the circumference, and is not a line segment.
  54309. *
  54310. * @param {ol.Feature} feature Feature.
  54311. * @param {ol.geom.Circle} geometry Geometry.
  54312. * @private
  54313. */
  54314. ol.interaction.Modify.prototype.writeCircleGeometry_ = function(feature, geometry) {
  54315. var coordinates = geometry.getCenter();
  54316. var centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54317. feature: feature,
  54318. geometry: geometry,
  54319. index: ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX,
  54320. segment: [coordinates, coordinates]
  54321. });
  54322. var circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54323. feature: feature,
  54324. geometry: geometry,
  54325. index: ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX,
  54326. segment: [coordinates, coordinates]
  54327. });
  54328. var featureSegments = [centerSegmentData, circumferenceSegmentData];
  54329. centerSegmentData.featureSegments = circumferenceSegmentData.featureSegments = featureSegments;
  54330. this.rBush_.insert(ol.extent.createOrUpdateFromCoordinate(coordinates), centerSegmentData);
  54331. this.rBush_.insert(geometry.getExtent(), circumferenceSegmentData);
  54332. };
  54333. /**
  54334. * @param {ol.Feature} feature Feature
  54335. * @param {ol.geom.GeometryCollection} geometry Geometry.
  54336. * @private
  54337. */
  54338. ol.interaction.Modify.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) {
  54339. var i, geometries = geometry.getGeometriesArray();
  54340. for (i = 0; i < geometries.length; ++i) {
  54341. this.SEGMENT_WRITERS_[geometries[i].getType()].call(
  54342. this, feature, geometries[i]);
  54343. }
  54344. };
  54345. /**
  54346. * @param {ol.Coordinate} coordinates Coordinates.
  54347. * @return {ol.Feature} Vertex feature.
  54348. * @private
  54349. */
  54350. ol.interaction.Modify.prototype.createOrUpdateVertexFeature_ = function(coordinates) {
  54351. var vertexFeature = this.vertexFeature_;
  54352. if (!vertexFeature) {
  54353. vertexFeature = new ol.Feature(new ol.geom.Point(coordinates));
  54354. this.vertexFeature_ = vertexFeature;
  54355. this.overlay_.getSource().addFeature(vertexFeature);
  54356. } else {
  54357. var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
  54358. geometry.setCoordinates(coordinates);
  54359. }
  54360. return vertexFeature;
  54361. };
  54362. /**
  54363. * @param {ol.ModifySegmentDataType} a The first segment data.
  54364. * @param {ol.ModifySegmentDataType} b The second segment data.
  54365. * @return {number} The difference in indexes.
  54366. * @private
  54367. */
  54368. ol.interaction.Modify.compareIndexes_ = function(a, b) {
  54369. return a.index - b.index;
  54370. };
  54371. /**
  54372. * @param {ol.MapBrowserPointerEvent} evt Event.
  54373. * @return {boolean} Start drag sequence?
  54374. * @this {ol.interaction.Modify}
  54375. * @private
  54376. */
  54377. ol.interaction.Modify.handleDownEvent_ = function(evt) {
  54378. if (!this.condition_(evt)) {
  54379. return false;
  54380. }
  54381. this.handlePointerAtPixel_(evt.pixel, evt.map);
  54382. var pixelCoordinate = evt.map.getCoordinateFromPixel(evt.pixel);
  54383. this.dragSegments_.length = 0;
  54384. this.modified_ = false;
  54385. var vertexFeature = this.vertexFeature_;
  54386. if (vertexFeature) {
  54387. var insertVertices = [];
  54388. var geometry = /** @type {ol.geom.Point} */ (vertexFeature.getGeometry());
  54389. var vertex = geometry.getCoordinates();
  54390. var vertexExtent = ol.extent.boundingExtent([vertex]);
  54391. var segmentDataMatches = this.rBush_.getInExtent(vertexExtent);
  54392. var componentSegments = {};
  54393. segmentDataMatches.sort(ol.interaction.Modify.compareIndexes_);
  54394. for (var i = 0, ii = segmentDataMatches.length; i < ii; ++i) {
  54395. var segmentDataMatch = segmentDataMatches[i];
  54396. var segment = segmentDataMatch.segment;
  54397. var uid = ol.getUid(segmentDataMatch.feature);
  54398. var depth = segmentDataMatch.depth;
  54399. if (depth) {
  54400. uid += '-' + depth.join('-'); // separate feature components
  54401. }
  54402. if (!componentSegments[uid]) {
  54403. componentSegments[uid] = new Array(2);
  54404. }
  54405. if (segmentDataMatch.geometry.getType() === ol.geom.GeometryType.CIRCLE &&
  54406. segmentDataMatch.index === ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
  54407. var closestVertex = ol.interaction.Modify.closestOnSegmentData_(pixelCoordinate, segmentDataMatch);
  54408. if (ol.coordinate.equals(closestVertex, vertex) && !componentSegments[uid][0]) {
  54409. this.dragSegments_.push([segmentDataMatch, 0]);
  54410. componentSegments[uid][0] = segmentDataMatch;
  54411. }
  54412. } else if (ol.coordinate.equals(segment[0], vertex) &&
  54413. !componentSegments[uid][0]) {
  54414. this.dragSegments_.push([segmentDataMatch, 0]);
  54415. componentSegments[uid][0] = segmentDataMatch;
  54416. } else if (ol.coordinate.equals(segment[1], vertex) &&
  54417. !componentSegments[uid][1]) {
  54418. // prevent dragging closed linestrings by the connecting node
  54419. if ((segmentDataMatch.geometry.getType() ===
  54420. ol.geom.GeometryType.LINE_STRING ||
  54421. segmentDataMatch.geometry.getType() ===
  54422. ol.geom.GeometryType.MULTI_LINE_STRING) &&
  54423. componentSegments[uid][0] &&
  54424. componentSegments[uid][0].index === 0) {
  54425. continue;
  54426. }
  54427. this.dragSegments_.push([segmentDataMatch, 1]);
  54428. componentSegments[uid][1] = segmentDataMatch;
  54429. } else if (this.insertVertexCondition_(evt) && ol.getUid(segment) in this.vertexSegments_ &&
  54430. (!componentSegments[uid][0] && !componentSegments[uid][1])) {
  54431. insertVertices.push([segmentDataMatch, vertex]);
  54432. }
  54433. }
  54434. if (insertVertices.length) {
  54435. this.willModifyFeatures_(evt);
  54436. }
  54437. for (var j = insertVertices.length - 1; j >= 0; --j) {
  54438. this.insertVertex_.apply(this, insertVertices[j]);
  54439. }
  54440. }
  54441. return !!this.vertexFeature_;
  54442. };
  54443. /**
  54444. * @param {ol.MapBrowserPointerEvent} evt Event.
  54445. * @this {ol.interaction.Modify}
  54446. * @private
  54447. */
  54448. ol.interaction.Modify.handleDragEvent_ = function(evt) {
  54449. this.ignoreNextSingleClick_ = false;
  54450. this.willModifyFeatures_(evt);
  54451. var vertex = evt.coordinate;
  54452. for (var i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
  54453. var dragSegment = this.dragSegments_[i];
  54454. var segmentData = dragSegment[0];
  54455. var depth = segmentData.depth;
  54456. var geometry = segmentData.geometry;
  54457. var coordinates;
  54458. var segment = segmentData.segment;
  54459. var index = dragSegment[1];
  54460. while (vertex.length < geometry.getStride()) {
  54461. vertex.push(segment[index][vertex.length]);
  54462. }
  54463. switch (geometry.getType()) {
  54464. case ol.geom.GeometryType.POINT:
  54465. coordinates = vertex;
  54466. segment[0] = segment[1] = vertex;
  54467. break;
  54468. case ol.geom.GeometryType.MULTI_POINT:
  54469. coordinates = geometry.getCoordinates();
  54470. coordinates[segmentData.index] = vertex;
  54471. segment[0] = segment[1] = vertex;
  54472. break;
  54473. case ol.geom.GeometryType.LINE_STRING:
  54474. coordinates = geometry.getCoordinates();
  54475. coordinates[segmentData.index + index] = vertex;
  54476. segment[index] = vertex;
  54477. break;
  54478. case ol.geom.GeometryType.MULTI_LINE_STRING:
  54479. coordinates = geometry.getCoordinates();
  54480. coordinates[depth[0]][segmentData.index + index] = vertex;
  54481. segment[index] = vertex;
  54482. break;
  54483. case ol.geom.GeometryType.POLYGON:
  54484. coordinates = geometry.getCoordinates();
  54485. coordinates[depth[0]][segmentData.index + index] = vertex;
  54486. segment[index] = vertex;
  54487. break;
  54488. case ol.geom.GeometryType.MULTI_POLYGON:
  54489. coordinates = geometry.getCoordinates();
  54490. coordinates[depth[1]][depth[0]][segmentData.index + index] = vertex;
  54491. segment[index] = vertex;
  54492. break;
  54493. case ol.geom.GeometryType.CIRCLE:
  54494. segment[0] = segment[1] = vertex;
  54495. if (segmentData.index === ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX) {
  54496. this.changingFeature_ = true;
  54497. geometry.setCenter(vertex);
  54498. this.changingFeature_ = false;
  54499. } else { // We're dragging the circle's circumference:
  54500. this.changingFeature_ = true;
  54501. geometry.setRadius(ol.coordinate.distance(geometry.getCenter(), vertex));
  54502. this.changingFeature_ = false;
  54503. }
  54504. break;
  54505. default:
  54506. // pass
  54507. }
  54508. if (coordinates) {
  54509. this.setGeometryCoordinates_(geometry, coordinates);
  54510. }
  54511. }
  54512. this.createOrUpdateVertexFeature_(vertex);
  54513. };
  54514. /**
  54515. * @param {ol.MapBrowserPointerEvent} evt Event.
  54516. * @return {boolean} Stop drag sequence?
  54517. * @this {ol.interaction.Modify}
  54518. * @private
  54519. */
  54520. ol.interaction.Modify.handleUpEvent_ = function(evt) {
  54521. var segmentData;
  54522. var geometry;
  54523. for (var i = this.dragSegments_.length - 1; i >= 0; --i) {
  54524. segmentData = this.dragSegments_[i][0];
  54525. geometry = segmentData.geometry;
  54526. if (geometry.getType() === ol.geom.GeometryType.CIRCLE) {
  54527. // Update a circle object in the R* bush:
  54528. var coordinates = geometry.getCenter();
  54529. var centerSegmentData = segmentData.featureSegments[0];
  54530. var circumferenceSegmentData = segmentData.featureSegments[1];
  54531. centerSegmentData.segment[0] = centerSegmentData.segment[1] = coordinates;
  54532. circumferenceSegmentData.segment[0] = circumferenceSegmentData.segment[1] = coordinates;
  54533. this.rBush_.update(ol.extent.createOrUpdateFromCoordinate(coordinates), centerSegmentData);
  54534. this.rBush_.update(geometry.getExtent(), circumferenceSegmentData);
  54535. } else {
  54536. this.rBush_.update(ol.extent.boundingExtent(segmentData.segment),
  54537. segmentData);
  54538. }
  54539. }
  54540. if (this.modified_) {
  54541. this.dispatchEvent(new ol.interaction.Modify.Event(
  54542. ol.interaction.ModifyEventType.MODIFYEND, this.features_, evt));
  54543. this.modified_ = false;
  54544. }
  54545. return false;
  54546. };
  54547. /**
  54548. * Handles the {@link ol.MapBrowserEvent map browser event} and may modify the
  54549. * geometry.
  54550. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  54551. * @return {boolean} `false` to stop event propagation.
  54552. * @this {ol.interaction.Modify}
  54553. * @api
  54554. */
  54555. ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
  54556. if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
  54557. return true;
  54558. }
  54559. this.lastPointerEvent_ = mapBrowserEvent;
  54560. var handled;
  54561. if (!mapBrowserEvent.map.getView().getInteracting() &&
  54562. mapBrowserEvent.type == ol.MapBrowserEventType.POINTERMOVE &&
  54563. !this.handlingDownUpSequence) {
  54564. this.handlePointerMove_(mapBrowserEvent);
  54565. }
  54566. if (this.vertexFeature_ && this.deleteCondition_(mapBrowserEvent)) {
  54567. if (mapBrowserEvent.type != ol.MapBrowserEventType.SINGLECLICK ||
  54568. !this.ignoreNextSingleClick_) {
  54569. handled = this.removePoint();
  54570. } else {
  54571. handled = true;
  54572. }
  54573. }
  54574. if (mapBrowserEvent.type == ol.MapBrowserEventType.SINGLECLICK) {
  54575. this.ignoreNextSingleClick_ = false;
  54576. }
  54577. return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) &&
  54578. !handled;
  54579. };
  54580. /**
  54581. * @param {ol.MapBrowserEvent} evt Event.
  54582. * @private
  54583. */
  54584. ol.interaction.Modify.prototype.handlePointerMove_ = function(evt) {
  54585. this.lastPixel_ = evt.pixel;
  54586. this.handlePointerAtPixel_(evt.pixel, evt.map);
  54587. };
  54588. /**
  54589. * @param {ol.Pixel} pixel Pixel
  54590. * @param {ol.PluggableMap} map Map.
  54591. * @private
  54592. */
  54593. ol.interaction.Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
  54594. var pixelCoordinate = map.getCoordinateFromPixel(pixel);
  54595. var sortByDistance = function(a, b) {
  54596. return ol.interaction.Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, a) -
  54597. ol.interaction.Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, b);
  54598. };
  54599. var box = ol.extent.buffer(
  54600. ol.extent.createOrUpdateFromCoordinate(pixelCoordinate),
  54601. map.getView().getResolution() * this.pixelTolerance_);
  54602. var rBush = this.rBush_;
  54603. var nodes = rBush.getInExtent(box);
  54604. if (nodes.length > 0) {
  54605. nodes.sort(sortByDistance);
  54606. var node = nodes[0];
  54607. var closestSegment = node.segment;
  54608. var vertex = ol.interaction.Modify.closestOnSegmentData_(pixelCoordinate, node);
  54609. var vertexPixel = map.getPixelFromCoordinate(vertex);
  54610. var dist = ol.coordinate.distance(pixel, vertexPixel);
  54611. if (dist <= this.pixelTolerance_) {
  54612. var vertexSegments = {};
  54613. if (node.geometry.getType() === ol.geom.GeometryType.CIRCLE &&
  54614. node.index === ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
  54615. this.snappedToVertex_ = true;
  54616. this.createOrUpdateVertexFeature_(vertex);
  54617. } else {
  54618. var pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
  54619. var pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
  54620. var squaredDist1 = ol.coordinate.squaredDistance(vertexPixel, pixel1);
  54621. var squaredDist2 = ol.coordinate.squaredDistance(vertexPixel, pixel2);
  54622. dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
  54623. this.snappedToVertex_ = dist <= this.pixelTolerance_;
  54624. if (this.snappedToVertex_) {
  54625. vertex = squaredDist1 > squaredDist2 ?
  54626. closestSegment[1] : closestSegment[0];
  54627. }
  54628. this.createOrUpdateVertexFeature_(vertex);
  54629. var segment;
  54630. for (var i = 1, ii = nodes.length; i < ii; ++i) {
  54631. segment = nodes[i].segment;
  54632. if ((ol.coordinate.equals(closestSegment[0], segment[0]) &&
  54633. ol.coordinate.equals(closestSegment[1], segment[1]) ||
  54634. (ol.coordinate.equals(closestSegment[0], segment[1]) &&
  54635. ol.coordinate.equals(closestSegment[1], segment[0])))) {
  54636. vertexSegments[ol.getUid(segment)] = true;
  54637. } else {
  54638. break;
  54639. }
  54640. }
  54641. }
  54642. vertexSegments[ol.getUid(closestSegment)] = true;
  54643. this.vertexSegments_ = vertexSegments;
  54644. return;
  54645. }
  54646. }
  54647. if (this.vertexFeature_) {
  54648. this.overlay_.getSource().removeFeature(this.vertexFeature_);
  54649. this.vertexFeature_ = null;
  54650. }
  54651. };
  54652. /**
  54653. * Returns the distance from a point to a line segment.
  54654. *
  54655. * @param {ol.Coordinate} pointCoordinates The coordinates of the point from
  54656. * which to calculate the distance.
  54657. * @param {ol.ModifySegmentDataType} segmentData The object describing the line
  54658. * segment we are calculating the distance to.
  54659. * @return {number} The square of the distance between a point and a line segment.
  54660. */
  54661. ol.interaction.Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentData) {
  54662. var geometry = segmentData.geometry;
  54663. if (geometry.getType() === ol.geom.GeometryType.CIRCLE) {
  54664. var circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
  54665. if (segmentData.index === ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
  54666. var distanceToCenterSquared =
  54667. ol.coordinate.squaredDistance(circleGeometry.getCenter(), pointCoordinates);
  54668. var distanceToCircumference =
  54669. Math.sqrt(distanceToCenterSquared) - circleGeometry.getRadius();
  54670. return distanceToCircumference * distanceToCircumference;
  54671. }
  54672. }
  54673. return ol.coordinate.squaredDistanceToSegment(pointCoordinates, segmentData.segment);
  54674. };
  54675. /**
  54676. * Returns the point closest to a given line segment.
  54677. *
  54678. * @param {ol.Coordinate} pointCoordinates The point to which a closest point
  54679. * should be found.
  54680. * @param {ol.ModifySegmentDataType} segmentData The object describing the line
  54681. * segment which should contain the closest point.
  54682. * @return {ol.Coordinate} The point closest to the specified line segment.
  54683. */
  54684. ol.interaction.Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) {
  54685. var geometry = segmentData.geometry;
  54686. if (geometry.getType() === ol.geom.GeometryType.CIRCLE &&
  54687. segmentData.index === ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
  54688. return geometry.getClosestPoint(pointCoordinates);
  54689. }
  54690. return ol.coordinate.closestOnSegment(pointCoordinates, segmentData.segment);
  54691. };
  54692. /**
  54693. * @param {ol.ModifySegmentDataType} segmentData Segment data.
  54694. * @param {ol.Coordinate} vertex Vertex.
  54695. * @private
  54696. */
  54697. ol.interaction.Modify.prototype.insertVertex_ = function(segmentData, vertex) {
  54698. var segment = segmentData.segment;
  54699. var feature = segmentData.feature;
  54700. var geometry = segmentData.geometry;
  54701. var depth = segmentData.depth;
  54702. var index = /** @type {number} */ (segmentData.index);
  54703. var coordinates;
  54704. while (vertex.length < geometry.getStride()) {
  54705. vertex.push(0);
  54706. }
  54707. switch (geometry.getType()) {
  54708. case ol.geom.GeometryType.MULTI_LINE_STRING:
  54709. coordinates = geometry.getCoordinates();
  54710. coordinates[depth[0]].splice(index + 1, 0, vertex);
  54711. break;
  54712. case ol.geom.GeometryType.POLYGON:
  54713. coordinates = geometry.getCoordinates();
  54714. coordinates[depth[0]].splice(index + 1, 0, vertex);
  54715. break;
  54716. case ol.geom.GeometryType.MULTI_POLYGON:
  54717. coordinates = geometry.getCoordinates();
  54718. coordinates[depth[1]][depth[0]].splice(index + 1, 0, vertex);
  54719. break;
  54720. case ol.geom.GeometryType.LINE_STRING:
  54721. coordinates = geometry.getCoordinates();
  54722. coordinates.splice(index + 1, 0, vertex);
  54723. break;
  54724. default:
  54725. return;
  54726. }
  54727. this.setGeometryCoordinates_(geometry, coordinates);
  54728. var rTree = this.rBush_;
  54729. rTree.remove(segmentData);
  54730. this.updateSegmentIndices_(geometry, index, depth, 1);
  54731. var newSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54732. segment: [segment[0], vertex],
  54733. feature: feature,
  54734. geometry: geometry,
  54735. depth: depth,
  54736. index: index
  54737. });
  54738. rTree.insert(ol.extent.boundingExtent(newSegmentData.segment),
  54739. newSegmentData);
  54740. this.dragSegments_.push([newSegmentData, 1]);
  54741. var newSegmentData2 = /** @type {ol.ModifySegmentDataType} */ ({
  54742. segment: [vertex, segment[1]],
  54743. feature: feature,
  54744. geometry: geometry,
  54745. depth: depth,
  54746. index: index + 1
  54747. });
  54748. rTree.insert(ol.extent.boundingExtent(newSegmentData2.segment),
  54749. newSegmentData2);
  54750. this.dragSegments_.push([newSegmentData2, 0]);
  54751. this.ignoreNextSingleClick_ = true;
  54752. };
  54753. /**
  54754. * Removes the vertex currently being pointed.
  54755. * @return {boolean} True when a vertex was removed.
  54756. * @api
  54757. */
  54758. ol.interaction.Modify.prototype.removePoint = function() {
  54759. if (this.lastPointerEvent_ && this.lastPointerEvent_.type != ol.MapBrowserEventType.POINTERDRAG) {
  54760. var evt = this.lastPointerEvent_;
  54761. this.willModifyFeatures_(evt);
  54762. this.removeVertex_();
  54763. this.dispatchEvent(new ol.interaction.Modify.Event(
  54764. ol.interaction.ModifyEventType.MODIFYEND, this.features_, evt));
  54765. this.modified_ = false;
  54766. return true;
  54767. }
  54768. return false;
  54769. };
  54770. /**
  54771. * Removes a vertex from all matching features.
  54772. * @return {boolean} True when a vertex was removed.
  54773. * @private
  54774. */
  54775. ol.interaction.Modify.prototype.removeVertex_ = function() {
  54776. var dragSegments = this.dragSegments_;
  54777. var segmentsByFeature = {};
  54778. var deleted = false;
  54779. var component, coordinates, dragSegment, geometry, i, index, left;
  54780. var newIndex, right, segmentData, uid;
  54781. for (i = dragSegments.length - 1; i >= 0; --i) {
  54782. dragSegment = dragSegments[i];
  54783. segmentData = dragSegment[0];
  54784. uid = ol.getUid(segmentData.feature);
  54785. if (segmentData.depth) {
  54786. // separate feature components
  54787. uid += '-' + segmentData.depth.join('-');
  54788. }
  54789. if (!(uid in segmentsByFeature)) {
  54790. segmentsByFeature[uid] = {};
  54791. }
  54792. if (dragSegment[1] === 0) {
  54793. segmentsByFeature[uid].right = segmentData;
  54794. segmentsByFeature[uid].index = segmentData.index;
  54795. } else if (dragSegment[1] == 1) {
  54796. segmentsByFeature[uid].left = segmentData;
  54797. segmentsByFeature[uid].index = segmentData.index + 1;
  54798. }
  54799. }
  54800. for (uid in segmentsByFeature) {
  54801. right = segmentsByFeature[uid].right;
  54802. left = segmentsByFeature[uid].left;
  54803. index = segmentsByFeature[uid].index;
  54804. newIndex = index - 1;
  54805. if (left !== undefined) {
  54806. segmentData = left;
  54807. } else {
  54808. segmentData = right;
  54809. }
  54810. if (newIndex < 0) {
  54811. newIndex = 0;
  54812. }
  54813. geometry = segmentData.geometry;
  54814. coordinates = geometry.getCoordinates();
  54815. component = coordinates;
  54816. deleted = false;
  54817. switch (geometry.getType()) {
  54818. case ol.geom.GeometryType.MULTI_LINE_STRING:
  54819. if (coordinates[segmentData.depth[0]].length > 2) {
  54820. coordinates[segmentData.depth[0]].splice(index, 1);
  54821. deleted = true;
  54822. }
  54823. break;
  54824. case ol.geom.GeometryType.LINE_STRING:
  54825. if (coordinates.length > 2) {
  54826. coordinates.splice(index, 1);
  54827. deleted = true;
  54828. }
  54829. break;
  54830. case ol.geom.GeometryType.MULTI_POLYGON:
  54831. component = component[segmentData.depth[1]];
  54832. /* falls through */
  54833. case ol.geom.GeometryType.POLYGON:
  54834. component = component[segmentData.depth[0]];
  54835. if (component.length > 4) {
  54836. if (index == component.length - 1) {
  54837. index = 0;
  54838. }
  54839. component.splice(index, 1);
  54840. deleted = true;
  54841. if (index === 0) {
  54842. // close the ring again
  54843. component.pop();
  54844. component.push(component[0]);
  54845. newIndex = component.length - 1;
  54846. }
  54847. }
  54848. break;
  54849. default:
  54850. // pass
  54851. }
  54852. if (deleted) {
  54853. this.setGeometryCoordinates_(geometry, coordinates);
  54854. var segments = [];
  54855. if (left !== undefined) {
  54856. this.rBush_.remove(left);
  54857. segments.push(left.segment[0]);
  54858. }
  54859. if (right !== undefined) {
  54860. this.rBush_.remove(right);
  54861. segments.push(right.segment[1]);
  54862. }
  54863. if (left !== undefined && right !== undefined) {
  54864. var newSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
  54865. depth: segmentData.depth,
  54866. feature: segmentData.feature,
  54867. geometry: segmentData.geometry,
  54868. index: newIndex,
  54869. segment: segments
  54870. });
  54871. this.rBush_.insert(ol.extent.boundingExtent(newSegmentData.segment),
  54872. newSegmentData);
  54873. }
  54874. this.updateSegmentIndices_(geometry, index, segmentData.depth, -1);
  54875. if (this.vertexFeature_) {
  54876. this.overlay_.getSource().removeFeature(this.vertexFeature_);
  54877. this.vertexFeature_ = null;
  54878. }
  54879. dragSegments.length = 0;
  54880. }
  54881. }
  54882. return deleted;
  54883. };
  54884. /**
  54885. * @param {ol.geom.SimpleGeometry} geometry Geometry.
  54886. * @param {Array} coordinates Coordinates.
  54887. * @private
  54888. */
  54889. ol.interaction.Modify.prototype.setGeometryCoordinates_ = function(geometry, coordinates) {
  54890. this.changingFeature_ = true;
  54891. geometry.setCoordinates(coordinates);
  54892. this.changingFeature_ = false;
  54893. };
  54894. /**
  54895. * @param {ol.geom.SimpleGeometry} geometry Geometry.
  54896. * @param {number} index Index.
  54897. * @param {Array.<number>|undefined} depth Depth.
  54898. * @param {number} delta Delta (1 or -1).
  54899. * @private
  54900. */
  54901. ol.interaction.Modify.prototype.updateSegmentIndices_ = function(
  54902. geometry, index, depth, delta) {
  54903. this.rBush_.forEachInExtent(geometry.getExtent(), function(segmentDataMatch) {
  54904. if (segmentDataMatch.geometry === geometry &&
  54905. (depth === undefined || segmentDataMatch.depth === undefined ||
  54906. ol.array.equals(segmentDataMatch.depth, depth)) &&
  54907. segmentDataMatch.index > index) {
  54908. segmentDataMatch.index += delta;
  54909. }
  54910. });
  54911. };
  54912. /**
  54913. * @return {ol.StyleFunction} Styles.
  54914. */
  54915. ol.interaction.Modify.getDefaultStyleFunction = function() {
  54916. var style = ol.style.Style.createDefaultEditing();
  54917. return function(feature, resolution) {
  54918. return style[ol.geom.GeometryType.POINT];
  54919. };
  54920. };
  54921. /**
  54922. * @classdesc
  54923. * Events emitted by {@link ol.interaction.Modify} instances are instances of
  54924. * this type.
  54925. *
  54926. * @constructor
  54927. * @extends {ol.events.Event}
  54928. * @implements {oli.ModifyEvent}
  54929. * @param {ol.interaction.ModifyEventType} type Type.
  54930. * @param {ol.Collection.<ol.Feature>} features The features modified.
  54931. * @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated
  54932. * {@link ol.MapBrowserPointerEvent}.
  54933. */
  54934. ol.interaction.Modify.Event = function(type, features, mapBrowserPointerEvent) {
  54935. ol.events.Event.call(this, type);
  54936. /**
  54937. * The features being modified.
  54938. * @type {ol.Collection.<ol.Feature>}
  54939. * @api
  54940. */
  54941. this.features = features;
  54942. /**
  54943. * Associated {@link ol.MapBrowserEvent}.
  54944. * @type {ol.MapBrowserEvent}
  54945. * @api
  54946. */
  54947. this.mapBrowserEvent = mapBrowserPointerEvent;
  54948. };
  54949. ol.inherits(ol.interaction.Modify.Event, ol.events.Event);
  54950. goog.provide('ol.interaction.Select');
  54951. goog.require('ol');
  54952. goog.require('ol.CollectionEventType');
  54953. goog.require('ol.array');
  54954. goog.require('ol.events');
  54955. goog.require('ol.events.Event');
  54956. goog.require('ol.events.condition');
  54957. goog.require('ol.functions');
  54958. goog.require('ol.geom.GeometryType');
  54959. goog.require('ol.interaction.Interaction');
  54960. goog.require('ol.layer.Vector');
  54961. goog.require('ol.obj');
  54962. goog.require('ol.source.Vector');
  54963. goog.require('ol.style.Style');
  54964. /**
  54965. * @classdesc
  54966. * Interaction for selecting vector features. By default, selected features are
  54967. * styled differently, so this interaction can be used for visual highlighting,
  54968. * as well as selecting features for other actions, such as modification or
  54969. * output. There are three ways of controlling which features are selected:
  54970. * using the browser event as defined by the `condition` and optionally the
  54971. * `toggle`, `add`/`remove`, and `multi` options; a `layers` filter; and a
  54972. * further feature filter using the `filter` option.
  54973. *
  54974. * Selected features are added to an internal unmanaged layer.
  54975. *
  54976. * @constructor
  54977. * @extends {ol.interaction.Interaction}
  54978. * @param {olx.interaction.SelectOptions=} opt_options Options.
  54979. * @fires ol.interaction.Select.Event
  54980. * @api
  54981. */
  54982. ol.interaction.Select = function(opt_options) {
  54983. ol.interaction.Interaction.call(this, {
  54984. handleEvent: ol.interaction.Select.handleEvent
  54985. });
  54986. var options = opt_options ? opt_options : {};
  54987. /**
  54988. * @private
  54989. * @type {ol.EventsConditionType}
  54990. */
  54991. this.condition_ = options.condition ?
  54992. options.condition : ol.events.condition.singleClick;
  54993. /**
  54994. * @private
  54995. * @type {ol.EventsConditionType}
  54996. */
  54997. this.addCondition_ = options.addCondition ?
  54998. options.addCondition : ol.events.condition.never;
  54999. /**
  55000. * @private
  55001. * @type {ol.EventsConditionType}
  55002. */
  55003. this.removeCondition_ = options.removeCondition ?
  55004. options.removeCondition : ol.events.condition.never;
  55005. /**
  55006. * @private
  55007. * @type {ol.EventsConditionType}
  55008. */
  55009. this.toggleCondition_ = options.toggleCondition ?
  55010. options.toggleCondition : ol.events.condition.shiftKeyOnly;
  55011. /**
  55012. * @private
  55013. * @type {boolean}
  55014. */
  55015. this.multi_ = options.multi ? options.multi : false;
  55016. /**
  55017. * @private
  55018. * @type {ol.SelectFilterFunction}
  55019. */
  55020. this.filter_ = options.filter ? options.filter :
  55021. ol.functions.TRUE;
  55022. /**
  55023. * @private
  55024. * @type {number}
  55025. */
  55026. this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
  55027. var featureOverlay = new ol.layer.Vector({
  55028. source: new ol.source.Vector({
  55029. useSpatialIndex: false,
  55030. features: options.features,
  55031. wrapX: options.wrapX
  55032. }),
  55033. style: options.style ? options.style :
  55034. ol.interaction.Select.getDefaultStyleFunction(),
  55035. updateWhileAnimating: true,
  55036. updateWhileInteracting: true
  55037. });
  55038. /**
  55039. * @private
  55040. * @type {ol.layer.Vector}
  55041. */
  55042. this.featureOverlay_ = featureOverlay;
  55043. /** @type {function(ol.layer.Layer): boolean} */
  55044. var layerFilter;
  55045. if (options.layers) {
  55046. if (typeof options.layers === 'function') {
  55047. layerFilter = options.layers;
  55048. } else {
  55049. var layers = options.layers;
  55050. layerFilter = function(layer) {
  55051. return ol.array.includes(layers, layer);
  55052. };
  55053. }
  55054. } else {
  55055. layerFilter = ol.functions.TRUE;
  55056. }
  55057. /**
  55058. * @private
  55059. * @type {function(ol.layer.Layer): boolean}
  55060. */
  55061. this.layerFilter_ = layerFilter;
  55062. /**
  55063. * An association between selected feature (key)
  55064. * and layer (value)
  55065. * @private
  55066. * @type {Object.<number, ol.layer.Layer>}
  55067. */
  55068. this.featureLayerAssociation_ = {};
  55069. var features = this.featureOverlay_.getSource().getFeaturesCollection();
  55070. ol.events.listen(features, ol.CollectionEventType.ADD,
  55071. this.addFeature_, this);
  55072. ol.events.listen(features, ol.CollectionEventType.REMOVE,
  55073. this.removeFeature_, this);
  55074. };
  55075. ol.inherits(ol.interaction.Select, ol.interaction.Interaction);
  55076. /**
  55077. * @param {ol.Feature|ol.render.Feature} feature Feature.
  55078. * @param {ol.layer.Layer} layer Layer.
  55079. * @private
  55080. */
  55081. ol.interaction.Select.prototype.addFeatureLayerAssociation_ = function(feature, layer) {
  55082. var key = ol.getUid(feature);
  55083. this.featureLayerAssociation_[key] = layer;
  55084. };
  55085. /**
  55086. * Get the selected features.
  55087. * @return {ol.Collection.<ol.Feature>} Features collection.
  55088. * @api
  55089. */
  55090. ol.interaction.Select.prototype.getFeatures = function() {
  55091. return this.featureOverlay_.getSource().getFeaturesCollection();
  55092. };
  55093. /**
  55094. * Returns the Hit-detection tolerance.
  55095. * @returns {number} Hit tolerance in pixels.
  55096. * @api
  55097. */
  55098. ol.interaction.Select.prototype.getHitTolerance = function() {
  55099. return this.hitTolerance_;
  55100. };
  55101. /**
  55102. * Returns the associated {@link ol.layer.Vector vectorlayer} of
  55103. * the (last) selected feature. Note that this will not work with any
  55104. * programmatic method like pushing features to
  55105. * {@link ol.interaction.Select#getFeatures collection}.
  55106. * @param {ol.Feature|ol.render.Feature} feature Feature
  55107. * @return {ol.layer.Vector} Layer.
  55108. * @api
  55109. */
  55110. ol.interaction.Select.prototype.getLayer = function(feature) {
  55111. var key = ol.getUid(feature);
  55112. return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]);
  55113. };
  55114. /**
  55115. * Handles the {@link ol.MapBrowserEvent map browser event} and may change the
  55116. * selected state of features.
  55117. * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
  55118. * @return {boolean} `false` to stop event propagation.
  55119. * @this {ol.interaction.Select}
  55120. * @api
  55121. */
  55122. ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
  55123. if (!this.condition_(mapBrowserEvent)) {
  55124. return true;
  55125. }
  55126. var add = this.addCondition_(mapBrowserEvent);
  55127. var remove = this.removeCondition_(mapBrowserEvent);
  55128. var toggle = this.toggleCondition_(mapBrowserEvent);
  55129. var set = !add && !remove && !toggle;
  55130. var map = mapBrowserEvent.map;
  55131. var features = this.featureOverlay_.getSource().getFeaturesCollection();
  55132. var deselected = [];
  55133. var selected = [];
  55134. if (set) {
  55135. // Replace the currently selected feature(s) with the feature(s) at the
  55136. // pixel, or clear the selected feature(s) if there is no feature at
  55137. // the pixel.
  55138. ol.obj.clear(this.featureLayerAssociation_);
  55139. map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
  55140. (
  55141. /**
  55142. * @param {ol.Feature|ol.render.Feature} feature Feature.
  55143. * @param {ol.layer.Layer} layer Layer.
  55144. * @return {boolean|undefined} Continue to iterate over the features.
  55145. */
  55146. function(feature, layer) {
  55147. if (this.filter_(feature, layer)) {
  55148. selected.push(feature);
  55149. this.addFeatureLayerAssociation_(feature, layer);
  55150. return !this.multi_;
  55151. }
  55152. }).bind(this), {
  55153. layerFilter: this.layerFilter_,
  55154. hitTolerance: this.hitTolerance_
  55155. });
  55156. var i;
  55157. for (i = features.getLength() - 1; i >= 0; --i) {
  55158. var feature = features.item(i);
  55159. var index = selected.indexOf(feature);
  55160. if (index > -1) {
  55161. // feature is already selected
  55162. selected.splice(index, 1);
  55163. } else {
  55164. features.remove(feature);
  55165. deselected.push(feature);
  55166. }
  55167. }
  55168. if (selected.length !== 0) {
  55169. features.extend(selected);
  55170. }
  55171. } else {
  55172. // Modify the currently selected feature(s).
  55173. map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
  55174. (
  55175. /**
  55176. * @param {ol.Feature|ol.render.Feature} feature Feature.
  55177. * @param {ol.layer.Layer} layer Layer.
  55178. * @return {boolean|undefined} Continue to iterate over the features.
  55179. */
  55180. function(feature, layer) {
  55181. if (this.filter_(feature, layer)) {
  55182. if ((add || toggle) &&
  55183. !ol.array.includes(features.getArray(), feature)) {
  55184. selected.push(feature);
  55185. this.addFeatureLayerAssociation_(feature, layer);
  55186. } else if ((remove || toggle) &&
  55187. ol.array.includes(features.getArray(), feature)) {
  55188. deselected.push(feature);
  55189. this.removeFeatureLayerAssociation_(feature);
  55190. }
  55191. return !this.multi_;
  55192. }
  55193. }).bind(this), {
  55194. layerFilter: this.layerFilter_,
  55195. hitTolerance: this.hitTolerance_
  55196. });
  55197. var j;
  55198. for (j = deselected.length - 1; j >= 0; --j) {
  55199. features.remove(deselected[j]);
  55200. }
  55201. features.extend(selected);
  55202. }
  55203. if (selected.length > 0 || deselected.length > 0) {
  55204. this.dispatchEvent(
  55205. new ol.interaction.Select.Event(ol.interaction.Select.EventType_.SELECT,
  55206. selected, deselected, mapBrowserEvent));
  55207. }
  55208. return ol.events.condition.pointerMove(mapBrowserEvent);
  55209. };
  55210. /**
  55211. * Hit-detection tolerance. Pixels inside the radius around the given position
  55212. * will be checked for features. This only works for the canvas renderer and
  55213. * not for WebGL.
  55214. * @param {number} hitTolerance Hit tolerance in pixels.
  55215. * @api
  55216. */
  55217. ol.interaction.Select.prototype.setHitTolerance = function(hitTolerance) {
  55218. this.hitTolerance_ = hitTolerance;
  55219. };
  55220. /**
  55221. * Remove the interaction from its current map, if any, and attach it to a new
  55222. * map, if any. Pass `null` to just remove the interaction from the current map.
  55223. * @param {ol.PluggableMap} map Map.
  55224. * @override
  55225. * @api
  55226. */
  55227. ol.interaction.Select.prototype.setMap = function(map) {
  55228. var currentMap = this.getMap();
  55229. var selectedFeatures =
  55230. this.featureOverlay_.getSource().getFeaturesCollection();
  55231. if (currentMap) {
  55232. selectedFeatures.forEach(currentMap.unskipFeature, currentMap);
  55233. }
  55234. ol.interaction.Interaction.prototype.setMap.call(this, map);
  55235. this.featureOverlay_.setMap(map);
  55236. if (map) {
  55237. selectedFeatures.forEach(map.skipFeature, map);
  55238. }
  55239. };
  55240. /**
  55241. * @return {ol.StyleFunction} Styles.
  55242. */
  55243. ol.interaction.Select.getDefaultStyleFunction = function() {
  55244. var styles = ol.style.Style.createDefaultEditing();
  55245. ol.array.extend(styles[ol.geom.GeometryType.POLYGON],
  55246. styles[ol.geom.GeometryType.LINE_STRING]);
  55247. ol.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION],
  55248. styles[ol.geom.GeometryType.LINE_STRING]);
  55249. return function(feature, resolution) {
  55250. if (!feature.getGeometry()) {
  55251. return null;
  55252. }
  55253. return styles[feature.getGeometry().getType()];
  55254. };
  55255. };
  55256. /**
  55257. * @param {ol.Collection.Event} evt Event.
  55258. * @private
  55259. */
  55260. ol.interaction.Select.prototype.addFeature_ = function(evt) {
  55261. var map = this.getMap();
  55262. if (map) {
  55263. map.skipFeature(/** @type {ol.Feature} */ (evt.element));
  55264. }
  55265. };
  55266. /**
  55267. * @param {ol.Collection.Event} evt Event.
  55268. * @private
  55269. */
  55270. ol.interaction.Select.prototype.removeFeature_ = function(evt) {
  55271. var map = this.getMap();
  55272. if (map) {
  55273. map.unskipFeature(/** @type {ol.Feature} */ (evt.element));
  55274. }
  55275. };
  55276. /**
  55277. * @param {ol.Feature|ol.render.Feature} feature Feature.
  55278. * @private
  55279. */
  55280. ol.interaction.Select.prototype.removeFeatureLayerAssociation_ = function(feature) {
  55281. var key = ol.getUid(feature);
  55282. delete this.featureLayerAssociation_[key];
  55283. };
  55284. /**
  55285. * @classdesc
  55286. * Events emitted by {@link ol.interaction.Select} instances are instances of
  55287. * this type.
  55288. *
  55289. * @param {ol.interaction.Select.EventType_} type The event type.
  55290. * @param {Array.<ol.Feature>} selected Selected features.
  55291. * @param {Array.<ol.Feature>} deselected Deselected features.
  55292. * @param {ol.MapBrowserEvent} mapBrowserEvent Associated
  55293. * {@link ol.MapBrowserEvent}.
  55294. * @implements {oli.SelectEvent}
  55295. * @extends {ol.events.Event}
  55296. * @constructor
  55297. */
  55298. ol.interaction.Select.Event = function(type, selected, deselected, mapBrowserEvent) {
  55299. ol.events.Event.call(this, type);
  55300. /**
  55301. * Selected features array.
  55302. * @type {Array.<ol.Feature>}
  55303. * @api
  55304. */
  55305. this.selected = selected;
  55306. /**
  55307. * Deselected features array.
  55308. * @type {Array.<ol.Feature>}
  55309. * @api
  55310. */
  55311. this.deselected = deselected;
  55312. /**
  55313. * Associated {@link ol.MapBrowserEvent}.
  55314. * @type {ol.MapBrowserEvent}
  55315. * @api
  55316. */
  55317. this.mapBrowserEvent = mapBrowserEvent;
  55318. };
  55319. ol.inherits(ol.interaction.Select.Event, ol.events.Event);
  55320. /**
  55321. * @enum {string}
  55322. * @private
  55323. */
  55324. ol.interaction.Select.EventType_ = {
  55325. /**
  55326. * Triggered when feature(s) has been (de)selected.
  55327. * @event ol.interaction.Select.Event#select
  55328. * @api
  55329. */
  55330. SELECT: 'select'
  55331. };
  55332. goog.provide('ol.interaction.Snap');
  55333. goog.require('ol');
  55334. goog.require('ol.Collection');
  55335. goog.require('ol.CollectionEventType');
  55336. goog.require('ol.coordinate');
  55337. goog.require('ol.events');
  55338. goog.require('ol.events.EventType');
  55339. goog.require('ol.extent');
  55340. goog.require('ol.functions');
  55341. goog.require('ol.geom.GeometryType');
  55342. goog.require('ol.geom.Polygon');
  55343. goog.require('ol.interaction.Pointer');
  55344. goog.require('ol.obj');
  55345. goog.require('ol.source.Vector');
  55346. goog.require('ol.source.VectorEventType');
  55347. goog.require('ol.structs.RBush');
  55348. /**
  55349. * @classdesc
  55350. * Handles snapping of vector features while modifying or drawing them. The
  55351. * features can come from a {@link ol.source.Vector} or {@link ol.Collection}
  55352. * Any interaction object that allows the user to interact
  55353. * with the features using the mouse can benefit from the snapping, as long
  55354. * as it is added before.
  55355. *
  55356. * The snap interaction modifies map browser event `coordinate` and `pixel`
  55357. * properties to force the snap to occur to any interaction that them.
  55358. *
  55359. * Example:
  55360. *
  55361. * var snap = new ol.interaction.Snap({
  55362. * source: source
  55363. * });
  55364. *
  55365. * @constructor
  55366. * @extends {ol.interaction.Pointer}
  55367. * @param {olx.interaction.SnapOptions=} opt_options Options.
  55368. * @api
  55369. */
  55370. ol.interaction.Snap = function(opt_options) {
  55371. ol.interaction.Pointer.call(this, {
  55372. handleEvent: ol.interaction.Snap.handleEvent_,
  55373. handleDownEvent: ol.functions.TRUE,
  55374. handleUpEvent: ol.interaction.Snap.handleUpEvent_
  55375. });
  55376. var options = opt_options ? opt_options : {};
  55377. /**
  55378. * @type {ol.source.Vector}
  55379. * @private
  55380. */
  55381. this.source_ = options.source ? options.source : null;
  55382. /**
  55383. * @private
  55384. * @type {boolean}
  55385. */
  55386. this.vertex_ = options.vertex !== undefined ? options.vertex : true;
  55387. /**
  55388. * @private
  55389. * @type {boolean}
  55390. */
  55391. this.edge_ = options.edge !== undefined ? options.edge : true;
  55392. /**
  55393. * @type {ol.Collection.<ol.Feature>}
  55394. * @private
  55395. */
  55396. this.features_ = options.features ? options.features : null;
  55397. /**
  55398. * @type {Array.<ol.EventsKey>}
  55399. * @private
  55400. */
  55401. this.featuresListenerKeys_ = [];
  55402. /**
  55403. * @type {Object.<number, ol.EventsKey>}
  55404. * @private
  55405. */
  55406. this.featureChangeListenerKeys_ = {};
  55407. /**
  55408. * Extents are preserved so indexed segment can be quickly removed
  55409. * when its feature geometry changes
  55410. * @type {Object.<number, ol.Extent>}
  55411. * @private
  55412. */
  55413. this.indexedFeaturesExtents_ = {};
  55414. /**
  55415. * If a feature geometry changes while a pointer drag|move event occurs, the
  55416. * feature doesn't get updated right away. It will be at the next 'pointerup'
  55417. * event fired.
  55418. * @type {Object.<number, ol.Feature>}
  55419. * @private
  55420. */
  55421. this.pendingFeatures_ = {};
  55422. /**
  55423. * Used for distance sorting in sortByDistance_
  55424. * @type {ol.Coordinate}
  55425. * @private
  55426. */
  55427. this.pixelCoordinate_ = null;
  55428. /**
  55429. * @type {number}
  55430. * @private
  55431. */
  55432. this.pixelTolerance_ = options.pixelTolerance !== undefined ?
  55433. options.pixelTolerance : 10;
  55434. /**
  55435. * @type {function(ol.SnapSegmentDataType, ol.SnapSegmentDataType): number}
  55436. * @private
  55437. */
  55438. this.sortByDistance_ = ol.interaction.Snap.sortByDistance.bind(this);
  55439. /**
  55440. * Segment RTree for each layer
  55441. * @type {ol.structs.RBush.<ol.SnapSegmentDataType>}
  55442. * @private
  55443. */
  55444. this.rBush_ = new ol.structs.RBush();
  55445. /**
  55446. * @const
  55447. * @private
  55448. * @type {Object.<string, function(ol.Feature, ol.geom.Geometry)>}
  55449. */
  55450. this.SEGMENT_WRITERS_ = {
  55451. 'Point': this.writePointGeometry_,
  55452. 'LineString': this.writeLineStringGeometry_,
  55453. 'LinearRing': this.writeLineStringGeometry_,
  55454. 'Polygon': this.writePolygonGeometry_,
  55455. 'MultiPoint': this.writeMultiPointGeometry_,
  55456. 'MultiLineString': this.writeMultiLineStringGeometry_,
  55457. 'MultiPolygon': this.writeMultiPolygonGeometry_,
  55458. 'GeometryCollection': this.writeGeometryCollectionGeometry_,
  55459. 'Circle': this.writeCircleGeometry_
  55460. };
  55461. };
  55462. ol.inherits(ol.interaction.Snap, ol.interaction.Pointer);
  55463. /**
  55464. * Add a feature to the collection of features that we may snap to.
  55465. * @param {ol.Feature} feature Feature.
  55466. * @param {boolean=} opt_listen Whether to listen to the feature change or not
  55467. * Defaults to `true`.
  55468. * @api
  55469. */
  55470. ol.interaction.Snap.prototype.addFeature = function(feature, opt_listen) {
  55471. var listen = opt_listen !== undefined ? opt_listen : true;
  55472. var feature_uid = ol.getUid(feature);
  55473. var geometry = feature.getGeometry();
  55474. if (geometry) {
  55475. var segmentWriter = this.SEGMENT_WRITERS_[geometry.getType()];
  55476. if (segmentWriter) {
  55477. this.indexedFeaturesExtents_[feature_uid] = geometry.getExtent(
  55478. ol.extent.createEmpty());
  55479. segmentWriter.call(this, feature, geometry);
  55480. }
  55481. }
  55482. if (listen) {
  55483. this.featureChangeListenerKeys_[feature_uid] = ol.events.listen(
  55484. feature,
  55485. ol.events.EventType.CHANGE,
  55486. this.handleFeatureChange_, this);
  55487. }
  55488. };
  55489. /**
  55490. * @param {ol.Feature} feature Feature.
  55491. * @private
  55492. */
  55493. ol.interaction.Snap.prototype.forEachFeatureAdd_ = function(feature) {
  55494. this.addFeature(feature);
  55495. };
  55496. /**
  55497. * @param {ol.Feature} feature Feature.
  55498. * @private
  55499. */
  55500. ol.interaction.Snap.prototype.forEachFeatureRemove_ = function(feature) {
  55501. this.removeFeature(feature);
  55502. };
  55503. /**
  55504. * @return {ol.Collection.<ol.Feature>|Array.<ol.Feature>} Features.
  55505. * @private
  55506. */
  55507. ol.interaction.Snap.prototype.getFeatures_ = function() {
  55508. var features;
  55509. if (this.features_) {
  55510. features = this.features_;
  55511. } else if (this.source_) {
  55512. features = this.source_.getFeatures();
  55513. }
  55514. return /** @type {!Array.<ol.Feature>|!ol.Collection.<ol.Feature>} */ (features);
  55515. };
  55516. /**
  55517. * @param {ol.source.Vector.Event|ol.Collection.Event} evt Event.
  55518. * @private
  55519. */
  55520. ol.interaction.Snap.prototype.handleFeatureAdd_ = function(evt) {
  55521. var feature;
  55522. if (evt instanceof ol.source.Vector.Event) {
  55523. feature = evt.feature;
  55524. } else if (evt instanceof ol.Collection.Event) {
  55525. feature = evt.element;
  55526. }
  55527. this.addFeature(/** @type {ol.Feature} */ (feature));
  55528. };
  55529. /**
  55530. * @param {ol.source.Vector.Event|ol.Collection.Event} evt Event.
  55531. * @private
  55532. */
  55533. ol.interaction.Snap.prototype.handleFeatureRemove_ = function(evt) {
  55534. var feature;
  55535. if (evt instanceof ol.source.Vector.Event) {
  55536. feature = evt.feature;
  55537. } else if (evt instanceof ol.Collection.Event) {
  55538. feature = evt.element;
  55539. }
  55540. this.removeFeature(/** @type {ol.Feature} */ (feature));
  55541. };
  55542. /**
  55543. * @param {ol.events.Event} evt Event.
  55544. * @private
  55545. */
  55546. ol.interaction.Snap.prototype.handleFeatureChange_ = function(evt) {
  55547. var feature = /** @type {ol.Feature} */ (evt.target);
  55548. if (this.handlingDownUpSequence) {
  55549. var uid = ol.getUid(feature);
  55550. if (!(uid in this.pendingFeatures_)) {
  55551. this.pendingFeatures_[uid] = feature;
  55552. }
  55553. } else {
  55554. this.updateFeature_(feature);
  55555. }
  55556. };
  55557. /**
  55558. * Remove a feature from the collection of features that we may snap to.
  55559. * @param {ol.Feature} feature Feature
  55560. * @param {boolean=} opt_unlisten Whether to unlisten to the feature change
  55561. * or not. Defaults to `true`.
  55562. * @api
  55563. */
  55564. ol.interaction.Snap.prototype.removeFeature = function(feature, opt_unlisten) {
  55565. var unlisten = opt_unlisten !== undefined ? opt_unlisten : true;
  55566. var feature_uid = ol.getUid(feature);
  55567. var extent = this.indexedFeaturesExtents_[feature_uid];
  55568. if (extent) {
  55569. var rBush = this.rBush_;
  55570. var i, nodesToRemove = [];
  55571. rBush.forEachInExtent(extent, function(node) {
  55572. if (feature === node.feature) {
  55573. nodesToRemove.push(node);
  55574. }
  55575. });
  55576. for (i = nodesToRemove.length - 1; i >= 0; --i) {
  55577. rBush.remove(nodesToRemove[i]);
  55578. }
  55579. }
  55580. if (unlisten) {
  55581. ol.events.unlistenByKey(this.featureChangeListenerKeys_[feature_uid]);
  55582. delete this.featureChangeListenerKeys_[feature_uid];
  55583. }
  55584. };
  55585. /**
  55586. * @inheritDoc
  55587. */
  55588. ol.interaction.Snap.prototype.setMap = function(map) {
  55589. var currentMap = this.getMap();
  55590. var keys = this.featuresListenerKeys_;
  55591. var features = this.getFeatures_();
  55592. if (currentMap) {
  55593. keys.forEach(ol.events.unlistenByKey);
  55594. keys.length = 0;
  55595. features.forEach(this.forEachFeatureRemove_, this);
  55596. }
  55597. ol.interaction.Pointer.prototype.setMap.call(this, map);
  55598. if (map) {
  55599. if (this.features_) {
  55600. keys.push(
  55601. ol.events.listen(this.features_, ol.CollectionEventType.ADD,
  55602. this.handleFeatureAdd_, this),
  55603. ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
  55604. this.handleFeatureRemove_, this)
  55605. );
  55606. } else if (this.source_) {
  55607. keys.push(
  55608. ol.events.listen(this.source_, ol.source.VectorEventType.ADDFEATURE,
  55609. this.handleFeatureAdd_, this),
  55610. ol.events.listen(this.source_, ol.source.VectorEventType.REMOVEFEATURE,
  55611. this.handleFeatureRemove_, this)
  55612. );
  55613. }
  55614. features.forEach(this.forEachFeatureAdd_, this);
  55615. }
  55616. };
  55617. /**
  55618. * @inheritDoc
  55619. */
  55620. ol.interaction.Snap.prototype.shouldStopEvent = ol.functions.FALSE;
  55621. /**
  55622. * @param {ol.Pixel} pixel Pixel
  55623. * @param {ol.Coordinate} pixelCoordinate Coordinate
  55624. * @param {ol.PluggableMap} map Map.
  55625. * @return {ol.SnapResultType} Snap result
  55626. */
  55627. ol.interaction.Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
  55628. var lowerLeft = map.getCoordinateFromPixel(
  55629. [pixel[0] - this.pixelTolerance_, pixel[1] + this.pixelTolerance_]);
  55630. var upperRight = map.getCoordinateFromPixel(
  55631. [pixel[0] + this.pixelTolerance_, pixel[1] - this.pixelTolerance_]);
  55632. var box = ol.extent.boundingExtent([lowerLeft, upperRight]);
  55633. var segments = this.rBush_.getInExtent(box);
  55634. // If snapping on vertices only, don't consider circles
  55635. if (this.vertex_ && !this.edge_) {
  55636. segments = segments.filter(function(segment) {
  55637. return segment.feature.getGeometry().getType() !==
  55638. ol.geom.GeometryType.CIRCLE;
  55639. });
  55640. }
  55641. var snappedToVertex = false;
  55642. var snapped = false;
  55643. var vertex = null;
  55644. var vertexPixel = null;
  55645. var dist, pixel1, pixel2, squaredDist1, squaredDist2;
  55646. if (segments.length > 0) {
  55647. this.pixelCoordinate_ = pixelCoordinate;
  55648. segments.sort(this.sortByDistance_);
  55649. var closestSegment = segments[0].segment;
  55650. var isCircle = segments[0].feature.getGeometry().getType() ===
  55651. ol.geom.GeometryType.CIRCLE;
  55652. if (this.vertex_ && !this.edge_) {
  55653. pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
  55654. pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
  55655. squaredDist1 = ol.coordinate.squaredDistance(pixel, pixel1);
  55656. squaredDist2 = ol.coordinate.squaredDistance(pixel, pixel2);
  55657. dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
  55658. snappedToVertex = dist <= this.pixelTolerance_;
  55659. if (snappedToVertex) {
  55660. snapped = true;
  55661. vertex = squaredDist1 > squaredDist2 ?
  55662. closestSegment[1] : closestSegment[0];
  55663. vertexPixel = map.getPixelFromCoordinate(vertex);
  55664. }
  55665. } else if (this.edge_) {
  55666. if (isCircle) {
  55667. vertex = ol.coordinate.closestOnCircle(pixelCoordinate,
  55668. /** @type {ol.geom.Circle} */ (segments[0].feature.getGeometry()));
  55669. } else {
  55670. vertex = (ol.coordinate.closestOnSegment(pixelCoordinate,
  55671. closestSegment));
  55672. }
  55673. vertexPixel = map.getPixelFromCoordinate(vertex);
  55674. if (ol.coordinate.distance(pixel, vertexPixel) <= this.pixelTolerance_) {
  55675. snapped = true;
  55676. if (this.vertex_ && !isCircle) {
  55677. pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
  55678. pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
  55679. squaredDist1 = ol.coordinate.squaredDistance(vertexPixel, pixel1);
  55680. squaredDist2 = ol.coordinate.squaredDistance(vertexPixel, pixel2);
  55681. dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
  55682. snappedToVertex = dist <= this.pixelTolerance_;
  55683. if (snappedToVertex) {
  55684. vertex = squaredDist1 > squaredDist2 ?
  55685. closestSegment[1] : closestSegment[0];
  55686. vertexPixel = map.getPixelFromCoordinate(vertex);
  55687. }
  55688. }
  55689. }
  55690. }
  55691. if (snapped) {
  55692. vertexPixel = [Math.round(vertexPixel[0]), Math.round(vertexPixel[1])];
  55693. }
  55694. }
  55695. return /** @type {ol.SnapResultType} */ ({
  55696. snapped: snapped,
  55697. vertex: vertex,
  55698. vertexPixel: vertexPixel
  55699. });
  55700. };
  55701. /**
  55702. * @param {ol.Feature} feature Feature
  55703. * @private
  55704. */
  55705. ol.interaction.Snap.prototype.updateFeature_ = function(feature) {
  55706. this.removeFeature(feature, false);
  55707. this.addFeature(feature, false);
  55708. };
  55709. /**
  55710. * @param {ol.Feature} feature Feature
  55711. * @param {ol.geom.Circle} geometry Geometry.
  55712. * @private
  55713. */
  55714. ol.interaction.Snap.prototype.writeCircleGeometry_ = function(feature, geometry) {
  55715. var polygon = ol.geom.Polygon.fromCircle(geometry);
  55716. var coordinates = polygon.getCoordinates()[0];
  55717. var i, ii, segment, segmentData;
  55718. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  55719. segment = coordinates.slice(i, i + 2);
  55720. segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55721. feature: feature,
  55722. segment: segment
  55723. });
  55724. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  55725. }
  55726. };
  55727. /**
  55728. * @param {ol.Feature} feature Feature
  55729. * @param {ol.geom.GeometryCollection} geometry Geometry.
  55730. * @private
  55731. */
  55732. ol.interaction.Snap.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) {
  55733. var i, geometries = geometry.getGeometriesArray();
  55734. for (i = 0; i < geometries.length; ++i) {
  55735. var segmentWriter = this.SEGMENT_WRITERS_[geometries[i].getType()];
  55736. if (segmentWriter) {
  55737. segmentWriter.call(this, feature, geometries[i]);
  55738. }
  55739. }
  55740. };
  55741. /**
  55742. * @param {ol.Feature} feature Feature
  55743. * @param {ol.geom.LineString} geometry Geometry.
  55744. * @private
  55745. */
  55746. ol.interaction.Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) {
  55747. var coordinates = geometry.getCoordinates();
  55748. var i, ii, segment, segmentData;
  55749. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  55750. segment = coordinates.slice(i, i + 2);
  55751. segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55752. feature: feature,
  55753. segment: segment
  55754. });
  55755. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  55756. }
  55757. };
  55758. /**
  55759. * @param {ol.Feature} feature Feature
  55760. * @param {ol.geom.MultiLineString} geometry Geometry.
  55761. * @private
  55762. */
  55763. ol.interaction.Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
  55764. var lines = geometry.getCoordinates();
  55765. var coordinates, i, ii, j, jj, segment, segmentData;
  55766. for (j = 0, jj = lines.length; j < jj; ++j) {
  55767. coordinates = lines[j];
  55768. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  55769. segment = coordinates.slice(i, i + 2);
  55770. segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55771. feature: feature,
  55772. segment: segment
  55773. });
  55774. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  55775. }
  55776. }
  55777. };
  55778. /**
  55779. * @param {ol.Feature} feature Feature
  55780. * @param {ol.geom.MultiPoint} geometry Geometry.
  55781. * @private
  55782. */
  55783. ol.interaction.Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
  55784. var points = geometry.getCoordinates();
  55785. var coordinates, i, ii, segmentData;
  55786. for (i = 0, ii = points.length; i < ii; ++i) {
  55787. coordinates = points[i];
  55788. segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55789. feature: feature,
  55790. segment: [coordinates, coordinates]
  55791. });
  55792. this.rBush_.insert(geometry.getExtent(), segmentData);
  55793. }
  55794. };
  55795. /**
  55796. * @param {ol.Feature} feature Feature
  55797. * @param {ol.geom.MultiPolygon} geometry Geometry.
  55798. * @private
  55799. */
  55800. ol.interaction.Snap.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
  55801. var polygons = geometry.getCoordinates();
  55802. var coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
  55803. for (k = 0, kk = polygons.length; k < kk; ++k) {
  55804. rings = polygons[k];
  55805. for (j = 0, jj = rings.length; j < jj; ++j) {
  55806. coordinates = rings[j];
  55807. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  55808. segment = coordinates.slice(i, i + 2);
  55809. segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55810. feature: feature,
  55811. segment: segment
  55812. });
  55813. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  55814. }
  55815. }
  55816. }
  55817. };
  55818. /**
  55819. * @param {ol.Feature} feature Feature
  55820. * @param {ol.geom.Point} geometry Geometry.
  55821. * @private
  55822. */
  55823. ol.interaction.Snap.prototype.writePointGeometry_ = function(feature, geometry) {
  55824. var coordinates = geometry.getCoordinates();
  55825. var segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55826. feature: feature,
  55827. segment: [coordinates, coordinates]
  55828. });
  55829. this.rBush_.insert(geometry.getExtent(), segmentData);
  55830. };
  55831. /**
  55832. * @param {ol.Feature} feature Feature
  55833. * @param {ol.geom.Polygon} geometry Geometry.
  55834. * @private
  55835. */
  55836. ol.interaction.Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
  55837. var rings = geometry.getCoordinates();
  55838. var coordinates, i, ii, j, jj, segment, segmentData;
  55839. for (j = 0, jj = rings.length; j < jj; ++j) {
  55840. coordinates = rings[j];
  55841. for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
  55842. segment = coordinates.slice(i, i + 2);
  55843. segmentData = /** @type {ol.SnapSegmentDataType} */ ({
  55844. feature: feature,
  55845. segment: segment
  55846. });
  55847. this.rBush_.insert(ol.extent.boundingExtent(segment), segmentData);
  55848. }
  55849. }
  55850. };
  55851. /**
  55852. * Handle all pointer events events.
  55853. * @param {ol.MapBrowserEvent} evt A move event.
  55854. * @return {boolean} Pass the event to other interactions.
  55855. * @this {ol.interaction.Snap}
  55856. * @private
  55857. */
  55858. ol.interaction.Snap.handleEvent_ = function(evt) {
  55859. var result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
  55860. if (result.snapped) {
  55861. evt.coordinate = result.vertex.slice(0, 2);
  55862. evt.pixel = result.vertexPixel;
  55863. }
  55864. return ol.interaction.Pointer.handleEvent.call(this, evt);
  55865. };
  55866. /**
  55867. * @param {ol.MapBrowserPointerEvent} evt Event.
  55868. * @return {boolean} Stop drag sequence?
  55869. * @this {ol.interaction.Snap}
  55870. * @private
  55871. */
  55872. ol.interaction.Snap.handleUpEvent_ = function(evt) {
  55873. var featuresToUpdate = ol.obj.getValues(this.pendingFeatures_);
  55874. if (featuresToUpdate.length) {
  55875. featuresToUpdate.forEach(this.updateFeature_, this);
  55876. this.pendingFeatures_ = {};
  55877. }
  55878. return false;
  55879. };
  55880. /**
  55881. * Sort segments by distance, helper function
  55882. * @param {ol.SnapSegmentDataType} a The first segment data.
  55883. * @param {ol.SnapSegmentDataType} b The second segment data.
  55884. * @return {number} The difference in distance.
  55885. * @this {ol.interaction.Snap}
  55886. */
  55887. ol.interaction.Snap.sortByDistance = function(a, b) {
  55888. return ol.coordinate.squaredDistanceToSegment(
  55889. this.pixelCoordinate_, a.segment) -
  55890. ol.coordinate.squaredDistanceToSegment(
  55891. this.pixelCoordinate_, b.segment);
  55892. };
  55893. goog.provide('ol.interaction.TranslateEventType');
  55894. /**
  55895. * @enum {string}
  55896. */
  55897. ol.interaction.TranslateEventType = {
  55898. /**
  55899. * Triggered upon feature translation start.
  55900. * @event ol.interaction.Translate.Event#translatestart
  55901. * @api
  55902. */
  55903. TRANSLATESTART: 'translatestart',
  55904. /**
  55905. * Triggered upon feature translation.
  55906. * @event ol.interaction.Translate.Event#translating
  55907. * @api
  55908. */
  55909. TRANSLATING: 'translating',
  55910. /**
  55911. * Triggered upon feature translation end.
  55912. * @event ol.interaction.Translate.Event#translateend
  55913. * @api
  55914. */
  55915. TRANSLATEEND: 'translateend'
  55916. };
  55917. goog.provide('ol.interaction.Translate');
  55918. goog.require('ol');
  55919. goog.require('ol.Collection');
  55920. goog.require('ol.Object');
  55921. goog.require('ol.events');
  55922. goog.require('ol.events.Event');
  55923. goog.require('ol.functions');
  55924. goog.require('ol.array');
  55925. goog.require('ol.interaction.Pointer');
  55926. goog.require('ol.interaction.Property');
  55927. goog.require('ol.interaction.TranslateEventType');
  55928. /**
  55929. * @classdesc
  55930. * Interaction for translating (moving) features.
  55931. *
  55932. * @constructor
  55933. * @extends {ol.interaction.Pointer}
  55934. * @fires ol.interaction.Translate.Event
  55935. * @param {olx.interaction.TranslateOptions=} opt_options Options.
  55936. * @api
  55937. */
  55938. ol.interaction.Translate = function(opt_options) {
  55939. ol.interaction.Pointer.call(this, {
  55940. handleDownEvent: ol.interaction.Translate.handleDownEvent_,
  55941. handleDragEvent: ol.interaction.Translate.handleDragEvent_,
  55942. handleMoveEvent: ol.interaction.Translate.handleMoveEvent_,
  55943. handleUpEvent: ol.interaction.Translate.handleUpEvent_
  55944. });
  55945. var options = opt_options ? opt_options : {};
  55946. /**
  55947. * The last position we translated to.
  55948. * @type {ol.Coordinate}
  55949. * @private
  55950. */
  55951. this.lastCoordinate_ = null;
  55952. /**
  55953. * @type {ol.Collection.<ol.Feature>}
  55954. * @private
  55955. */
  55956. this.features_ = options.features !== undefined ? options.features : null;
  55957. /** @type {function(ol.layer.Layer): boolean} */
  55958. var layerFilter;
  55959. if (options.layers) {
  55960. if (typeof options.layers === 'function') {
  55961. layerFilter = options.layers;
  55962. } else {
  55963. var layers = options.layers;
  55964. layerFilter = function(layer) {
  55965. return ol.array.includes(layers, layer);
  55966. };
  55967. }
  55968. } else {
  55969. layerFilter = ol.functions.TRUE;
  55970. }
  55971. /**
  55972. * @private
  55973. * @type {function(ol.layer.Layer): boolean}
  55974. */
  55975. this.layerFilter_ = layerFilter;
  55976. /**
  55977. * @private
  55978. * @type {number}
  55979. */
  55980. this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
  55981. /**
  55982. * @type {ol.Feature}
  55983. * @private
  55984. */
  55985. this.lastFeature_ = null;
  55986. ol.events.listen(this,
  55987. ol.Object.getChangeEventType(ol.interaction.Property.ACTIVE),
  55988. this.handleActiveChanged_, this);
  55989. };
  55990. ol.inherits(ol.interaction.Translate, ol.interaction.Pointer);
  55991. /**
  55992. * @param {ol.MapBrowserPointerEvent} event Event.
  55993. * @return {boolean} Start drag sequence?
  55994. * @this {ol.interaction.Translate}
  55995. * @private
  55996. */
  55997. ol.interaction.Translate.handleDownEvent_ = function(event) {
  55998. this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
  55999. if (!this.lastCoordinate_ && this.lastFeature_) {
  56000. this.lastCoordinate_ = event.coordinate;
  56001. ol.interaction.Translate.handleMoveEvent_.call(this, event);
  56002. var features = this.features_ || new ol.Collection([this.lastFeature_]);
  56003. this.dispatchEvent(
  56004. new ol.interaction.Translate.Event(
  56005. ol.interaction.TranslateEventType.TRANSLATESTART, features,
  56006. event.coordinate));
  56007. return true;
  56008. }
  56009. return false;
  56010. };
  56011. /**
  56012. * @param {ol.MapBrowserPointerEvent} event Event.
  56013. * @return {boolean} Stop drag sequence?
  56014. * @this {ol.interaction.Translate}
  56015. * @private
  56016. */
  56017. ol.interaction.Translate.handleUpEvent_ = function(event) {
  56018. if (this.lastCoordinate_) {
  56019. this.lastCoordinate_ = null;
  56020. ol.interaction.Translate.handleMoveEvent_.call(this, event);
  56021. var features = this.features_ || new ol.Collection([this.lastFeature_]);
  56022. this.dispatchEvent(
  56023. new ol.interaction.Translate.Event(
  56024. ol.interaction.TranslateEventType.TRANSLATEEND, features,
  56025. event.coordinate));
  56026. return true;
  56027. }
  56028. return false;
  56029. };
  56030. /**
  56031. * @param {ol.MapBrowserPointerEvent} event Event.
  56032. * @this {ol.interaction.Translate}
  56033. * @private
  56034. */
  56035. ol.interaction.Translate.handleDragEvent_ = function(event) {
  56036. if (this.lastCoordinate_) {
  56037. var newCoordinate = event.coordinate;
  56038. var deltaX = newCoordinate[0] - this.lastCoordinate_[0];
  56039. var deltaY = newCoordinate[1] - this.lastCoordinate_[1];
  56040. var features = this.features_ || new ol.Collection([this.lastFeature_]);
  56041. features.forEach(function(feature) {
  56042. var geom = feature.getGeometry();
  56043. geom.translate(deltaX, deltaY);
  56044. feature.setGeometry(geom);
  56045. });
  56046. this.lastCoordinate_ = newCoordinate;
  56047. this.dispatchEvent(
  56048. new ol.interaction.Translate.Event(
  56049. ol.interaction.TranslateEventType.TRANSLATING, features,
  56050. newCoordinate));
  56051. }
  56052. };
  56053. /**
  56054. * @param {ol.MapBrowserEvent} event Event.
  56055. * @this {ol.interaction.Translate}
  56056. * @private
  56057. */
  56058. ol.interaction.Translate.handleMoveEvent_ = function(event) {
  56059. var elem = event.map.getViewport();
  56060. // Change the cursor to grab/grabbing if hovering any of the features managed
  56061. // by the interaction
  56062. if (this.featuresAtPixel_(event.pixel, event.map)) {
  56063. elem.classList.remove(this.lastCoordinate_ ? 'ol-grab' : 'ol-grabbing');
  56064. elem.classList.add(this.lastCoordinate_ ? 'ol-grabbing' : 'ol-grab');
  56065. } else {
  56066. elem.classList.remove('ol-grab', 'ol-grabbing');
  56067. }
  56068. };
  56069. /**
  56070. * Tests to see if the given coordinates intersects any of our selected
  56071. * features.
  56072. * @param {ol.Pixel} pixel Pixel coordinate to test for intersection.
  56073. * @param {ol.PluggableMap} map Map to test the intersection on.
  56074. * @return {ol.Feature} Returns the feature found at the specified pixel
  56075. * coordinates.
  56076. * @private
  56077. */
  56078. ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
  56079. return map.forEachFeatureAtPixel(pixel,
  56080. function(feature) {
  56081. if (!this.features_ ||
  56082. ol.array.includes(this.features_.getArray(), feature)) {
  56083. return feature;
  56084. }
  56085. }.bind(this), {
  56086. layerFilter: this.layerFilter_,
  56087. hitTolerance: this.hitTolerance_
  56088. });
  56089. };
  56090. /**
  56091. * Returns the Hit-detection tolerance.
  56092. * @returns {number} Hit tolerance in pixels.
  56093. * @api
  56094. */
  56095. ol.interaction.Translate.prototype.getHitTolerance = function() {
  56096. return this.hitTolerance_;
  56097. };
  56098. /**
  56099. * Hit-detection tolerance. Pixels inside the radius around the given position
  56100. * will be checked for features. This only works for the canvas renderer and
  56101. * not for WebGL.
  56102. * @param {number} hitTolerance Hit tolerance in pixels.
  56103. * @api
  56104. */
  56105. ol.interaction.Translate.prototype.setHitTolerance = function(hitTolerance) {
  56106. this.hitTolerance_ = hitTolerance;
  56107. };
  56108. /**
  56109. * @inheritDoc
  56110. */
  56111. ol.interaction.Translate.prototype.setMap = function(map) {
  56112. var oldMap = this.getMap();
  56113. ol.interaction.Pointer.prototype.setMap.call(this, map);
  56114. this.updateState_(oldMap);
  56115. };
  56116. /**
  56117. * @private
  56118. */
  56119. ol.interaction.Translate.prototype.handleActiveChanged_ = function() {
  56120. this.updateState_(null);
  56121. };
  56122. /**
  56123. * @param {ol.PluggableMap} oldMap Old map.
  56124. * @private
  56125. */
  56126. ol.interaction.Translate.prototype.updateState_ = function(oldMap) {
  56127. var map = this.getMap();
  56128. var active = this.getActive();
  56129. if (!map || !active) {
  56130. map = map || oldMap;
  56131. if (map) {
  56132. var elem = map.getViewport();
  56133. elem.classList.remove('ol-grab', 'ol-grabbing');
  56134. }
  56135. }
  56136. };
  56137. /**
  56138. * @classdesc
  56139. * Events emitted by {@link ol.interaction.Translate} instances are instances of
  56140. * this type.
  56141. *
  56142. * @constructor
  56143. * @extends {ol.events.Event}
  56144. * @implements {oli.interaction.TranslateEvent}
  56145. * @param {ol.interaction.TranslateEventType} type Type.
  56146. * @param {ol.Collection.<ol.Feature>} features The features translated.
  56147. * @param {ol.Coordinate} coordinate The event coordinate.
  56148. */
  56149. ol.interaction.Translate.Event = function(type, features, coordinate) {
  56150. ol.events.Event.call(this, type);
  56151. /**
  56152. * The features being translated.
  56153. * @type {ol.Collection.<ol.Feature>}
  56154. * @api
  56155. */
  56156. this.features = features;
  56157. /**
  56158. * The coordinate of the drag event.
  56159. * @const
  56160. * @type {ol.Coordinate}
  56161. * @api
  56162. */
  56163. this.coordinate = coordinate;
  56164. };
  56165. ol.inherits(ol.interaction.Translate.Event, ol.events.Event);
  56166. goog.provide('ol.layer.Heatmap');
  56167. goog.require('ol.events');
  56168. goog.require('ol');
  56169. goog.require('ol.Object');
  56170. goog.require('ol.dom');
  56171. goog.require('ol.layer.Vector');
  56172. goog.require('ol.math');
  56173. goog.require('ol.obj');
  56174. goog.require('ol.render.EventType');
  56175. goog.require('ol.style.Icon');
  56176. goog.require('ol.style.Style');
  56177. /**
  56178. * @classdesc
  56179. * Layer for rendering vector data as a heatmap.
  56180. * Note that any property set in the options is set as a {@link ol.Object}
  56181. * property on the layer object; for example, setting `title: 'My Title'` in the
  56182. * options means that `title` is observable, and has get/set accessors.
  56183. *
  56184. * @constructor
  56185. * @extends {ol.layer.Vector}
  56186. * @fires ol.render.Event
  56187. * @param {olx.layer.HeatmapOptions=} opt_options Options.
  56188. * @api
  56189. */
  56190. ol.layer.Heatmap = function(opt_options) {
  56191. var options = opt_options ? opt_options : {};
  56192. var baseOptions = ol.obj.assign({}, options);
  56193. delete baseOptions.gradient;
  56194. delete baseOptions.radius;
  56195. delete baseOptions.blur;
  56196. delete baseOptions.shadow;
  56197. delete baseOptions.weight;
  56198. ol.layer.Vector.call(this, /** @type {olx.layer.VectorOptions} */ (baseOptions));
  56199. /**
  56200. * @private
  56201. * @type {Uint8ClampedArray}
  56202. */
  56203. this.gradient_ = null;
  56204. /**
  56205. * @private
  56206. * @type {number}
  56207. */
  56208. this.shadow_ = options.shadow !== undefined ? options.shadow : 250;
  56209. /**
  56210. * @private
  56211. * @type {string|undefined}
  56212. */
  56213. this.circleImage_ = undefined;
  56214. /**
  56215. * @private
  56216. * @type {Array.<Array.<ol.style.Style>>}
  56217. */
  56218. this.styleCache_ = null;
  56219. ol.events.listen(this,
  56220. ol.Object.getChangeEventType(ol.layer.Heatmap.Property_.GRADIENT),
  56221. this.handleGradientChanged_, this);
  56222. this.setGradient(options.gradient ?
  56223. options.gradient : ol.layer.Heatmap.DEFAULT_GRADIENT);
  56224. this.setBlur(options.blur !== undefined ? options.blur : 15);
  56225. this.setRadius(options.radius !== undefined ? options.radius : 8);
  56226. ol.events.listen(this,
  56227. ol.Object.getChangeEventType(ol.layer.Heatmap.Property_.BLUR),
  56228. this.handleStyleChanged_, this);
  56229. ol.events.listen(this,
  56230. ol.Object.getChangeEventType(ol.layer.Heatmap.Property_.RADIUS),
  56231. this.handleStyleChanged_, this);
  56232. this.handleStyleChanged_();
  56233. var weight = options.weight ? options.weight : 'weight';
  56234. var weightFunction;
  56235. if (typeof weight === 'string') {
  56236. weightFunction = function(feature) {
  56237. return feature.get(weight);
  56238. };
  56239. } else {
  56240. weightFunction = weight;
  56241. }
  56242. this.setStyle(function(feature, resolution) {
  56243. var weight = weightFunction(feature);
  56244. var opacity = weight !== undefined ? ol.math.clamp(weight, 0, 1) : 1;
  56245. // cast to 8 bits
  56246. var index = (255 * opacity) | 0;
  56247. var style = this.styleCache_[index];
  56248. if (!style) {
  56249. style = [
  56250. new ol.style.Style({
  56251. image: new ol.style.Icon({
  56252. opacity: opacity,
  56253. src: this.circleImage_
  56254. })
  56255. })
  56256. ];
  56257. this.styleCache_[index] = style;
  56258. }
  56259. return style;
  56260. }.bind(this));
  56261. // For performance reasons, don't sort the features before rendering.
  56262. // The render order is not relevant for a heatmap representation.
  56263. this.setRenderOrder(null);
  56264. ol.events.listen(this, ol.render.EventType.RENDER, this.handleRender_, this);
  56265. };
  56266. ol.inherits(ol.layer.Heatmap, ol.layer.Vector);
  56267. /**
  56268. * @const
  56269. * @type {Array.<string>}
  56270. */
  56271. ol.layer.Heatmap.DEFAULT_GRADIENT = ['#00f', '#0ff', '#0f0', '#ff0', '#f00'];
  56272. /**
  56273. * @param {Array.<string>} colors A list of colored.
  56274. * @return {Uint8ClampedArray} An array.
  56275. * @private
  56276. */
  56277. ol.layer.Heatmap.createGradient_ = function(colors) {
  56278. var width = 1;
  56279. var height = 256;
  56280. var context = ol.dom.createCanvasContext2D(width, height);
  56281. var gradient = context.createLinearGradient(0, 0, width, height);
  56282. var step = 1 / (colors.length - 1);
  56283. for (var i = 0, ii = colors.length; i < ii; ++i) {
  56284. gradient.addColorStop(i * step, colors[i]);
  56285. }
  56286. context.fillStyle = gradient;
  56287. context.fillRect(0, 0, width, height);
  56288. return context.getImageData(0, 0, width, height).data;
  56289. };
  56290. /**
  56291. * @return {string} Data URL for a circle.
  56292. * @private
  56293. */
  56294. ol.layer.Heatmap.prototype.createCircle_ = function() {
  56295. var radius = this.getRadius();
  56296. var blur = this.getBlur();
  56297. var halfSize = radius + blur + 1;
  56298. var size = 2 * halfSize;
  56299. var context = ol.dom.createCanvasContext2D(size, size);
  56300. context.shadowOffsetX = context.shadowOffsetY = this.shadow_;
  56301. context.shadowBlur = blur;
  56302. context.shadowColor = '#000';
  56303. context.beginPath();
  56304. var center = halfSize - this.shadow_;
  56305. context.arc(center, center, radius, 0, Math.PI * 2, true);
  56306. context.fill();
  56307. return context.canvas.toDataURL();
  56308. };
  56309. /**
  56310. * Return the blur size in pixels.
  56311. * @return {number} Blur size in pixels.
  56312. * @api
  56313. * @observable
  56314. */
  56315. ol.layer.Heatmap.prototype.getBlur = function() {
  56316. return /** @type {number} */ (this.get(ol.layer.Heatmap.Property_.BLUR));
  56317. };
  56318. /**
  56319. * Return the gradient colors as array of strings.
  56320. * @return {Array.<string>} Colors.
  56321. * @api
  56322. * @observable
  56323. */
  56324. ol.layer.Heatmap.prototype.getGradient = function() {
  56325. return /** @type {Array.<string>} */ (
  56326. this.get(ol.layer.Heatmap.Property_.GRADIENT));
  56327. };
  56328. /**
  56329. * Return the size of the radius in pixels.
  56330. * @return {number} Radius size in pixel.
  56331. * @api
  56332. * @observable
  56333. */
  56334. ol.layer.Heatmap.prototype.getRadius = function() {
  56335. return /** @type {number} */ (this.get(ol.layer.Heatmap.Property_.RADIUS));
  56336. };
  56337. /**
  56338. * @private
  56339. */
  56340. ol.layer.Heatmap.prototype.handleGradientChanged_ = function() {
  56341. this.gradient_ = ol.layer.Heatmap.createGradient_(this.getGradient());
  56342. };
  56343. /**
  56344. * @private
  56345. */
  56346. ol.layer.Heatmap.prototype.handleStyleChanged_ = function() {
  56347. this.circleImage_ = this.createCircle_();
  56348. this.styleCache_ = new Array(256);
  56349. this.changed();
  56350. };
  56351. /**
  56352. * @param {ol.render.Event} event Post compose event
  56353. * @private
  56354. */
  56355. ol.layer.Heatmap.prototype.handleRender_ = function(event) {
  56356. var context = event.context;
  56357. var canvas = context.canvas;
  56358. var image = context.getImageData(0, 0, canvas.width, canvas.height);
  56359. var view8 = image.data;
  56360. var i, ii, alpha;
  56361. for (i = 0, ii = view8.length; i < ii; i += 4) {
  56362. alpha = view8[i + 3] * 4;
  56363. if (alpha) {
  56364. view8[i] = this.gradient_[alpha];
  56365. view8[i + 1] = this.gradient_[alpha + 1];
  56366. view8[i + 2] = this.gradient_[alpha + 2];
  56367. }
  56368. }
  56369. context.putImageData(image, 0, 0);
  56370. };
  56371. /**
  56372. * Set the blur size in pixels.
  56373. * @param {number} blur Blur size in pixels.
  56374. * @api
  56375. * @observable
  56376. */
  56377. ol.layer.Heatmap.prototype.setBlur = function(blur) {
  56378. this.set(ol.layer.Heatmap.Property_.BLUR, blur);
  56379. };
  56380. /**
  56381. * Set the gradient colors as array of strings.
  56382. * @param {Array.<string>} colors Gradient.
  56383. * @api
  56384. * @observable
  56385. */
  56386. ol.layer.Heatmap.prototype.setGradient = function(colors) {
  56387. this.set(ol.layer.Heatmap.Property_.GRADIENT, colors);
  56388. };
  56389. /**
  56390. * Set the size of the radius in pixels.
  56391. * @param {number} radius Radius size in pixel.
  56392. * @api
  56393. * @observable
  56394. */
  56395. ol.layer.Heatmap.prototype.setRadius = function(radius) {
  56396. this.set(ol.layer.Heatmap.Property_.RADIUS, radius);
  56397. };
  56398. /**
  56399. * @enum {string}
  56400. * @private
  56401. */
  56402. ol.layer.Heatmap.Property_ = {
  56403. BLUR: 'blur',
  56404. GRADIENT: 'gradient',
  56405. RADIUS: 'radius'
  56406. };
  56407. goog.provide('ol.layer.Image');
  56408. goog.require('ol');
  56409. goog.require('ol.LayerType');
  56410. goog.require('ol.layer.Layer');
  56411. /**
  56412. * @classdesc
  56413. * Server-rendered images that are available for arbitrary extents and
  56414. * resolutions.
  56415. * Note that any property set in the options is set as a {@link ol.Object}
  56416. * property on the layer object; for example, setting `title: 'My Title'` in the
  56417. * options means that `title` is observable, and has get/set accessors.
  56418. *
  56419. * @constructor
  56420. * @extends {ol.layer.Layer}
  56421. * @fires ol.render.Event
  56422. * @param {olx.layer.ImageOptions=} opt_options Layer options.
  56423. * @api
  56424. */
  56425. ol.layer.Image = function(opt_options) {
  56426. var options = opt_options ? opt_options : {};
  56427. ol.layer.Layer.call(this, /** @type {olx.layer.LayerOptions} */ (options));
  56428. /**
  56429. * The layer type.
  56430. * @protected
  56431. * @type {ol.LayerType}
  56432. */
  56433. this.type = ol.LayerType.IMAGE;
  56434. };
  56435. ol.inherits(ol.layer.Image, ol.layer.Layer);
  56436. /**
  56437. * Return the associated {@link ol.source.Image source} of the image layer.
  56438. * @function
  56439. * @return {ol.source.Image} Source.
  56440. * @api
  56441. */
  56442. ol.layer.Image.prototype.getSource;
  56443. goog.provide('ol.layer.TileProperty');
  56444. /**
  56445. * @enum {string}
  56446. */
  56447. ol.layer.TileProperty = {
  56448. PRELOAD: 'preload',
  56449. USE_INTERIM_TILES_ON_ERROR: 'useInterimTilesOnError'
  56450. };
  56451. goog.provide('ol.layer.Tile');
  56452. goog.require('ol');
  56453. goog.require('ol.LayerType');
  56454. goog.require('ol.layer.Layer');
  56455. goog.require('ol.layer.TileProperty');
  56456. goog.require('ol.obj');
  56457. /**
  56458. * @classdesc
  56459. * For layer sources that provide pre-rendered, tiled images in grids that are
  56460. * organized by zoom levels for specific resolutions.
  56461. * Note that any property set in the options is set as a {@link ol.Object}
  56462. * property on the layer object; for example, setting `title: 'My Title'` in the
  56463. * options means that `title` is observable, and has get/set accessors.
  56464. *
  56465. * @constructor
  56466. * @extends {ol.layer.Layer}
  56467. * @fires ol.render.Event
  56468. * @param {olx.layer.TileOptions=} opt_options Tile layer options.
  56469. * @api
  56470. */
  56471. ol.layer.Tile = function(opt_options) {
  56472. var options = opt_options ? opt_options : {};
  56473. var baseOptions = ol.obj.assign({}, options);
  56474. delete baseOptions.preload;
  56475. delete baseOptions.useInterimTilesOnError;
  56476. ol.layer.Layer.call(this, /** @type {olx.layer.LayerOptions} */ (baseOptions));
  56477. this.setPreload(options.preload !== undefined ? options.preload : 0);
  56478. this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
  56479. options.useInterimTilesOnError : true);
  56480. /**
  56481. * The layer type.
  56482. * @protected
  56483. * @type {ol.LayerType}
  56484. */
  56485. this.type = ol.LayerType.TILE;
  56486. };
  56487. ol.inherits(ol.layer.Tile, ol.layer.Layer);
  56488. /**
  56489. * Return the level as number to which we will preload tiles up to.
  56490. * @return {number} The level to preload tiles up to.
  56491. * @observable
  56492. * @api
  56493. */
  56494. ol.layer.Tile.prototype.getPreload = function() {
  56495. return /** @type {number} */ (this.get(ol.layer.TileProperty.PRELOAD));
  56496. };
  56497. /**
  56498. * Return the associated {@link ol.source.Tile tilesource} of the layer.
  56499. * @function
  56500. * @return {ol.source.Tile} Source.
  56501. * @api
  56502. */
  56503. ol.layer.Tile.prototype.getSource;
  56504. /**
  56505. * Set the level as number to which we will preload tiles up to.
  56506. * @param {number} preload The level to preload tiles up to.
  56507. * @observable
  56508. * @api
  56509. */
  56510. ol.layer.Tile.prototype.setPreload = function(preload) {
  56511. this.set(ol.layer.TileProperty.PRELOAD, preload);
  56512. };
  56513. /**
  56514. * Whether we use interim tiles on error.
  56515. * @return {boolean} Use interim tiles on error.
  56516. * @observable
  56517. * @api
  56518. */
  56519. ol.layer.Tile.prototype.getUseInterimTilesOnError = function() {
  56520. return /** @type {boolean} */ (
  56521. this.get(ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR));
  56522. };
  56523. /**
  56524. * Set whether we use interim tiles on error.
  56525. * @param {boolean} useInterimTilesOnError Use interim tiles on error.
  56526. * @observable
  56527. * @api
  56528. */
  56529. ol.layer.Tile.prototype.setUseInterimTilesOnError = function(useInterimTilesOnError) {
  56530. this.set(
  56531. ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
  56532. };
  56533. goog.provide('ol.layer.VectorTile');
  56534. goog.require('ol');
  56535. goog.require('ol.LayerType');
  56536. goog.require('ol.asserts');
  56537. goog.require('ol.layer.TileProperty');
  56538. goog.require('ol.layer.Vector');
  56539. goog.require('ol.layer.VectorTileRenderType');
  56540. goog.require('ol.obj');
  56541. /**
  56542. * @classdesc
  56543. * Layer for vector tile data that is rendered client-side.
  56544. * Note that any property set in the options is set as a {@link ol.Object}
  56545. * property on the layer object; for example, setting `title: 'My Title'` in the
  56546. * options means that `title` is observable, and has get/set accessors.
  56547. *
  56548. * @constructor
  56549. * @extends {ol.layer.Vector}
  56550. * @param {olx.layer.VectorTileOptions=} opt_options Options.
  56551. * @api
  56552. */
  56553. ol.layer.VectorTile = function(opt_options) {
  56554. var options = opt_options ? opt_options : {};
  56555. var renderMode = options.renderMode || ol.layer.VectorTileRenderType.HYBRID;
  56556. ol.asserts.assert(renderMode == undefined ||
  56557. renderMode == ol.layer.VectorTileRenderType.IMAGE ||
  56558. renderMode == ol.layer.VectorTileRenderType.HYBRID ||
  56559. renderMode == ol.layer.VectorTileRenderType.VECTOR,
  56560. 28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'`
  56561. if (options.declutter && renderMode == ol.layer.VectorTileRenderType.IMAGE) {
  56562. renderMode = ol.layer.VectorTileRenderType.HYBRID;
  56563. }
  56564. options.renderMode = renderMode;
  56565. var baseOptions = ol.obj.assign({}, options);
  56566. delete baseOptions.preload;
  56567. delete baseOptions.useInterimTilesOnError;
  56568. ol.layer.Vector.call(this, /** @type {olx.layer.VectorOptions} */ (baseOptions));
  56569. this.setPreload(options.preload ? options.preload : 0);
  56570. this.setUseInterimTilesOnError(options.useInterimTilesOnError ?
  56571. options.useInterimTilesOnError : true);
  56572. /**
  56573. * The layer type.
  56574. * @protected
  56575. * @type {ol.LayerType}
  56576. */
  56577. this.type = ol.LayerType.VECTOR_TILE;
  56578. };
  56579. ol.inherits(ol.layer.VectorTile, ol.layer.Vector);
  56580. /**
  56581. * Return the level as number to which we will preload tiles up to.
  56582. * @return {number} The level to preload tiles up to.
  56583. * @observable
  56584. * @api
  56585. */
  56586. ol.layer.VectorTile.prototype.getPreload = function() {
  56587. return /** @type {number} */ (this.get(ol.layer.TileProperty.PRELOAD));
  56588. };
  56589. /**
  56590. * Whether we use interim tiles on error.
  56591. * @return {boolean} Use interim tiles on error.
  56592. * @observable
  56593. * @api
  56594. */
  56595. ol.layer.VectorTile.prototype.getUseInterimTilesOnError = function() {
  56596. return /** @type {boolean} */ (
  56597. this.get(ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR));
  56598. };
  56599. /**
  56600. * Set the level as number to which we will preload tiles up to.
  56601. * @param {number} preload The level to preload tiles up to.
  56602. * @observable
  56603. * @api
  56604. */
  56605. ol.layer.VectorTile.prototype.setPreload = function(preload) {
  56606. this.set(ol.layer.TileProperty.PRELOAD, preload);
  56607. };
  56608. /**
  56609. * Set whether we use interim tiles on error.
  56610. * @param {boolean} useInterimTilesOnError Use interim tiles on error.
  56611. * @observable
  56612. * @api
  56613. */
  56614. ol.layer.VectorTile.prototype.setUseInterimTilesOnError = function(useInterimTilesOnError) {
  56615. this.set(
  56616. ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
  56617. };
  56618. /**
  56619. * Return the associated {@link ol.source.VectorTile vectortilesource} of the layer.
  56620. * @function
  56621. * @return {ol.source.VectorTile} Source.
  56622. * @api
  56623. */
  56624. ol.layer.VectorTile.prototype.getSource;
  56625. goog.provide('ol.webgl.Shader');
  56626. goog.require('ol.functions');
  56627. /**
  56628. * @constructor
  56629. * @abstract
  56630. * @param {string} source Source.
  56631. * @struct
  56632. */
  56633. ol.webgl.Shader = function(source) {
  56634. /**
  56635. * @private
  56636. * @type {string}
  56637. */
  56638. this.source_ = source;
  56639. };
  56640. /**
  56641. * @abstract
  56642. * @return {number} Type.
  56643. */
  56644. ol.webgl.Shader.prototype.getType = function() {};
  56645. /**
  56646. * @return {string} Source.
  56647. */
  56648. ol.webgl.Shader.prototype.getSource = function() {
  56649. return this.source_;
  56650. };
  56651. /**
  56652. * @return {boolean} Is animated?
  56653. */
  56654. ol.webgl.Shader.prototype.isAnimated = ol.functions.FALSE;
  56655. goog.provide('ol.webgl.Fragment');
  56656. goog.require('ol');
  56657. goog.require('ol.webgl');
  56658. goog.require('ol.webgl.Shader');
  56659. /**
  56660. * @constructor
  56661. * @extends {ol.webgl.Shader}
  56662. * @param {string} source Source.
  56663. * @struct
  56664. */
  56665. ol.webgl.Fragment = function(source) {
  56666. ol.webgl.Shader.call(this, source);
  56667. };
  56668. ol.inherits(ol.webgl.Fragment, ol.webgl.Shader);
  56669. /**
  56670. * @inheritDoc
  56671. */
  56672. ol.webgl.Fragment.prototype.getType = function() {
  56673. return ol.webgl.FRAGMENT_SHADER;
  56674. };
  56675. goog.provide('ol.webgl.Vertex');
  56676. goog.require('ol');
  56677. goog.require('ol.webgl');
  56678. goog.require('ol.webgl.Shader');
  56679. /**
  56680. * @constructor
  56681. * @extends {ol.webgl.Shader}
  56682. * @param {string} source Source.
  56683. * @struct
  56684. */
  56685. ol.webgl.Vertex = function(source) {
  56686. ol.webgl.Shader.call(this, source);
  56687. };
  56688. ol.inherits(ol.webgl.Vertex, ol.webgl.Shader);
  56689. /**
  56690. * @inheritDoc
  56691. */
  56692. ol.webgl.Vertex.prototype.getType = function() {
  56693. return ol.webgl.VERTEX_SHADER;
  56694. };
  56695. // This file is automatically generated, do not edit
  56696. goog.provide('ol.render.webgl.circlereplay.defaultshader');
  56697. goog.require('ol');
  56698. goog.require('ol.webgl.Fragment');
  56699. goog.require('ol.webgl.Vertex');
  56700. ol.render.webgl.circlereplay.defaultshader.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
  56701. 'precision mediump float;\nvarying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_fillColor;\nuniform vec4 u_strokeColor;\nuniform vec2 u_size;\n\nvoid main(void) {\n vec2 windowCenter = vec2((v_center.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_center.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n vec2 windowOffset = vec2((v_offset.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_offset.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n float radius = length(windowCenter - windowOffset);\n float dist = length(windowCenter - gl_FragCoord.xy);\n if (dist > radius + v_halfWidth) {\n if (u_strokeColor.a == 0.0) {\n gl_FragColor = u_fillColor;\n } else {\n gl_FragColor = u_strokeColor;\n }\n gl_FragColor.a = gl_FragColor.a - (dist - (radius + v_halfWidth));\n } else if (u_fillColor.a == 0.0) {\n // Hooray, no fill, just stroke. We can use real antialiasing.\n gl_FragColor = u_strokeColor;\n if (dist < radius - v_halfWidth) {\n gl_FragColor.a = gl_FragColor.a - (radius - v_halfWidth - dist);\n }\n } else {\n gl_FragColor = u_fillColor;\n float strokeDist = radius - v_halfWidth;\n float antialias = 2.0 * v_pixelRatio;\n if (dist > strokeDist) {\n gl_FragColor = u_strokeColor;\n } else if (dist >= strokeDist - antialias) {\n float step = smoothstep(strokeDist - antialias, strokeDist, dist);\n gl_FragColor = mix(u_fillColor, u_strokeColor, step);\n }\n }\n gl_FragColor.a = gl_FragColor.a * u_opacity;\n if (gl_FragColor.a <= 0.0) {\n discard;\n }\n}\n' :
  56702. 'precision mediump float;varying vec2 a;varying vec2 b;varying float c;varying float d;uniform float m;uniform vec4 n;uniform vec4 o;uniform vec2 p;void main(void){vec2 windowCenter=vec2((a.x+1.0)/2.0*p.x*d,(a.y+1.0)/2.0*p.y*d);vec2 windowOffset=vec2((b.x+1.0)/2.0*p.x*d,(b.y+1.0)/2.0*p.y*d);float radius=length(windowCenter-windowOffset);float dist=length(windowCenter-gl_FragCoord.xy);if(dist>radius+c){if(o.a==0.0){gl_FragColor=n;}else{gl_FragColor=o;}gl_FragColor.a=gl_FragColor.a-(dist-(radius+c));}else if(n.a==0.0){gl_FragColor=o;if(dist<radius-c){gl_FragColor.a=gl_FragColor.a-(radius-c-dist);}} else{gl_FragColor=n;float strokeDist=radius-c;float antialias=2.0*d;if(dist>strokeDist){gl_FragColor=o;}else if(dist>=strokeDist-antialias){float step=smoothstep(strokeDist-antialias,strokeDist,dist);gl_FragColor=mix(n,o,step);}} gl_FragColor.a=gl_FragColor.a*m;if(gl_FragColor.a<=0.0){discard;}}');
  56703. ol.render.webgl.circlereplay.defaultshader.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
  56704. 'varying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\nattribute vec2 a_position;\nattribute float a_instruction;\nattribute float a_radius;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\nuniform float u_lineWidth;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n v_center = vec4(u_projectionMatrix * vec4(a_position, 0.0, 1.0)).xy;\n v_pixelRatio = u_pixelRatio;\n float lineWidth = u_lineWidth * u_pixelRatio;\n v_halfWidth = lineWidth / 2.0;\n if (lineWidth == 0.0) {\n lineWidth = 2.0 * u_pixelRatio;\n }\n vec2 offset;\n // Radius with anitaliasing (roughly).\n float radius = a_radius + 3.0 * u_pixelRatio;\n // Until we get gl_VertexID in WebGL, we store an instruction.\n if (a_instruction == 0.0) {\n // Offsetting the edges of the triangle by lineWidth / 2 is necessary, however\n // we should also leave some space for the antialiasing, thus we offset by lineWidth.\n offset = vec2(-1.0, 1.0);\n } else if (a_instruction == 1.0) {\n offset = vec2(-1.0, -1.0);\n } else if (a_instruction == 2.0) {\n offset = vec2(1.0, -1.0);\n } else {\n offset = vec2(1.0, 1.0);\n }\n\n gl_Position = u_projectionMatrix * vec4(a_position + offset * radius, 0.0, 1.0) +\n offsetMatrix * vec4(offset * lineWidth, 0.0, 0.0);\n v_offset = vec4(u_projectionMatrix * vec4(a_position.x + a_radius, a_position.y,\n 0.0, 1.0)).xy;\n\n if (distance(v_center, v_offset) > 20000.0) {\n gl_Position = vec4(v_center, 0.0, 1.0);\n }\n}\n\n\n' :
  56705. 'varying vec2 a;varying vec2 b;varying float c;varying float d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;uniform float k;uniform float l;void main(void){mat4 offsetMatrix=i*j;a=vec4(h*vec4(e,0.0,1.0)).xy;d=l;float lineWidth=k*l;c=lineWidth/2.0;if(lineWidth==0.0){lineWidth=2.0*l;}vec2 offset;float radius=g+3.0*l;//Until we get gl_VertexID in WebGL,we store an instruction.if(f==0.0){//Offsetting the edges of the triangle by lineWidth/2 is necessary,however//we should also leave some space for the antialiasing,thus we offset by lineWidth.offset=vec2(-1.0,1.0);}else if(f==1.0){offset=vec2(-1.0,-1.0);}else if(f==2.0){offset=vec2(1.0,-1.0);}else{offset=vec2(1.0,1.0);}gl_Position=h*vec4(e+offset*radius,0.0,1.0)+offsetMatrix*vec4(offset*lineWidth,0.0,0.0);b=vec4(h*vec4(e.x+g,e.y,0.0,1.0)).xy;if(distance(a,b)>20000.0){gl_Position=vec4(a,0.0,1.0);}}');
  56706. // This file is automatically generated, do not edit
  56707. goog.provide('ol.render.webgl.circlereplay.defaultshader.Locations');
  56708. goog.require('ol');
  56709. /**
  56710. * @constructor
  56711. * @param {WebGLRenderingContext} gl GL.
  56712. * @param {WebGLProgram} program Program.
  56713. * @struct
  56714. */
  56715. ol.render.webgl.circlereplay.defaultshader.Locations = function(gl, program) {
  56716. /**
  56717. * @type {WebGLUniformLocation}
  56718. */
  56719. this.u_projectionMatrix = gl.getUniformLocation(
  56720. program, ol.DEBUG_WEBGL ? 'u_projectionMatrix' : 'h');
  56721. /**
  56722. * @type {WebGLUniformLocation}
  56723. */
  56724. this.u_offsetScaleMatrix = gl.getUniformLocation(
  56725. program, ol.DEBUG_WEBGL ? 'u_offsetScaleMatrix' : 'i');
  56726. /**
  56727. * @type {WebGLUniformLocation}
  56728. */
  56729. this.u_offsetRotateMatrix = gl.getUniformLocation(
  56730. program, ol.DEBUG_WEBGL ? 'u_offsetRotateMatrix' : 'j');
  56731. /**
  56732. * @type {WebGLUniformLocation}
  56733. */
  56734. this.u_lineWidth = gl.getUniformLocation(
  56735. program, ol.DEBUG_WEBGL ? 'u_lineWidth' : 'k');
  56736. /**
  56737. * @type {WebGLUniformLocation}
  56738. */
  56739. this.u_pixelRatio = gl.getUniformLocation(
  56740. program, ol.DEBUG_WEBGL ? 'u_pixelRatio' : 'l');
  56741. /**
  56742. * @type {WebGLUniformLocation}
  56743. */
  56744. this.u_opacity = gl.getUniformLocation(
  56745. program, ol.DEBUG_WEBGL ? 'u_opacity' : 'm');
  56746. /**
  56747. * @type {WebGLUniformLocation}
  56748. */
  56749. this.u_fillColor = gl.getUniformLocation(
  56750. program, ol.DEBUG_WEBGL ? 'u_fillColor' : 'n');
  56751. /**
  56752. * @type {WebGLUniformLocation}
  56753. */
  56754. this.u_strokeColor = gl.getUniformLocation(
  56755. program, ol.DEBUG_WEBGL ? 'u_strokeColor' : 'o');
  56756. /**
  56757. * @type {WebGLUniformLocation}
  56758. */
  56759. this.u_size = gl.getUniformLocation(
  56760. program, ol.DEBUG_WEBGL ? 'u_size' : 'p');
  56761. /**
  56762. * @type {number}
  56763. */
  56764. this.a_position = gl.getAttribLocation(
  56765. program, ol.DEBUG_WEBGL ? 'a_position' : 'e');
  56766. /**
  56767. * @type {number}
  56768. */
  56769. this.a_instruction = gl.getAttribLocation(
  56770. program, ol.DEBUG_WEBGL ? 'a_instruction' : 'f');
  56771. /**
  56772. * @type {number}
  56773. */
  56774. this.a_radius = gl.getAttribLocation(
  56775. program, ol.DEBUG_WEBGL ? 'a_radius' : 'g');
  56776. };
  56777. goog.provide('ol.vec.Mat4');
  56778. /**
  56779. * @return {Array.<number>} 4x4 matrix representing a 3D identity transform.
  56780. */
  56781. ol.vec.Mat4.create = function() {
  56782. return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  56783. };
  56784. /**
  56785. * @param {Array.<number>} mat4 Flattened 4x4 matrix receiving the result.
  56786. * @param {ol.Transform} transform Transformation matrix.
  56787. * @return {Array.<number>} 2D transformation matrix as flattened 4x4 matrix.
  56788. */
  56789. ol.vec.Mat4.fromTransform = function(mat4, transform) {
  56790. mat4[0] = transform[0];
  56791. mat4[1] = transform[1];
  56792. mat4[4] = transform[2];
  56793. mat4[5] = transform[3];
  56794. mat4[12] = transform[4];
  56795. mat4[13] = transform[5];
  56796. return mat4;
  56797. };
  56798. goog.provide('ol.render.webgl.Replay');
  56799. goog.require('ol');
  56800. goog.require('ol.extent');
  56801. goog.require('ol.render.VectorContext');
  56802. goog.require('ol.transform');
  56803. goog.require('ol.vec.Mat4');
  56804. goog.require('ol.webgl');
  56805. /**
  56806. * @constructor
  56807. * @abstract
  56808. * @extends {ol.render.VectorContext}
  56809. * @param {number} tolerance Tolerance.
  56810. * @param {ol.Extent} maxExtent Max extent.
  56811. * @struct
  56812. */
  56813. ol.render.webgl.Replay = function(tolerance, maxExtent) {
  56814. ol.render.VectorContext.call(this);
  56815. /**
  56816. * @protected
  56817. * @type {number}
  56818. */
  56819. this.tolerance = tolerance;
  56820. /**
  56821. * @protected
  56822. * @const
  56823. * @type {ol.Extent}
  56824. */
  56825. this.maxExtent = maxExtent;
  56826. /**
  56827. * The origin of the coordinate system for the point coordinates sent to
  56828. * the GPU. To eliminate jitter caused by precision problems in the GPU
  56829. * we use the "Rendering Relative to Eye" technique described in the "3D
  56830. * Engine Design for Virtual Globes" book.
  56831. * @protected
  56832. * @type {ol.Coordinate}
  56833. */
  56834. this.origin = ol.extent.getCenter(maxExtent);
  56835. /**
  56836. * @private
  56837. * @type {ol.Transform}
  56838. */
  56839. this.projectionMatrix_ = ol.transform.create();
  56840. /**
  56841. * @private
  56842. * @type {ol.Transform}
  56843. */
  56844. this.offsetRotateMatrix_ = ol.transform.create();
  56845. /**
  56846. * @private
  56847. * @type {ol.Transform}
  56848. */
  56849. this.offsetScaleMatrix_ = ol.transform.create();
  56850. /**
  56851. * @private
  56852. * @type {Array.<number>}
  56853. */
  56854. this.tmpMat4_ = ol.vec.Mat4.create();
  56855. /**
  56856. * @protected
  56857. * @type {Array.<number>}
  56858. */
  56859. this.indices = [];
  56860. /**
  56861. * @protected
  56862. * @type {?ol.webgl.Buffer}
  56863. */
  56864. this.indicesBuffer = null;
  56865. /**
  56866. * Start index per feature (the index).
  56867. * @protected
  56868. * @type {Array.<number>}
  56869. */
  56870. this.startIndices = [];
  56871. /**
  56872. * Start index per feature (the feature).
  56873. * @protected
  56874. * @type {Array.<ol.Feature|ol.render.Feature>}
  56875. */
  56876. this.startIndicesFeature = [];
  56877. /**
  56878. * @protected
  56879. * @type {Array.<number>}
  56880. */
  56881. this.vertices = [];
  56882. /**
  56883. * @protected
  56884. * @type {?ol.webgl.Buffer}
  56885. */
  56886. this.verticesBuffer = null;
  56887. /**
  56888. * Optional parameter for PolygonReplay instances.
  56889. * @protected
  56890. * @type {ol.render.webgl.LineStringReplay|undefined}
  56891. */
  56892. this.lineStringReplay = undefined;
  56893. };
  56894. ol.inherits(ol.render.webgl.Replay, ol.render.VectorContext);
  56895. /**
  56896. * @abstract
  56897. * @param {ol.webgl.Context} context WebGL context.
  56898. * @return {function()} Delete resources function.
  56899. */
  56900. ol.render.webgl.Replay.prototype.getDeleteResourcesFunction = function(context) {};
  56901. /**
  56902. * @abstract
  56903. * @param {ol.webgl.Context} context Context.
  56904. */
  56905. ol.render.webgl.Replay.prototype.finish = function(context) {};
  56906. /**
  56907. * @abstract
  56908. * @protected
  56909. * @param {WebGLRenderingContext} gl gl.
  56910. * @param {ol.webgl.Context} context Context.
  56911. * @param {ol.Size} size Size.
  56912. * @param {number} pixelRatio Pixel ratio.
  56913. * @return {ol.render.webgl.circlereplay.defaultshader.Locations|
  56914. ol.render.webgl.linestringreplay.defaultshader.Locations|
  56915. ol.render.webgl.polygonreplay.defaultshader.Locations|
  56916. ol.render.webgl.texturereplay.defaultshader.Locations} Locations.
  56917. */
  56918. ol.render.webgl.Replay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {};
  56919. /**
  56920. * @abstract
  56921. * @protected
  56922. * @param {WebGLRenderingContext} gl gl.
  56923. * @param {ol.render.webgl.circlereplay.defaultshader.Locations|
  56924. ol.render.webgl.linestringreplay.defaultshader.Locations|
  56925. ol.render.webgl.polygonreplay.defaultshader.Locations|
  56926. ol.render.webgl.texturereplay.defaultshader.Locations} locations Locations.
  56927. */
  56928. ol.render.webgl.Replay.prototype.shutDownProgram = function(gl, locations) {};
  56929. /**
  56930. * @abstract
  56931. * @protected
  56932. * @param {WebGLRenderingContext} gl gl.
  56933. * @param {ol.webgl.Context} context Context.
  56934. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  56935. * to skip.
  56936. * @param {boolean} hitDetection Hit detection mode.
  56937. */
  56938. ol.render.webgl.Replay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {};
  56939. /**
  56940. * @abstract
  56941. * @protected
  56942. * @param {WebGLRenderingContext} gl gl.
  56943. * @param {ol.webgl.Context} context Context.
  56944. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  56945. * to skip.
  56946. * @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
  56947. * @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
  56948. * this extent are checked.
  56949. * @return {T|undefined} Callback result.
  56950. * @template T
  56951. */
  56952. ol.render.webgl.Replay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, featureCallback, opt_hitExtent) {};
  56953. /**
  56954. * @protected
  56955. * @param {WebGLRenderingContext} gl gl.
  56956. * @param {ol.webgl.Context} context Context.
  56957. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  56958. * to skip.
  56959. * @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
  56960. * @param {boolean} oneByOne Draw features one-by-one for the hit-detecion.
  56961. * @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
  56962. * this extent are checked.
  56963. * @return {T|undefined} Callback result.
  56964. * @template T
  56965. */
  56966. ol.render.webgl.Replay.prototype.drawHitDetectionReplay = function(gl, context, skippedFeaturesHash,
  56967. featureCallback, oneByOne, opt_hitExtent) {
  56968. if (!oneByOne) {
  56969. // draw all hit-detection features in "once" (by texture group)
  56970. return this.drawHitDetectionReplayAll(gl, context,
  56971. skippedFeaturesHash, featureCallback);
  56972. } else {
  56973. // draw hit-detection features one by one
  56974. return this.drawHitDetectionReplayOneByOne(gl, context,
  56975. skippedFeaturesHash, featureCallback, opt_hitExtent);
  56976. }
  56977. };
  56978. /**
  56979. * @protected
  56980. * @param {WebGLRenderingContext} gl gl.
  56981. * @param {ol.webgl.Context} context Context.
  56982. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  56983. * to skip.
  56984. * @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
  56985. * @return {T|undefined} Callback result.
  56986. * @template T
  56987. */
  56988. ol.render.webgl.Replay.prototype.drawHitDetectionReplayAll = function(gl, context, skippedFeaturesHash,
  56989. featureCallback) {
  56990. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  56991. this.drawReplay(gl, context, skippedFeaturesHash, true);
  56992. var result = featureCallback(null);
  56993. if (result) {
  56994. return result;
  56995. } else {
  56996. return undefined;
  56997. }
  56998. };
  56999. /**
  57000. * @param {ol.webgl.Context} context Context.
  57001. * @param {ol.Coordinate} center Center.
  57002. * @param {number} resolution Resolution.
  57003. * @param {number} rotation Rotation.
  57004. * @param {ol.Size} size Size.
  57005. * @param {number} pixelRatio Pixel ratio.
  57006. * @param {number} opacity Global opacity.
  57007. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  57008. * to skip.
  57009. * @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
  57010. * @param {boolean} oneByOne Draw features one-by-one for the hit-detecion.
  57011. * @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
  57012. * this extent are checked.
  57013. * @return {T|undefined} Callback result.
  57014. * @template T
  57015. */
  57016. ol.render.webgl.Replay.prototype.replay = function(context,
  57017. center, resolution, rotation, size, pixelRatio,
  57018. opacity, skippedFeaturesHash,
  57019. featureCallback, oneByOne, opt_hitExtent) {
  57020. var gl = context.getGL();
  57021. var tmpStencil, tmpStencilFunc, tmpStencilMaskVal, tmpStencilRef, tmpStencilMask,
  57022. tmpStencilOpFail, tmpStencilOpPass, tmpStencilOpZFail;
  57023. if (this.lineStringReplay) {
  57024. tmpStencil = gl.isEnabled(gl.STENCIL_TEST);
  57025. tmpStencilFunc = gl.getParameter(gl.STENCIL_FUNC);
  57026. tmpStencilMaskVal = gl.getParameter(gl.STENCIL_VALUE_MASK);
  57027. tmpStencilRef = gl.getParameter(gl.STENCIL_REF);
  57028. tmpStencilMask = gl.getParameter(gl.STENCIL_WRITEMASK);
  57029. tmpStencilOpFail = gl.getParameter(gl.STENCIL_FAIL);
  57030. tmpStencilOpPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
  57031. tmpStencilOpZFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
  57032. gl.enable(gl.STENCIL_TEST);
  57033. gl.clear(gl.STENCIL_BUFFER_BIT);
  57034. gl.stencilMask(255);
  57035. gl.stencilFunc(gl.ALWAYS, 1, 255);
  57036. gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
  57037. this.lineStringReplay.replay(context,
  57038. center, resolution, rotation, size, pixelRatio,
  57039. opacity, skippedFeaturesHash,
  57040. featureCallback, oneByOne, opt_hitExtent);
  57041. gl.stencilMask(0);
  57042. gl.stencilFunc(gl.NOTEQUAL, 1, 255);
  57043. }
  57044. context.bindBuffer(ol.webgl.ARRAY_BUFFER, this.verticesBuffer);
  57045. context.bindBuffer(ol.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  57046. var locations = this.setUpProgram(gl, context, size, pixelRatio);
  57047. // set the "uniform" values
  57048. var projectionMatrix = ol.transform.reset(this.projectionMatrix_);
  57049. ol.transform.scale(projectionMatrix, 2 / (resolution * size[0]), 2 / (resolution * size[1]));
  57050. ol.transform.rotate(projectionMatrix, -rotation);
  57051. ol.transform.translate(projectionMatrix, -(center[0] - this.origin[0]), -(center[1] - this.origin[1]));
  57052. var offsetScaleMatrix = ol.transform.reset(this.offsetScaleMatrix_);
  57053. ol.transform.scale(offsetScaleMatrix, 2 / size[0], 2 / size[1]);
  57054. var offsetRotateMatrix = ol.transform.reset(this.offsetRotateMatrix_);
  57055. if (rotation !== 0) {
  57056. ol.transform.rotate(offsetRotateMatrix, -rotation);
  57057. }
  57058. gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
  57059. ol.vec.Mat4.fromTransform(this.tmpMat4_, projectionMatrix));
  57060. gl.uniformMatrix4fv(locations.u_offsetScaleMatrix, false,
  57061. ol.vec.Mat4.fromTransform(this.tmpMat4_, offsetScaleMatrix));
  57062. gl.uniformMatrix4fv(locations.u_offsetRotateMatrix, false,
  57063. ol.vec.Mat4.fromTransform(this.tmpMat4_, offsetRotateMatrix));
  57064. gl.uniform1f(locations.u_opacity, opacity);
  57065. // draw!
  57066. var result;
  57067. if (featureCallback === undefined) {
  57068. this.drawReplay(gl, context, skippedFeaturesHash, false);
  57069. } else {
  57070. // draw feature by feature for the hit-detection
  57071. result = this.drawHitDetectionReplay(gl, context, skippedFeaturesHash,
  57072. featureCallback, oneByOne, opt_hitExtent);
  57073. }
  57074. // disable the vertex attrib arrays
  57075. this.shutDownProgram(gl, locations);
  57076. if (this.lineStringReplay) {
  57077. if (!tmpStencil) {
  57078. gl.disable(gl.STENCIL_TEST);
  57079. }
  57080. gl.clear(gl.STENCIL_BUFFER_BIT);
  57081. gl.stencilFunc(/** @type {number} */ (tmpStencilFunc),
  57082. /** @type {number} */ (tmpStencilRef), /** @type {number} */ (tmpStencilMaskVal));
  57083. gl.stencilMask(/** @type {number} */ (tmpStencilMask));
  57084. gl.stencilOp(/** @type {number} */ (tmpStencilOpFail),
  57085. /** @type {number} */ (tmpStencilOpZFail), /** @type {number} */ (tmpStencilOpPass));
  57086. }
  57087. return result;
  57088. };
  57089. /**
  57090. * @protected
  57091. * @param {WebGLRenderingContext} gl gl.
  57092. * @param {ol.webgl.Context} context Context.
  57093. * @param {number} start Start index.
  57094. * @param {number} end End index.
  57095. */
  57096. ol.render.webgl.Replay.prototype.drawElements = function(
  57097. gl, context, start, end) {
  57098. var elementType = context.hasOESElementIndexUint ?
  57099. ol.webgl.UNSIGNED_INT : ol.webgl.UNSIGNED_SHORT;
  57100. var elementSize = context.hasOESElementIndexUint ? 4 : 2;
  57101. var numItems = end - start;
  57102. var offsetInBytes = start * elementSize;
  57103. gl.drawElements(ol.webgl.TRIANGLES, numItems, elementType, offsetInBytes);
  57104. };
  57105. goog.provide('ol.render.webgl');
  57106. /**
  57107. * @const
  57108. * @type {string}
  57109. */
  57110. ol.render.webgl.defaultFont = '10px sans-serif';
  57111. /**
  57112. * @const
  57113. * @type {ol.Color}
  57114. */
  57115. ol.render.webgl.defaultFillStyle = [0.0, 0.0, 0.0, 1.0];
  57116. /**
  57117. * @const
  57118. * @type {string}
  57119. */
  57120. ol.render.webgl.defaultLineCap = 'round';
  57121. /**
  57122. * @const
  57123. * @type {Array.<number>}
  57124. */
  57125. ol.render.webgl.defaultLineDash = [];
  57126. /**
  57127. * @const
  57128. * @type {number}
  57129. */
  57130. ol.render.webgl.defaultLineDashOffset = 0;
  57131. /**
  57132. * @const
  57133. * @type {string}
  57134. */
  57135. ol.render.webgl.defaultLineJoin = 'round';
  57136. /**
  57137. * @const
  57138. * @type {number}
  57139. */
  57140. ol.render.webgl.defaultMiterLimit = 10;
  57141. /**
  57142. * @const
  57143. * @type {ol.Color}
  57144. */
  57145. ol.render.webgl.defaultStrokeStyle = [0.0, 0.0, 0.0, 1.0];
  57146. /**
  57147. * @const
  57148. * @type {number}
  57149. */
  57150. ol.render.webgl.defaultTextAlign = 0.5;
  57151. /**
  57152. * @const
  57153. * @type {number}
  57154. */
  57155. ol.render.webgl.defaultTextBaseline = 0.5;
  57156. /**
  57157. * @const
  57158. * @type {number}
  57159. */
  57160. ol.render.webgl.defaultLineWidth = 1;
  57161. /**
  57162. * Calculates the orientation of a triangle based on the determinant method.
  57163. * @param {number} x1 First X coordinate.
  57164. * @param {number} y1 First Y coordinate.
  57165. * @param {number} x2 Second X coordinate.
  57166. * @param {number} y2 Second Y coordinate.
  57167. * @param {number} x3 Third X coordinate.
  57168. * @param {number} y3 Third Y coordinate.
  57169. * @return {boolean|undefined} Triangle is clockwise.
  57170. */
  57171. ol.render.webgl.triangleIsCounterClockwise = function(x1, y1, x2, y2, x3, y3) {
  57172. var area = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
  57173. return (area <= ol.render.webgl.EPSILON && area >= -ol.render.webgl.EPSILON) ?
  57174. undefined : area > 0;
  57175. };
  57176. /**
  57177. * @const
  57178. * @type {number}
  57179. */
  57180. ol.render.webgl.EPSILON = Number.EPSILON || 2.220446049250313e-16;
  57181. goog.provide('ol.webgl.Buffer');
  57182. goog.require('ol.webgl');
  57183. /**
  57184. * @constructor
  57185. * @param {Array.<number>=} opt_arr Array.
  57186. * @param {number=} opt_usage Usage.
  57187. * @struct
  57188. */
  57189. ol.webgl.Buffer = function(opt_arr, opt_usage) {
  57190. /**
  57191. * @private
  57192. * @type {Array.<number>}
  57193. */
  57194. this.arr_ = opt_arr !== undefined ? opt_arr : [];
  57195. /**
  57196. * @private
  57197. * @type {number}
  57198. */
  57199. this.usage_ = opt_usage !== undefined ?
  57200. opt_usage : ol.webgl.Buffer.Usage_.STATIC_DRAW;
  57201. };
  57202. /**
  57203. * @return {Array.<number>} Array.
  57204. */
  57205. ol.webgl.Buffer.prototype.getArray = function() {
  57206. return this.arr_;
  57207. };
  57208. /**
  57209. * @return {number} Usage.
  57210. */
  57211. ol.webgl.Buffer.prototype.getUsage = function() {
  57212. return this.usage_;
  57213. };
  57214. /**
  57215. * @enum {number}
  57216. * @private
  57217. */
  57218. ol.webgl.Buffer.Usage_ = {
  57219. STATIC_DRAW: ol.webgl.STATIC_DRAW,
  57220. STREAM_DRAW: ol.webgl.STREAM_DRAW,
  57221. DYNAMIC_DRAW: ol.webgl.DYNAMIC_DRAW
  57222. };
  57223. goog.provide('ol.render.webgl.CircleReplay');
  57224. goog.require('ol');
  57225. goog.require('ol.array');
  57226. goog.require('ol.color');
  57227. goog.require('ol.extent');
  57228. goog.require('ol.obj');
  57229. goog.require('ol.geom.flat.transform');
  57230. goog.require('ol.render.webgl.circlereplay.defaultshader');
  57231. goog.require('ol.render.webgl.circlereplay.defaultshader.Locations');
  57232. goog.require('ol.render.webgl.Replay');
  57233. goog.require('ol.render.webgl');
  57234. goog.require('ol.webgl');
  57235. goog.require('ol.webgl.Buffer');
  57236. /**
  57237. * @constructor
  57238. * @extends {ol.render.webgl.Replay}
  57239. * @param {number} tolerance Tolerance.
  57240. * @param {ol.Extent} maxExtent Max extent.
  57241. * @struct
  57242. */
  57243. ol.render.webgl.CircleReplay = function(tolerance, maxExtent) {
  57244. ol.render.webgl.Replay.call(this, tolerance, maxExtent);
  57245. /**
  57246. * @private
  57247. * @type {ol.render.webgl.circlereplay.defaultshader.Locations}
  57248. */
  57249. this.defaultLocations_ = null;
  57250. /**
  57251. * @private
  57252. * @type {Array.<Array.<Array.<number>|number>>}
  57253. */
  57254. this.styles_ = [];
  57255. /**
  57256. * @private
  57257. * @type {Array.<number>}
  57258. */
  57259. this.styleIndices_ = [];
  57260. /**
  57261. * @private
  57262. * @type {number}
  57263. */
  57264. this.radius_ = 0;
  57265. /**
  57266. * @private
  57267. * @type {{fillColor: (Array.<number>|null),
  57268. * strokeColor: (Array.<number>|null),
  57269. * lineDash: Array.<number>,
  57270. * lineDashOffset: (number|undefined),
  57271. * lineWidth: (number|undefined),
  57272. * changed: boolean}|null}
  57273. */
  57274. this.state_ = {
  57275. fillColor: null,
  57276. strokeColor: null,
  57277. lineDash: null,
  57278. lineDashOffset: undefined,
  57279. lineWidth: undefined,
  57280. changed: false
  57281. };
  57282. };
  57283. ol.inherits(ol.render.webgl.CircleReplay, ol.render.webgl.Replay);
  57284. /**
  57285. * @private
  57286. * @param {Array.<number>} flatCoordinates Flat coordinates.
  57287. * @param {number} offset Offset.
  57288. * @param {number} end End.
  57289. * @param {number} stride Stride.
  57290. */
  57291. ol.render.webgl.CircleReplay.prototype.drawCoordinates_ = function(
  57292. flatCoordinates, offset, end, stride) {
  57293. var numVertices = this.vertices.length;
  57294. var numIndices = this.indices.length;
  57295. var n = numVertices / 4;
  57296. var i, ii;
  57297. for (i = offset, ii = end; i < ii; i += stride) {
  57298. this.vertices[numVertices++] = flatCoordinates[i];
  57299. this.vertices[numVertices++] = flatCoordinates[i + 1];
  57300. this.vertices[numVertices++] = 0;
  57301. this.vertices[numVertices++] = this.radius_;
  57302. this.vertices[numVertices++] = flatCoordinates[i];
  57303. this.vertices[numVertices++] = flatCoordinates[i + 1];
  57304. this.vertices[numVertices++] = 1;
  57305. this.vertices[numVertices++] = this.radius_;
  57306. this.vertices[numVertices++] = flatCoordinates[i];
  57307. this.vertices[numVertices++] = flatCoordinates[i + 1];
  57308. this.vertices[numVertices++] = 2;
  57309. this.vertices[numVertices++] = this.radius_;
  57310. this.vertices[numVertices++] = flatCoordinates[i];
  57311. this.vertices[numVertices++] = flatCoordinates[i + 1];
  57312. this.vertices[numVertices++] = 3;
  57313. this.vertices[numVertices++] = this.radius_;
  57314. this.indices[numIndices++] = n;
  57315. this.indices[numIndices++] = n + 1;
  57316. this.indices[numIndices++] = n + 2;
  57317. this.indices[numIndices++] = n + 2;
  57318. this.indices[numIndices++] = n + 3;
  57319. this.indices[numIndices++] = n;
  57320. n += 4;
  57321. }
  57322. };
  57323. /**
  57324. * @inheritDoc
  57325. */
  57326. ol.render.webgl.CircleReplay.prototype.drawCircle = function(circleGeometry, feature) {
  57327. var radius = circleGeometry.getRadius();
  57328. var stride = circleGeometry.getStride();
  57329. if (radius) {
  57330. this.startIndices.push(this.indices.length);
  57331. this.startIndicesFeature.push(feature);
  57332. if (this.state_.changed) {
  57333. this.styleIndices_.push(this.indices.length);
  57334. this.state_.changed = false;
  57335. }
  57336. this.radius_ = radius;
  57337. var flatCoordinates = circleGeometry.getFlatCoordinates();
  57338. flatCoordinates = ol.geom.flat.transform.translate(flatCoordinates, 0, 2,
  57339. stride, -this.origin[0], -this.origin[1]);
  57340. this.drawCoordinates_(flatCoordinates, 0, 2, stride);
  57341. } else {
  57342. if (this.state_.changed) {
  57343. this.styles_.pop();
  57344. if (this.styles_.length) {
  57345. var lastState = this.styles_[this.styles_.length - 1];
  57346. this.state_.fillColor = /** @type {Array.<number>} */ (lastState[0]);
  57347. this.state_.strokeColor = /** @type {Array.<number>} */ (lastState[1]);
  57348. this.state_.lineWidth = /** @type {number} */ (lastState[2]);
  57349. this.state_.changed = false;
  57350. }
  57351. }
  57352. }
  57353. };
  57354. /**
  57355. * @inheritDoc
  57356. **/
  57357. ol.render.webgl.CircleReplay.prototype.finish = function(context) {
  57358. // create, bind, and populate the vertices buffer
  57359. this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
  57360. // create, bind, and populate the indices buffer
  57361. this.indicesBuffer = new ol.webgl.Buffer(this.indices);
  57362. this.startIndices.push(this.indices.length);
  57363. //Clean up, if there is nothing to draw
  57364. if (this.styleIndices_.length === 0 && this.styles_.length > 0) {
  57365. this.styles_ = [];
  57366. }
  57367. this.vertices = null;
  57368. this.indices = null;
  57369. };
  57370. /**
  57371. * @inheritDoc
  57372. */
  57373. ol.render.webgl.CircleReplay.prototype.getDeleteResourcesFunction = function(context) {
  57374. // We only delete our stuff here. The shaders and the program may
  57375. // be used by other CircleReplay instances (for other layers). And
  57376. // they will be deleted when disposing of the ol.webgl.Context
  57377. // object.
  57378. var verticesBuffer = this.verticesBuffer;
  57379. var indicesBuffer = this.indicesBuffer;
  57380. return function() {
  57381. context.deleteBuffer(verticesBuffer);
  57382. context.deleteBuffer(indicesBuffer);
  57383. };
  57384. };
  57385. /**
  57386. * @inheritDoc
  57387. */
  57388. ol.render.webgl.CircleReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
  57389. // get the program
  57390. var fragmentShader, vertexShader;
  57391. fragmentShader = ol.render.webgl.circlereplay.defaultshader.fragment;
  57392. vertexShader = ol.render.webgl.circlereplay.defaultshader.vertex;
  57393. var program = context.getProgram(fragmentShader, vertexShader);
  57394. // get the locations
  57395. var locations;
  57396. if (!this.defaultLocations_) {
  57397. locations = new ol.render.webgl.circlereplay.defaultshader.Locations(gl, program);
  57398. this.defaultLocations_ = locations;
  57399. } else {
  57400. locations = this.defaultLocations_;
  57401. }
  57402. context.useProgram(program);
  57403. // enable the vertex attrib arrays
  57404. gl.enableVertexAttribArray(locations.a_position);
  57405. gl.vertexAttribPointer(locations.a_position, 2, ol.webgl.FLOAT,
  57406. false, 16, 0);
  57407. gl.enableVertexAttribArray(locations.a_instruction);
  57408. gl.vertexAttribPointer(locations.a_instruction, 1, ol.webgl.FLOAT,
  57409. false, 16, 8);
  57410. gl.enableVertexAttribArray(locations.a_radius);
  57411. gl.vertexAttribPointer(locations.a_radius, 1, ol.webgl.FLOAT,
  57412. false, 16, 12);
  57413. // Enable renderer specific uniforms.
  57414. gl.uniform2fv(locations.u_size, size);
  57415. gl.uniform1f(locations.u_pixelRatio, pixelRatio);
  57416. return locations;
  57417. };
  57418. /**
  57419. * @inheritDoc
  57420. */
  57421. ol.render.webgl.CircleReplay.prototype.shutDownProgram = function(gl, locations) {
  57422. gl.disableVertexAttribArray(locations.a_position);
  57423. gl.disableVertexAttribArray(locations.a_instruction);
  57424. gl.disableVertexAttribArray(locations.a_radius);
  57425. };
  57426. /**
  57427. * @inheritDoc
  57428. */
  57429. ol.render.webgl.CircleReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
  57430. if (!ol.obj.isEmpty(skippedFeaturesHash)) {
  57431. this.drawReplaySkipping_(gl, context, skippedFeaturesHash);
  57432. } else {
  57433. //Draw by style groups to minimize drawElements() calls.
  57434. var i, start, end, nextStyle;
  57435. end = this.startIndices[this.startIndices.length - 1];
  57436. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  57437. start = this.styleIndices_[i];
  57438. nextStyle = this.styles_[i];
  57439. this.setFillStyle_(gl, /** @type {Array.<number>} */ (nextStyle[0]));
  57440. this.setStrokeStyle_(gl, /** @type {Array.<number>} */ (nextStyle[1]),
  57441. /** @type {number} */ (nextStyle[2]));
  57442. this.drawElements(gl, context, start, end);
  57443. end = start;
  57444. }
  57445. }
  57446. };
  57447. /**
  57448. * @inheritDoc
  57449. */
  57450. ol.render.webgl.CircleReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
  57451. featureCallback, opt_hitExtent) {
  57452. var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
  57453. featureIndex = this.startIndices.length - 2;
  57454. end = this.startIndices[featureIndex + 1];
  57455. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  57456. nextStyle = this.styles_[i];
  57457. this.setFillStyle_(gl, /** @type {Array.<number>} */ (nextStyle[0]));
  57458. this.setStrokeStyle_(gl, /** @type {Array.<number>} */ (nextStyle[1]),
  57459. /** @type {number} */ (nextStyle[2]));
  57460. groupStart = this.styleIndices_[i];
  57461. while (featureIndex >= 0 &&
  57462. this.startIndices[featureIndex] >= groupStart) {
  57463. start = this.startIndices[featureIndex];
  57464. feature = this.startIndicesFeature[featureIndex];
  57465. featureUid = ol.getUid(feature).toString();
  57466. if (skippedFeaturesHash[featureUid] === undefined &&
  57467. feature.getGeometry() &&
  57468. (opt_hitExtent === undefined || ol.extent.intersects(
  57469. /** @type {Array<number>} */ (opt_hitExtent),
  57470. feature.getGeometry().getExtent()))) {
  57471. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  57472. this.drawElements(gl, context, start, end);
  57473. var result = featureCallback(feature);
  57474. if (result) {
  57475. return result;
  57476. }
  57477. }
  57478. featureIndex--;
  57479. end = start;
  57480. }
  57481. }
  57482. return undefined;
  57483. };
  57484. /**
  57485. * @private
  57486. * @param {WebGLRenderingContext} gl gl.
  57487. * @param {ol.webgl.Context} context Context.
  57488. * @param {Object} skippedFeaturesHash Ids of features to skip.
  57489. */
  57490. ol.render.webgl.CircleReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
  57491. var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
  57492. featureIndex = this.startIndices.length - 2;
  57493. end = start = this.startIndices[featureIndex + 1];
  57494. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  57495. nextStyle = this.styles_[i];
  57496. this.setFillStyle_(gl, /** @type {Array.<number>} */ (nextStyle[0]));
  57497. this.setStrokeStyle_(gl, /** @type {Array.<number>} */ (nextStyle[1]),
  57498. /** @type {number} */ (nextStyle[2]));
  57499. groupStart = this.styleIndices_[i];
  57500. while (featureIndex >= 0 &&
  57501. this.startIndices[featureIndex] >= groupStart) {
  57502. featureStart = this.startIndices[featureIndex];
  57503. feature = this.startIndicesFeature[featureIndex];
  57504. featureUid = ol.getUid(feature).toString();
  57505. if (skippedFeaturesHash[featureUid]) {
  57506. if (start !== end) {
  57507. this.drawElements(gl, context, start, end);
  57508. }
  57509. end = featureStart;
  57510. }
  57511. featureIndex--;
  57512. start = featureStart;
  57513. }
  57514. if (start !== end) {
  57515. this.drawElements(gl, context, start, end);
  57516. }
  57517. start = end = groupStart;
  57518. }
  57519. };
  57520. /**
  57521. * @private
  57522. * @param {WebGLRenderingContext} gl gl.
  57523. * @param {Array.<number>} color Color.
  57524. */
  57525. ol.render.webgl.CircleReplay.prototype.setFillStyle_ = function(gl, color) {
  57526. gl.uniform4fv(this.defaultLocations_.u_fillColor, color);
  57527. };
  57528. /**
  57529. * @private
  57530. * @param {WebGLRenderingContext} gl gl.
  57531. * @param {Array.<number>} color Color.
  57532. * @param {number} lineWidth Line width.
  57533. */
  57534. ol.render.webgl.CircleReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth) {
  57535. gl.uniform4fv(this.defaultLocations_.u_strokeColor, color);
  57536. gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth);
  57537. };
  57538. /**
  57539. * @inheritDoc
  57540. */
  57541. ol.render.webgl.CircleReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
  57542. var strokeStyleColor, strokeStyleWidth;
  57543. if (strokeStyle) {
  57544. var strokeStyleLineDash = strokeStyle.getLineDash();
  57545. this.state_.lineDash = strokeStyleLineDash ?
  57546. strokeStyleLineDash : ol.render.webgl.defaultLineDash;
  57547. var strokeStyleLineDashOffset = strokeStyle.getLineDashOffset();
  57548. this.state_.lineDashOffset = strokeStyleLineDashOffset ?
  57549. strokeStyleLineDashOffset : ol.render.webgl.defaultLineDashOffset;
  57550. strokeStyleColor = strokeStyle.getColor();
  57551. if (!(strokeStyleColor instanceof CanvasGradient) &&
  57552. !(strokeStyleColor instanceof CanvasPattern)) {
  57553. strokeStyleColor = ol.color.asArray(strokeStyleColor).map(function(c, i) {
  57554. return i != 3 ? c / 255 : c;
  57555. }) || ol.render.webgl.defaultStrokeStyle;
  57556. } else {
  57557. strokeStyleColor = ol.render.webgl.defaultStrokeStyle;
  57558. }
  57559. strokeStyleWidth = strokeStyle.getWidth();
  57560. strokeStyleWidth = strokeStyleWidth !== undefined ?
  57561. strokeStyleWidth : ol.render.webgl.defaultLineWidth;
  57562. } else {
  57563. strokeStyleColor = [0, 0, 0, 0];
  57564. strokeStyleWidth = 0;
  57565. }
  57566. var fillStyleColor = fillStyle ? fillStyle.getColor() : [0, 0, 0, 0];
  57567. if (!(fillStyleColor instanceof CanvasGradient) &&
  57568. !(fillStyleColor instanceof CanvasPattern)) {
  57569. fillStyleColor = ol.color.asArray(fillStyleColor).map(function(c, i) {
  57570. return i != 3 ? c / 255 : c;
  57571. }) || ol.render.webgl.defaultFillStyle;
  57572. } else {
  57573. fillStyleColor = ol.render.webgl.defaultFillStyle;
  57574. }
  57575. if (!this.state_.strokeColor || !ol.array.equals(this.state_.strokeColor, strokeStyleColor) ||
  57576. !this.state_.fillColor || !ol.array.equals(this.state_.fillColor, fillStyleColor) ||
  57577. this.state_.lineWidth !== strokeStyleWidth) {
  57578. this.state_.changed = true;
  57579. this.state_.fillColor = fillStyleColor;
  57580. this.state_.strokeColor = strokeStyleColor;
  57581. this.state_.lineWidth = strokeStyleWidth;
  57582. this.styles_.push([fillStyleColor, strokeStyleColor, strokeStyleWidth]);
  57583. }
  57584. };
  57585. // This file is automatically generated, do not edit
  57586. goog.provide('ol.render.webgl.texturereplay.defaultshader');
  57587. goog.require('ol');
  57588. goog.require('ol.webgl.Fragment');
  57589. goog.require('ol.webgl.Vertex');
  57590. ol.render.webgl.texturereplay.defaultshader.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
  57591. 'precision mediump float;\nvarying vec2 v_texCoord;\nvarying float v_opacity;\n\nuniform float u_opacity;\nuniform sampler2D u_image;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_image, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n float alpha = texColor.a * v_opacity * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n' :
  57592. 'precision mediump float;varying vec2 a;varying float b;uniform float k;uniform sampler2D l;void main(void){vec4 texColor=texture2D(l,a);gl_FragColor.rgb=texColor.rgb;float alpha=texColor.a*b*k;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}');
  57593. ol.render.webgl.texturereplay.defaultshader.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
  57594. 'varying vec2 v_texCoord;\nvarying float v_opacity;\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nattribute vec2 a_offsets;\nattribute float a_opacity;\nattribute float a_rotateWithView;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix;\n if (a_rotateWithView == 1.0) {\n offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n }\n vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;\n v_texCoord = a_texCoord;\n v_opacity = a_opacity;\n}\n\n\n' :
  57595. 'varying vec2 a;varying float b;attribute vec2 c;attribute vec2 d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;void main(void){mat4 offsetMatrix=i;if(g==1.0){offsetMatrix=i*j;}vec4 offsets=offsetMatrix*vec4(e,0.0,0.0);gl_Position=h*vec4(c,0.0,1.0)+offsets;a=d;b=f;}');
  57596. // This file is automatically generated, do not edit
  57597. goog.provide('ol.render.webgl.texturereplay.defaultshader.Locations');
  57598. goog.require('ol');
  57599. /**
  57600. * @constructor
  57601. * @param {WebGLRenderingContext} gl GL.
  57602. * @param {WebGLProgram} program Program.
  57603. * @struct
  57604. */
  57605. ol.render.webgl.texturereplay.defaultshader.Locations = function(gl, program) {
  57606. /**
  57607. * @type {WebGLUniformLocation}
  57608. */
  57609. this.u_projectionMatrix = gl.getUniformLocation(
  57610. program, ol.DEBUG_WEBGL ? 'u_projectionMatrix' : 'h');
  57611. /**
  57612. * @type {WebGLUniformLocation}
  57613. */
  57614. this.u_offsetScaleMatrix = gl.getUniformLocation(
  57615. program, ol.DEBUG_WEBGL ? 'u_offsetScaleMatrix' : 'i');
  57616. /**
  57617. * @type {WebGLUniformLocation}
  57618. */
  57619. this.u_offsetRotateMatrix = gl.getUniformLocation(
  57620. program, ol.DEBUG_WEBGL ? 'u_offsetRotateMatrix' : 'j');
  57621. /**
  57622. * @type {WebGLUniformLocation}
  57623. */
  57624. this.u_opacity = gl.getUniformLocation(
  57625. program, ol.DEBUG_WEBGL ? 'u_opacity' : 'k');
  57626. /**
  57627. * @type {WebGLUniformLocation}
  57628. */
  57629. this.u_image = gl.getUniformLocation(
  57630. program, ol.DEBUG_WEBGL ? 'u_image' : 'l');
  57631. /**
  57632. * @type {number}
  57633. */
  57634. this.a_position = gl.getAttribLocation(
  57635. program, ol.DEBUG_WEBGL ? 'a_position' : 'c');
  57636. /**
  57637. * @type {number}
  57638. */
  57639. this.a_texCoord = gl.getAttribLocation(
  57640. program, ol.DEBUG_WEBGL ? 'a_texCoord' : 'd');
  57641. /**
  57642. * @type {number}
  57643. */
  57644. this.a_offsets = gl.getAttribLocation(
  57645. program, ol.DEBUG_WEBGL ? 'a_offsets' : 'e');
  57646. /**
  57647. * @type {number}
  57648. */
  57649. this.a_opacity = gl.getAttribLocation(
  57650. program, ol.DEBUG_WEBGL ? 'a_opacity' : 'f');
  57651. /**
  57652. * @type {number}
  57653. */
  57654. this.a_rotateWithView = gl.getAttribLocation(
  57655. program, ol.DEBUG_WEBGL ? 'a_rotateWithView' : 'g');
  57656. };
  57657. goog.provide('ol.webgl.ContextEventType');
  57658. /**
  57659. * @enum {string}
  57660. */
  57661. ol.webgl.ContextEventType = {
  57662. LOST: 'webglcontextlost',
  57663. RESTORED: 'webglcontextrestored'
  57664. };
  57665. goog.provide('ol.webgl.Context');
  57666. goog.require('ol');
  57667. goog.require('ol.Disposable');
  57668. goog.require('ol.array');
  57669. goog.require('ol.events');
  57670. goog.require('ol.obj');
  57671. goog.require('ol.webgl');
  57672. goog.require('ol.webgl.ContextEventType');
  57673. /**
  57674. * @classdesc
  57675. * A WebGL context for accessing low-level WebGL capabilities.
  57676. *
  57677. * @constructor
  57678. * @extends {ol.Disposable}
  57679. * @param {HTMLCanvasElement} canvas Canvas.
  57680. * @param {WebGLRenderingContext} gl GL.
  57681. */
  57682. ol.webgl.Context = function(canvas, gl) {
  57683. /**
  57684. * @private
  57685. * @type {HTMLCanvasElement}
  57686. */
  57687. this.canvas_ = canvas;
  57688. /**
  57689. * @private
  57690. * @type {WebGLRenderingContext}
  57691. */
  57692. this.gl_ = gl;
  57693. /**
  57694. * @private
  57695. * @type {Object.<string, ol.WebglBufferCacheEntry>}
  57696. */
  57697. this.bufferCache_ = {};
  57698. /**
  57699. * @private
  57700. * @type {Object.<string, WebGLShader>}
  57701. */
  57702. this.shaderCache_ = {};
  57703. /**
  57704. * @private
  57705. * @type {Object.<string, WebGLProgram>}
  57706. */
  57707. this.programCache_ = {};
  57708. /**
  57709. * @private
  57710. * @type {WebGLProgram}
  57711. */
  57712. this.currentProgram_ = null;
  57713. /**
  57714. * @private
  57715. * @type {WebGLFramebuffer}
  57716. */
  57717. this.hitDetectionFramebuffer_ = null;
  57718. /**
  57719. * @private
  57720. * @type {WebGLTexture}
  57721. */
  57722. this.hitDetectionTexture_ = null;
  57723. /**
  57724. * @private
  57725. * @type {WebGLRenderbuffer}
  57726. */
  57727. this.hitDetectionRenderbuffer_ = null;
  57728. /**
  57729. * @type {boolean}
  57730. */
  57731. this.hasOESElementIndexUint = ol.array.includes(
  57732. ol.WEBGL_EXTENSIONS, 'OES_element_index_uint');
  57733. // use the OES_element_index_uint extension if available
  57734. if (this.hasOESElementIndexUint) {
  57735. gl.getExtension('OES_element_index_uint');
  57736. }
  57737. ol.events.listen(this.canvas_, ol.webgl.ContextEventType.LOST,
  57738. this.handleWebGLContextLost, this);
  57739. ol.events.listen(this.canvas_, ol.webgl.ContextEventType.RESTORED,
  57740. this.handleWebGLContextRestored, this);
  57741. };
  57742. ol.inherits(ol.webgl.Context, ol.Disposable);
  57743. /**
  57744. * Just bind the buffer if it's in the cache. Otherwise create
  57745. * the WebGL buffer, bind it, populate it, and add an entry to
  57746. * the cache.
  57747. * @param {number} target Target.
  57748. * @param {ol.webgl.Buffer} buf Buffer.
  57749. */
  57750. ol.webgl.Context.prototype.bindBuffer = function(target, buf) {
  57751. var gl = this.getGL();
  57752. var arr = buf.getArray();
  57753. var bufferKey = String(ol.getUid(buf));
  57754. if (bufferKey in this.bufferCache_) {
  57755. var bufferCacheEntry = this.bufferCache_[bufferKey];
  57756. gl.bindBuffer(target, bufferCacheEntry.buffer);
  57757. } else {
  57758. var buffer = gl.createBuffer();
  57759. gl.bindBuffer(target, buffer);
  57760. var /** @type {ArrayBufferView} */ arrayBuffer;
  57761. if (target == ol.webgl.ARRAY_BUFFER) {
  57762. arrayBuffer = new Float32Array(arr);
  57763. } else if (target == ol.webgl.ELEMENT_ARRAY_BUFFER) {
  57764. arrayBuffer = this.hasOESElementIndexUint ?
  57765. new Uint32Array(arr) : new Uint16Array(arr);
  57766. }
  57767. gl.bufferData(target, arrayBuffer, buf.getUsage());
  57768. this.bufferCache_[bufferKey] = {
  57769. buf: buf,
  57770. buffer: buffer
  57771. };
  57772. }
  57773. };
  57774. /**
  57775. * @param {ol.webgl.Buffer} buf Buffer.
  57776. */
  57777. ol.webgl.Context.prototype.deleteBuffer = function(buf) {
  57778. var gl = this.getGL();
  57779. var bufferKey = String(ol.getUid(buf));
  57780. var bufferCacheEntry = this.bufferCache_[bufferKey];
  57781. if (!gl.isContextLost()) {
  57782. gl.deleteBuffer(bufferCacheEntry.buffer);
  57783. }
  57784. delete this.bufferCache_[bufferKey];
  57785. };
  57786. /**
  57787. * @inheritDoc
  57788. */
  57789. ol.webgl.Context.prototype.disposeInternal = function() {
  57790. ol.events.unlistenAll(this.canvas_);
  57791. var gl = this.getGL();
  57792. if (!gl.isContextLost()) {
  57793. var key;
  57794. for (key in this.bufferCache_) {
  57795. gl.deleteBuffer(this.bufferCache_[key].buffer);
  57796. }
  57797. for (key in this.programCache_) {
  57798. gl.deleteProgram(this.programCache_[key]);
  57799. }
  57800. for (key in this.shaderCache_) {
  57801. gl.deleteShader(this.shaderCache_[key]);
  57802. }
  57803. // delete objects for hit-detection
  57804. gl.deleteFramebuffer(this.hitDetectionFramebuffer_);
  57805. gl.deleteRenderbuffer(this.hitDetectionRenderbuffer_);
  57806. gl.deleteTexture(this.hitDetectionTexture_);
  57807. }
  57808. };
  57809. /**
  57810. * @return {HTMLCanvasElement} Canvas.
  57811. */
  57812. ol.webgl.Context.prototype.getCanvas = function() {
  57813. return this.canvas_;
  57814. };
  57815. /**
  57816. * Get the WebGL rendering context
  57817. * @return {WebGLRenderingContext} The rendering context.
  57818. * @api
  57819. */
  57820. ol.webgl.Context.prototype.getGL = function() {
  57821. return this.gl_;
  57822. };
  57823. /**
  57824. * Get the frame buffer for hit detection.
  57825. * @return {WebGLFramebuffer} The hit detection frame buffer.
  57826. */
  57827. ol.webgl.Context.prototype.getHitDetectionFramebuffer = function() {
  57828. if (!this.hitDetectionFramebuffer_) {
  57829. this.initHitDetectionFramebuffer_();
  57830. }
  57831. return this.hitDetectionFramebuffer_;
  57832. };
  57833. /**
  57834. * Get shader from the cache if it's in the cache. Otherwise, create
  57835. * the WebGL shader, compile it, and add entry to cache.
  57836. * @param {ol.webgl.Shader} shaderObject Shader object.
  57837. * @return {WebGLShader} Shader.
  57838. */
  57839. ol.webgl.Context.prototype.getShader = function(shaderObject) {
  57840. var shaderKey = String(ol.getUid(shaderObject));
  57841. if (shaderKey in this.shaderCache_) {
  57842. return this.shaderCache_[shaderKey];
  57843. } else {
  57844. var gl = this.getGL();
  57845. var shader = gl.createShader(shaderObject.getType());
  57846. gl.shaderSource(shader, shaderObject.getSource());
  57847. gl.compileShader(shader);
  57848. this.shaderCache_[shaderKey] = shader;
  57849. return shader;
  57850. }
  57851. };
  57852. /**
  57853. * Get the program from the cache if it's in the cache. Otherwise create
  57854. * the WebGL program, attach the shaders to it, and add an entry to the
  57855. * cache.
  57856. * @param {ol.webgl.Fragment} fragmentShaderObject Fragment shader.
  57857. * @param {ol.webgl.Vertex} vertexShaderObject Vertex shader.
  57858. * @return {WebGLProgram} Program.
  57859. */
  57860. ol.webgl.Context.prototype.getProgram = function(
  57861. fragmentShaderObject, vertexShaderObject) {
  57862. var programKey =
  57863. ol.getUid(fragmentShaderObject) + '/' + ol.getUid(vertexShaderObject);
  57864. if (programKey in this.programCache_) {
  57865. return this.programCache_[programKey];
  57866. } else {
  57867. var gl = this.getGL();
  57868. var program = gl.createProgram();
  57869. gl.attachShader(program, this.getShader(fragmentShaderObject));
  57870. gl.attachShader(program, this.getShader(vertexShaderObject));
  57871. gl.linkProgram(program);
  57872. this.programCache_[programKey] = program;
  57873. return program;
  57874. }
  57875. };
  57876. /**
  57877. * FIXME empy description for jsdoc
  57878. */
  57879. ol.webgl.Context.prototype.handleWebGLContextLost = function() {
  57880. ol.obj.clear(this.bufferCache_);
  57881. ol.obj.clear(this.shaderCache_);
  57882. ol.obj.clear(this.programCache_);
  57883. this.currentProgram_ = null;
  57884. this.hitDetectionFramebuffer_ = null;
  57885. this.hitDetectionTexture_ = null;
  57886. this.hitDetectionRenderbuffer_ = null;
  57887. };
  57888. /**
  57889. * FIXME empy description for jsdoc
  57890. */
  57891. ol.webgl.Context.prototype.handleWebGLContextRestored = function() {
  57892. };
  57893. /**
  57894. * Creates a 1x1 pixel framebuffer for the hit-detection.
  57895. * @private
  57896. */
  57897. ol.webgl.Context.prototype.initHitDetectionFramebuffer_ = function() {
  57898. var gl = this.gl_;
  57899. var framebuffer = gl.createFramebuffer();
  57900. gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
  57901. var texture = ol.webgl.Context.createEmptyTexture(gl, 1, 1);
  57902. var renderbuffer = gl.createRenderbuffer();
  57903. gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
  57904. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 1, 1);
  57905. gl.framebufferTexture2D(
  57906. gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
  57907. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,
  57908. gl.RENDERBUFFER, renderbuffer);
  57909. gl.bindTexture(gl.TEXTURE_2D, null);
  57910. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  57911. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  57912. this.hitDetectionFramebuffer_ = framebuffer;
  57913. this.hitDetectionTexture_ = texture;
  57914. this.hitDetectionRenderbuffer_ = renderbuffer;
  57915. };
  57916. /**
  57917. * Use a program. If the program is already in use, this will return `false`.
  57918. * @param {WebGLProgram} program Program.
  57919. * @return {boolean} Changed.
  57920. * @api
  57921. */
  57922. ol.webgl.Context.prototype.useProgram = function(program) {
  57923. if (program == this.currentProgram_) {
  57924. return false;
  57925. } else {
  57926. var gl = this.getGL();
  57927. gl.useProgram(program);
  57928. this.currentProgram_ = program;
  57929. return true;
  57930. }
  57931. };
  57932. /**
  57933. * @param {WebGLRenderingContext} gl WebGL rendering context.
  57934. * @param {number=} opt_wrapS wrapS.
  57935. * @param {number=} opt_wrapT wrapT.
  57936. * @return {WebGLTexture} The texture.
  57937. * @private
  57938. */
  57939. ol.webgl.Context.createTexture_ = function(gl, opt_wrapS, opt_wrapT) {
  57940. var texture = gl.createTexture();
  57941. gl.bindTexture(gl.TEXTURE_2D, texture);
  57942. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  57943. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  57944. if (opt_wrapS !== undefined) {
  57945. gl.texParameteri(
  57946. ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_WRAP_S, opt_wrapS);
  57947. }
  57948. if (opt_wrapT !== undefined) {
  57949. gl.texParameteri(
  57950. ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_WRAP_T, opt_wrapT);
  57951. }
  57952. return texture;
  57953. };
  57954. /**
  57955. * @param {WebGLRenderingContext} gl WebGL rendering context.
  57956. * @param {number} width Width.
  57957. * @param {number} height Height.
  57958. * @param {number=} opt_wrapS wrapS.
  57959. * @param {number=} opt_wrapT wrapT.
  57960. * @return {WebGLTexture} The texture.
  57961. */
  57962. ol.webgl.Context.createEmptyTexture = function(
  57963. gl, width, height, opt_wrapS, opt_wrapT) {
  57964. var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT);
  57965. gl.texImage2D(
  57966. gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE,
  57967. null);
  57968. return texture;
  57969. };
  57970. /**
  57971. * @param {WebGLRenderingContext} gl WebGL rendering context.
  57972. * @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} image Image.
  57973. * @param {number=} opt_wrapS wrapS.
  57974. * @param {number=} opt_wrapT wrapT.
  57975. * @return {WebGLTexture} The texture.
  57976. */
  57977. ol.webgl.Context.createTexture = function(gl, image, opt_wrapS, opt_wrapT) {
  57978. var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT);
  57979. gl.texImage2D(
  57980. gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  57981. return texture;
  57982. };
  57983. goog.provide('ol.render.webgl.TextureReplay');
  57984. goog.require('ol');
  57985. goog.require('ol.extent');
  57986. goog.require('ol.obj');
  57987. goog.require('ol.render.webgl.texturereplay.defaultshader');
  57988. goog.require('ol.render.webgl.texturereplay.defaultshader.Locations');
  57989. goog.require('ol.render.webgl.Replay');
  57990. goog.require('ol.webgl');
  57991. goog.require('ol.webgl.Context');
  57992. /**
  57993. * @constructor
  57994. * @abstract
  57995. * @extends {ol.render.webgl.Replay}
  57996. * @param {number} tolerance Tolerance.
  57997. * @param {ol.Extent} maxExtent Max extent.
  57998. * @struct
  57999. */
  58000. ol.render.webgl.TextureReplay = function(tolerance, maxExtent) {
  58001. ol.render.webgl.Replay.call(this, tolerance, maxExtent);
  58002. /**
  58003. * @type {number|undefined}
  58004. * @protected
  58005. */
  58006. this.anchorX = undefined;
  58007. /**
  58008. * @type {number|undefined}
  58009. * @protected
  58010. */
  58011. this.anchorY = undefined;
  58012. /**
  58013. * @type {Array.<number>}
  58014. * @protected
  58015. */
  58016. this.groupIndices = [];
  58017. /**
  58018. * @type {Array.<number>}
  58019. * @protected
  58020. */
  58021. this.hitDetectionGroupIndices = [];
  58022. /**
  58023. * @type {number|undefined}
  58024. * @protected
  58025. */
  58026. this.height = undefined;
  58027. /**
  58028. * @type {number|undefined}
  58029. * @protected
  58030. */
  58031. this.imageHeight = undefined;
  58032. /**
  58033. * @type {number|undefined}
  58034. * @protected
  58035. */
  58036. this.imageWidth = undefined;
  58037. /**
  58038. * @protected
  58039. * @type {ol.render.webgl.texturereplay.defaultshader.Locations}
  58040. */
  58041. this.defaultLocations = null;
  58042. /**
  58043. * @protected
  58044. * @type {number|undefined}
  58045. */
  58046. this.opacity = undefined;
  58047. /**
  58048. * @type {number|undefined}
  58049. * @protected
  58050. */
  58051. this.originX = undefined;
  58052. /**
  58053. * @type {number|undefined}
  58054. * @protected
  58055. */
  58056. this.originY = undefined;
  58057. /**
  58058. * @protected
  58059. * @type {boolean|undefined}
  58060. */
  58061. this.rotateWithView = undefined;
  58062. /**
  58063. * @protected
  58064. * @type {number|undefined}
  58065. */
  58066. this.rotation = undefined;
  58067. /**
  58068. * @protected
  58069. * @type {number|undefined}
  58070. */
  58071. this.scale = undefined;
  58072. /**
  58073. * @type {number|undefined}
  58074. * @protected
  58075. */
  58076. this.width = undefined;
  58077. };
  58078. ol.inherits(ol.render.webgl.TextureReplay, ol.render.webgl.Replay);
  58079. /**
  58080. * @inheritDoc
  58081. */
  58082. ol.render.webgl.TextureReplay.prototype.getDeleteResourcesFunction = function(context) {
  58083. var verticesBuffer = this.verticesBuffer;
  58084. var indicesBuffer = this.indicesBuffer;
  58085. var textures = this.getTextures(true);
  58086. var gl = context.getGL();
  58087. return function() {
  58088. if (!gl.isContextLost()) {
  58089. var i, ii;
  58090. for (i = 0, ii = textures.length; i < ii; ++i) {
  58091. gl.deleteTexture(textures[i]);
  58092. }
  58093. }
  58094. context.deleteBuffer(verticesBuffer);
  58095. context.deleteBuffer(indicesBuffer);
  58096. };
  58097. };
  58098. /**
  58099. * @param {Array.<number>} flatCoordinates Flat coordinates.
  58100. * @param {number} offset Offset.
  58101. * @param {number} end End.
  58102. * @param {number} stride Stride.
  58103. * @return {number} My end.
  58104. * @protected
  58105. */
  58106. ol.render.webgl.TextureReplay.prototype.drawCoordinates = function(flatCoordinates, offset, end, stride) {
  58107. var anchorX = /** @type {number} */ (this.anchorX);
  58108. var anchorY = /** @type {number} */ (this.anchorY);
  58109. var height = /** @type {number} */ (this.height);
  58110. var imageHeight = /** @type {number} */ (this.imageHeight);
  58111. var imageWidth = /** @type {number} */ (this.imageWidth);
  58112. var opacity = /** @type {number} */ (this.opacity);
  58113. var originX = /** @type {number} */ (this.originX);
  58114. var originY = /** @type {number} */ (this.originY);
  58115. var rotateWithView = this.rotateWithView ? 1.0 : 0.0;
  58116. // this.rotation_ is anti-clockwise, but rotation is clockwise
  58117. var rotation = /** @type {number} */ (-this.rotation);
  58118. var scale = /** @type {number} */ (this.scale);
  58119. var width = /** @type {number} */ (this.width);
  58120. var cos = Math.cos(rotation);
  58121. var sin = Math.sin(rotation);
  58122. var numIndices = this.indices.length;
  58123. var numVertices = this.vertices.length;
  58124. var i, n, offsetX, offsetY, x, y;
  58125. for (i = offset; i < end; i += stride) {
  58126. x = flatCoordinates[i] - this.origin[0];
  58127. y = flatCoordinates[i + 1] - this.origin[1];
  58128. // There are 4 vertices per [x, y] point, one for each corner of the
  58129. // rectangle we're going to draw. We'd use 1 vertex per [x, y] point if
  58130. // WebGL supported Geometry Shaders (which can emit new vertices), but that
  58131. // is not currently the case.
  58132. //
  58133. // And each vertex includes 8 values: the x and y coordinates, the x and
  58134. // y offsets used to calculate the position of the corner, the u and
  58135. // v texture coordinates for the corner, the opacity, and whether the
  58136. // the image should be rotated with the view (rotateWithView).
  58137. n = numVertices / 8;
  58138. // bottom-left corner
  58139. offsetX = -scale * anchorX;
  58140. offsetY = -scale * (height - anchorY);
  58141. this.vertices[numVertices++] = x;
  58142. this.vertices[numVertices++] = y;
  58143. this.vertices[numVertices++] = offsetX * cos - offsetY * sin;
  58144. this.vertices[numVertices++] = offsetX * sin + offsetY * cos;
  58145. this.vertices[numVertices++] = originX / imageWidth;
  58146. this.vertices[numVertices++] = (originY + height) / imageHeight;
  58147. this.vertices[numVertices++] = opacity;
  58148. this.vertices[numVertices++] = rotateWithView;
  58149. // bottom-right corner
  58150. offsetX = scale * (width - anchorX);
  58151. offsetY = -scale * (height - anchorY);
  58152. this.vertices[numVertices++] = x;
  58153. this.vertices[numVertices++] = y;
  58154. this.vertices[numVertices++] = offsetX * cos - offsetY * sin;
  58155. this.vertices[numVertices++] = offsetX * sin + offsetY * cos;
  58156. this.vertices[numVertices++] = (originX + width) / imageWidth;
  58157. this.vertices[numVertices++] = (originY + height) / imageHeight;
  58158. this.vertices[numVertices++] = opacity;
  58159. this.vertices[numVertices++] = rotateWithView;
  58160. // top-right corner
  58161. offsetX = scale * (width - anchorX);
  58162. offsetY = scale * anchorY;
  58163. this.vertices[numVertices++] = x;
  58164. this.vertices[numVertices++] = y;
  58165. this.vertices[numVertices++] = offsetX * cos - offsetY * sin;
  58166. this.vertices[numVertices++] = offsetX * sin + offsetY * cos;
  58167. this.vertices[numVertices++] = (originX + width) / imageWidth;
  58168. this.vertices[numVertices++] = originY / imageHeight;
  58169. this.vertices[numVertices++] = opacity;
  58170. this.vertices[numVertices++] = rotateWithView;
  58171. // top-left corner
  58172. offsetX = -scale * anchorX;
  58173. offsetY = scale * anchorY;
  58174. this.vertices[numVertices++] = x;
  58175. this.vertices[numVertices++] = y;
  58176. this.vertices[numVertices++] = offsetX * cos - offsetY * sin;
  58177. this.vertices[numVertices++] = offsetX * sin + offsetY * cos;
  58178. this.vertices[numVertices++] = originX / imageWidth;
  58179. this.vertices[numVertices++] = originY / imageHeight;
  58180. this.vertices[numVertices++] = opacity;
  58181. this.vertices[numVertices++] = rotateWithView;
  58182. this.indices[numIndices++] = n;
  58183. this.indices[numIndices++] = n + 1;
  58184. this.indices[numIndices++] = n + 2;
  58185. this.indices[numIndices++] = n;
  58186. this.indices[numIndices++] = n + 2;
  58187. this.indices[numIndices++] = n + 3;
  58188. }
  58189. return numVertices;
  58190. };
  58191. /**
  58192. * @protected
  58193. * @param {Array.<WebGLTexture>} textures Textures.
  58194. * @param {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>} images
  58195. * Images.
  58196. * @param {Object.<string, WebGLTexture>} texturePerImage Texture cache.
  58197. * @param {WebGLRenderingContext} gl Gl.
  58198. */
  58199. ol.render.webgl.TextureReplay.prototype.createTextures = function(textures, images, texturePerImage, gl) {
  58200. var texture, image, uid, i;
  58201. var ii = images.length;
  58202. for (i = 0; i < ii; ++i) {
  58203. image = images[i];
  58204. uid = ol.getUid(image).toString();
  58205. if (uid in texturePerImage) {
  58206. texture = texturePerImage[uid];
  58207. } else {
  58208. texture = ol.webgl.Context.createTexture(
  58209. gl, image, ol.webgl.CLAMP_TO_EDGE, ol.webgl.CLAMP_TO_EDGE);
  58210. texturePerImage[uid] = texture;
  58211. }
  58212. textures[i] = texture;
  58213. }
  58214. };
  58215. /**
  58216. * @inheritDoc
  58217. */
  58218. ol.render.webgl.TextureReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
  58219. // get the program
  58220. var fragmentShader = ol.render.webgl.texturereplay.defaultshader.fragment;
  58221. var vertexShader = ol.render.webgl.texturereplay.defaultshader.vertex;
  58222. var program = context.getProgram(fragmentShader, vertexShader);
  58223. // get the locations
  58224. var locations;
  58225. if (!this.defaultLocations) {
  58226. locations = new ol.render.webgl.texturereplay.defaultshader.Locations(gl, program);
  58227. this.defaultLocations = locations;
  58228. } else {
  58229. locations = this.defaultLocations;
  58230. }
  58231. // use the program (FIXME: use the return value)
  58232. context.useProgram(program);
  58233. // enable the vertex attrib arrays
  58234. gl.enableVertexAttribArray(locations.a_position);
  58235. gl.vertexAttribPointer(locations.a_position, 2, ol.webgl.FLOAT,
  58236. false, 32, 0);
  58237. gl.enableVertexAttribArray(locations.a_offsets);
  58238. gl.vertexAttribPointer(locations.a_offsets, 2, ol.webgl.FLOAT,
  58239. false, 32, 8);
  58240. gl.enableVertexAttribArray(locations.a_texCoord);
  58241. gl.vertexAttribPointer(locations.a_texCoord, 2, ol.webgl.FLOAT,
  58242. false, 32, 16);
  58243. gl.enableVertexAttribArray(locations.a_opacity);
  58244. gl.vertexAttribPointer(locations.a_opacity, 1, ol.webgl.FLOAT,
  58245. false, 32, 24);
  58246. gl.enableVertexAttribArray(locations.a_rotateWithView);
  58247. gl.vertexAttribPointer(locations.a_rotateWithView, 1, ol.webgl.FLOAT,
  58248. false, 32, 28);
  58249. return locations;
  58250. };
  58251. /**
  58252. * @inheritDoc
  58253. */
  58254. ol.render.webgl.TextureReplay.prototype.shutDownProgram = function(gl, locations) {
  58255. gl.disableVertexAttribArray(locations.a_position);
  58256. gl.disableVertexAttribArray(locations.a_offsets);
  58257. gl.disableVertexAttribArray(locations.a_texCoord);
  58258. gl.disableVertexAttribArray(locations.a_opacity);
  58259. gl.disableVertexAttribArray(locations.a_rotateWithView);
  58260. };
  58261. /**
  58262. * @inheritDoc
  58263. */
  58264. ol.render.webgl.TextureReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
  58265. var textures = hitDetection ? this.getHitDetectionTextures() : this.getTextures();
  58266. var groupIndices = hitDetection ? this.hitDetectionGroupIndices : this.groupIndices;
  58267. if (!ol.obj.isEmpty(skippedFeaturesHash)) {
  58268. this.drawReplaySkipping(
  58269. gl, context, skippedFeaturesHash, textures, groupIndices);
  58270. } else {
  58271. var i, ii, start;
  58272. for (i = 0, ii = textures.length, start = 0; i < ii; ++i) {
  58273. gl.bindTexture(ol.webgl.TEXTURE_2D, textures[i]);
  58274. var end = groupIndices[i];
  58275. this.drawElements(gl, context, start, end);
  58276. start = end;
  58277. }
  58278. }
  58279. };
  58280. /**
  58281. * Draw the replay while paying attention to skipped features.
  58282. *
  58283. * This functions creates groups of features that can be drawn to together,
  58284. * so that the number of `drawElements` calls is minimized.
  58285. *
  58286. * For example given the following texture groups:
  58287. *
  58288. * Group 1: A B C
  58289. * Group 2: D [E] F G
  58290. *
  58291. * If feature E should be skipped, the following `drawElements` calls will be
  58292. * made:
  58293. *
  58294. * drawElements with feature A, B and C
  58295. * drawElements with feature D
  58296. * drawElements with feature F and G
  58297. *
  58298. * @protected
  58299. * @param {WebGLRenderingContext} gl gl.
  58300. * @param {ol.webgl.Context} context Context.
  58301. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  58302. * to skip.
  58303. * @param {Array.<WebGLTexture>} textures Textures.
  58304. * @param {Array.<number>} groupIndices Texture group indices.
  58305. */
  58306. ol.render.webgl.TextureReplay.prototype.drawReplaySkipping = function(gl, context, skippedFeaturesHash, textures,
  58307. groupIndices) {
  58308. var featureIndex = 0;
  58309. var i, ii;
  58310. for (i = 0, ii = textures.length; i < ii; ++i) {
  58311. gl.bindTexture(ol.webgl.TEXTURE_2D, textures[i]);
  58312. var groupStart = (i > 0) ? groupIndices[i - 1] : 0;
  58313. var groupEnd = groupIndices[i];
  58314. var start = groupStart;
  58315. var end = groupStart;
  58316. while (featureIndex < this.startIndices.length &&
  58317. this.startIndices[featureIndex] <= groupEnd) {
  58318. var feature = this.startIndicesFeature[featureIndex];
  58319. var featureUid = ol.getUid(feature).toString();
  58320. if (skippedFeaturesHash[featureUid] !== undefined) {
  58321. // feature should be skipped
  58322. if (start !== end) {
  58323. // draw the features so far
  58324. this.drawElements(gl, context, start, end);
  58325. }
  58326. // continue with the next feature
  58327. start = (featureIndex === this.startIndices.length - 1) ?
  58328. groupEnd : this.startIndices[featureIndex + 1];
  58329. end = start;
  58330. } else {
  58331. // the feature is not skipped, augment the end index
  58332. end = (featureIndex === this.startIndices.length - 1) ?
  58333. groupEnd : this.startIndices[featureIndex + 1];
  58334. }
  58335. featureIndex++;
  58336. }
  58337. if (start !== end) {
  58338. // draw the remaining features (in case there was no skipped feature
  58339. // in this texture group, all features of a group are drawn together)
  58340. this.drawElements(gl, context, start, end);
  58341. }
  58342. }
  58343. };
  58344. /**
  58345. * @inheritDoc
  58346. */
  58347. ol.render.webgl.TextureReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
  58348. featureCallback, opt_hitExtent) {
  58349. var i, groupStart, start, end, feature, featureUid;
  58350. var featureIndex = this.startIndices.length - 1;
  58351. var hitDetectionTextures = this.getHitDetectionTextures();
  58352. for (i = hitDetectionTextures.length - 1; i >= 0; --i) {
  58353. gl.bindTexture(ol.webgl.TEXTURE_2D, hitDetectionTextures[i]);
  58354. groupStart = (i > 0) ? this.hitDetectionGroupIndices[i - 1] : 0;
  58355. end = this.hitDetectionGroupIndices[i];
  58356. // draw all features for this texture group
  58357. while (featureIndex >= 0 &&
  58358. this.startIndices[featureIndex] >= groupStart) {
  58359. start = this.startIndices[featureIndex];
  58360. feature = this.startIndicesFeature[featureIndex];
  58361. featureUid = ol.getUid(feature).toString();
  58362. if (skippedFeaturesHash[featureUid] === undefined &&
  58363. feature.getGeometry() &&
  58364. (opt_hitExtent === undefined || ol.extent.intersects(
  58365. /** @type {Array<number>} */ (opt_hitExtent),
  58366. feature.getGeometry().getExtent()))) {
  58367. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  58368. this.drawElements(gl, context, start, end);
  58369. var result = featureCallback(feature);
  58370. if (result) {
  58371. return result;
  58372. }
  58373. }
  58374. end = start;
  58375. featureIndex--;
  58376. }
  58377. }
  58378. return undefined;
  58379. };
  58380. /**
  58381. * @inheritDoc
  58382. */
  58383. ol.render.webgl.TextureReplay.prototype.finish = function(context) {
  58384. this.anchorX = undefined;
  58385. this.anchorY = undefined;
  58386. this.height = undefined;
  58387. this.imageHeight = undefined;
  58388. this.imageWidth = undefined;
  58389. this.indices = null;
  58390. this.opacity = undefined;
  58391. this.originX = undefined;
  58392. this.originY = undefined;
  58393. this.rotateWithView = undefined;
  58394. this.rotation = undefined;
  58395. this.scale = undefined;
  58396. this.vertices = null;
  58397. this.width = undefined;
  58398. };
  58399. /**
  58400. * @abstract
  58401. * @protected
  58402. * @param {boolean=} opt_all Return hit detection textures with regular ones.
  58403. * @returns {Array.<WebGLTexture>} Textures.
  58404. */
  58405. ol.render.webgl.TextureReplay.prototype.getTextures = function(opt_all) {};
  58406. /**
  58407. * @abstract
  58408. * @protected
  58409. * @returns {Array.<WebGLTexture>} Textures.
  58410. */
  58411. ol.render.webgl.TextureReplay.prototype.getHitDetectionTextures = function() {};
  58412. goog.provide('ol.render.webgl.ImageReplay');
  58413. goog.require('ol');
  58414. goog.require('ol.render.webgl.TextureReplay');
  58415. goog.require('ol.webgl.Buffer');
  58416. /**
  58417. * @constructor
  58418. * @extends {ol.render.webgl.TextureReplay}
  58419. * @param {number} tolerance Tolerance.
  58420. * @param {ol.Extent} maxExtent Max extent.
  58421. * @struct
  58422. */
  58423. ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
  58424. ol.render.webgl.TextureReplay.call(this, tolerance, maxExtent);
  58425. /**
  58426. * @type {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>}
  58427. * @protected
  58428. */
  58429. this.images_ = [];
  58430. /**
  58431. * @type {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>}
  58432. * @protected
  58433. */
  58434. this.hitDetectionImages_ = [];
  58435. /**
  58436. * @type {Array.<WebGLTexture>}
  58437. * @private
  58438. */
  58439. this.textures_ = [];
  58440. /**
  58441. * @type {Array.<WebGLTexture>}
  58442. * @private
  58443. */
  58444. this.hitDetectionTextures_ = [];
  58445. };
  58446. ol.inherits(ol.render.webgl.ImageReplay, ol.render.webgl.TextureReplay);
  58447. /**
  58448. * @inheritDoc
  58449. */
  58450. ol.render.webgl.ImageReplay.prototype.drawMultiPoint = function(multiPointGeometry, feature) {
  58451. this.startIndices.push(this.indices.length);
  58452. this.startIndicesFeature.push(feature);
  58453. var flatCoordinates = multiPointGeometry.getFlatCoordinates();
  58454. var stride = multiPointGeometry.getStride();
  58455. this.drawCoordinates(
  58456. flatCoordinates, 0, flatCoordinates.length, stride);
  58457. };
  58458. /**
  58459. * @inheritDoc
  58460. */
  58461. ol.render.webgl.ImageReplay.prototype.drawPoint = function(pointGeometry, feature) {
  58462. this.startIndices.push(this.indices.length);
  58463. this.startIndicesFeature.push(feature);
  58464. var flatCoordinates = pointGeometry.getFlatCoordinates();
  58465. var stride = pointGeometry.getStride();
  58466. this.drawCoordinates(
  58467. flatCoordinates, 0, flatCoordinates.length, stride);
  58468. };
  58469. /**
  58470. * @inheritDoc
  58471. */
  58472. ol.render.webgl.ImageReplay.prototype.finish = function(context) {
  58473. var gl = context.getGL();
  58474. this.groupIndices.push(this.indices.length);
  58475. this.hitDetectionGroupIndices.push(this.indices.length);
  58476. // create, bind, and populate the vertices buffer
  58477. this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
  58478. var indices = this.indices;
  58479. // create, bind, and populate the indices buffer
  58480. this.indicesBuffer = new ol.webgl.Buffer(indices);
  58481. // create textures
  58482. /** @type {Object.<string, WebGLTexture>} */
  58483. var texturePerImage = {};
  58484. this.createTextures(this.textures_, this.images_, texturePerImage, gl);
  58485. this.createTextures(this.hitDetectionTextures_, this.hitDetectionImages_,
  58486. texturePerImage, gl);
  58487. this.images_ = null;
  58488. this.hitDetectionImages_ = null;
  58489. ol.render.webgl.TextureReplay.prototype.finish.call(this, context);
  58490. };
  58491. /**
  58492. * @inheritDoc
  58493. */
  58494. ol.render.webgl.ImageReplay.prototype.setImageStyle = function(imageStyle) {
  58495. var anchor = imageStyle.getAnchor();
  58496. var image = imageStyle.getImage(1);
  58497. var imageSize = imageStyle.getImageSize();
  58498. var hitDetectionImage = imageStyle.getHitDetectionImage(1);
  58499. var opacity = imageStyle.getOpacity();
  58500. var origin = imageStyle.getOrigin();
  58501. var rotateWithView = imageStyle.getRotateWithView();
  58502. var rotation = imageStyle.getRotation();
  58503. var size = imageStyle.getSize();
  58504. var scale = imageStyle.getScale();
  58505. var currentImage;
  58506. if (this.images_.length === 0) {
  58507. this.images_.push(image);
  58508. } else {
  58509. currentImage = this.images_[this.images_.length - 1];
  58510. if (ol.getUid(currentImage) != ol.getUid(image)) {
  58511. this.groupIndices.push(this.indices.length);
  58512. this.images_.push(image);
  58513. }
  58514. }
  58515. if (this.hitDetectionImages_.length === 0) {
  58516. this.hitDetectionImages_.push(hitDetectionImage);
  58517. } else {
  58518. currentImage =
  58519. this.hitDetectionImages_[this.hitDetectionImages_.length - 1];
  58520. if (ol.getUid(currentImage) != ol.getUid(hitDetectionImage)) {
  58521. this.hitDetectionGroupIndices.push(this.indices.length);
  58522. this.hitDetectionImages_.push(hitDetectionImage);
  58523. }
  58524. }
  58525. this.anchorX = anchor[0];
  58526. this.anchorY = anchor[1];
  58527. this.height = size[1];
  58528. this.imageHeight = imageSize[1];
  58529. this.imageWidth = imageSize[0];
  58530. this.opacity = opacity;
  58531. this.originX = origin[0];
  58532. this.originY = origin[1];
  58533. this.rotation = rotation;
  58534. this.rotateWithView = rotateWithView;
  58535. this.scale = scale;
  58536. this.width = size[0];
  58537. };
  58538. /**
  58539. * @inheritDoc
  58540. */
  58541. ol.render.webgl.ImageReplay.prototype.getTextures = function(opt_all) {
  58542. return opt_all ? this.textures_.concat(this.hitDetectionTextures_) : this.textures_;
  58543. };
  58544. /**
  58545. * @inheritDoc
  58546. */
  58547. ol.render.webgl.ImageReplay.prototype.getHitDetectionTextures = function() {
  58548. return this.hitDetectionTextures_;
  58549. };
  58550. // This file is automatically generated, do not edit
  58551. goog.provide('ol.render.webgl.linestringreplay.defaultshader');
  58552. goog.require('ol');
  58553. goog.require('ol.webgl.Fragment');
  58554. goog.require('ol.webgl.Vertex');
  58555. ol.render.webgl.linestringreplay.defaultshader.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
  58556. 'precision mediump float;\nvarying float v_round;\nvarying vec2 v_roundVertex;\nvarying float v_halfWidth;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_color;\nuniform vec2 u_size;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n if (v_round > 0.0) {\n vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x * u_pixelRatio,\n (v_roundVertex.y + 1.0) / 2.0 * u_size.y * u_pixelRatio);\n if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth * u_pixelRatio) {\n discard;\n }\n }\n gl_FragColor = u_color;\n float alpha = u_color.a * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n' :
  58557. 'precision mediump float;varying float a;varying vec2 aVertex;varying float c;uniform float m;uniform vec4 n;uniform vec2 o;uniform float p;void main(void){if(a>0.0){vec2 windowCoords=vec2((aVertex.x+1.0)/2.0*o.x*p,(aVertex.y+1.0)/2.0*o.y*p);if(length(windowCoords-gl_FragCoord.xy)>c*p){discard;}} gl_FragColor=n;float alpha=n.a*m;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}');
  58558. ol.render.webgl.linestringreplay.defaultshader.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
  58559. 'varying float v_round;\nvarying vec2 v_roundVertex;\nvarying float v_halfWidth;\n\n\nattribute vec2 a_lastPos;\nattribute vec2 a_position;\nattribute vec2 a_nextPos;\nattribute float a_direction;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\nuniform float u_lineWidth;\nuniform float u_miterLimit;\n\nbool nearlyEquals(in float value, in float ref) {\n float epsilon = 0.000000000001;\n return value >= ref - epsilon && value <= ref + epsilon;\n}\n\nvoid alongNormal(out vec2 offset, in vec2 nextP, in float turnDir, in float direction) {\n vec2 dirVect = nextP - a_position;\n vec2 normal = normalize(vec2(-turnDir * dirVect.y, turnDir * dirVect.x));\n offset = u_lineWidth / 2.0 * normal * direction;\n}\n\nvoid miterUp(out vec2 offset, out float round, in bool isRound, in float direction) {\n float halfWidth = u_lineWidth / 2.0;\n vec2 tangent = normalize(normalize(a_nextPos - a_position) + normalize(a_position - a_lastPos));\n vec2 normal = vec2(-tangent.y, tangent.x);\n vec2 dirVect = a_nextPos - a_position;\n vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));\n float miterLength = abs(halfWidth / dot(normal, tmpNormal));\n offset = normal * direction * miterLength;\n round = 0.0;\n if (isRound) {\n round = 1.0;\n } else if (miterLength > u_miterLimit + u_lineWidth) {\n offset = halfWidth * tmpNormal * direction;\n }\n}\n\nbool miterDown(out vec2 offset, in vec4 projPos, in mat4 offsetMatrix, in float direction) {\n bool degenerate = false;\n vec2 tangent = normalize(normalize(a_nextPos - a_position) + normalize(a_position - a_lastPos));\n vec2 normal = vec2(-tangent.y, tangent.x);\n vec2 dirVect = a_lastPos - a_position;\n vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));\n vec2 longOffset, shortOffset, longVertex;\n vec4 shortProjVertex;\n float halfWidth = u_lineWidth / 2.0;\n if (length(a_nextPos - a_position) > length(a_lastPos - a_position)) {\n longOffset = tmpNormal * direction * halfWidth;\n shortOffset = normalize(vec2(dirVect.y, -dirVect.x)) * direction * halfWidth;\n longVertex = a_nextPos;\n shortProjVertex = u_projectionMatrix * vec4(a_lastPos, 0.0, 1.0);\n } else {\n shortOffset = tmpNormal * direction * halfWidth;\n longOffset = normalize(vec2(dirVect.y, -dirVect.x)) * direction * halfWidth;\n longVertex = a_lastPos;\n shortProjVertex = u_projectionMatrix * vec4(a_nextPos, 0.0, 1.0);\n }\n //Intersection algorithm based on theory by Paul Bourke (http://paulbourke.net/geometry/pointlineplane/).\n vec4 p1 = u_projectionMatrix * vec4(longVertex, 0.0, 1.0) + offsetMatrix * vec4(longOffset, 0.0, 0.0);\n vec4 p2 = projPos + offsetMatrix * vec4(longOffset, 0.0, 0.0);\n vec4 p3 = shortProjVertex + offsetMatrix * vec4(-shortOffset, 0.0, 0.0);\n vec4 p4 = shortProjVertex + offsetMatrix * vec4(shortOffset, 0.0, 0.0);\n float denom = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);\n float firstU = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / denom;\n float secondU = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / denom;\n float epsilon = 0.000000000001;\n if (firstU > epsilon && firstU < 1.0 - epsilon && secondU > epsilon && secondU < 1.0 - epsilon) {\n shortProjVertex.x = p1.x + firstU * (p2.x - p1.x);\n shortProjVertex.y = p1.y + firstU * (p2.y - p1.y);\n offset = shortProjVertex.xy;\n degenerate = true;\n } else {\n float miterLength = abs(halfWidth / dot(normal, tmpNormal));\n offset = normal * direction * miterLength;\n }\n return degenerate;\n}\n\nvoid squareCap(out vec2 offset, out float round, in bool isRound, in vec2 nextP,\n in float turnDir, in float direction) {\n round = 0.0;\n vec2 dirVect = a_position - nextP;\n vec2 firstNormal = normalize(dirVect);\n vec2 secondNormal = vec2(turnDir * firstNormal.y * direction, -turnDir * firstNormal.x * direction);\n vec2 hypotenuse = normalize(firstNormal - secondNormal);\n vec2 normal = vec2(turnDir * hypotenuse.y * direction, -turnDir * hypotenuse.x * direction);\n float length = sqrt(v_halfWidth * v_halfWidth * 2.0);\n offset = normal * length;\n if (isRound) {\n round = 1.0;\n }\n}\n\nvoid main(void) {\n bool degenerate = false;\n float direction = float(sign(a_direction));\n mat4 offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n vec2 offset;\n vec4 projPos = u_projectionMatrix * vec4(a_position, 0.0, 1.0);\n bool round = nearlyEquals(mod(a_direction, 2.0), 0.0);\n\n v_round = 0.0;\n v_halfWidth = u_lineWidth / 2.0;\n v_roundVertex = projPos.xy;\n\n if (nearlyEquals(mod(a_direction, 3.0), 0.0) || nearlyEquals(mod(a_direction, 17.0), 0.0)) {\n alongNormal(offset, a_nextPos, 1.0, direction);\n } else if (nearlyEquals(mod(a_direction, 5.0), 0.0) || nearlyEquals(mod(a_direction, 13.0), 0.0)) {\n alongNormal(offset, a_lastPos, -1.0, direction);\n } else if (nearlyEquals(mod(a_direction, 23.0), 0.0)) {\n miterUp(offset, v_round, round, direction);\n } else if (nearlyEquals(mod(a_direction, 19.0), 0.0)) {\n degenerate = miterDown(offset, projPos, offsetMatrix, direction);\n } else if (nearlyEquals(mod(a_direction, 7.0), 0.0)) {\n squareCap(offset, v_round, round, a_nextPos, 1.0, direction);\n } else if (nearlyEquals(mod(a_direction, 11.0), 0.0)) {\n squareCap(offset, v_round, round, a_lastPos, -1.0, direction);\n }\n if (!degenerate) {\n vec4 offsets = offsetMatrix * vec4(offset, 0.0, 0.0);\n gl_Position = projPos + offsets;\n } else {\n gl_Position = vec4(offset, 0.0, 1.0);\n }\n}\n\n\n' :
  58560. 'varying float a;varying vec2 aVertex;varying float c;attribute vec2 d;attribute vec2 e;attribute vec2 f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;uniform float k;uniform float l;bool nearlyEquals(in float value,in float ref){float epsilon=0.000000000001;return value>=ref-epsilon&&value<=ref+epsilon;}void alongNormal(out vec2 offset,in vec2 nextP,in float turnDir,in float direction){vec2 dirVect=nextP-e;vec2 normal=normalize(vec2(-turnDir*dirVect.y,turnDir*dirVect.x));offset=k/2.0*normal*direction;}void miterUp(out vec2 offset,out float round,in bool isRound,in float direction){float halfWidth=k/2.0;vec2 tangent=normalize(normalize(f-e)+normalize(e-d));vec2 normal=vec2(-tangent.y,tangent.x);vec2 dirVect=f-e;vec2 tmpNormal=normalize(vec2(-dirVect.y,dirVect.x));float miterLength=abs(halfWidth/dot(normal,tmpNormal));offset=normal*direction*miterLength;round=0.0;if(isRound){round=1.0;}else if(miterLength>l+k){offset=halfWidth*tmpNormal*direction;}} bool miterDown(out vec2 offset,in vec4 projPos,in mat4 offsetMatrix,in float direction){bool degenerate=false;vec2 tangent=normalize(normalize(f-e)+normalize(e-d));vec2 normal=vec2(-tangent.y,tangent.x);vec2 dirVect=d-e;vec2 tmpNormal=normalize(vec2(-dirVect.y,dirVect.x));vec2 longOffset,shortOffset,longVertex;vec4 shortProjVertex;float halfWidth=k/2.0;if(length(f-e)>length(d-e)){longOffset=tmpNormal*direction*halfWidth;shortOffset=normalize(vec2(dirVect.y,-dirVect.x))*direction*halfWidth;longVertex=f;shortProjVertex=h*vec4(d,0.0,1.0);}else{shortOffset=tmpNormal*direction*halfWidth;longOffset=normalize(vec2(dirVect.y,-dirVect.x))*direction*halfWidth;longVertex=d;shortProjVertex=h*vec4(f,0.0,1.0);}vec4 p1=h*vec4(longVertex,0.0,1.0)+offsetMatrix*vec4(longOffset,0.0,0.0);vec4 p2=projPos+offsetMatrix*vec4(longOffset,0.0,0.0);vec4 p3=shortProjVertex+offsetMatrix*vec4(-shortOffset,0.0,0.0);vec4 p4=shortProjVertex+offsetMatrix*vec4(shortOffset,0.0,0.0);float denom=(p4.y-p3.y)*(p2.x-p1.x)-(p4.x-p3.x)*(p2.y-p1.y);float firstU=((p4.x-p3.x)*(p1.y-p3.y)-(p4.y-p3.y)*(p1.x-p3.x))/denom;float secondU=((p2.x-p1.x)*(p1.y-p3.y)-(p2.y-p1.y)*(p1.x-p3.x))/denom;float epsilon=0.000000000001;if(firstU>epsilon&&firstU<1.0-epsilon&&secondU>epsilon&&secondU<1.0-epsilon){shortProjVertex.x=p1.x+firstU*(p2.x-p1.x);shortProjVertex.y=p1.y+firstU*(p2.y-p1.y);offset=shortProjVertex.xy;degenerate=true;}else{float miterLength=abs(halfWidth/dot(normal,tmpNormal));offset=normal*direction*miterLength;}return degenerate;}void squareCap(out vec2 offset,out float round,in bool isRound,in vec2 nextP,in float turnDir,in float direction){round=0.0;vec2 dirVect=e-nextP;vec2 firstNormal=normalize(dirVect);vec2 secondNormal=vec2(turnDir*firstNormal.y*direction,-turnDir*firstNormal.x*direction);vec2 hypotenuse=normalize(firstNormal-secondNormal);vec2 normal=vec2(turnDir*hypotenuse.y*direction,-turnDir*hypotenuse.x*direction);float length=sqrt(c*c*2.0);offset=normal*length;if(isRound){round=1.0;}} void main(void){bool degenerate=false;float direction=float(sign(g));mat4 offsetMatrix=i*j;vec2 offset;vec4 projPos=h*vec4(e,0.0,1.0);bool round=nearlyEquals(mod(g,2.0),0.0);a=0.0;c=k/2.0;aVertex=projPos.xy;if(nearlyEquals(mod(g,3.0),0.0)||nearlyEquals(mod(g,17.0),0.0)){alongNormal(offset,f,1.0,direction);}else if(nearlyEquals(mod(g,5.0),0.0)||nearlyEquals(mod(g,13.0),0.0)){alongNormal(offset,d,-1.0,direction);}else if(nearlyEquals(mod(g,23.0),0.0)){miterUp(offset,a,round,direction);}else if(nearlyEquals(mod(g,19.0),0.0)){degenerate=miterDown(offset,projPos,offsetMatrix,direction);}else if(nearlyEquals(mod(g,7.0),0.0)){squareCap(offset,a,round,f,1.0,direction);}else if(nearlyEquals(mod(g,11.0),0.0)){squareCap(offset,a,round,d,-1.0,direction);}if(!degenerate){vec4 offsets=offsetMatrix*vec4(offset,0.0,0.0);gl_Position=projPos+offsets;}else{gl_Position=vec4(offset,0.0,1.0);}}');
  58561. // This file is automatically generated, do not edit
  58562. goog.provide('ol.render.webgl.linestringreplay.defaultshader.Locations');
  58563. goog.require('ol');
  58564. /**
  58565. * @constructor
  58566. * @param {WebGLRenderingContext} gl GL.
  58567. * @param {WebGLProgram} program Program.
  58568. * @struct
  58569. */
  58570. ol.render.webgl.linestringreplay.defaultshader.Locations = function(gl, program) {
  58571. /**
  58572. * @type {WebGLUniformLocation}
  58573. */
  58574. this.u_projectionMatrix = gl.getUniformLocation(
  58575. program, ol.DEBUG_WEBGL ? 'u_projectionMatrix' : 'h');
  58576. /**
  58577. * @type {WebGLUniformLocation}
  58578. */
  58579. this.u_offsetScaleMatrix = gl.getUniformLocation(
  58580. program, ol.DEBUG_WEBGL ? 'u_offsetScaleMatrix' : 'i');
  58581. /**
  58582. * @type {WebGLUniformLocation}
  58583. */
  58584. this.u_offsetRotateMatrix = gl.getUniformLocation(
  58585. program, ol.DEBUG_WEBGL ? 'u_offsetRotateMatrix' : 'j');
  58586. /**
  58587. * @type {WebGLUniformLocation}
  58588. */
  58589. this.u_lineWidth = gl.getUniformLocation(
  58590. program, ol.DEBUG_WEBGL ? 'u_lineWidth' : 'k');
  58591. /**
  58592. * @type {WebGLUniformLocation}
  58593. */
  58594. this.u_miterLimit = gl.getUniformLocation(
  58595. program, ol.DEBUG_WEBGL ? 'u_miterLimit' : 'l');
  58596. /**
  58597. * @type {WebGLUniformLocation}
  58598. */
  58599. this.u_opacity = gl.getUniformLocation(
  58600. program, ol.DEBUG_WEBGL ? 'u_opacity' : 'm');
  58601. /**
  58602. * @type {WebGLUniformLocation}
  58603. */
  58604. this.u_color = gl.getUniformLocation(
  58605. program, ol.DEBUG_WEBGL ? 'u_color' : 'n');
  58606. /**
  58607. * @type {WebGLUniformLocation}
  58608. */
  58609. this.u_size = gl.getUniformLocation(
  58610. program, ol.DEBUG_WEBGL ? 'u_size' : 'o');
  58611. /**
  58612. * @type {WebGLUniformLocation}
  58613. */
  58614. this.u_pixelRatio = gl.getUniformLocation(
  58615. program, ol.DEBUG_WEBGL ? 'u_pixelRatio' : 'p');
  58616. /**
  58617. * @type {number}
  58618. */
  58619. this.a_lastPos = gl.getAttribLocation(
  58620. program, ol.DEBUG_WEBGL ? 'a_lastPos' : 'd');
  58621. /**
  58622. * @type {number}
  58623. */
  58624. this.a_position = gl.getAttribLocation(
  58625. program, ol.DEBUG_WEBGL ? 'a_position' : 'e');
  58626. /**
  58627. * @type {number}
  58628. */
  58629. this.a_nextPos = gl.getAttribLocation(
  58630. program, ol.DEBUG_WEBGL ? 'a_nextPos' : 'f');
  58631. /**
  58632. * @type {number}
  58633. */
  58634. this.a_direction = gl.getAttribLocation(
  58635. program, ol.DEBUG_WEBGL ? 'a_direction' : 'g');
  58636. };
  58637. goog.provide('ol.render.webgl.LineStringReplay');
  58638. goog.require('ol');
  58639. goog.require('ol.array');
  58640. goog.require('ol.color');
  58641. goog.require('ol.extent');
  58642. goog.require('ol.geom.flat.orient');
  58643. goog.require('ol.geom.flat.transform');
  58644. goog.require('ol.geom.flat.topology');
  58645. goog.require('ol.obj');
  58646. goog.require('ol.render.webgl');
  58647. goog.require('ol.render.webgl.Replay');
  58648. goog.require('ol.render.webgl.linestringreplay.defaultshader');
  58649. goog.require('ol.render.webgl.linestringreplay.defaultshader.Locations');
  58650. goog.require('ol.webgl');
  58651. goog.require('ol.webgl.Buffer');
  58652. /**
  58653. * @constructor
  58654. * @extends {ol.render.webgl.Replay}
  58655. * @param {number} tolerance Tolerance.
  58656. * @param {ol.Extent} maxExtent Max extent.
  58657. * @struct
  58658. */
  58659. ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
  58660. ol.render.webgl.Replay.call(this, tolerance, maxExtent);
  58661. /**
  58662. * @private
  58663. * @type {ol.render.webgl.linestringreplay.defaultshader.Locations}
  58664. */
  58665. this.defaultLocations_ = null;
  58666. /**
  58667. * @private
  58668. * @type {Array.<Array.<?>>}
  58669. */
  58670. this.styles_ = [];
  58671. /**
  58672. * @private
  58673. * @type {Array.<number>}
  58674. */
  58675. this.styleIndices_ = [];
  58676. /**
  58677. * @private
  58678. * @type {{strokeColor: (Array.<number>|null),
  58679. * lineCap: (string|undefined),
  58680. * lineDash: Array.<number>,
  58681. * lineDashOffset: (number|undefined),
  58682. * lineJoin: (string|undefined),
  58683. * lineWidth: (number|undefined),
  58684. * miterLimit: (number|undefined),
  58685. * changed: boolean}|null}
  58686. */
  58687. this.state_ = {
  58688. strokeColor: null,
  58689. lineCap: undefined,
  58690. lineDash: null,
  58691. lineDashOffset: undefined,
  58692. lineJoin: undefined,
  58693. lineWidth: undefined,
  58694. miterLimit: undefined,
  58695. changed: false
  58696. };
  58697. };
  58698. ol.inherits(ol.render.webgl.LineStringReplay, ol.render.webgl.Replay);
  58699. /**
  58700. * Draw one segment.
  58701. * @private
  58702. * @param {Array.<number>} flatCoordinates Flat coordinates.
  58703. * @param {number} offset Offset.
  58704. * @param {number} end End.
  58705. * @param {number} stride Stride.
  58706. */
  58707. ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) {
  58708. var i, ii;
  58709. var numVertices = this.vertices.length;
  58710. var numIndices = this.indices.length;
  58711. //To save a vertex, the direction of a point is a product of the sign (1 or -1), a prime from
  58712. //ol.render.webgl.LineStringReplay.Instruction_, and a rounding factor (1 or 2). If the product is even,
  58713. //we round it. If it is odd, we don't.
  58714. var lineJoin = this.state_.lineJoin === 'bevel' ? 0 :
  58715. this.state_.lineJoin === 'miter' ? 1 : 2;
  58716. var lineCap = this.state_.lineCap === 'butt' ? 0 :
  58717. this.state_.lineCap === 'square' ? 1 : 2;
  58718. var closed = ol.geom.flat.topology.lineStringIsClosed(flatCoordinates, offset, end, stride);
  58719. var startCoords, sign, n;
  58720. var lastIndex = numIndices;
  58721. var lastSign = 1;
  58722. //We need the adjacent vertices to define normals in joins. p0 = last, p1 = current, p2 = next.
  58723. var p0, p1, p2;
  58724. for (i = offset, ii = end; i < ii; i += stride) {
  58725. n = numVertices / 7;
  58726. p0 = p1;
  58727. p1 = p2 || [flatCoordinates[i], flatCoordinates[i + 1]];
  58728. //First vertex.
  58729. if (i === offset) {
  58730. p2 = [flatCoordinates[i + stride], flatCoordinates[i + stride + 1]];
  58731. if (end - offset === stride * 2 && ol.array.equals(p1, p2)) {
  58732. break;
  58733. }
  58734. if (closed) {
  58735. //A closed line! Complete the circle.
  58736. p0 = [flatCoordinates[end - stride * 2],
  58737. flatCoordinates[end - stride * 2 + 1]];
  58738. startCoords = p2;
  58739. } else {
  58740. //Add the first two/four vertices.
  58741. if (lineCap) {
  58742. numVertices = this.addVertices_([0, 0], p1, p2,
  58743. lastSign * ol.render.webgl.LineStringReplay.Instruction_.BEGIN_LINE_CAP * lineCap, numVertices);
  58744. numVertices = this.addVertices_([0, 0], p1, p2,
  58745. -lastSign * ol.render.webgl.LineStringReplay.Instruction_.BEGIN_LINE_CAP * lineCap, numVertices);
  58746. this.indices[numIndices++] = n + 2;
  58747. this.indices[numIndices++] = n;
  58748. this.indices[numIndices++] = n + 1;
  58749. this.indices[numIndices++] = n + 1;
  58750. this.indices[numIndices++] = n + 3;
  58751. this.indices[numIndices++] = n + 2;
  58752. }
  58753. numVertices = this.addVertices_([0, 0], p1, p2,
  58754. lastSign * ol.render.webgl.LineStringReplay.Instruction_.BEGIN_LINE * (lineCap || 1), numVertices);
  58755. numVertices = this.addVertices_([0, 0], p1, p2,
  58756. -lastSign * ol.render.webgl.LineStringReplay.Instruction_.BEGIN_LINE * (lineCap || 1), numVertices);
  58757. lastIndex = numVertices / 7 - 1;
  58758. continue;
  58759. }
  58760. } else if (i === end - stride) {
  58761. //Last vertex.
  58762. if (closed) {
  58763. //Same as the first vertex.
  58764. p2 = startCoords;
  58765. break;
  58766. } else {
  58767. p0 = p0 || [0, 0];
  58768. numVertices = this.addVertices_(p0, p1, [0, 0],
  58769. lastSign * ol.render.webgl.LineStringReplay.Instruction_.END_LINE * (lineCap || 1), numVertices);
  58770. numVertices = this.addVertices_(p0, p1, [0, 0],
  58771. -lastSign * ol.render.webgl.LineStringReplay.Instruction_.END_LINE * (lineCap || 1), numVertices);
  58772. this.indices[numIndices++] = n;
  58773. this.indices[numIndices++] = lastIndex - 1;
  58774. this.indices[numIndices++] = lastIndex;
  58775. this.indices[numIndices++] = lastIndex;
  58776. this.indices[numIndices++] = n + 1;
  58777. this.indices[numIndices++] = n;
  58778. if (lineCap) {
  58779. numVertices = this.addVertices_(p0, p1, [0, 0],
  58780. lastSign * ol.render.webgl.LineStringReplay.Instruction_.END_LINE_CAP * lineCap, numVertices);
  58781. numVertices = this.addVertices_(p0, p1, [0, 0],
  58782. -lastSign * ol.render.webgl.LineStringReplay.Instruction_.END_LINE_CAP * lineCap, numVertices);
  58783. this.indices[numIndices++] = n + 2;
  58784. this.indices[numIndices++] = n;
  58785. this.indices[numIndices++] = n + 1;
  58786. this.indices[numIndices++] = n + 1;
  58787. this.indices[numIndices++] = n + 3;
  58788. this.indices[numIndices++] = n + 2;
  58789. }
  58790. break;
  58791. }
  58792. } else {
  58793. p2 = [flatCoordinates[i + stride], flatCoordinates[i + stride + 1]];
  58794. }
  58795. // We group CW and straight lines, thus the not so inituitive CCW checking function.
  58796. sign = ol.render.webgl.triangleIsCounterClockwise(p0[0], p0[1], p1[0], p1[1], p2[0], p2[1])
  58797. ? -1 : 1;
  58798. numVertices = this.addVertices_(p0, p1, p2,
  58799. sign * ol.render.webgl.LineStringReplay.Instruction_.BEVEL_FIRST * (lineJoin || 1), numVertices);
  58800. numVertices = this.addVertices_(p0, p1, p2,
  58801. sign * ol.render.webgl.LineStringReplay.Instruction_.BEVEL_SECOND * (lineJoin || 1), numVertices);
  58802. numVertices = this.addVertices_(p0, p1, p2,
  58803. -sign * ol.render.webgl.LineStringReplay.Instruction_.MITER_BOTTOM * (lineJoin || 1), numVertices);
  58804. if (i > offset) {
  58805. this.indices[numIndices++] = n;
  58806. this.indices[numIndices++] = lastIndex - 1;
  58807. this.indices[numIndices++] = lastIndex;
  58808. this.indices[numIndices++] = n + 2;
  58809. this.indices[numIndices++] = n;
  58810. this.indices[numIndices++] = lastSign * sign > 0 ? lastIndex : lastIndex - 1;
  58811. }
  58812. this.indices[numIndices++] = n;
  58813. this.indices[numIndices++] = n + 2;
  58814. this.indices[numIndices++] = n + 1;
  58815. lastIndex = n + 2;
  58816. lastSign = sign;
  58817. //Add miter
  58818. if (lineJoin) {
  58819. numVertices = this.addVertices_(p0, p1, p2,
  58820. sign * ol.render.webgl.LineStringReplay.Instruction_.MITER_TOP * lineJoin, numVertices);
  58821. this.indices[numIndices++] = n + 1;
  58822. this.indices[numIndices++] = n + 3;
  58823. this.indices[numIndices++] = n;
  58824. }
  58825. }
  58826. if (closed) {
  58827. n = n || numVertices / 7;
  58828. sign = ol.geom.flat.orient.linearRingIsClockwise([p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]], 0, 6, 2)
  58829. ? 1 : -1;
  58830. numVertices = this.addVertices_(p0, p1, p2,
  58831. sign * ol.render.webgl.LineStringReplay.Instruction_.BEVEL_FIRST * (lineJoin || 1), numVertices);
  58832. numVertices = this.addVertices_(p0, p1, p2,
  58833. -sign * ol.render.webgl.LineStringReplay.Instruction_.MITER_BOTTOM * (lineJoin || 1), numVertices);
  58834. this.indices[numIndices++] = n;
  58835. this.indices[numIndices++] = lastIndex - 1;
  58836. this.indices[numIndices++] = lastIndex;
  58837. this.indices[numIndices++] = n + 1;
  58838. this.indices[numIndices++] = n;
  58839. this.indices[numIndices++] = lastSign * sign > 0 ? lastIndex : lastIndex - 1;
  58840. }
  58841. };
  58842. /**
  58843. * @param {Array.<number>} p0 Last coordinates.
  58844. * @param {Array.<number>} p1 Current coordinates.
  58845. * @param {Array.<number>} p2 Next coordinates.
  58846. * @param {number} product Sign, instruction, and rounding product.
  58847. * @param {number} numVertices Vertex counter.
  58848. * @return {number} Vertex counter.
  58849. * @private
  58850. */
  58851. ol.render.webgl.LineStringReplay.prototype.addVertices_ = function(p0, p1, p2, product, numVertices) {
  58852. this.vertices[numVertices++] = p0[0];
  58853. this.vertices[numVertices++] = p0[1];
  58854. this.vertices[numVertices++] = p1[0];
  58855. this.vertices[numVertices++] = p1[1];
  58856. this.vertices[numVertices++] = p2[0];
  58857. this.vertices[numVertices++] = p2[1];
  58858. this.vertices[numVertices++] = product;
  58859. return numVertices;
  58860. };
  58861. /**
  58862. * Check if the linestring can be drawn (i. e. valid).
  58863. * @param {Array.<number>} flatCoordinates Flat coordinates.
  58864. * @param {number} offset Offset.
  58865. * @param {number} end End.
  58866. * @param {number} stride Stride.
  58867. * @return {boolean} The linestring can be drawn.
  58868. * @private
  58869. */
  58870. ol.render.webgl.LineStringReplay.prototype.isValid_ = function(flatCoordinates, offset, end, stride) {
  58871. var range = end - offset;
  58872. if (range < stride * 2) {
  58873. return false;
  58874. } else if (range === stride * 2) {
  58875. var firstP = [flatCoordinates[offset], flatCoordinates[offset + 1]];
  58876. var lastP = [flatCoordinates[offset + stride], flatCoordinates[offset + stride + 1]];
  58877. return !ol.array.equals(firstP, lastP);
  58878. }
  58879. return true;
  58880. };
  58881. /**
  58882. * @inheritDoc
  58883. */
  58884. ol.render.webgl.LineStringReplay.prototype.drawLineString = function(lineStringGeometry, feature) {
  58885. var flatCoordinates = lineStringGeometry.getFlatCoordinates();
  58886. var stride = lineStringGeometry.getStride();
  58887. if (this.isValid_(flatCoordinates, 0, flatCoordinates.length, stride)) {
  58888. flatCoordinates = ol.geom.flat.transform.translate(flatCoordinates, 0, flatCoordinates.length,
  58889. stride, -this.origin[0], -this.origin[1]);
  58890. if (this.state_.changed) {
  58891. this.styleIndices_.push(this.indices.length);
  58892. this.state_.changed = false;
  58893. }
  58894. this.startIndices.push(this.indices.length);
  58895. this.startIndicesFeature.push(feature);
  58896. this.drawCoordinates_(
  58897. flatCoordinates, 0, flatCoordinates.length, stride);
  58898. }
  58899. };
  58900. /**
  58901. * @inheritDoc
  58902. */
  58903. ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiLineStringGeometry, feature) {
  58904. var indexCount = this.indices.length;
  58905. var ends = multiLineStringGeometry.getEnds();
  58906. ends.unshift(0);
  58907. var flatCoordinates = multiLineStringGeometry.getFlatCoordinates();
  58908. var stride = multiLineStringGeometry.getStride();
  58909. var i, ii;
  58910. if (ends.length > 1) {
  58911. for (i = 1, ii = ends.length; i < ii; ++i) {
  58912. if (this.isValid_(flatCoordinates, ends[i - 1], ends[i], stride)) {
  58913. var lineString = ol.geom.flat.transform.translate(flatCoordinates, ends[i - 1], ends[i],
  58914. stride, -this.origin[0], -this.origin[1]);
  58915. this.drawCoordinates_(
  58916. lineString, 0, lineString.length, stride);
  58917. }
  58918. }
  58919. }
  58920. if (this.indices.length > indexCount) {
  58921. this.startIndices.push(indexCount);
  58922. this.startIndicesFeature.push(feature);
  58923. if (this.state_.changed) {
  58924. this.styleIndices_.push(indexCount);
  58925. this.state_.changed = false;
  58926. }
  58927. }
  58928. };
  58929. /**
  58930. * @param {Array.<number>} flatCoordinates Flat coordinates.
  58931. * @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates.
  58932. * @param {number} stride Stride.
  58933. */
  58934. ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function(
  58935. flatCoordinates, holeFlatCoordinates, stride) {
  58936. if (!ol.geom.flat.topology.lineStringIsClosed(flatCoordinates, 0,
  58937. flatCoordinates.length, stride)) {
  58938. flatCoordinates.push(flatCoordinates[0]);
  58939. flatCoordinates.push(flatCoordinates[1]);
  58940. }
  58941. this.drawCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
  58942. if (holeFlatCoordinates.length) {
  58943. var i, ii;
  58944. for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
  58945. if (!ol.geom.flat.topology.lineStringIsClosed(holeFlatCoordinates[i], 0,
  58946. holeFlatCoordinates[i].length, stride)) {
  58947. holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]);
  58948. holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]);
  58949. }
  58950. this.drawCoordinates_(holeFlatCoordinates[i], 0,
  58951. holeFlatCoordinates[i].length, stride);
  58952. }
  58953. }
  58954. };
  58955. /**
  58956. * @param {ol.Feature|ol.render.Feature} feature Feature.
  58957. * @param {number=} opt_index Index count.
  58958. */
  58959. ol.render.webgl.LineStringReplay.prototype.setPolygonStyle = function(feature, opt_index) {
  58960. var index = opt_index === undefined ? this.indices.length : opt_index;
  58961. this.startIndices.push(index);
  58962. this.startIndicesFeature.push(feature);
  58963. if (this.state_.changed) {
  58964. this.styleIndices_.push(index);
  58965. this.state_.changed = false;
  58966. }
  58967. };
  58968. /**
  58969. * @return {number} Current index.
  58970. */
  58971. ol.render.webgl.LineStringReplay.prototype.getCurrentIndex = function() {
  58972. return this.indices.length;
  58973. };
  58974. /**
  58975. * @inheritDoc
  58976. **/
  58977. ol.render.webgl.LineStringReplay.prototype.finish = function(context) {
  58978. // create, bind, and populate the vertices buffer
  58979. this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
  58980. // create, bind, and populate the indices buffer
  58981. this.indicesBuffer = new ol.webgl.Buffer(this.indices);
  58982. this.startIndices.push(this.indices.length);
  58983. //Clean up, if there is nothing to draw
  58984. if (this.styleIndices_.length === 0 && this.styles_.length > 0) {
  58985. this.styles_ = [];
  58986. }
  58987. this.vertices = null;
  58988. this.indices = null;
  58989. };
  58990. /**
  58991. * @inheritDoc
  58992. */
  58993. ol.render.webgl.LineStringReplay.prototype.getDeleteResourcesFunction = function(context) {
  58994. var verticesBuffer = this.verticesBuffer;
  58995. var indicesBuffer = this.indicesBuffer;
  58996. return function() {
  58997. context.deleteBuffer(verticesBuffer);
  58998. context.deleteBuffer(indicesBuffer);
  58999. };
  59000. };
  59001. /**
  59002. * @inheritDoc
  59003. */
  59004. ol.render.webgl.LineStringReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
  59005. // get the program
  59006. var fragmentShader, vertexShader;
  59007. fragmentShader = ol.render.webgl.linestringreplay.defaultshader.fragment;
  59008. vertexShader = ol.render.webgl.linestringreplay.defaultshader.vertex;
  59009. var program = context.getProgram(fragmentShader, vertexShader);
  59010. // get the locations
  59011. var locations;
  59012. if (!this.defaultLocations_) {
  59013. locations = new ol.render.webgl.linestringreplay.defaultshader.Locations(gl, program);
  59014. this.defaultLocations_ = locations;
  59015. } else {
  59016. locations = this.defaultLocations_;
  59017. }
  59018. context.useProgram(program);
  59019. // enable the vertex attrib arrays
  59020. gl.enableVertexAttribArray(locations.a_lastPos);
  59021. gl.vertexAttribPointer(locations.a_lastPos, 2, ol.webgl.FLOAT,
  59022. false, 28, 0);
  59023. gl.enableVertexAttribArray(locations.a_position);
  59024. gl.vertexAttribPointer(locations.a_position, 2, ol.webgl.FLOAT,
  59025. false, 28, 8);
  59026. gl.enableVertexAttribArray(locations.a_nextPos);
  59027. gl.vertexAttribPointer(locations.a_nextPos, 2, ol.webgl.FLOAT,
  59028. false, 28, 16);
  59029. gl.enableVertexAttribArray(locations.a_direction);
  59030. gl.vertexAttribPointer(locations.a_direction, 1, ol.webgl.FLOAT,
  59031. false, 28, 24);
  59032. // Enable renderer specific uniforms.
  59033. gl.uniform2fv(locations.u_size, size);
  59034. gl.uniform1f(locations.u_pixelRatio, pixelRatio);
  59035. return locations;
  59036. };
  59037. /**
  59038. * @inheritDoc
  59039. */
  59040. ol.render.webgl.LineStringReplay.prototype.shutDownProgram = function(gl, locations) {
  59041. gl.disableVertexAttribArray(locations.a_lastPos);
  59042. gl.disableVertexAttribArray(locations.a_position);
  59043. gl.disableVertexAttribArray(locations.a_nextPos);
  59044. gl.disableVertexAttribArray(locations.a_direction);
  59045. };
  59046. /**
  59047. * @inheritDoc
  59048. */
  59049. ol.render.webgl.LineStringReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
  59050. //Save GL parameters.
  59051. var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC));
  59052. var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK));
  59053. if (!hitDetection) {
  59054. gl.enable(gl.DEPTH_TEST);
  59055. gl.depthMask(true);
  59056. gl.depthFunc(gl.NOTEQUAL);
  59057. }
  59058. if (!ol.obj.isEmpty(skippedFeaturesHash)) {
  59059. this.drawReplaySkipping_(gl, context, skippedFeaturesHash);
  59060. } else {
  59061. //Draw by style groups to minimize drawElements() calls.
  59062. var i, start, end, nextStyle;
  59063. end = this.startIndices[this.startIndices.length - 1];
  59064. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  59065. start = this.styleIndices_[i];
  59066. nextStyle = this.styles_[i];
  59067. this.setStrokeStyle_(gl, nextStyle[0], nextStyle[1], nextStyle[2]);
  59068. this.drawElements(gl, context, start, end);
  59069. gl.clear(gl.DEPTH_BUFFER_BIT);
  59070. end = start;
  59071. }
  59072. }
  59073. if (!hitDetection) {
  59074. gl.disable(gl.DEPTH_TEST);
  59075. gl.clear(gl.DEPTH_BUFFER_BIT);
  59076. //Restore GL parameters.
  59077. gl.depthMask(tmpDepthMask);
  59078. gl.depthFunc(tmpDepthFunc);
  59079. }
  59080. };
  59081. /**
  59082. * @private
  59083. * @param {WebGLRenderingContext} gl gl.
  59084. * @param {ol.webgl.Context} context Context.
  59085. * @param {Object} skippedFeaturesHash Ids of features to skip.
  59086. */
  59087. ol.render.webgl.LineStringReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
  59088. var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
  59089. featureIndex = this.startIndices.length - 2;
  59090. end = start = this.startIndices[featureIndex + 1];
  59091. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  59092. nextStyle = this.styles_[i];
  59093. this.setStrokeStyle_(gl, nextStyle[0], nextStyle[1], nextStyle[2]);
  59094. groupStart = this.styleIndices_[i];
  59095. while (featureIndex >= 0 &&
  59096. this.startIndices[featureIndex] >= groupStart) {
  59097. featureStart = this.startIndices[featureIndex];
  59098. feature = this.startIndicesFeature[featureIndex];
  59099. featureUid = ol.getUid(feature).toString();
  59100. if (skippedFeaturesHash[featureUid]) {
  59101. if (start !== end) {
  59102. this.drawElements(gl, context, start, end);
  59103. gl.clear(gl.DEPTH_BUFFER_BIT);
  59104. }
  59105. end = featureStart;
  59106. }
  59107. featureIndex--;
  59108. start = featureStart;
  59109. }
  59110. if (start !== end) {
  59111. this.drawElements(gl, context, start, end);
  59112. gl.clear(gl.DEPTH_BUFFER_BIT);
  59113. }
  59114. start = end = groupStart;
  59115. }
  59116. };
  59117. /**
  59118. * @inheritDoc
  59119. */
  59120. ol.render.webgl.LineStringReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
  59121. featureCallback, opt_hitExtent) {
  59122. var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
  59123. featureIndex = this.startIndices.length - 2;
  59124. end = this.startIndices[featureIndex + 1];
  59125. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  59126. nextStyle = this.styles_[i];
  59127. this.setStrokeStyle_(gl, nextStyle[0], nextStyle[1], nextStyle[2]);
  59128. groupStart = this.styleIndices_[i];
  59129. while (featureIndex >= 0 &&
  59130. this.startIndices[featureIndex] >= groupStart) {
  59131. start = this.startIndices[featureIndex];
  59132. feature = this.startIndicesFeature[featureIndex];
  59133. featureUid = ol.getUid(feature).toString();
  59134. if (skippedFeaturesHash[featureUid] === undefined &&
  59135. feature.getGeometry() &&
  59136. (opt_hitExtent === undefined || ol.extent.intersects(
  59137. /** @type {Array<number>} */ (opt_hitExtent),
  59138. feature.getGeometry().getExtent()))) {
  59139. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  59140. this.drawElements(gl, context, start, end);
  59141. var result = featureCallback(feature);
  59142. if (result) {
  59143. return result;
  59144. }
  59145. }
  59146. featureIndex--;
  59147. end = start;
  59148. }
  59149. }
  59150. return undefined;
  59151. };
  59152. /**
  59153. * @private
  59154. * @param {WebGLRenderingContext} gl gl.
  59155. * @param {Array.<number>} color Color.
  59156. * @param {number} lineWidth Line width.
  59157. * @param {number} miterLimit Miter limit.
  59158. */
  59159. ol.render.webgl.LineStringReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth, miterLimit) {
  59160. gl.uniform4fv(this.defaultLocations_.u_color, color);
  59161. gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth);
  59162. gl.uniform1f(this.defaultLocations_.u_miterLimit, miterLimit);
  59163. };
  59164. /**
  59165. * @inheritDoc
  59166. */
  59167. ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
  59168. var strokeStyleLineCap = strokeStyle.getLineCap();
  59169. this.state_.lineCap = strokeStyleLineCap !== undefined ?
  59170. strokeStyleLineCap : ol.render.webgl.defaultLineCap;
  59171. var strokeStyleLineDash = strokeStyle.getLineDash();
  59172. this.state_.lineDash = strokeStyleLineDash ?
  59173. strokeStyleLineDash : ol.render.webgl.defaultLineDash;
  59174. var strokeStyleLineDashOffset = strokeStyle.getLineDashOffset();
  59175. this.state_.lineDashOffset = strokeStyleLineDashOffset ?
  59176. strokeStyleLineDashOffset : ol.render.webgl.defaultLineDashOffset;
  59177. var strokeStyleLineJoin = strokeStyle.getLineJoin();
  59178. this.state_.lineJoin = strokeStyleLineJoin !== undefined ?
  59179. strokeStyleLineJoin : ol.render.webgl.defaultLineJoin;
  59180. var strokeStyleColor = strokeStyle.getColor();
  59181. if (!(strokeStyleColor instanceof CanvasGradient) &&
  59182. !(strokeStyleColor instanceof CanvasPattern)) {
  59183. strokeStyleColor = ol.color.asArray(strokeStyleColor).map(function(c, i) {
  59184. return i != 3 ? c / 255 : c;
  59185. }) || ol.render.webgl.defaultStrokeStyle;
  59186. } else {
  59187. strokeStyleColor = ol.render.webgl.defaultStrokeStyle;
  59188. }
  59189. var strokeStyleWidth = strokeStyle.getWidth();
  59190. strokeStyleWidth = strokeStyleWidth !== undefined ?
  59191. strokeStyleWidth : ol.render.webgl.defaultLineWidth;
  59192. var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
  59193. strokeStyleMiterLimit = strokeStyleMiterLimit !== undefined ?
  59194. strokeStyleMiterLimit : ol.render.webgl.defaultMiterLimit;
  59195. if (!this.state_.strokeColor || !ol.array.equals(this.state_.strokeColor, strokeStyleColor) ||
  59196. this.state_.lineWidth !== strokeStyleWidth || this.state_.miterLimit !== strokeStyleMiterLimit) {
  59197. this.state_.changed = true;
  59198. this.state_.strokeColor = strokeStyleColor;
  59199. this.state_.lineWidth = strokeStyleWidth;
  59200. this.state_.miterLimit = strokeStyleMiterLimit;
  59201. this.styles_.push([strokeStyleColor, strokeStyleWidth, strokeStyleMiterLimit]);
  59202. }
  59203. };
  59204. /**
  59205. * @enum {number}
  59206. * @private
  59207. */
  59208. ol.render.webgl.LineStringReplay.Instruction_ = {
  59209. ROUND: 2,
  59210. BEGIN_LINE: 3,
  59211. END_LINE: 5,
  59212. BEGIN_LINE_CAP: 7,
  59213. END_LINE_CAP: 11,
  59214. BEVEL_FIRST: 13,
  59215. BEVEL_SECOND: 17,
  59216. MITER_BOTTOM: 19,
  59217. MITER_TOP: 23
  59218. };
  59219. // This file is automatically generated, do not edit
  59220. goog.provide('ol.render.webgl.polygonreplay.defaultshader');
  59221. goog.require('ol');
  59222. goog.require('ol.webgl.Fragment');
  59223. goog.require('ol.webgl.Vertex');
  59224. ol.render.webgl.polygonreplay.defaultshader.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
  59225. 'precision mediump float;\n\n\n\nuniform vec4 u_color;\nuniform float u_opacity;\n\nvoid main(void) {\n gl_FragColor = u_color;\n float alpha = u_color.a * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n' :
  59226. 'precision mediump float;uniform vec4 e;uniform float f;void main(void){gl_FragColor=e;float alpha=e.a*f;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}');
  59227. ol.render.webgl.polygonreplay.defaultshader.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
  59228. '\n\nattribute vec2 a_position;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0);\n}\n\n\n' :
  59229. 'attribute vec2 a;uniform mat4 b;uniform mat4 c;uniform mat4 d;void main(void){gl_Position=b*vec4(a,0.0,1.0);}');
  59230. // This file is automatically generated, do not edit
  59231. goog.provide('ol.render.webgl.polygonreplay.defaultshader.Locations');
  59232. goog.require('ol');
  59233. /**
  59234. * @constructor
  59235. * @param {WebGLRenderingContext} gl GL.
  59236. * @param {WebGLProgram} program Program.
  59237. * @struct
  59238. */
  59239. ol.render.webgl.polygonreplay.defaultshader.Locations = function(gl, program) {
  59240. /**
  59241. * @type {WebGLUniformLocation}
  59242. */
  59243. this.u_projectionMatrix = gl.getUniformLocation(
  59244. program, ol.DEBUG_WEBGL ? 'u_projectionMatrix' : 'b');
  59245. /**
  59246. * @type {WebGLUniformLocation}
  59247. */
  59248. this.u_offsetScaleMatrix = gl.getUniformLocation(
  59249. program, ol.DEBUG_WEBGL ? 'u_offsetScaleMatrix' : 'c');
  59250. /**
  59251. * @type {WebGLUniformLocation}
  59252. */
  59253. this.u_offsetRotateMatrix = gl.getUniformLocation(
  59254. program, ol.DEBUG_WEBGL ? 'u_offsetRotateMatrix' : 'd');
  59255. /**
  59256. * @type {WebGLUniformLocation}
  59257. */
  59258. this.u_color = gl.getUniformLocation(
  59259. program, ol.DEBUG_WEBGL ? 'u_color' : 'e');
  59260. /**
  59261. * @type {WebGLUniformLocation}
  59262. */
  59263. this.u_opacity = gl.getUniformLocation(
  59264. program, ol.DEBUG_WEBGL ? 'u_opacity' : 'f');
  59265. /**
  59266. * @type {number}
  59267. */
  59268. this.a_position = gl.getAttribLocation(
  59269. program, ol.DEBUG_WEBGL ? 'a_position' : 'a');
  59270. };
  59271. goog.provide('ol.structs.LinkedList');
  59272. /**
  59273. * Creates an empty linked list structure.
  59274. *
  59275. * @constructor
  59276. * @struct
  59277. * @param {boolean=} opt_circular The last item is connected to the first one,
  59278. * and the first item to the last one. Default is true.
  59279. */
  59280. ol.structs.LinkedList = function(opt_circular) {
  59281. /**
  59282. * @private
  59283. * @type {ol.LinkedListItem|undefined}
  59284. */
  59285. this.first_ = undefined;
  59286. /**
  59287. * @private
  59288. * @type {ol.LinkedListItem|undefined}
  59289. */
  59290. this.last_ = undefined;
  59291. /**
  59292. * @private
  59293. * @type {ol.LinkedListItem|undefined}
  59294. */
  59295. this.head_ = undefined;
  59296. /**
  59297. * @private
  59298. * @type {boolean}
  59299. */
  59300. this.circular_ = opt_circular === undefined ? true : opt_circular;
  59301. /**
  59302. * @private
  59303. * @type {number}
  59304. */
  59305. this.length_ = 0;
  59306. };
  59307. /**
  59308. * Inserts an item into the linked list right after the current one.
  59309. *
  59310. * @param {?} data Item data.
  59311. */
  59312. ol.structs.LinkedList.prototype.insertItem = function(data) {
  59313. /** @type {ol.LinkedListItem} */
  59314. var item = {
  59315. prev: undefined,
  59316. next: undefined,
  59317. data: data
  59318. };
  59319. var head = this.head_;
  59320. //Initialize the list.
  59321. if (!head) {
  59322. this.first_ = item;
  59323. this.last_ = item;
  59324. if (this.circular_) {
  59325. item.next = item;
  59326. item.prev = item;
  59327. }
  59328. } else {
  59329. //Link the new item to the adjacent ones.
  59330. var next = head.next;
  59331. item.prev = head;
  59332. item.next = next;
  59333. head.next = item;
  59334. if (next) {
  59335. next.prev = item;
  59336. }
  59337. if (head === this.last_) {
  59338. this.last_ = item;
  59339. }
  59340. }
  59341. this.head_ = item;
  59342. this.length_++;
  59343. };
  59344. /**
  59345. * Removes the current item from the list. Sets the cursor to the next item,
  59346. * if possible.
  59347. */
  59348. ol.structs.LinkedList.prototype.removeItem = function() {
  59349. var head = this.head_;
  59350. if (head) {
  59351. var next = head.next;
  59352. var prev = head.prev;
  59353. if (next) {
  59354. next.prev = prev;
  59355. }
  59356. if (prev) {
  59357. prev.next = next;
  59358. }
  59359. this.head_ = next || prev;
  59360. if (this.first_ === this.last_) {
  59361. this.head_ = undefined;
  59362. this.first_ = undefined;
  59363. this.last_ = undefined;
  59364. } else if (this.first_ === head) {
  59365. this.first_ = this.head_;
  59366. } else if (this.last_ === head) {
  59367. this.last_ = prev ? this.head_.prev : this.head_;
  59368. }
  59369. this.length_--;
  59370. }
  59371. };
  59372. /**
  59373. * Sets the cursor to the first item, and returns the associated data.
  59374. *
  59375. * @return {?} Item data.
  59376. */
  59377. ol.structs.LinkedList.prototype.firstItem = function() {
  59378. this.head_ = this.first_;
  59379. if (this.head_) {
  59380. return this.head_.data;
  59381. }
  59382. return undefined;
  59383. };
  59384. /**
  59385. * Sets the cursor to the last item, and returns the associated data.
  59386. *
  59387. * @return {?} Item data.
  59388. */
  59389. ol.structs.LinkedList.prototype.lastItem = function() {
  59390. this.head_ = this.last_;
  59391. if (this.head_) {
  59392. return this.head_.data;
  59393. }
  59394. return undefined;
  59395. };
  59396. /**
  59397. * Sets the cursor to the next item, and returns the associated data.
  59398. *
  59399. * @return {?} Item data.
  59400. */
  59401. ol.structs.LinkedList.prototype.nextItem = function() {
  59402. if (this.head_ && this.head_.next) {
  59403. this.head_ = this.head_.next;
  59404. return this.head_.data;
  59405. }
  59406. return undefined;
  59407. };
  59408. /**
  59409. * Returns the next item's data without moving the cursor.
  59410. *
  59411. * @return {?} Item data.
  59412. */
  59413. ol.structs.LinkedList.prototype.getNextItem = function() {
  59414. if (this.head_ && this.head_.next) {
  59415. return this.head_.next.data;
  59416. }
  59417. return undefined;
  59418. };
  59419. /**
  59420. * Sets the cursor to the previous item, and returns the associated data.
  59421. *
  59422. * @return {?} Item data.
  59423. */
  59424. ol.structs.LinkedList.prototype.prevItem = function() {
  59425. if (this.head_ && this.head_.prev) {
  59426. this.head_ = this.head_.prev;
  59427. return this.head_.data;
  59428. }
  59429. return undefined;
  59430. };
  59431. /**
  59432. * Returns the previous item's data without moving the cursor.
  59433. *
  59434. * @return {?} Item data.
  59435. */
  59436. ol.structs.LinkedList.prototype.getPrevItem = function() {
  59437. if (this.head_ && this.head_.prev) {
  59438. return this.head_.prev.data;
  59439. }
  59440. return undefined;
  59441. };
  59442. /**
  59443. * Returns the current item's data.
  59444. *
  59445. * @return {?} Item data.
  59446. */
  59447. ol.structs.LinkedList.prototype.getCurrItem = function() {
  59448. if (this.head_) {
  59449. return this.head_.data;
  59450. }
  59451. return undefined;
  59452. };
  59453. /**
  59454. * Sets the first item of the list. This only works for circular lists, and sets
  59455. * the last item accordingly.
  59456. */
  59457. ol.structs.LinkedList.prototype.setFirstItem = function() {
  59458. if (this.circular_ && this.head_) {
  59459. this.first_ = this.head_;
  59460. this.last_ = this.head_.prev;
  59461. }
  59462. };
  59463. /**
  59464. * Concatenates two lists.
  59465. * @param {ol.structs.LinkedList} list List to merge into the current list.
  59466. */
  59467. ol.structs.LinkedList.prototype.concat = function(list) {
  59468. if (list.head_) {
  59469. if (this.head_) {
  59470. var end = this.head_.next;
  59471. this.head_.next = list.first_;
  59472. list.first_.prev = this.head_;
  59473. end.prev = list.last_;
  59474. list.last_.next = end;
  59475. this.length_ += list.length_;
  59476. } else {
  59477. this.head_ = list.head_;
  59478. this.first_ = list.first_;
  59479. this.last_ = list.last_;
  59480. this.length_ = list.length_;
  59481. }
  59482. list.head_ = undefined;
  59483. list.first_ = undefined;
  59484. list.last_ = undefined;
  59485. list.length_ = 0;
  59486. }
  59487. };
  59488. /**
  59489. * Returns the current length of the list.
  59490. *
  59491. * @return {number} Length.
  59492. */
  59493. ol.structs.LinkedList.prototype.getLength = function() {
  59494. return this.length_;
  59495. };
  59496. goog.provide('ol.render.webgl.PolygonReplay');
  59497. goog.require('ol');
  59498. goog.require('ol.array');
  59499. goog.require('ol.color');
  59500. goog.require('ol.extent');
  59501. goog.require('ol.obj');
  59502. goog.require('ol.geom.flat.contains');
  59503. goog.require('ol.geom.flat.orient');
  59504. goog.require('ol.geom.flat.transform');
  59505. goog.require('ol.render.webgl.polygonreplay.defaultshader');
  59506. goog.require('ol.render.webgl.polygonreplay.defaultshader.Locations');
  59507. goog.require('ol.render.webgl.LineStringReplay');
  59508. goog.require('ol.render.webgl.Replay');
  59509. goog.require('ol.render.webgl');
  59510. goog.require('ol.style.Stroke');
  59511. goog.require('ol.structs.LinkedList');
  59512. goog.require('ol.structs.RBush');
  59513. goog.require('ol.webgl');
  59514. goog.require('ol.webgl.Buffer');
  59515. /**
  59516. * @constructor
  59517. * @extends {ol.render.webgl.Replay}
  59518. * @param {number} tolerance Tolerance.
  59519. * @param {ol.Extent} maxExtent Max extent.
  59520. * @struct
  59521. */
  59522. ol.render.webgl.PolygonReplay = function(tolerance, maxExtent) {
  59523. ol.render.webgl.Replay.call(this, tolerance, maxExtent);
  59524. this.lineStringReplay = new ol.render.webgl.LineStringReplay(
  59525. tolerance, maxExtent);
  59526. /**
  59527. * @private
  59528. * @type {ol.render.webgl.polygonreplay.defaultshader.Locations}
  59529. */
  59530. this.defaultLocations_ = null;
  59531. /**
  59532. * @private
  59533. * @type {Array.<Array.<number>>}
  59534. */
  59535. this.styles_ = [];
  59536. /**
  59537. * @private
  59538. * @type {Array.<number>}
  59539. */
  59540. this.styleIndices_ = [];
  59541. /**
  59542. * @private
  59543. * @type {{fillColor: (Array.<number>|null),
  59544. * changed: boolean}|null}
  59545. */
  59546. this.state_ = {
  59547. fillColor: null,
  59548. changed: false
  59549. };
  59550. };
  59551. ol.inherits(ol.render.webgl.PolygonReplay, ol.render.webgl.Replay);
  59552. /**
  59553. * Draw one polygon.
  59554. * @param {Array.<number>} flatCoordinates Flat coordinates.
  59555. * @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates.
  59556. * @param {number} stride Stride.
  59557. * @private
  59558. */
  59559. ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = function(
  59560. flatCoordinates, holeFlatCoordinates, stride) {
  59561. // Triangulate the polygon
  59562. var outerRing = new ol.structs.LinkedList();
  59563. var rtree = new ol.structs.RBush();
  59564. // Initialize the outer ring
  59565. this.processFlatCoordinates_(flatCoordinates, stride, outerRing, rtree, true);
  59566. var maxCoords = this.getMaxCoords_(outerRing);
  59567. // Eliminate holes, if there are any
  59568. if (holeFlatCoordinates.length) {
  59569. var i, ii;
  59570. var holeLists = [];
  59571. for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
  59572. var holeList = {
  59573. list: new ol.structs.LinkedList(),
  59574. maxCoords: undefined,
  59575. rtree: new ol.structs.RBush()
  59576. };
  59577. holeLists.push(holeList);
  59578. this.processFlatCoordinates_(holeFlatCoordinates[i],
  59579. stride, holeList.list, holeList.rtree, false);
  59580. this.classifyPoints_(holeList.list, holeList.rtree, true);
  59581. holeList.maxCoords = this.getMaxCoords_(holeList.list);
  59582. }
  59583. holeLists.sort(function(a, b) {
  59584. return b.maxCoords[0] === a.maxCoords[0] ?
  59585. a.maxCoords[1] - b.maxCoords[1] : b.maxCoords[0] - a.maxCoords[0];
  59586. });
  59587. for (i = 0; i < holeLists.length; ++i) {
  59588. var currList = holeLists[i].list;
  59589. var start = currList.firstItem();
  59590. var currItem = start;
  59591. var intersection;
  59592. do {
  59593. //TODO: Triangulate holes when they intersect the outer ring.
  59594. if (this.getIntersections_(currItem, rtree).length) {
  59595. intersection = true;
  59596. break;
  59597. }
  59598. currItem = currList.nextItem();
  59599. } while (start !== currItem);
  59600. if (!intersection) {
  59601. if (this.bridgeHole_(currList, holeLists[i].maxCoords[0], outerRing, maxCoords[0], rtree)) {
  59602. rtree.concat(holeLists[i].rtree);
  59603. this.classifyPoints_(outerRing, rtree, false);
  59604. }
  59605. }
  59606. }
  59607. } else {
  59608. this.classifyPoints_(outerRing, rtree, false);
  59609. }
  59610. this.triangulate_(outerRing, rtree);
  59611. };
  59612. /**
  59613. * Inserts flat coordinates in a linked list and adds them to the vertex buffer.
  59614. * @private
  59615. * @param {Array.<number>} flatCoordinates Flat coordinates.
  59616. * @param {number} stride Stride.
  59617. * @param {ol.structs.LinkedList} list Linked list.
  59618. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59619. * @param {boolean} clockwise Coordinate order should be clockwise.
  59620. */
  59621. ol.render.webgl.PolygonReplay.prototype.processFlatCoordinates_ = function(
  59622. flatCoordinates, stride, list, rtree, clockwise) {
  59623. var isClockwise = ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates,
  59624. 0, flatCoordinates.length, stride);
  59625. var i, ii;
  59626. var n = this.vertices.length / 2;
  59627. /** @type {ol.WebglPolygonVertex} */
  59628. var start;
  59629. /** @type {ol.WebglPolygonVertex} */
  59630. var p0;
  59631. /** @type {ol.WebglPolygonVertex} */
  59632. var p1;
  59633. var extents = [];
  59634. var segments = [];
  59635. if (clockwise === isClockwise) {
  59636. start = this.createPoint_(flatCoordinates[0], flatCoordinates[1], n++);
  59637. p0 = start;
  59638. for (i = stride, ii = flatCoordinates.length; i < ii; i += stride) {
  59639. p1 = this.createPoint_(flatCoordinates[i], flatCoordinates[i + 1], n++);
  59640. segments.push(this.insertItem_(p0, p1, list));
  59641. extents.push([Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.max(p0.x, p1.x),
  59642. Math.max(p0.y, p1.y)]);
  59643. p0 = p1;
  59644. }
  59645. segments.push(this.insertItem_(p1, start, list));
  59646. extents.push([Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.max(p0.x, p1.x),
  59647. Math.max(p0.y, p1.y)]);
  59648. } else {
  59649. var end = flatCoordinates.length - stride;
  59650. start = this.createPoint_(flatCoordinates[end], flatCoordinates[end + 1], n++);
  59651. p0 = start;
  59652. for (i = end - stride, ii = 0; i >= ii; i -= stride) {
  59653. p1 = this.createPoint_(flatCoordinates[i], flatCoordinates[i + 1], n++);
  59654. segments.push(this.insertItem_(p0, p1, list));
  59655. extents.push([Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.max(p0.x, p1.x),
  59656. Math.max(p0.y, p1.y)]);
  59657. p0 = p1;
  59658. }
  59659. segments.push(this.insertItem_(p1, start, list));
  59660. extents.push([Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.max(p0.x, p1.x),
  59661. Math.max(p0.y, p1.y)]);
  59662. }
  59663. rtree.load(extents, segments);
  59664. };
  59665. /**
  59666. * Returns the rightmost coordinates of a polygon on the X axis.
  59667. * @private
  59668. * @param {ol.structs.LinkedList} list Polygons ring.
  59669. * @return {Array.<number>} Max X coordinates.
  59670. */
  59671. ol.render.webgl.PolygonReplay.prototype.getMaxCoords_ = function(list) {
  59672. var start = list.firstItem();
  59673. var seg = start;
  59674. var maxCoords = [seg.p0.x, seg.p0.y];
  59675. do {
  59676. seg = list.nextItem();
  59677. if (seg.p0.x > maxCoords[0]) {
  59678. maxCoords = [seg.p0.x, seg.p0.y];
  59679. }
  59680. } while (seg !== start);
  59681. return maxCoords;
  59682. };
  59683. /**
  59684. * Classifies the points of a polygon list as convex, reflex. Removes collinear vertices.
  59685. * @private
  59686. * @param {ol.structs.LinkedList} list Polygon ring.
  59687. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59688. * @param {boolean} ccw The orientation of the polygon is counter-clockwise.
  59689. * @return {boolean} There were reclassified points.
  59690. */
  59691. ol.render.webgl.PolygonReplay.prototype.classifyPoints_ = function(list, rtree, ccw) {
  59692. var start = list.firstItem();
  59693. var s0 = start;
  59694. var s1 = list.nextItem();
  59695. var pointsReclassified = false;
  59696. do {
  59697. var reflex = ccw ? ol.render.webgl.triangleIsCounterClockwise(s1.p1.x,
  59698. s1.p1.y, s0.p1.x, s0.p1.y, s0.p0.x, s0.p0.y) :
  59699. ol.render.webgl.triangleIsCounterClockwise(s0.p0.x, s0.p0.y, s0.p1.x,
  59700. s0.p1.y, s1.p1.x, s1.p1.y);
  59701. if (reflex === undefined) {
  59702. this.removeItem_(s0, s1, list, rtree);
  59703. pointsReclassified = true;
  59704. if (s1 === start) {
  59705. start = list.getNextItem();
  59706. }
  59707. s1 = s0;
  59708. list.prevItem();
  59709. } else if (s0.p1.reflex !== reflex) {
  59710. s0.p1.reflex = reflex;
  59711. pointsReclassified = true;
  59712. }
  59713. s0 = s1;
  59714. s1 = list.nextItem();
  59715. } while (s0 !== start);
  59716. return pointsReclassified;
  59717. };
  59718. /**
  59719. * @private
  59720. * @param {ol.structs.LinkedList} hole Linked list of the hole.
  59721. * @param {number} holeMaxX Maximum X value of the hole.
  59722. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59723. * @param {number} listMaxX Maximum X value of the polygon.
  59724. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59725. * @return {boolean} Bridging was successful.
  59726. */
  59727. ol.render.webgl.PolygonReplay.prototype.bridgeHole_ = function(hole, holeMaxX,
  59728. list, listMaxX, rtree) {
  59729. var seg = hole.firstItem();
  59730. while (seg.p1.x !== holeMaxX) {
  59731. seg = hole.nextItem();
  59732. }
  59733. var p1 = seg.p1;
  59734. /** @type {ol.WebglPolygonVertex} */
  59735. var p2 = {x: listMaxX, y: p1.y, i: -1};
  59736. var minDist = Infinity;
  59737. var i, ii, bestPoint;
  59738. /** @type {ol.WebglPolygonVertex} */
  59739. var p5;
  59740. var intersectingSegments = this.getIntersections_({p0: p1, p1: p2}, rtree, true);
  59741. for (i = 0, ii = intersectingSegments.length; i < ii; ++i) {
  59742. var currSeg = intersectingSegments[i];
  59743. var intersection = this.calculateIntersection_(p1, p2, currSeg.p0,
  59744. currSeg.p1, true);
  59745. var dist = Math.abs(p1.x - intersection[0]);
  59746. if (dist < minDist && ol.render.webgl.triangleIsCounterClockwise(p1.x, p1.y,
  59747. currSeg.p0.x, currSeg.p0.y, currSeg.p1.x, currSeg.p1.y) !== undefined) {
  59748. minDist = dist;
  59749. p5 = {x: intersection[0], y: intersection[1], i: -1};
  59750. seg = currSeg;
  59751. }
  59752. }
  59753. if (minDist === Infinity) {
  59754. return false;
  59755. }
  59756. bestPoint = seg.p1;
  59757. if (minDist > 0) {
  59758. var pointsInTriangle = this.getPointsInTriangle_(p1, p5, seg.p1, rtree);
  59759. if (pointsInTriangle.length) {
  59760. var theta = Infinity;
  59761. for (i = 0, ii = pointsInTriangle.length; i < ii; ++i) {
  59762. var currPoint = pointsInTriangle[i];
  59763. var currTheta = Math.atan2(p1.y - currPoint.y, p2.x - currPoint.x);
  59764. if (currTheta < theta || (currTheta === theta && currPoint.x < bestPoint.x)) {
  59765. theta = currTheta;
  59766. bestPoint = currPoint;
  59767. }
  59768. }
  59769. }
  59770. }
  59771. seg = list.firstItem();
  59772. while (seg.p1.x !== bestPoint.x || seg.p1.y !== bestPoint.y) {
  59773. seg = list.nextItem();
  59774. }
  59775. //We clone the bridge points as they can have different convexity.
  59776. var p0Bridge = {x: p1.x, y: p1.y, i: p1.i, reflex: undefined};
  59777. var p1Bridge = {x: seg.p1.x, y: seg.p1.y, i: seg.p1.i, reflex: undefined};
  59778. hole.getNextItem().p0 = p0Bridge;
  59779. this.insertItem_(p1, seg.p1, hole, rtree);
  59780. this.insertItem_(p1Bridge, p0Bridge, hole, rtree);
  59781. seg.p1 = p1Bridge;
  59782. hole.setFirstItem();
  59783. list.concat(hole);
  59784. return true;
  59785. };
  59786. /**
  59787. * @private
  59788. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59789. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59790. */
  59791. ol.render.webgl.PolygonReplay.prototype.triangulate_ = function(list, rtree) {
  59792. var ccw = false;
  59793. var simple = this.isSimple_(list, rtree);
  59794. // Start clipping ears
  59795. while (list.getLength() > 3) {
  59796. if (simple) {
  59797. if (!this.clipEars_(list, rtree, simple, ccw)) {
  59798. if (!this.classifyPoints_(list, rtree, ccw)) {
  59799. // Due to the behavior of OL's PIP algorithm, the ear clipping cannot
  59800. // introduce touching segments. However, the original data may have some.
  59801. if (!this.resolveSelfIntersections_(list, rtree, true)) {
  59802. break;
  59803. }
  59804. }
  59805. }
  59806. } else {
  59807. if (!this.clipEars_(list, rtree, simple, ccw)) {
  59808. // We ran out of ears, try to reclassify.
  59809. if (!this.classifyPoints_(list, rtree, ccw)) {
  59810. // We have a bad polygon, try to resolve local self-intersections.
  59811. if (!this.resolveSelfIntersections_(list, rtree)) {
  59812. simple = this.isSimple_(list, rtree);
  59813. if (!simple) {
  59814. // We have a really bad polygon, try more time consuming methods.
  59815. this.splitPolygon_(list, rtree);
  59816. break;
  59817. } else {
  59818. ccw = !this.isClockwise_(list);
  59819. this.classifyPoints_(list, rtree, ccw);
  59820. }
  59821. }
  59822. }
  59823. }
  59824. }
  59825. }
  59826. if (list.getLength() === 3) {
  59827. var numIndices = this.indices.length;
  59828. this.indices[numIndices++] = list.getPrevItem().p0.i;
  59829. this.indices[numIndices++] = list.getCurrItem().p0.i;
  59830. this.indices[numIndices++] = list.getNextItem().p0.i;
  59831. }
  59832. };
  59833. /**
  59834. * @private
  59835. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59836. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59837. * @param {boolean} simple The polygon is simple.
  59838. * @param {boolean} ccw Orientation of the polygon is counter-clockwise.
  59839. * @return {boolean} There were processed ears.
  59840. */
  59841. ol.render.webgl.PolygonReplay.prototype.clipEars_ = function(list, rtree, simple, ccw) {
  59842. var numIndices = this.indices.length;
  59843. var start = list.firstItem();
  59844. var s0 = list.getPrevItem();
  59845. var s1 = start;
  59846. var s2 = list.nextItem();
  59847. var s3 = list.getNextItem();
  59848. var p0, p1, p2;
  59849. var processedEars = false;
  59850. do {
  59851. p0 = s1.p0;
  59852. p1 = s1.p1;
  59853. p2 = s2.p1;
  59854. if (p1.reflex === false) {
  59855. // We might have a valid ear
  59856. var variableCriterion;
  59857. if (simple) {
  59858. variableCriterion = this.getPointsInTriangle_(p0, p1, p2, rtree, true).length === 0;
  59859. } else {
  59860. variableCriterion = ccw ? this.diagonalIsInside_(s3.p1, p2, p1, p0,
  59861. s0.p0) : this.diagonalIsInside_(s0.p0, p0, p1, p2, s3.p1);
  59862. }
  59863. if ((simple || this.getIntersections_({p0: p0, p1: p2}, rtree).length === 0) &&
  59864. variableCriterion) {
  59865. //The diagonal is completely inside the polygon
  59866. if (simple || p0.reflex === false || p2.reflex === false ||
  59867. ol.geom.flat.orient.linearRingIsClockwise([s0.p0.x, s0.p0.y, p0.x,
  59868. p0.y, p1.x, p1.y, p2.x, p2.y, s3.p1.x, s3.p1.y], 0, 10, 2) === !ccw) {
  59869. //The diagonal is persumably valid, we have an ear
  59870. this.indices[numIndices++] = p0.i;
  59871. this.indices[numIndices++] = p1.i;
  59872. this.indices[numIndices++] = p2.i;
  59873. this.removeItem_(s1, s2, list, rtree);
  59874. if (s2 === start) {
  59875. start = s3;
  59876. }
  59877. processedEars = true;
  59878. }
  59879. }
  59880. }
  59881. // Else we have a reflex point.
  59882. s0 = list.getPrevItem();
  59883. s1 = list.getCurrItem();
  59884. s2 = list.nextItem();
  59885. s3 = list.getNextItem();
  59886. } while (s1 !== start && list.getLength() > 3);
  59887. return processedEars;
  59888. };
  59889. /**
  59890. * @private
  59891. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59892. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59893. * @param {boolean=} opt_touch Resolve touching segments.
  59894. * @return {boolean} There were resolved intersections.
  59895. */
  59896. ol.render.webgl.PolygonReplay.prototype.resolveSelfIntersections_ = function(
  59897. list, rtree, opt_touch) {
  59898. var start = list.firstItem();
  59899. list.nextItem();
  59900. var s0 = start;
  59901. var s1 = list.nextItem();
  59902. var resolvedIntersections = false;
  59903. do {
  59904. var intersection = this.calculateIntersection_(s0.p0, s0.p1, s1.p0, s1.p1,
  59905. opt_touch);
  59906. if (intersection) {
  59907. var breakCond = false;
  59908. var numVertices = this.vertices.length;
  59909. var numIndices = this.indices.length;
  59910. var n = numVertices / 2;
  59911. var seg = list.prevItem();
  59912. list.removeItem();
  59913. rtree.remove(seg);
  59914. breakCond = (seg === start);
  59915. var p;
  59916. if (opt_touch) {
  59917. if (intersection[0] === s0.p0.x && intersection[1] === s0.p0.y) {
  59918. list.prevItem();
  59919. p = s0.p0;
  59920. s1.p0 = p;
  59921. rtree.remove(s0);
  59922. breakCond = breakCond || (s0 === start);
  59923. } else {
  59924. p = s1.p1;
  59925. s0.p1 = p;
  59926. rtree.remove(s1);
  59927. breakCond = breakCond || (s1 === start);
  59928. }
  59929. list.removeItem();
  59930. } else {
  59931. p = this.createPoint_(intersection[0], intersection[1], n);
  59932. s0.p1 = p;
  59933. s1.p0 = p;
  59934. rtree.update([Math.min(s0.p0.x, s0.p1.x), Math.min(s0.p0.y, s0.p1.y),
  59935. Math.max(s0.p0.x, s0.p1.x), Math.max(s0.p0.y, s0.p1.y)], s0);
  59936. rtree.update([Math.min(s1.p0.x, s1.p1.x), Math.min(s1.p0.y, s1.p1.y),
  59937. Math.max(s1.p0.x, s1.p1.x), Math.max(s1.p0.y, s1.p1.y)], s1);
  59938. }
  59939. this.indices[numIndices++] = seg.p0.i;
  59940. this.indices[numIndices++] = seg.p1.i;
  59941. this.indices[numIndices++] = p.i;
  59942. resolvedIntersections = true;
  59943. if (breakCond) {
  59944. break;
  59945. }
  59946. }
  59947. s0 = list.getPrevItem();
  59948. s1 = list.nextItem();
  59949. } while (s0 !== start);
  59950. return resolvedIntersections;
  59951. };
  59952. /**
  59953. * @private
  59954. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59955. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59956. * @return {boolean} The polygon is simple.
  59957. */
  59958. ol.render.webgl.PolygonReplay.prototype.isSimple_ = function(list, rtree) {
  59959. var start = list.firstItem();
  59960. var seg = start;
  59961. do {
  59962. if (this.getIntersections_(seg, rtree).length) {
  59963. return false;
  59964. }
  59965. seg = list.nextItem();
  59966. } while (seg !== start);
  59967. return true;
  59968. };
  59969. /**
  59970. * @private
  59971. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59972. * @return {boolean} Orientation is clockwise.
  59973. */
  59974. ol.render.webgl.PolygonReplay.prototype.isClockwise_ = function(list) {
  59975. var length = list.getLength() * 2;
  59976. var flatCoordinates = new Array(length);
  59977. var start = list.firstItem();
  59978. var seg = start;
  59979. var i = 0;
  59980. do {
  59981. flatCoordinates[i++] = seg.p0.x;
  59982. flatCoordinates[i++] = seg.p0.y;
  59983. seg = list.nextItem();
  59984. } while (seg !== start);
  59985. return ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates, 0, length, 2);
  59986. };
  59987. /**
  59988. * @private
  59989. * @param {ol.structs.LinkedList} list Linked list of the polygon.
  59990. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  59991. */
  59992. ol.render.webgl.PolygonReplay.prototype.splitPolygon_ = function(list, rtree) {
  59993. var start = list.firstItem();
  59994. var s0 = start;
  59995. do {
  59996. var intersections = this.getIntersections_(s0, rtree);
  59997. if (intersections.length) {
  59998. var s1 = intersections[0];
  59999. var n = this.vertices.length / 2;
  60000. var intersection = this.calculateIntersection_(s0.p0,
  60001. s0.p1, s1.p0, s1.p1);
  60002. var p = this.createPoint_(intersection[0], intersection[1], n);
  60003. var newPolygon = new ol.structs.LinkedList();
  60004. var newRtree = new ol.structs.RBush();
  60005. this.insertItem_(p, s0.p1, newPolygon, newRtree);
  60006. s0.p1 = p;
  60007. rtree.update([Math.min(s0.p0.x, p.x), Math.min(s0.p0.y, p.y),
  60008. Math.max(s0.p0.x, p.x), Math.max(s0.p0.y, p.y)], s0);
  60009. var currItem = list.nextItem();
  60010. while (currItem !== s1) {
  60011. this.insertItem_(currItem.p0, currItem.p1, newPolygon, newRtree);
  60012. rtree.remove(currItem);
  60013. list.removeItem();
  60014. currItem = list.getCurrItem();
  60015. }
  60016. this.insertItem_(s1.p0, p, newPolygon, newRtree);
  60017. s1.p0 = p;
  60018. rtree.update([Math.min(s1.p1.x, p.x), Math.min(s1.p1.y, p.y),
  60019. Math.max(s1.p1.x, p.x), Math.max(s1.p1.y, p.y)], s1);
  60020. this.classifyPoints_(list, rtree, false);
  60021. this.triangulate_(list, rtree);
  60022. this.classifyPoints_(newPolygon, newRtree, false);
  60023. this.triangulate_(newPolygon, newRtree);
  60024. break;
  60025. }
  60026. s0 = list.nextItem();
  60027. } while (s0 !== start);
  60028. };
  60029. /**
  60030. * @private
  60031. * @param {number} x X coordinate.
  60032. * @param {number} y Y coordinate.
  60033. * @param {number} i Index.
  60034. * @return {ol.WebglPolygonVertex} List item.
  60035. */
  60036. ol.render.webgl.PolygonReplay.prototype.createPoint_ = function(x, y, i) {
  60037. var numVertices = this.vertices.length;
  60038. this.vertices[numVertices++] = x;
  60039. this.vertices[numVertices++] = y;
  60040. /** @type {ol.WebglPolygonVertex} */
  60041. var p = {
  60042. x: x,
  60043. y: y,
  60044. i: i,
  60045. reflex: undefined
  60046. };
  60047. return p;
  60048. };
  60049. /**
  60050. * @private
  60051. * @param {ol.WebglPolygonVertex} p0 First point of segment.
  60052. * @param {ol.WebglPolygonVertex} p1 Second point of segment.
  60053. * @param {ol.structs.LinkedList} list Polygon ring.
  60054. * @param {ol.structs.RBush=} opt_rtree Insert the segment into the R-Tree.
  60055. * @return {ol.WebglPolygonSegment} segment.
  60056. */
  60057. ol.render.webgl.PolygonReplay.prototype.insertItem_ = function(p0, p1, list, opt_rtree) {
  60058. var seg = {
  60059. p0: p0,
  60060. p1: p1
  60061. };
  60062. list.insertItem(seg);
  60063. if (opt_rtree) {
  60064. opt_rtree.insert([Math.min(p0.x, p1.x), Math.min(p0.y, p1.y),
  60065. Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)], seg);
  60066. }
  60067. return seg;
  60068. };
  60069. /**
  60070. * @private
  60071. * @param {ol.WebglPolygonSegment} s0 Segment before the remove candidate.
  60072. * @param {ol.WebglPolygonSegment} s1 Remove candidate segment.
  60073. * @param {ol.structs.LinkedList} list Polygon ring.
  60074. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  60075. */
  60076. ol.render.webgl.PolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtree) {
  60077. if (list.getCurrItem() === s1) {
  60078. list.removeItem();
  60079. s0.p1 = s1.p1;
  60080. rtree.remove(s1);
  60081. rtree.update([Math.min(s0.p0.x, s0.p1.x), Math.min(s0.p0.y, s0.p1.y),
  60082. Math.max(s0.p0.x, s0.p1.x), Math.max(s0.p0.y, s0.p1.y)], s0);
  60083. }
  60084. };
  60085. /**
  60086. * @private
  60087. * @param {ol.WebglPolygonVertex} p0 First point.
  60088. * @param {ol.WebglPolygonVertex} p1 Second point.
  60089. * @param {ol.WebglPolygonVertex} p2 Third point.
  60090. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  60091. * @param {boolean=} opt_reflex Only include reflex points.
  60092. * @return {Array.<ol.WebglPolygonVertex>} Points in the triangle.
  60093. */
  60094. ol.render.webgl.PolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1,
  60095. p2, rtree, opt_reflex) {
  60096. var i, ii, j, p;
  60097. var result = [];
  60098. var segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x, p2.x),
  60099. Math.min(p0.y, p1.y, p2.y), Math.max(p0.x, p1.x, p2.x), Math.max(p0.y,
  60100. p1.y, p2.y)]);
  60101. for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
  60102. for (j in segmentsInExtent[i]) {
  60103. p = segmentsInExtent[i][j];
  60104. if (typeof p === 'object' && (!opt_reflex || p.reflex)) {
  60105. if ((p.x !== p0.x || p.y !== p0.y) && (p.x !== p1.x || p.y !== p1.y) &&
  60106. (p.x !== p2.x || p.y !== p2.y) && result.indexOf(p) === -1 &&
  60107. ol.geom.flat.contains.linearRingContainsXY([p0.x, p0.y, p1.x, p1.y,
  60108. p2.x, p2.y], 0, 6, 2, p.x, p.y)) {
  60109. result.push(p);
  60110. }
  60111. }
  60112. }
  60113. }
  60114. return result;
  60115. };
  60116. /**
  60117. * @private
  60118. * @param {ol.WebglPolygonSegment} segment Segment.
  60119. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
  60120. * @param {boolean=} opt_touch Touching segments should be considered an intersection.
  60121. * @return {Array.<ol.WebglPolygonSegment>} Intersecting segments.
  60122. */
  60123. ol.render.webgl.PolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_touch) {
  60124. var p0 = segment.p0;
  60125. var p1 = segment.p1;
  60126. var segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x),
  60127. Math.min(p0.y, p1.y), Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)]);
  60128. var result = [];
  60129. var i, ii;
  60130. for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
  60131. var currSeg = segmentsInExtent[i];
  60132. if (segment !== currSeg && (opt_touch || currSeg.p0 !== p1 || currSeg.p1 !== p0) &&
  60133. this.calculateIntersection_(p0, p1, currSeg.p0, currSeg.p1, opt_touch)) {
  60134. result.push(currSeg);
  60135. }
  60136. }
  60137. return result;
  60138. };
  60139. /**
  60140. * Line intersection algorithm by Paul Bourke.
  60141. * @see http://paulbourke.net/geometry/pointlineplane/
  60142. *
  60143. * @private
  60144. * @param {ol.WebglPolygonVertex} p0 First point.
  60145. * @param {ol.WebglPolygonVertex} p1 Second point.
  60146. * @param {ol.WebglPolygonVertex} p2 Third point.
  60147. * @param {ol.WebglPolygonVertex} p3 Fourth point.
  60148. * @param {boolean=} opt_touch Touching segments should be considered an intersection.
  60149. * @return {Array.<number>|undefined} Intersection coordinates.
  60150. */
  60151. ol.render.webgl.PolygonReplay.prototype.calculateIntersection_ = function(p0,
  60152. p1, p2, p3, opt_touch) {
  60153. var denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y);
  60154. if (denom !== 0) {
  60155. var ua = ((p3.x - p2.x) * (p0.y - p2.y) - (p3.y - p2.y) * (p0.x - p2.x)) / denom;
  60156. var ub = ((p1.x - p0.x) * (p0.y - p2.y) - (p1.y - p0.y) * (p0.x - p2.x)) / denom;
  60157. if ((!opt_touch && ua > ol.render.webgl.EPSILON && ua < 1 - ol.render.webgl.EPSILON &&
  60158. ub > ol.render.webgl.EPSILON && ub < 1 - ol.render.webgl.EPSILON) || (opt_touch &&
  60159. ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1)) {
  60160. return [p0.x + ua * (p1.x - p0.x), p0.y + ua * (p1.y - p0.y)];
  60161. }
  60162. }
  60163. return undefined;
  60164. };
  60165. /**
  60166. * @private
  60167. * @param {ol.WebglPolygonVertex} p0 Point before the start of the diagonal.
  60168. * @param {ol.WebglPolygonVertex} p1 Start point of the diagonal.
  60169. * @param {ol.WebglPolygonVertex} p2 Ear candidate.
  60170. * @param {ol.WebglPolygonVertex} p3 End point of the diagonal.
  60171. * @param {ol.WebglPolygonVertex} p4 Point after the end of the diagonal.
  60172. * @return {boolean} Diagonal is inside the polygon.
  60173. */
  60174. ol.render.webgl.PolygonReplay.prototype.diagonalIsInside_ = function(p0, p1, p2, p3, p4) {
  60175. if (p1.reflex === undefined || p3.reflex === undefined) {
  60176. return false;
  60177. }
  60178. var p1IsLeftOf = (p2.x - p3.x) * (p1.y - p3.y) > (p2.y - p3.y) * (p1.x - p3.x);
  60179. var p1IsRightOf = (p4.x - p3.x) * (p1.y - p3.y) < (p4.y - p3.y) * (p1.x - p3.x);
  60180. var p3IsLeftOf = (p0.x - p1.x) * (p3.y - p1.y) > (p0.y - p1.y) * (p3.x - p1.x);
  60181. var p3IsRightOf = (p2.x - p1.x) * (p3.y - p1.y) < (p2.y - p1.y) * (p3.x - p1.x);
  60182. var p1InCone = p3.reflex ? p1IsRightOf || p1IsLeftOf : p1IsRightOf && p1IsLeftOf;
  60183. var p3InCone = p1.reflex ? p3IsRightOf || p3IsLeftOf : p3IsRightOf && p3IsLeftOf;
  60184. return p1InCone && p3InCone;
  60185. };
  60186. /**
  60187. * @inheritDoc
  60188. */
  60189. ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon = function(multiPolygonGeometry, feature) {
  60190. var endss = multiPolygonGeometry.getEndss();
  60191. var stride = multiPolygonGeometry.getStride();
  60192. var currIndex = this.indices.length;
  60193. var currLineIndex = this.lineStringReplay.getCurrentIndex();
  60194. var flatCoordinates = multiPolygonGeometry.getFlatCoordinates();
  60195. var i, ii, j, jj;
  60196. var start = 0;
  60197. for (i = 0, ii = endss.length; i < ii; ++i) {
  60198. var ends = endss[i];
  60199. if (ends.length > 0) {
  60200. var outerRing = ol.geom.flat.transform.translate(flatCoordinates, start, ends[0],
  60201. stride, -this.origin[0], -this.origin[1]);
  60202. if (outerRing.length) {
  60203. var holes = [];
  60204. var holeFlatCoords;
  60205. for (j = 1, jj = ends.length; j < jj; ++j) {
  60206. if (ends[j] !== ends[j - 1]) {
  60207. holeFlatCoords = ol.geom.flat.transform.translate(flatCoordinates, ends[j - 1],
  60208. ends[j], stride, -this.origin[0], -this.origin[1]);
  60209. holes.push(holeFlatCoords);
  60210. }
  60211. }
  60212. this.lineStringReplay.drawPolygonCoordinates(outerRing, holes, stride);
  60213. this.drawCoordinates_(outerRing, holes, stride);
  60214. }
  60215. }
  60216. start = ends[ends.length - 1];
  60217. }
  60218. if (this.indices.length > currIndex) {
  60219. this.startIndices.push(currIndex);
  60220. this.startIndicesFeature.push(feature);
  60221. if (this.state_.changed) {
  60222. this.styleIndices_.push(currIndex);
  60223. this.state_.changed = false;
  60224. }
  60225. }
  60226. if (this.lineStringReplay.getCurrentIndex() > currLineIndex) {
  60227. this.lineStringReplay.setPolygonStyle(feature, currLineIndex);
  60228. }
  60229. };
  60230. /**
  60231. * @inheritDoc
  60232. */
  60233. ol.render.webgl.PolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) {
  60234. var ends = polygonGeometry.getEnds();
  60235. var stride = polygonGeometry.getStride();
  60236. if (ends.length > 0) {
  60237. var flatCoordinates = polygonGeometry.getFlatCoordinates().map(Number);
  60238. var outerRing = ol.geom.flat.transform.translate(flatCoordinates, 0, ends[0],
  60239. stride, -this.origin[0], -this.origin[1]);
  60240. if (outerRing.length) {
  60241. var holes = [];
  60242. var i, ii, holeFlatCoords;
  60243. for (i = 1, ii = ends.length; i < ii; ++i) {
  60244. if (ends[i] !== ends[i - 1]) {
  60245. holeFlatCoords = ol.geom.flat.transform.translate(flatCoordinates, ends[i - 1],
  60246. ends[i], stride, -this.origin[0], -this.origin[1]);
  60247. holes.push(holeFlatCoords);
  60248. }
  60249. }
  60250. this.startIndices.push(this.indices.length);
  60251. this.startIndicesFeature.push(feature);
  60252. if (this.state_.changed) {
  60253. this.styleIndices_.push(this.indices.length);
  60254. this.state_.changed = false;
  60255. }
  60256. this.lineStringReplay.setPolygonStyle(feature);
  60257. this.lineStringReplay.drawPolygonCoordinates(outerRing, holes, stride);
  60258. this.drawCoordinates_(outerRing, holes, stride);
  60259. }
  60260. }
  60261. };
  60262. /**
  60263. * @inheritDoc
  60264. **/
  60265. ol.render.webgl.PolygonReplay.prototype.finish = function(context) {
  60266. // create, bind, and populate the vertices buffer
  60267. this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
  60268. // create, bind, and populate the indices buffer
  60269. this.indicesBuffer = new ol.webgl.Buffer(this.indices);
  60270. this.startIndices.push(this.indices.length);
  60271. this.lineStringReplay.finish(context);
  60272. //Clean up, if there is nothing to draw
  60273. if (this.styleIndices_.length === 0 && this.styles_.length > 0) {
  60274. this.styles_ = [];
  60275. }
  60276. this.vertices = null;
  60277. this.indices = null;
  60278. };
  60279. /**
  60280. * @inheritDoc
  60281. */
  60282. ol.render.webgl.PolygonReplay.prototype.getDeleteResourcesFunction = function(context) {
  60283. var verticesBuffer = this.verticesBuffer;
  60284. var indicesBuffer = this.indicesBuffer;
  60285. var lineDeleter = this.lineStringReplay.getDeleteResourcesFunction(context);
  60286. return function() {
  60287. context.deleteBuffer(verticesBuffer);
  60288. context.deleteBuffer(indicesBuffer);
  60289. lineDeleter();
  60290. };
  60291. };
  60292. /**
  60293. * @inheritDoc
  60294. */
  60295. ol.render.webgl.PolygonReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
  60296. // get the program
  60297. var fragmentShader, vertexShader;
  60298. fragmentShader = ol.render.webgl.polygonreplay.defaultshader.fragment;
  60299. vertexShader = ol.render.webgl.polygonreplay.defaultshader.vertex;
  60300. var program = context.getProgram(fragmentShader, vertexShader);
  60301. // get the locations
  60302. var locations;
  60303. if (!this.defaultLocations_) {
  60304. locations = new ol.render.webgl.polygonreplay.defaultshader.Locations(gl, program);
  60305. this.defaultLocations_ = locations;
  60306. } else {
  60307. locations = this.defaultLocations_;
  60308. }
  60309. context.useProgram(program);
  60310. // enable the vertex attrib arrays
  60311. gl.enableVertexAttribArray(locations.a_position);
  60312. gl.vertexAttribPointer(locations.a_position, 2, ol.webgl.FLOAT,
  60313. false, 8, 0);
  60314. return locations;
  60315. };
  60316. /**
  60317. * @inheritDoc
  60318. */
  60319. ol.render.webgl.PolygonReplay.prototype.shutDownProgram = function(gl, locations) {
  60320. gl.disableVertexAttribArray(locations.a_position);
  60321. };
  60322. /**
  60323. * @inheritDoc
  60324. */
  60325. ol.render.webgl.PolygonReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
  60326. //Save GL parameters.
  60327. var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC));
  60328. var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK));
  60329. if (!hitDetection) {
  60330. gl.enable(gl.DEPTH_TEST);
  60331. gl.depthMask(true);
  60332. gl.depthFunc(gl.NOTEQUAL);
  60333. }
  60334. if (!ol.obj.isEmpty(skippedFeaturesHash)) {
  60335. this.drawReplaySkipping_(gl, context, skippedFeaturesHash);
  60336. } else {
  60337. //Draw by style groups to minimize drawElements() calls.
  60338. var i, start, end, nextStyle;
  60339. end = this.startIndices[this.startIndices.length - 1];
  60340. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  60341. start = this.styleIndices_[i];
  60342. nextStyle = this.styles_[i];
  60343. this.setFillStyle_(gl, nextStyle);
  60344. this.drawElements(gl, context, start, end);
  60345. end = start;
  60346. }
  60347. }
  60348. if (!hitDetection) {
  60349. gl.disable(gl.DEPTH_TEST);
  60350. gl.clear(gl.DEPTH_BUFFER_BIT);
  60351. //Restore GL parameters.
  60352. gl.depthMask(tmpDepthMask);
  60353. gl.depthFunc(tmpDepthFunc);
  60354. }
  60355. };
  60356. /**
  60357. * @inheritDoc
  60358. */
  60359. ol.render.webgl.PolygonReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
  60360. featureCallback, opt_hitExtent) {
  60361. var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
  60362. featureIndex = this.startIndices.length - 2;
  60363. end = this.startIndices[featureIndex + 1];
  60364. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  60365. nextStyle = this.styles_[i];
  60366. this.setFillStyle_(gl, nextStyle);
  60367. groupStart = this.styleIndices_[i];
  60368. while (featureIndex >= 0 &&
  60369. this.startIndices[featureIndex] >= groupStart) {
  60370. start = this.startIndices[featureIndex];
  60371. feature = this.startIndicesFeature[featureIndex];
  60372. featureUid = ol.getUid(feature).toString();
  60373. if (skippedFeaturesHash[featureUid] === undefined &&
  60374. feature.getGeometry() &&
  60375. (opt_hitExtent === undefined || ol.extent.intersects(
  60376. /** @type {Array<number>} */ (opt_hitExtent),
  60377. feature.getGeometry().getExtent()))) {
  60378. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
  60379. this.drawElements(gl, context, start, end);
  60380. var result = featureCallback(feature);
  60381. if (result) {
  60382. return result;
  60383. }
  60384. }
  60385. featureIndex--;
  60386. end = start;
  60387. }
  60388. }
  60389. return undefined;
  60390. };
  60391. /**
  60392. * @private
  60393. * @param {WebGLRenderingContext} gl gl.
  60394. * @param {ol.webgl.Context} context Context.
  60395. * @param {Object} skippedFeaturesHash Ids of features to skip.
  60396. */
  60397. ol.render.webgl.PolygonReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
  60398. var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
  60399. featureIndex = this.startIndices.length - 2;
  60400. end = start = this.startIndices[featureIndex + 1];
  60401. for (i = this.styleIndices_.length - 1; i >= 0; --i) {
  60402. nextStyle = this.styles_[i];
  60403. this.setFillStyle_(gl, nextStyle);
  60404. groupStart = this.styleIndices_[i];
  60405. while (featureIndex >= 0 &&
  60406. this.startIndices[featureIndex] >= groupStart) {
  60407. featureStart = this.startIndices[featureIndex];
  60408. feature = this.startIndicesFeature[featureIndex];
  60409. featureUid = ol.getUid(feature).toString();
  60410. if (skippedFeaturesHash[featureUid]) {
  60411. if (start !== end) {
  60412. this.drawElements(gl, context, start, end);
  60413. gl.clear(gl.DEPTH_BUFFER_BIT);
  60414. }
  60415. end = featureStart;
  60416. }
  60417. featureIndex--;
  60418. start = featureStart;
  60419. }
  60420. if (start !== end) {
  60421. this.drawElements(gl, context, start, end);
  60422. gl.clear(gl.DEPTH_BUFFER_BIT);
  60423. }
  60424. start = end = groupStart;
  60425. }
  60426. };
  60427. /**
  60428. * @private
  60429. * @param {WebGLRenderingContext} gl gl.
  60430. * @param {Array.<number>} color Color.
  60431. */
  60432. ol.render.webgl.PolygonReplay.prototype.setFillStyle_ = function(gl, color) {
  60433. gl.uniform4fv(this.defaultLocations_.u_color, color);
  60434. };
  60435. /**
  60436. * @inheritDoc
  60437. */
  60438. ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
  60439. var fillStyleColor = fillStyle ? fillStyle.getColor() : [0, 0, 0, 0];
  60440. if (!(fillStyleColor instanceof CanvasGradient) &&
  60441. !(fillStyleColor instanceof CanvasPattern)) {
  60442. fillStyleColor = ol.color.asArray(fillStyleColor).map(function(c, i) {
  60443. return i != 3 ? c / 255 : c;
  60444. }) || ol.render.webgl.defaultFillStyle;
  60445. } else {
  60446. fillStyleColor = ol.render.webgl.defaultFillStyle;
  60447. }
  60448. if (!this.state_.fillColor || !ol.array.equals(fillStyleColor, this.state_.fillColor)) {
  60449. this.state_.fillColor = fillStyleColor;
  60450. this.state_.changed = true;
  60451. this.styles_.push(fillStyleColor);
  60452. }
  60453. //Provide a null stroke style, if no strokeStyle is provided. Required for the draw interaction to work.
  60454. if (strokeStyle) {
  60455. this.lineStringReplay.setFillStrokeStyle(null, strokeStyle);
  60456. } else {
  60457. var nullStrokeStyle = new ol.style.Stroke({
  60458. color: [0, 0, 0, 0],
  60459. lineWidth: 0
  60460. });
  60461. this.lineStringReplay.setFillStrokeStyle(null, nullStrokeStyle);
  60462. }
  60463. };
  60464. goog.provide('ol.style.Atlas');
  60465. goog.require('ol.dom');
  60466. /**
  60467. * This class facilitates the creation of image atlases.
  60468. *
  60469. * Images added to an atlas will be rendered onto a single
  60470. * atlas canvas. The distribution of images on the canvas is
  60471. * managed with the bin packing algorithm described in:
  60472. * http://www.blackpawn.com/texts/lightmaps/
  60473. *
  60474. * @constructor
  60475. * @struct
  60476. * @param {number} size The size in pixels of the sprite image.
  60477. * @param {number} space The space in pixels between images.
  60478. * Because texture coordinates are float values, the edges of
  60479. * images might not be completely correct (in a way that the
  60480. * edges overlap when being rendered). To avoid this we add a
  60481. * padding around each image.
  60482. */
  60483. ol.style.Atlas = function(size, space) {
  60484. /**
  60485. * @private
  60486. * @type {number}
  60487. */
  60488. this.space_ = space;
  60489. /**
  60490. * @private
  60491. * @type {Array.<ol.AtlasBlock>}
  60492. */
  60493. this.emptyBlocks_ = [{x: 0, y: 0, width: size, height: size}];
  60494. /**
  60495. * @private
  60496. * @type {Object.<string, ol.AtlasInfo>}
  60497. */
  60498. this.entries_ = {};
  60499. /**
  60500. * @private
  60501. * @type {CanvasRenderingContext2D}
  60502. */
  60503. this.context_ = ol.dom.createCanvasContext2D(size, size);
  60504. /**
  60505. * @private
  60506. * @type {HTMLCanvasElement}
  60507. */
  60508. this.canvas_ = this.context_.canvas;
  60509. };
  60510. /**
  60511. * @param {string} id The identifier of the entry to check.
  60512. * @return {?ol.AtlasInfo} The atlas info.
  60513. */
  60514. ol.style.Atlas.prototype.get = function(id) {
  60515. return this.entries_[id] || null;
  60516. };
  60517. /**
  60518. * @param {string} id The identifier of the entry to add.
  60519. * @param {number} width The width.
  60520. * @param {number} height The height.
  60521. * @param {function(CanvasRenderingContext2D, number, number)} renderCallback
  60522. * Called to render the new image onto an atlas image.
  60523. * @param {Object=} opt_this Value to use as `this` when executing
  60524. * `renderCallback`.
  60525. * @return {?ol.AtlasInfo} The position and atlas image for the entry.
  60526. */
  60527. ol.style.Atlas.prototype.add = function(id, width, height, renderCallback, opt_this) {
  60528. var block, i, ii;
  60529. for (i = 0, ii = this.emptyBlocks_.length; i < ii; ++i) {
  60530. block = this.emptyBlocks_[i];
  60531. if (block.width >= width + this.space_ &&
  60532. block.height >= height + this.space_) {
  60533. // we found a block that is big enough for our entry
  60534. var entry = {
  60535. offsetX: block.x + this.space_,
  60536. offsetY: block.y + this.space_,
  60537. image: this.canvas_
  60538. };
  60539. this.entries_[id] = entry;
  60540. // render the image on the atlas image
  60541. renderCallback.call(opt_this, this.context_,
  60542. block.x + this.space_, block.y + this.space_);
  60543. // split the block after the insertion, either horizontally or vertically
  60544. this.split_(i, block, width + this.space_, height + this.space_);
  60545. return entry;
  60546. }
  60547. }
  60548. // there is no space for the new entry in this atlas
  60549. return null;
  60550. };
  60551. /**
  60552. * @private
  60553. * @param {number} index The index of the block.
  60554. * @param {ol.AtlasBlock} block The block to split.
  60555. * @param {number} width The width of the entry to insert.
  60556. * @param {number} height The height of the entry to insert.
  60557. */
  60558. ol.style.Atlas.prototype.split_ = function(index, block, width, height) {
  60559. var deltaWidth = block.width - width;
  60560. var deltaHeight = block.height - height;
  60561. /** @type {ol.AtlasBlock} */
  60562. var newBlock1;
  60563. /** @type {ol.AtlasBlock} */
  60564. var newBlock2;
  60565. if (deltaWidth > deltaHeight) {
  60566. // split vertically
  60567. // block right of the inserted entry
  60568. newBlock1 = {
  60569. x: block.x + width,
  60570. y: block.y,
  60571. width: block.width - width,
  60572. height: block.height
  60573. };
  60574. // block below the inserted entry
  60575. newBlock2 = {
  60576. x: block.x,
  60577. y: block.y + height,
  60578. width: width,
  60579. height: block.height - height
  60580. };
  60581. this.updateBlocks_(index, newBlock1, newBlock2);
  60582. } else {
  60583. // split horizontally
  60584. // block right of the inserted entry
  60585. newBlock1 = {
  60586. x: block.x + width,
  60587. y: block.y,
  60588. width: block.width - width,
  60589. height: height
  60590. };
  60591. // block below the inserted entry
  60592. newBlock2 = {
  60593. x: block.x,
  60594. y: block.y + height,
  60595. width: block.width,
  60596. height: block.height - height
  60597. };
  60598. this.updateBlocks_(index, newBlock1, newBlock2);
  60599. }
  60600. };
  60601. /**
  60602. * Remove the old block and insert new blocks at the same array position.
  60603. * The new blocks are inserted at the same position, so that splitted
  60604. * blocks (that are potentially smaller) are filled first.
  60605. * @private
  60606. * @param {number} index The index of the block to remove.
  60607. * @param {ol.AtlasBlock} newBlock1 The 1st block to add.
  60608. * @param {ol.AtlasBlock} newBlock2 The 2nd block to add.
  60609. */
  60610. ol.style.Atlas.prototype.updateBlocks_ = function(index, newBlock1, newBlock2) {
  60611. var args = [index, 1];
  60612. if (newBlock1.width > 0 && newBlock1.height > 0) {
  60613. args.push(newBlock1);
  60614. }
  60615. if (newBlock2.width > 0 && newBlock2.height > 0) {
  60616. args.push(newBlock2);
  60617. }
  60618. this.emptyBlocks_.splice.apply(this.emptyBlocks_, args);
  60619. };
  60620. goog.provide('ol.style.AtlasManager');
  60621. goog.require('ol');
  60622. goog.require('ol.style.Atlas');
  60623. /**
  60624. * Manages the creation of image atlases.
  60625. *
  60626. * Images added to this manager will be inserted into an atlas, which
  60627. * will be used for rendering.
  60628. * The `size` given in the constructor is the size for the first
  60629. * atlas. After that, when new atlases are created, they will have
  60630. * twice the size as the latest atlas (until `maxSize` is reached).
  60631. *
  60632. * If an application uses many images or very large images, it is recommended
  60633. * to set a higher `size` value to avoid the creation of too many atlases.
  60634. *
  60635. * @constructor
  60636. * @struct
  60637. * @api
  60638. * @param {olx.style.AtlasManagerOptions=} opt_options Options.
  60639. */
  60640. ol.style.AtlasManager = function(opt_options) {
  60641. var options = opt_options || {};
  60642. /**
  60643. * The size in pixels of the latest atlas image.
  60644. * @private
  60645. * @type {number}
  60646. */
  60647. this.currentSize_ = options.initialSize !== undefined ?
  60648. options.initialSize : ol.INITIAL_ATLAS_SIZE;
  60649. /**
  60650. * The maximum size in pixels of atlas images.
  60651. * @private
  60652. * @type {number}
  60653. */
  60654. this.maxSize_ = options.maxSize !== undefined ?
  60655. options.maxSize : ol.MAX_ATLAS_SIZE != -1 ?
  60656. ol.MAX_ATLAS_SIZE : ol.WEBGL_MAX_TEXTURE_SIZE !== undefined ?
  60657. ol.WEBGL_MAX_TEXTURE_SIZE : 2048;
  60658. /**
  60659. * The size in pixels between images.
  60660. * @private
  60661. * @type {number}
  60662. */
  60663. this.space_ = options.space !== undefined ? options.space : 1;
  60664. /**
  60665. * @private
  60666. * @type {Array.<ol.style.Atlas>}
  60667. */
  60668. this.atlases_ = [new ol.style.Atlas(this.currentSize_, this.space_)];
  60669. /**
  60670. * The size in pixels of the latest atlas image for hit-detection images.
  60671. * @private
  60672. * @type {number}
  60673. */
  60674. this.currentHitSize_ = this.currentSize_;
  60675. /**
  60676. * @private
  60677. * @type {Array.<ol.style.Atlas>}
  60678. */
  60679. this.hitAtlases_ = [new ol.style.Atlas(this.currentHitSize_, this.space_)];
  60680. };
  60681. /**
  60682. * @param {string} id The identifier of the entry to check.
  60683. * @return {?ol.AtlasManagerInfo} The position and atlas image for the
  60684. * entry, or `null` if the entry is not part of the atlas manager.
  60685. */
  60686. ol.style.AtlasManager.prototype.getInfo = function(id) {
  60687. /** @type {?ol.AtlasInfo} */
  60688. var info = this.getInfo_(this.atlases_, id);
  60689. if (!info) {
  60690. return null;
  60691. }
  60692. var hitInfo = /** @type {ol.AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id));
  60693. return this.mergeInfos_(info, hitInfo);
  60694. };
  60695. /**
  60696. * @private
  60697. * @param {Array.<ol.style.Atlas>} atlases The atlases to search.
  60698. * @param {string} id The identifier of the entry to check.
  60699. * @return {?ol.AtlasInfo} The position and atlas image for the entry,
  60700. * or `null` if the entry is not part of the atlases.
  60701. */
  60702. ol.style.AtlasManager.prototype.getInfo_ = function(atlases, id) {
  60703. var atlas, info, i, ii;
  60704. for (i = 0, ii = atlases.length; i < ii; ++i) {
  60705. atlas = atlases[i];
  60706. info = atlas.get(id);
  60707. if (info) {
  60708. return info;
  60709. }
  60710. }
  60711. return null;
  60712. };
  60713. /**
  60714. * @private
  60715. * @param {ol.AtlasInfo} info The info for the real image.
  60716. * @param {ol.AtlasInfo} hitInfo The info for the hit-detection
  60717. * image.
  60718. * @return {?ol.AtlasManagerInfo} The position and atlas image for the
  60719. * entry, or `null` if the entry is not part of the atlases.
  60720. */
  60721. ol.style.AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
  60722. return /** @type {ol.AtlasManagerInfo} */ ({
  60723. offsetX: info.offsetX,
  60724. offsetY: info.offsetY,
  60725. image: info.image,
  60726. hitImage: hitInfo.image
  60727. });
  60728. };
  60729. /**
  60730. * Add an image to the atlas manager.
  60731. *
  60732. * If an entry for the given id already exists, the entry will
  60733. * be overridden (but the space on the atlas graphic will not be freed).
  60734. *
  60735. * If `renderHitCallback` is provided, the image (or the hit-detection version
  60736. * of the image) will be rendered into a separate hit-detection atlas image.
  60737. *
  60738. * @param {string} id The identifier of the entry to add.
  60739. * @param {number} width The width.
  60740. * @param {number} height The height.
  60741. * @param {function(CanvasRenderingContext2D, number, number)} renderCallback
  60742. * Called to render the new image onto an atlas image.
  60743. * @param {function(CanvasRenderingContext2D, number, number)=}
  60744. * opt_renderHitCallback Called to render a hit-detection image onto a hit
  60745. * detection atlas image.
  60746. * @param {Object=} opt_this Value to use as `this` when executing
  60747. * `renderCallback` and `renderHitCallback`.
  60748. * @return {?ol.AtlasManagerInfo} The position and atlas image for the
  60749. * entry, or `null` if the image is too big.
  60750. */
  60751. ol.style.AtlasManager.prototype.add = function(id, width, height,
  60752. renderCallback, opt_renderHitCallback, opt_this) {
  60753. if (width + this.space_ > this.maxSize_ ||
  60754. height + this.space_ > this.maxSize_) {
  60755. return null;
  60756. }
  60757. /** @type {?ol.AtlasInfo} */
  60758. var info = this.add_(false,
  60759. id, width, height, renderCallback, opt_this);
  60760. if (!info) {
  60761. return null;
  60762. }
  60763. // even if no hit-detection entry is requested, we insert a fake entry into
  60764. // the hit-detection atlas, to make sure that the offset is the same for
  60765. // the original image and the hit-detection image.
  60766. var renderHitCallback = opt_renderHitCallback !== undefined ?
  60767. opt_renderHitCallback : ol.nullFunction;
  60768. var hitInfo = /** @type {ol.AtlasInfo} */ (this.add_(true,
  60769. id, width, height, renderHitCallback, opt_this));
  60770. return this.mergeInfos_(info, hitInfo);
  60771. };
  60772. /**
  60773. * @private
  60774. * @param {boolean} isHitAtlas If the hit-detection atlases are used.
  60775. * @param {string} id The identifier of the entry to add.
  60776. * @param {number} width The width.
  60777. * @param {number} height The height.
  60778. * @param {function(CanvasRenderingContext2D, number, number)} renderCallback
  60779. * Called to render the new image onto an atlas image.
  60780. * @param {Object=} opt_this Value to use as `this` when executing
  60781. * `renderCallback` and `renderHitCallback`.
  60782. * @return {?ol.AtlasInfo} The position and atlas image for the entry,
  60783. * or `null` if the image is too big.
  60784. */
  60785. ol.style.AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height,
  60786. renderCallback, opt_this) {
  60787. var atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_;
  60788. var atlas, info, i, ii;
  60789. for (i = 0, ii = atlases.length; i < ii; ++i) {
  60790. atlas = atlases[i];
  60791. info = atlas.add(id, width, height, renderCallback, opt_this);
  60792. if (info) {
  60793. return info;
  60794. } else if (!info && i === ii - 1) {
  60795. // the entry could not be added to one of the existing atlases,
  60796. // create a new atlas that is twice as big and try to add to this one.
  60797. var size;
  60798. if (isHitAtlas) {
  60799. size = Math.min(this.currentHitSize_ * 2, this.maxSize_);
  60800. this.currentHitSize_ = size;
  60801. } else {
  60802. size = Math.min(this.currentSize_ * 2, this.maxSize_);
  60803. this.currentSize_ = size;
  60804. }
  60805. atlas = new ol.style.Atlas(size, this.space_);
  60806. atlases.push(atlas);
  60807. // run the loop another time
  60808. ++ii;
  60809. }
  60810. }
  60811. return null;
  60812. };
  60813. goog.provide('ol.render.webgl.TextReplay');
  60814. goog.require('ol');
  60815. goog.require('ol.colorlike');
  60816. goog.require('ol.dom');
  60817. goog.require('ol.geom.GeometryType');
  60818. goog.require('ol.has');
  60819. goog.require('ol.render.replay');
  60820. goog.require('ol.render.webgl');
  60821. goog.require('ol.render.webgl.TextureReplay');
  60822. goog.require('ol.style.AtlasManager');
  60823. goog.require('ol.webgl.Buffer');
  60824. /**
  60825. * @constructor
  60826. * @extends {ol.render.webgl.TextureReplay}
  60827. * @param {number} tolerance Tolerance.
  60828. * @param {ol.Extent} maxExtent Max extent.
  60829. * @struct
  60830. */
  60831. ol.render.webgl.TextReplay = function(tolerance, maxExtent) {
  60832. ol.render.webgl.TextureReplay.call(this, tolerance, maxExtent);
  60833. /**
  60834. * @private
  60835. * @type {Array.<HTMLCanvasElement>}
  60836. */
  60837. this.images_ = [];
  60838. /**
  60839. * @private
  60840. * @type {Array.<WebGLTexture>}
  60841. */
  60842. this.textures_ = [];
  60843. /**
  60844. * @private
  60845. * @type {HTMLCanvasElement}
  60846. */
  60847. this.measureCanvas_ = ol.dom.createCanvasContext2D(0, 0).canvas;
  60848. /**
  60849. * @private
  60850. * @type {{strokeColor: (ol.ColorLike|null),
  60851. * lineCap: (string|undefined),
  60852. * lineDash: Array.<number>,
  60853. * lineDashOffset: (number|undefined),
  60854. * lineJoin: (string|undefined),
  60855. * lineWidth: number,
  60856. * miterLimit: (number|undefined),
  60857. * fillColor: (ol.ColorLike|null),
  60858. * font: (string|undefined),
  60859. * scale: (number|undefined)}}
  60860. */
  60861. this.state_ = {
  60862. strokeColor: null,
  60863. lineCap: undefined,
  60864. lineDash: null,
  60865. lineDashOffset: undefined,
  60866. lineJoin: undefined,
  60867. lineWidth: 0,
  60868. miterLimit: undefined,
  60869. fillColor: null,
  60870. font: undefined,
  60871. scale: undefined
  60872. };
  60873. /**
  60874. * @private
  60875. * @type {string}
  60876. */
  60877. this.text_ = '';
  60878. /**
  60879. * @private
  60880. * @type {number|undefined}
  60881. */
  60882. this.textAlign_ = undefined;
  60883. /**
  60884. * @private
  60885. * @type {number|undefined}
  60886. */
  60887. this.textBaseline_ = undefined;
  60888. /**
  60889. * @private
  60890. * @type {number|undefined}
  60891. */
  60892. this.offsetX_ = undefined;
  60893. /**
  60894. * @private
  60895. * @type {number|undefined}
  60896. */
  60897. this.offsetY_ = undefined;
  60898. /**
  60899. * @private
  60900. * @type {Object.<string, ol.WebglGlyphAtlas>}
  60901. */
  60902. this.atlases_ = {};
  60903. /**
  60904. * @private
  60905. * @type {ol.WebglGlyphAtlas|undefined}
  60906. */
  60907. this.currAtlas_ = undefined;
  60908. this.scale = 1;
  60909. this.opacity = 1;
  60910. };
  60911. ol.inherits(ol.render.webgl.TextReplay, ol.render.webgl.TextureReplay);
  60912. /**
  60913. * @inheritDoc
  60914. */
  60915. ol.render.webgl.TextReplay.prototype.drawText = function(geometry, feature) {
  60916. if (this.text_) {
  60917. var flatCoordinates = null;
  60918. var offset = 0;
  60919. var end = 2;
  60920. var stride = 2;
  60921. switch (geometry.getType()) {
  60922. case ol.geom.GeometryType.POINT:
  60923. case ol.geom.GeometryType.MULTI_POINT:
  60924. flatCoordinates = geometry.getFlatCoordinates();
  60925. end = flatCoordinates.length;
  60926. stride = geometry.getStride();
  60927. break;
  60928. case ol.geom.GeometryType.CIRCLE:
  60929. flatCoordinates = /** @type {ol.geom.Circle} */ (geometry).getCenter();
  60930. break;
  60931. case ol.geom.GeometryType.LINE_STRING:
  60932. flatCoordinates = /** @type {ol.geom.LineString} */ (geometry).getFlatMidpoint();
  60933. break;
  60934. case ol.geom.GeometryType.MULTI_LINE_STRING:
  60935. flatCoordinates = /** @type {ol.geom.MultiLineString} */ (geometry).getFlatMidpoints();
  60936. end = flatCoordinates.length;
  60937. break;
  60938. case ol.geom.GeometryType.POLYGON:
  60939. flatCoordinates = /** @type {ol.geom.Polygon} */ (geometry).getFlatInteriorPoint();
  60940. break;
  60941. case ol.geom.GeometryType.MULTI_POLYGON:
  60942. flatCoordinates = /** @type {ol.geom.MultiPolygon} */ (geometry).getFlatInteriorPoints();
  60943. end = flatCoordinates.length;
  60944. break;
  60945. default:
  60946. }
  60947. this.startIndices.push(this.indices.length);
  60948. this.startIndicesFeature.push(feature);
  60949. var glyphAtlas = this.currAtlas_;
  60950. var lines = this.text_.split('\n');
  60951. var textSize = this.getTextSize_(lines);
  60952. var i, ii, j, jj, currX, currY, charArr, charInfo;
  60953. var anchorX = Math.round(textSize[0] * this.textAlign_ - this.offsetX_);
  60954. var anchorY = Math.round(textSize[1] * this.textBaseline_ - this.offsetY_);
  60955. var lineWidth = (this.state_.lineWidth / 2) * this.state_.scale;
  60956. for (i = 0, ii = lines.length; i < ii; ++i) {
  60957. currX = 0;
  60958. currY = glyphAtlas.height * i;
  60959. charArr = lines[i].split('');
  60960. for (j = 0, jj = charArr.length; j < jj; ++j) {
  60961. charInfo = glyphAtlas.atlas.getInfo(charArr[j]);
  60962. if (charInfo) {
  60963. var image = charInfo.image;
  60964. this.anchorX = anchorX - currX;
  60965. this.anchorY = anchorY - currY;
  60966. this.originX = j === 0 ? charInfo.offsetX - lineWidth : charInfo.offsetX;
  60967. this.originY = charInfo.offsetY;
  60968. this.height = glyphAtlas.height;
  60969. this.width = j === 0 || j === charArr.length - 1 ?
  60970. glyphAtlas.width[charArr[j]] + lineWidth : glyphAtlas.width[charArr[j]];
  60971. this.imageHeight = image.height;
  60972. this.imageWidth = image.width;
  60973. var currentImage;
  60974. if (this.images_.length === 0) {
  60975. this.images_.push(image);
  60976. } else {
  60977. currentImage = this.images_[this.images_.length - 1];
  60978. if (ol.getUid(currentImage) != ol.getUid(image)) {
  60979. this.groupIndices.push(this.indices.length);
  60980. this.images_.push(image);
  60981. }
  60982. }
  60983. this.drawText_(flatCoordinates, offset, end, stride);
  60984. }
  60985. currX += this.width;
  60986. }
  60987. }
  60988. }
  60989. };
  60990. /**
  60991. * @private
  60992. * @param {Array.<string>} lines Label to draw split to lines.
  60993. * @return {Array.<number>} Size of the label in pixels.
  60994. */
  60995. ol.render.webgl.TextReplay.prototype.getTextSize_ = function(lines) {
  60996. var self = this;
  60997. var glyphAtlas = this.currAtlas_;
  60998. var textHeight = lines.length * glyphAtlas.height;
  60999. //Split every line to an array of chars, sum up their width, and select the longest.
  61000. var textWidth = lines.map(function(str) {
  61001. var sum = 0;
  61002. var i, ii;
  61003. for (i = 0, ii = str.length; i < ii; ++i) {
  61004. var curr = str[i];
  61005. if (!glyphAtlas.width[curr]) {
  61006. self.addCharToAtlas_(curr);
  61007. }
  61008. sum += glyphAtlas.width[curr] ? glyphAtlas.width[curr] : 0;
  61009. }
  61010. return sum;
  61011. }).reduce(function(max, curr) {
  61012. return Math.max(max, curr);
  61013. });
  61014. return [textWidth, textHeight];
  61015. };
  61016. /**
  61017. * @private
  61018. * @param {Array.<number>} flatCoordinates Flat coordinates.
  61019. * @param {number} offset Offset.
  61020. * @param {number} end End.
  61021. * @param {number} stride Stride.
  61022. */
  61023. ol.render.webgl.TextReplay.prototype.drawText_ = function(flatCoordinates, offset,
  61024. end, stride) {
  61025. var i, ii;
  61026. for (i = offset, ii = end; i < ii; i += stride) {
  61027. this.drawCoordinates(flatCoordinates, offset, end, stride);
  61028. }
  61029. };
  61030. /**
  61031. * @private
  61032. * @param {string} char Character.
  61033. */
  61034. ol.render.webgl.TextReplay.prototype.addCharToAtlas_ = function(char) {
  61035. if (char.length === 1) {
  61036. var glyphAtlas = this.currAtlas_;
  61037. var state = this.state_;
  61038. var mCtx = this.measureCanvas_.getContext('2d');
  61039. mCtx.font = state.font;
  61040. var width = Math.ceil(mCtx.measureText(char).width * state.scale);
  61041. var info = glyphAtlas.atlas.add(char, width, glyphAtlas.height,
  61042. function(ctx, x, y) {
  61043. //Parameterize the canvas
  61044. ctx.font = /** @type {string} */ (state.font);
  61045. ctx.fillStyle = state.fillColor;
  61046. ctx.strokeStyle = state.strokeColor;
  61047. ctx.lineWidth = state.lineWidth;
  61048. ctx.lineCap = /*** @type {string} */ (state.lineCap);
  61049. ctx.lineJoin = /** @type {string} */ (state.lineJoin);
  61050. ctx.miterLimit = /** @type {number} */ (state.miterLimit);
  61051. ctx.textAlign = 'left';
  61052. ctx.textBaseline = 'top';
  61053. if (ol.has.CANVAS_LINE_DASH && state.lineDash) {
  61054. //FIXME: use pixelRatio
  61055. ctx.setLineDash(state.lineDash);
  61056. ctx.lineDashOffset = /** @type {number} */ (state.lineDashOffset);
  61057. }
  61058. if (state.scale !== 1) {
  61059. //FIXME: use pixelRatio
  61060. ctx.setTransform(/** @type {number} */ (state.scale), 0, 0,
  61061. /** @type {number} */ (state.scale), 0, 0);
  61062. }
  61063. //Draw the character on the canvas
  61064. if (state.strokeColor) {
  61065. ctx.strokeText(char, x, y);
  61066. }
  61067. if (state.fillColor) {
  61068. ctx.fillText(char, x, y);
  61069. }
  61070. });
  61071. if (info) {
  61072. glyphAtlas.width[char] = width;
  61073. }
  61074. }
  61075. };
  61076. /**
  61077. * @inheritDoc
  61078. */
  61079. ol.render.webgl.TextReplay.prototype.finish = function(context) {
  61080. var gl = context.getGL();
  61081. this.groupIndices.push(this.indices.length);
  61082. this.hitDetectionGroupIndices = this.groupIndices;
  61083. // create, bind, and populate the vertices buffer
  61084. this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
  61085. // create, bind, and populate the indices buffer
  61086. this.indicesBuffer = new ol.webgl.Buffer(this.indices);
  61087. // create textures
  61088. /** @type {Object.<string, WebGLTexture>} */
  61089. var texturePerImage = {};
  61090. this.createTextures(this.textures_, this.images_, texturePerImage, gl);
  61091. this.state_ = {
  61092. strokeColor: null,
  61093. lineCap: undefined,
  61094. lineDash: null,
  61095. lineDashOffset: undefined,
  61096. lineJoin: undefined,
  61097. lineWidth: 0,
  61098. miterLimit: undefined,
  61099. fillColor: null,
  61100. font: undefined,
  61101. scale: undefined
  61102. };
  61103. this.text_ = '';
  61104. this.textAlign_ = undefined;
  61105. this.textBaseline_ = undefined;
  61106. this.offsetX_ = undefined;
  61107. this.offsetY_ = undefined;
  61108. this.images_ = null;
  61109. this.atlases_ = {};
  61110. this.currAtlas_ = undefined;
  61111. ol.render.webgl.TextureReplay.prototype.finish.call(this, context);
  61112. };
  61113. /**
  61114. * @inheritDoc
  61115. */
  61116. ol.render.webgl.TextReplay.prototype.setTextStyle = function(textStyle) {
  61117. var state = this.state_;
  61118. var textFillStyle = textStyle.getFill();
  61119. var textStrokeStyle = textStyle.getStroke();
  61120. if (!textStyle || !textStyle.getText() || (!textFillStyle && !textStrokeStyle)) {
  61121. this.text_ = '';
  61122. } else {
  61123. if (!textFillStyle) {
  61124. state.fillColor = null;
  61125. } else {
  61126. var textFillStyleColor = textFillStyle.getColor();
  61127. state.fillColor = ol.colorlike.asColorLike(textFillStyleColor ?
  61128. textFillStyleColor : ol.render.webgl.defaultFillStyle);
  61129. }
  61130. if (!textStrokeStyle) {
  61131. state.strokeColor = null;
  61132. state.lineWidth = 0;
  61133. } else {
  61134. var textStrokeStyleColor = textStrokeStyle.getColor();
  61135. state.strokeColor = ol.colorlike.asColorLike(textStrokeStyleColor ?
  61136. textStrokeStyleColor : ol.render.webgl.defaultStrokeStyle);
  61137. state.lineWidth = textStrokeStyle.getWidth() || ol.render.webgl.defaultLineWidth;
  61138. state.lineCap = textStrokeStyle.getLineCap() || ol.render.webgl.defaultLineCap;
  61139. state.lineDashOffset = textStrokeStyle.getLineDashOffset() || ol.render.webgl.defaultLineDashOffset;
  61140. state.lineJoin = textStrokeStyle.getLineJoin() || ol.render.webgl.defaultLineJoin;
  61141. state.miterLimit = textStrokeStyle.getMiterLimit() || ol.render.webgl.defaultMiterLimit;
  61142. var lineDash = textStrokeStyle.getLineDash();
  61143. state.lineDash = lineDash ? lineDash.slice() : ol.render.webgl.defaultLineDash;
  61144. }
  61145. state.font = textStyle.getFont() || ol.render.webgl.defaultFont;
  61146. state.scale = textStyle.getScale() || 1;
  61147. this.text_ = /** @type {string} */ (textStyle.getText());
  61148. var textAlign = ol.render.replay.TEXT_ALIGN[textStyle.getTextAlign()];
  61149. var textBaseline = ol.render.replay.TEXT_ALIGN[textStyle.getTextBaseline()];
  61150. this.textAlign_ = textAlign === undefined ?
  61151. ol.render.webgl.defaultTextAlign : textAlign;
  61152. this.textBaseline_ = textBaseline === undefined ?
  61153. ol.render.webgl.defaultTextBaseline : textBaseline;
  61154. this.offsetX_ = textStyle.getOffsetX() || 0;
  61155. this.offsetY_ = textStyle.getOffsetY() || 0;
  61156. this.rotateWithView = !!textStyle.getRotateWithView();
  61157. this.rotation = textStyle.getRotation() || 0;
  61158. this.currAtlas_ = this.getAtlas_(state);
  61159. }
  61160. };
  61161. /**
  61162. * @private
  61163. * @param {Object} state Font attributes.
  61164. * @return {ol.WebglGlyphAtlas} Glyph atlas.
  61165. */
  61166. ol.render.webgl.TextReplay.prototype.getAtlas_ = function(state) {
  61167. var params = [];
  61168. var i;
  61169. for (i in state) {
  61170. if (state[i] || state[i] === 0) {
  61171. if (Array.isArray(state[i])) {
  61172. params = params.concat(state[i]);
  61173. } else {
  61174. params.push(state[i]);
  61175. }
  61176. }
  61177. }
  61178. var hash = this.calculateHash_(params);
  61179. if (!this.atlases_[hash]) {
  61180. var mCtx = this.measureCanvas_.getContext('2d');
  61181. mCtx.font = state.font;
  61182. var height = Math.ceil((mCtx.measureText('M').width * 1.5 +
  61183. state.lineWidth / 2) * state.scale);
  61184. this.atlases_[hash] = {
  61185. atlas: new ol.style.AtlasManager({
  61186. space: state.lineWidth + 1
  61187. }),
  61188. width: {},
  61189. height: height
  61190. };
  61191. }
  61192. return this.atlases_[hash];
  61193. };
  61194. /**
  61195. * @private
  61196. * @param {Array.<string|number>} params Array of parameters.
  61197. * @return {string} Hash string.
  61198. */
  61199. ol.render.webgl.TextReplay.prototype.calculateHash_ = function(params) {
  61200. //TODO: Create a more performant, reliable, general hash function.
  61201. var i, ii;
  61202. var hash = '';
  61203. for (i = 0, ii = params.length; i < ii; ++i) {
  61204. hash += params[i];
  61205. }
  61206. return hash;
  61207. };
  61208. /**
  61209. * @inheritDoc
  61210. */
  61211. ol.render.webgl.TextReplay.prototype.getTextures = function(opt_all) {
  61212. return this.textures_;
  61213. };
  61214. /**
  61215. * @inheritDoc
  61216. */
  61217. ol.render.webgl.TextReplay.prototype.getHitDetectionTextures = function() {
  61218. return this.textures_;
  61219. };
  61220. goog.provide('ol.render.webgl.ReplayGroup');
  61221. goog.require('ol');
  61222. goog.require('ol.array');
  61223. goog.require('ol.extent');
  61224. goog.require('ol.obj');
  61225. goog.require('ol.render.replay');
  61226. goog.require('ol.render.ReplayGroup');
  61227. goog.require('ol.render.webgl.CircleReplay');
  61228. goog.require('ol.render.webgl.ImageReplay');
  61229. goog.require('ol.render.webgl.LineStringReplay');
  61230. goog.require('ol.render.webgl.PolygonReplay');
  61231. goog.require('ol.render.webgl.TextReplay');
  61232. /**
  61233. * @constructor
  61234. * @extends {ol.render.ReplayGroup}
  61235. * @param {number} tolerance Tolerance.
  61236. * @param {ol.Extent} maxExtent Max extent.
  61237. * @param {number=} opt_renderBuffer Render buffer.
  61238. * @struct
  61239. */
  61240. ol.render.webgl.ReplayGroup = function(tolerance, maxExtent, opt_renderBuffer) {
  61241. ol.render.ReplayGroup.call(this);
  61242. /**
  61243. * @type {ol.Extent}
  61244. * @private
  61245. */
  61246. this.maxExtent_ = maxExtent;
  61247. /**
  61248. * @type {number}
  61249. * @private
  61250. */
  61251. this.tolerance_ = tolerance;
  61252. /**
  61253. * @type {number|undefined}
  61254. * @private
  61255. */
  61256. this.renderBuffer_ = opt_renderBuffer;
  61257. /**
  61258. * @private
  61259. * @type {!Object.<string,
  61260. * Object.<ol.render.ReplayType, ol.render.webgl.Replay>>}
  61261. */
  61262. this.replaysByZIndex_ = {};
  61263. };
  61264. ol.inherits(ol.render.webgl.ReplayGroup, ol.render.ReplayGroup);
  61265. /**
  61266. * @param {ol.style.Style} style Style.
  61267. * @param {boolean} group Group with previous replay.
  61268. */
  61269. ol.render.webgl.ReplayGroup.prototype.addDeclutter = function(style, group) {};
  61270. /**
  61271. * @param {ol.webgl.Context} context WebGL context.
  61272. * @return {function()} Delete resources function.
  61273. */
  61274. ol.render.webgl.ReplayGroup.prototype.getDeleteResourcesFunction = function(context) {
  61275. var functions = [];
  61276. var zKey;
  61277. for (zKey in this.replaysByZIndex_) {
  61278. var replays = this.replaysByZIndex_[zKey];
  61279. var replayKey;
  61280. for (replayKey in replays) {
  61281. functions.push(
  61282. replays[replayKey].getDeleteResourcesFunction(context));
  61283. }
  61284. }
  61285. return function() {
  61286. var length = functions.length;
  61287. var result;
  61288. for (var i = 0; i < length; i++) {
  61289. result = functions[i].apply(this, arguments);
  61290. }
  61291. return result;
  61292. };
  61293. };
  61294. /**
  61295. * @param {ol.webgl.Context} context Context.
  61296. */
  61297. ol.render.webgl.ReplayGroup.prototype.finish = function(context) {
  61298. var zKey;
  61299. for (zKey in this.replaysByZIndex_) {
  61300. var replays = this.replaysByZIndex_[zKey];
  61301. var replayKey;
  61302. for (replayKey in replays) {
  61303. replays[replayKey].finish(context);
  61304. }
  61305. }
  61306. };
  61307. /**
  61308. * @inheritDoc
  61309. */
  61310. ol.render.webgl.ReplayGroup.prototype.getReplay = function(zIndex, replayType) {
  61311. var zIndexKey = zIndex !== undefined ? zIndex.toString() : '0';
  61312. var replays = this.replaysByZIndex_[zIndexKey];
  61313. if (replays === undefined) {
  61314. replays = {};
  61315. this.replaysByZIndex_[zIndexKey] = replays;
  61316. }
  61317. var replay = replays[replayType];
  61318. if (replay === undefined) {
  61319. /**
  61320. * @type {Function}
  61321. */
  61322. var Constructor = ol.render.webgl.ReplayGroup.BATCH_CONSTRUCTORS_[replayType];
  61323. replay = new Constructor(this.tolerance_, this.maxExtent_);
  61324. replays[replayType] = replay;
  61325. }
  61326. return replay;
  61327. };
  61328. /**
  61329. * @inheritDoc
  61330. */
  61331. ol.render.webgl.ReplayGroup.prototype.isEmpty = function() {
  61332. return ol.obj.isEmpty(this.replaysByZIndex_);
  61333. };
  61334. /**
  61335. * @param {ol.webgl.Context} context Context.
  61336. * @param {ol.Coordinate} center Center.
  61337. * @param {number} resolution Resolution.
  61338. * @param {number} rotation Rotation.
  61339. * @param {ol.Size} size Size.
  61340. * @param {number} pixelRatio Pixel ratio.
  61341. * @param {number} opacity Global opacity.
  61342. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  61343. * to skip.
  61344. */
  61345. ol.render.webgl.ReplayGroup.prototype.replay = function(context,
  61346. center, resolution, rotation, size, pixelRatio,
  61347. opacity, skippedFeaturesHash) {
  61348. /** @type {Array.<number>} */
  61349. var zs = Object.keys(this.replaysByZIndex_).map(Number);
  61350. zs.sort(ol.array.numberSafeCompareFunction);
  61351. var i, ii, j, jj, replays, replay;
  61352. for (i = 0, ii = zs.length; i < ii; ++i) {
  61353. replays = this.replaysByZIndex_[zs[i].toString()];
  61354. for (j = 0, jj = ol.render.replay.ORDER.length; j < jj; ++j) {
  61355. replay = replays[ol.render.replay.ORDER[j]];
  61356. if (replay !== undefined) {
  61357. replay.replay(context,
  61358. center, resolution, rotation, size, pixelRatio,
  61359. opacity, skippedFeaturesHash,
  61360. undefined, false);
  61361. }
  61362. }
  61363. }
  61364. };
  61365. /**
  61366. * @private
  61367. * @param {ol.webgl.Context} context Context.
  61368. * @param {ol.Coordinate} center Center.
  61369. * @param {number} resolution Resolution.
  61370. * @param {number} rotation Rotation.
  61371. * @param {ol.Size} size Size.
  61372. * @param {number} pixelRatio Pixel ratio.
  61373. * @param {number} opacity Global opacity.
  61374. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  61375. * to skip.
  61376. * @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
  61377. * @param {boolean} oneByOne Draw features one-by-one for the hit-detecion.
  61378. * @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
  61379. * this extent are checked.
  61380. * @return {T|undefined} Callback result.
  61381. * @template T
  61382. */
  61383. ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
  61384. center, resolution, rotation, size, pixelRatio, opacity,
  61385. skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent) {
  61386. /** @type {Array.<number>} */
  61387. var zs = Object.keys(this.replaysByZIndex_).map(Number);
  61388. zs.sort(function(a, b) {
  61389. return b - a;
  61390. });
  61391. var i, ii, j, replays, replay, result;
  61392. for (i = 0, ii = zs.length; i < ii; ++i) {
  61393. replays = this.replaysByZIndex_[zs[i].toString()];
  61394. for (j = ol.render.replay.ORDER.length - 1; j >= 0; --j) {
  61395. replay = replays[ol.render.replay.ORDER[j]];
  61396. if (replay !== undefined) {
  61397. result = replay.replay(context,
  61398. center, resolution, rotation, size, pixelRatio, opacity,
  61399. skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent);
  61400. if (result) {
  61401. return result;
  61402. }
  61403. }
  61404. }
  61405. }
  61406. return undefined;
  61407. };
  61408. /**
  61409. * @param {ol.Coordinate} coordinate Coordinate.
  61410. * @param {ol.webgl.Context} context Context.
  61411. * @param {ol.Coordinate} center Center.
  61412. * @param {number} resolution Resolution.
  61413. * @param {number} rotation Rotation.
  61414. * @param {ol.Size} size Size.
  61415. * @param {number} pixelRatio Pixel ratio.
  61416. * @param {number} opacity Global opacity.
  61417. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  61418. * to skip.
  61419. * @param {function((ol.Feature|ol.render.Feature)): T|undefined} callback Feature callback.
  61420. * @return {T|undefined} Callback result.
  61421. * @template T
  61422. */
  61423. ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
  61424. coordinate, context, center, resolution, rotation, size, pixelRatio,
  61425. opacity, skippedFeaturesHash,
  61426. callback) {
  61427. var gl = context.getGL();
  61428. gl.bindFramebuffer(
  61429. gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
  61430. /**
  61431. * @type {ol.Extent}
  61432. */
  61433. var hitExtent;
  61434. if (this.renderBuffer_ !== undefined) {
  61435. // build an extent around the coordinate, so that only features that
  61436. // intersect this extent are checked
  61437. hitExtent = ol.extent.buffer(
  61438. ol.extent.createOrUpdateFromCoordinate(coordinate),
  61439. resolution * this.renderBuffer_);
  61440. }
  61441. return this.replayHitDetection_(context,
  61442. coordinate, resolution, rotation, ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_,
  61443. pixelRatio, opacity, skippedFeaturesHash,
  61444. /**
  61445. * @param {ol.Feature|ol.render.Feature} feature Feature.
  61446. * @return {?} Callback result.
  61447. */
  61448. function(feature) {
  61449. var imageData = new Uint8Array(4);
  61450. gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
  61451. if (imageData[3] > 0) {
  61452. var result = callback(feature);
  61453. if (result) {
  61454. return result;
  61455. }
  61456. }
  61457. }, true, hitExtent);
  61458. };
  61459. /**
  61460. * @param {ol.Coordinate} coordinate Coordinate.
  61461. * @param {ol.webgl.Context} context Context.
  61462. * @param {ol.Coordinate} center Center.
  61463. * @param {number} resolution Resolution.
  61464. * @param {number} rotation Rotation.
  61465. * @param {ol.Size} size Size.
  61466. * @param {number} pixelRatio Pixel ratio.
  61467. * @param {number} opacity Global opacity.
  61468. * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
  61469. * to skip.
  61470. * @return {boolean} Is there a feature at the given coordinate?
  61471. */
  61472. ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function(
  61473. coordinate, context, center, resolution, rotation, size, pixelRatio,
  61474. opacity, skippedFeaturesHash) {
  61475. var gl = context.getGL();
  61476. gl.bindFramebuffer(
  61477. gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
  61478. var hasFeature = this.replayHitDetection_(context,
  61479. coordinate, resolution, rotation, ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_,
  61480. pixelRatio, opacity, skippedFeaturesHash,
  61481. /**
  61482. * @param {ol.Feature|ol.render.Feature} feature Feature.
  61483. * @return {boolean} Is there a feature?
  61484. */
  61485. function(feature) {
  61486. var imageData = new Uint8Array(4);
  61487. gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
  61488. return imageData[3] > 0;
  61489. }, false);
  61490. return hasFeature !== undefined;
  61491. };
  61492. /**
  61493. * @const
  61494. * @private
  61495. * @type {Array.<number>}
  61496. */
  61497. ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_ = [1, 1];
  61498. /**
  61499. * @const
  61500. * @private
  61501. * @type {Object.<ol.render.ReplayType,
  61502. * function(new: ol.render.webgl.Replay, number,
  61503. * ol.Extent)>}
  61504. */
  61505. ol.render.webgl.ReplayGroup.BATCH_CONSTRUCTORS_ = {
  61506. 'Circle': ol.render.webgl.CircleReplay,
  61507. 'Image': ol.render.webgl.ImageReplay,
  61508. 'LineString': ol.render.webgl.LineStringReplay,
  61509. 'Polygon': ol.render.webgl.PolygonReplay,
  61510. 'Text': ol.render.webgl.TextReplay
  61511. };
  61512. goog.provide('ol.render.webgl.Immediate');
  61513. goog.require('ol');
  61514. goog.require('ol.extent');
  61515. goog.require('ol.geom.GeometryType');
  61516. goog.require('ol.render.ReplayType');
  61517. goog.require('ol.render.VectorContext');
  61518. goog.require('ol.render.webgl.ReplayGroup');
  61519. /**
  61520. * @constructor
  61521. * @extends {ol.render.VectorContext}
  61522. * @param {ol.webgl.Context} context Context.
  61523. * @param {ol.Coordinate} center Center.
  61524. * @param {number} resolution Resolution.
  61525. * @param {number} rotation Rotation.
  61526. * @param {ol.Size} size Size.
  61527. * @param {ol.Extent} extent Extent.
  61528. * @param {number} pixelRatio Pixel ratio.
  61529. * @struct
  61530. */
  61531. ol.render.webgl.Immediate = function(context, center, resolution, rotation, size, extent, pixelRatio) {
  61532. ol.render.VectorContext.call(this);
  61533. /**
  61534. * @private
  61535. */
  61536. this.context_ = context;
  61537. /**
  61538. * @private
  61539. */
  61540. this.center_ = center;
  61541. /**
  61542. * @private
  61543. */
  61544. this.extent_ = extent;
  61545. /**
  61546. * @private
  61547. */
  61548. this.pixelRatio_ = pixelRatio;
  61549. /**
  61550. * @private
  61551. */
  61552. this.size_ = size;
  61553. /**
  61554. * @private
  61555. */
  61556. this.rotation_ = rotation;
  61557. /**
  61558. * @private
  61559. */
  61560. this.resolution_ = resolution;
  61561. /**
  61562. * @private
  61563. * @type {ol.style.Image}
  61564. */
  61565. this.imageStyle_ = null;
  61566. /**
  61567. * @private
  61568. * @type {ol.style.Fill}
  61569. */
  61570. this.fillStyle_ = null;
  61571. /**
  61572. * @private
  61573. * @type {ol.style.Stroke}
  61574. */
  61575. this.strokeStyle_ = null;
  61576. /**
  61577. * @private
  61578. * @type {ol.style.Text}
  61579. */
  61580. this.textStyle_ = null;
  61581. };
  61582. ol.inherits(ol.render.webgl.Immediate, ol.render.VectorContext);
  61583. /**
  61584. * @param {ol.render.webgl.ReplayGroup} replayGroup Replay group.
  61585. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
  61586. * @private
  61587. */
  61588. ol.render.webgl.Immediate.prototype.drawText_ = function(replayGroup, geometry) {
  61589. var context = this.context_;
  61590. var replay = /** @type {ol.render.webgl.TextReplay} */ (
  61591. replayGroup.getReplay(0, ol.render.ReplayType.TEXT));
  61592. replay.setTextStyle(this.textStyle_);
  61593. replay.drawText(geometry, null);
  61594. replay.finish(context);
  61595. // default colors
  61596. var opacity = 1;
  61597. var skippedFeatures = {};
  61598. var featureCallback;
  61599. var oneByOne = false;
  61600. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61601. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61602. oneByOne);
  61603. replay.getDeleteResourcesFunction(context)();
  61604. };
  61605. /**
  61606. * Set the rendering style. Note that since this is an immediate rendering API,
  61607. * any `zIndex` on the provided style will be ignored.
  61608. *
  61609. * @param {ol.style.Style} style The rendering style.
  61610. * @override
  61611. * @api
  61612. */
  61613. ol.render.webgl.Immediate.prototype.setStyle = function(style) {
  61614. this.setFillStrokeStyle(style.getFill(), style.getStroke());
  61615. this.setImageStyle(style.getImage());
  61616. this.setTextStyle(style.getText());
  61617. };
  61618. /**
  61619. * Render a geometry into the canvas. Call
  61620. * {@link ol.render.webgl.Immediate#setStyle} first to set the rendering style.
  61621. *
  61622. * @param {ol.geom.Geometry|ol.render.Feature} geometry The geometry to render.
  61623. * @override
  61624. * @api
  61625. */
  61626. ol.render.webgl.Immediate.prototype.drawGeometry = function(geometry) {
  61627. var type = geometry.getType();
  61628. switch (type) {
  61629. case ol.geom.GeometryType.POINT:
  61630. this.drawPoint(/** @type {ol.geom.Point} */ (geometry), null);
  61631. break;
  61632. case ol.geom.GeometryType.LINE_STRING:
  61633. this.drawLineString(/** @type {ol.geom.LineString} */ (geometry), null);
  61634. break;
  61635. case ol.geom.GeometryType.POLYGON:
  61636. this.drawPolygon(/** @type {ol.geom.Polygon} */ (geometry), null);
  61637. break;
  61638. case ol.geom.GeometryType.MULTI_POINT:
  61639. this.drawMultiPoint(/** @type {ol.geom.MultiPoint} */ (geometry), null);
  61640. break;
  61641. case ol.geom.GeometryType.MULTI_LINE_STRING:
  61642. this.drawMultiLineString(/** @type {ol.geom.MultiLineString} */ (geometry), null);
  61643. break;
  61644. case ol.geom.GeometryType.MULTI_POLYGON:
  61645. this.drawMultiPolygon(/** @type {ol.geom.MultiPolygon} */ (geometry), null);
  61646. break;
  61647. case ol.geom.GeometryType.GEOMETRY_COLLECTION:
  61648. this.drawGeometryCollection(/** @type {ol.geom.GeometryCollection} */ (geometry), null);
  61649. break;
  61650. case ol.geom.GeometryType.CIRCLE:
  61651. this.drawCircle(/** @type {ol.geom.Circle} */ (geometry), null);
  61652. break;
  61653. default:
  61654. // pass
  61655. }
  61656. };
  61657. /**
  61658. * @inheritDoc
  61659. * @api
  61660. */
  61661. ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) {
  61662. var geometry = style.getGeometryFunction()(feature);
  61663. if (!geometry ||
  61664. !ol.extent.intersects(this.extent_, geometry.getExtent())) {
  61665. return;
  61666. }
  61667. this.setStyle(style);
  61668. this.drawGeometry(geometry);
  61669. };
  61670. /**
  61671. * @inheritDoc
  61672. */
  61673. ol.render.webgl.Immediate.prototype.drawGeometryCollection = function(geometry, data) {
  61674. var geometries = geometry.getGeometriesArray();
  61675. var i, ii;
  61676. for (i = 0, ii = geometries.length; i < ii; ++i) {
  61677. this.drawGeometry(geometries[i]);
  61678. }
  61679. };
  61680. /**
  61681. * @inheritDoc
  61682. */
  61683. ol.render.webgl.Immediate.prototype.drawPoint = function(geometry, data) {
  61684. var context = this.context_;
  61685. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61686. var replay = /** @type {ol.render.webgl.ImageReplay} */ (
  61687. replayGroup.getReplay(0, ol.render.ReplayType.IMAGE));
  61688. replay.setImageStyle(this.imageStyle_);
  61689. replay.drawPoint(geometry, data);
  61690. replay.finish(context);
  61691. // default colors
  61692. var opacity = 1;
  61693. var skippedFeatures = {};
  61694. var featureCallback;
  61695. var oneByOne = false;
  61696. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61697. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61698. oneByOne);
  61699. replay.getDeleteResourcesFunction(context)();
  61700. if (this.textStyle_) {
  61701. this.drawText_(replayGroup, geometry);
  61702. }
  61703. };
  61704. /**
  61705. * @inheritDoc
  61706. */
  61707. ol.render.webgl.Immediate.prototype.drawMultiPoint = function(geometry, data) {
  61708. var context = this.context_;
  61709. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61710. var replay = /** @type {ol.render.webgl.ImageReplay} */ (
  61711. replayGroup.getReplay(0, ol.render.ReplayType.IMAGE));
  61712. replay.setImageStyle(this.imageStyle_);
  61713. replay.drawMultiPoint(geometry, data);
  61714. replay.finish(context);
  61715. var opacity = 1;
  61716. var skippedFeatures = {};
  61717. var featureCallback;
  61718. var oneByOne = false;
  61719. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61720. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61721. oneByOne);
  61722. replay.getDeleteResourcesFunction(context)();
  61723. if (this.textStyle_) {
  61724. this.drawText_(replayGroup, geometry);
  61725. }
  61726. };
  61727. /**
  61728. * @inheritDoc
  61729. */
  61730. ol.render.webgl.Immediate.prototype.drawLineString = function(geometry, data) {
  61731. var context = this.context_;
  61732. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61733. var replay = /** @type {ol.render.webgl.LineStringReplay} */ (
  61734. replayGroup.getReplay(0, ol.render.ReplayType.LINE_STRING));
  61735. replay.setFillStrokeStyle(null, this.strokeStyle_);
  61736. replay.drawLineString(geometry, data);
  61737. replay.finish(context);
  61738. var opacity = 1;
  61739. var skippedFeatures = {};
  61740. var featureCallback;
  61741. var oneByOne = false;
  61742. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61743. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61744. oneByOne);
  61745. replay.getDeleteResourcesFunction(context)();
  61746. if (this.textStyle_) {
  61747. this.drawText_(replayGroup, geometry);
  61748. }
  61749. };
  61750. /**
  61751. * @inheritDoc
  61752. */
  61753. ol.render.webgl.Immediate.prototype.drawMultiLineString = function(geometry, data) {
  61754. var context = this.context_;
  61755. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61756. var replay = /** @type {ol.render.webgl.LineStringReplay} */ (
  61757. replayGroup.getReplay(0, ol.render.ReplayType.LINE_STRING));
  61758. replay.setFillStrokeStyle(null, this.strokeStyle_);
  61759. replay.drawMultiLineString(geometry, data);
  61760. replay.finish(context);
  61761. var opacity = 1;
  61762. var skippedFeatures = {};
  61763. var featureCallback;
  61764. var oneByOne = false;
  61765. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61766. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61767. oneByOne);
  61768. replay.getDeleteResourcesFunction(context)();
  61769. if (this.textStyle_) {
  61770. this.drawText_(replayGroup, geometry);
  61771. }
  61772. };
  61773. /**
  61774. * @inheritDoc
  61775. */
  61776. ol.render.webgl.Immediate.prototype.drawPolygon = function(geometry, data) {
  61777. var context = this.context_;
  61778. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61779. var replay = /** @type {ol.render.webgl.PolygonReplay} */ (
  61780. replayGroup.getReplay(0, ol.render.ReplayType.POLYGON));
  61781. replay.setFillStrokeStyle(this.fillStyle_, this.strokeStyle_);
  61782. replay.drawPolygon(geometry, data);
  61783. replay.finish(context);
  61784. var opacity = 1;
  61785. var skippedFeatures = {};
  61786. var featureCallback;
  61787. var oneByOne = false;
  61788. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61789. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61790. oneByOne);
  61791. replay.getDeleteResourcesFunction(context)();
  61792. if (this.textStyle_) {
  61793. this.drawText_(replayGroup, geometry);
  61794. }
  61795. };
  61796. /**
  61797. * @inheritDoc
  61798. */
  61799. ol.render.webgl.Immediate.prototype.drawMultiPolygon = function(geometry, data) {
  61800. var context = this.context_;
  61801. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61802. var replay = /** @type {ol.render.webgl.PolygonReplay} */ (
  61803. replayGroup.getReplay(0, ol.render.ReplayType.POLYGON));
  61804. replay.setFillStrokeStyle(this.fillStyle_, this.strokeStyle_);
  61805. replay.drawMultiPolygon(geometry, data);
  61806. replay.finish(context);
  61807. var opacity = 1;
  61808. var skippedFeatures = {};
  61809. var featureCallback;
  61810. var oneByOne = false;
  61811. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61812. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61813. oneByOne);
  61814. replay.getDeleteResourcesFunction(context)();
  61815. if (this.textStyle_) {
  61816. this.drawText_(replayGroup, geometry);
  61817. }
  61818. };
  61819. /**
  61820. * @inheritDoc
  61821. */
  61822. ol.render.webgl.Immediate.prototype.drawCircle = function(geometry, data) {
  61823. var context = this.context_;
  61824. var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
  61825. var replay = /** @type {ol.render.webgl.CircleReplay} */ (
  61826. replayGroup.getReplay(0, ol.render.ReplayType.CIRCLE));
  61827. replay.setFillStrokeStyle(this.fillStyle_, this.strokeStyle_);
  61828. replay.drawCircle(geometry, data);
  61829. replay.finish(context);
  61830. var opacity = 1;
  61831. var skippedFeatures = {};
  61832. var featureCallback;
  61833. var oneByOne = false;
  61834. replay.replay(this.context_, this.center_, this.resolution_, this.rotation_,
  61835. this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
  61836. oneByOne);
  61837. replay.getDeleteResourcesFunction(context)();
  61838. if (this.textStyle_) {
  61839. this.drawText_(replayGroup, geometry);
  61840. }
  61841. };
  61842. /**
  61843. * @inheritDoc
  61844. */
  61845. ol.render.webgl.Immediate.prototype.setImageStyle = function(imageStyle) {
  61846. this.imageStyle_ = imageStyle;
  61847. };
  61848. /**
  61849. * @inheritDoc
  61850. */
  61851. ol.render.webgl.Immediate.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
  61852. this.fillStyle_ = fillStyle;
  61853. this.strokeStyle_ = strokeStyle;
  61854. };
  61855. /**
  61856. * @inheritDoc
  61857. */
  61858. ol.render.webgl.Immediate.prototype.setTextStyle = function(textStyle) {
  61859. this.textStyle_ = textStyle;
  61860. };
  61861. // This file is automatically generated, do not edit
  61862. goog.provide('ol.renderer.webgl.defaultmapshader');
  61863. goog.require('ol');
  61864. goog.require('ol.webgl.Fragment');
  61865. goog.require('ol.webgl.Vertex');
  61866. ol.renderer.webgl.defaultmapshader.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
  61867. 'precision mediump float;\nvarying vec2 v_texCoord;\n\n\nuniform float u_opacity;\nuniform sampler2D u_texture;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_texture, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n gl_FragColor.a = texColor.a * u_opacity;\n}\n' :
  61868. 'precision mediump float;varying vec2 a;uniform float f;uniform sampler2D g;void main(void){vec4 texColor=texture2D(g,a);gl_FragColor.rgb=texColor.rgb;gl_FragColor.a=texColor.a*f;}');
  61869. ol.renderer.webgl.defaultmapshader.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
  61870. 'varying vec2 v_texCoord;\n\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\n\nuniform mat4 u_texCoordMatrix;\nuniform mat4 u_projectionMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0., 1.);\n v_texCoord = (u_texCoordMatrix * vec4(a_texCoord, 0., 1.)).st;\n}\n\n\n' :
  61871. 'varying vec2 a;attribute vec2 b;attribute vec2 c;uniform mat4 d;uniform mat4 e;void main(void){gl_Position=e*vec4(b,0.,1.);a=(d*vec4(c,0.,1.)).st;}');
  61872. // This file is automatically generated, do not edit
  61873. goog.provide('ol.renderer.webgl.defaultmapshader.Locations');
  61874. goog.require('ol');
  61875. /**
  61876. * @constructor
  61877. * @param {WebGLRenderingContext} gl GL.
  61878. * @param {WebGLProgram} program Program.
  61879. * @struct
  61880. */
  61881. ol.renderer.webgl.defaultmapshader.Locations = function(gl, program) {
  61882. /**
  61883. * @type {WebGLUniformLocation}
  61884. */
  61885. this.u_texCoordMatrix = gl.getUniformLocation(
  61886. program, ol.DEBUG_WEBGL ? 'u_texCoordMatrix' : 'd');
  61887. /**
  61888. * @type {WebGLUniformLocation}
  61889. */
  61890. this.u_projectionMatrix = gl.getUniformLocation(
  61891. program, ol.DEBUG_WEBGL ? 'u_projectionMatrix' : 'e');
  61892. /**
  61893. * @type {WebGLUniformLocation}
  61894. */
  61895. this.u_opacity = gl.getUniformLocation(
  61896. program, ol.DEBUG_WEBGL ? 'u_opacity' : 'f');
  61897. /**
  61898. * @type {WebGLUniformLocation}
  61899. */
  61900. this.u_texture = gl.getUniformLocation(
  61901. program, ol.DEBUG_WEBGL ? 'u_texture' : 'g');
  61902. /**
  61903. * @type {number}
  61904. */
  61905. this.a_position = gl.getAttribLocation(
  61906. program, ol.DEBUG_WEBGL ? 'a_position' : 'b');
  61907. /**
  61908. * @type {number}
  61909. */
  61910. this.a_texCoord = gl.getAttribLocation(
  61911. program, ol.DEBUG_WEBGL ? 'a_texCoord' : 'c');
  61912. };
  61913. goog.provide('ol.renderer.webgl.Layer');
  61914. goog.require('ol');
  61915. goog.require('ol.render.Event');
  61916. goog.require('ol.render.EventType');
  61917. goog.require('ol.render.webgl.Immediate');
  61918. goog.require('ol.renderer.Layer');
  61919. goog.require('ol.renderer.webgl.defaultmapshader');
  61920. goog.require('ol.renderer.webgl.defaultmapshader.Locations');
  61921. goog.require('ol.transform');
  61922. goog.require('ol.vec.Mat4');
  61923. goog.require('ol.webgl');
  61924. goog.require('ol.webgl.Buffer');
  61925. goog.require('ol.webgl.Context');
  61926. /**
  61927. * @constructor
  61928. * @abstract
  61929. * @extends {ol.renderer.Layer}
  61930. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
  61931. * @param {ol.layer.Layer} layer Layer.
  61932. */
  61933. ol.renderer.webgl.Layer = function(mapRenderer, layer) {
  61934. ol.renderer.Layer.call(this, layer);
  61935. /**
  61936. * @protected
  61937. * @type {ol.renderer.webgl.Map}
  61938. */
  61939. this.mapRenderer = mapRenderer;
  61940. /**
  61941. * @private
  61942. * @type {ol.webgl.Buffer}
  61943. */
  61944. this.arrayBuffer_ = new ol.webgl.Buffer([
  61945. -1, -1, 0, 0,
  61946. 1, -1, 1, 0,
  61947. -1, 1, 0, 1,
  61948. 1, 1, 1, 1
  61949. ]);
  61950. /**
  61951. * @protected
  61952. * @type {WebGLTexture}
  61953. */
  61954. this.texture = null;
  61955. /**
  61956. * @protected
  61957. * @type {WebGLFramebuffer}
  61958. */
  61959. this.framebuffer = null;
  61960. /**
  61961. * @protected
  61962. * @type {number|undefined}
  61963. */
  61964. this.framebufferDimension = undefined;
  61965. /**
  61966. * @protected
  61967. * @type {ol.Transform}
  61968. */
  61969. this.texCoordMatrix = ol.transform.create();
  61970. /**
  61971. * @protected
  61972. * @type {ol.Transform}
  61973. */
  61974. this.projectionMatrix = ol.transform.create();
  61975. /**
  61976. * @type {Array.<number>}
  61977. * @private
  61978. */
  61979. this.tmpMat4_ = ol.vec.Mat4.create();
  61980. /**
  61981. * @private
  61982. * @type {ol.renderer.webgl.defaultmapshader.Locations}
  61983. */
  61984. this.defaultLocations_ = null;
  61985. };
  61986. ol.inherits(ol.renderer.webgl.Layer, ol.renderer.Layer);
  61987. /**
  61988. * @param {olx.FrameState} frameState Frame state.
  61989. * @param {number} framebufferDimension Framebuffer dimension.
  61990. * @protected
  61991. */
  61992. ol.renderer.webgl.Layer.prototype.bindFramebuffer = function(frameState, framebufferDimension) {
  61993. var gl = this.mapRenderer.getGL();
  61994. if (this.framebufferDimension === undefined ||
  61995. this.framebufferDimension != framebufferDimension) {
  61996. /**
  61997. * @param {WebGLRenderingContext} gl GL.
  61998. * @param {WebGLFramebuffer} framebuffer Framebuffer.
  61999. * @param {WebGLTexture} texture Texture.
  62000. */
  62001. var postRenderFunction = function(gl, framebuffer, texture) {
  62002. if (!gl.isContextLost()) {
  62003. gl.deleteFramebuffer(framebuffer);
  62004. gl.deleteTexture(texture);
  62005. }
  62006. }.bind(null, gl, this.framebuffer, this.texture);
  62007. frameState.postRenderFunctions.push(
  62008. /** @type {ol.PostRenderFunction} */ (postRenderFunction)
  62009. );
  62010. var texture = ol.webgl.Context.createEmptyTexture(
  62011. gl, framebufferDimension, framebufferDimension);
  62012. var framebuffer = gl.createFramebuffer();
  62013. gl.bindFramebuffer(ol.webgl.FRAMEBUFFER, framebuffer);
  62014. gl.framebufferTexture2D(ol.webgl.FRAMEBUFFER,
  62015. ol.webgl.COLOR_ATTACHMENT0, ol.webgl.TEXTURE_2D, texture, 0);
  62016. this.texture = texture;
  62017. this.framebuffer = framebuffer;
  62018. this.framebufferDimension = framebufferDimension;
  62019. } else {
  62020. gl.bindFramebuffer(ol.webgl.FRAMEBUFFER, this.framebuffer);
  62021. }
  62022. };
  62023. /**
  62024. * @param {olx.FrameState} frameState Frame state.
  62025. * @param {ol.LayerState} layerState Layer state.
  62026. * @param {ol.webgl.Context} context Context.
  62027. */
  62028. ol.renderer.webgl.Layer.prototype.composeFrame = function(frameState, layerState, context) {
  62029. this.dispatchComposeEvent_(
  62030. ol.render.EventType.PRECOMPOSE, context, frameState);
  62031. context.bindBuffer(ol.webgl.ARRAY_BUFFER, this.arrayBuffer_);
  62032. var gl = context.getGL();
  62033. var fragmentShader = ol.renderer.webgl.defaultmapshader.fragment;
  62034. var vertexShader = ol.renderer.webgl.defaultmapshader.vertex;
  62035. var program = context.getProgram(fragmentShader, vertexShader);
  62036. var locations;
  62037. if (!this.defaultLocations_) {
  62038. locations = new ol.renderer.webgl.defaultmapshader.Locations(gl, program);
  62039. this.defaultLocations_ = locations;
  62040. } else {
  62041. locations = this.defaultLocations_;
  62042. }
  62043. if (context.useProgram(program)) {
  62044. gl.enableVertexAttribArray(locations.a_position);
  62045. gl.vertexAttribPointer(
  62046. locations.a_position, 2, ol.webgl.FLOAT, false, 16, 0);
  62047. gl.enableVertexAttribArray(locations.a_texCoord);
  62048. gl.vertexAttribPointer(
  62049. locations.a_texCoord, 2, ol.webgl.FLOAT, false, 16, 8);
  62050. gl.uniform1i(locations.u_texture, 0);
  62051. }
  62052. gl.uniformMatrix4fv(locations.u_texCoordMatrix, false,
  62053. ol.vec.Mat4.fromTransform(this.tmpMat4_, this.getTexCoordMatrix()));
  62054. gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
  62055. ol.vec.Mat4.fromTransform(this.tmpMat4_, this.getProjectionMatrix()));
  62056. gl.uniform1f(locations.u_opacity, layerState.opacity);
  62057. gl.bindTexture(ol.webgl.TEXTURE_2D, this.getTexture());
  62058. gl.drawArrays(ol.webgl.TRIANGLE_STRIP, 0, 4);
  62059. this.dispatchComposeEvent_(
  62060. ol.render.EventType.POSTCOMPOSE, context, frameState);
  62061. };
  62062. /**
  62063. * @param {ol.render.EventType} type Event type.
  62064. * @param {ol.webgl.Context} context WebGL context.
  62065. * @param {olx.FrameState} frameState Frame state.
  62066. * @private
  62067. */
  62068. ol.renderer.webgl.Layer.prototype.dispatchComposeEvent_ = function(type, context, frameState) {
  62069. var layer = this.getLayer();
  62070. if (layer.hasListener(type)) {
  62071. var viewState = frameState.viewState;
  62072. var resolution = viewState.resolution;
  62073. var pixelRatio = frameState.pixelRatio;
  62074. var extent = frameState.extent;
  62075. var center = viewState.center;
  62076. var rotation = viewState.rotation;
  62077. var size = frameState.size;
  62078. var render = new ol.render.webgl.Immediate(
  62079. context, center, resolution, rotation, size, extent, pixelRatio);
  62080. var composeEvent = new ol.render.Event(
  62081. type, render, frameState, null, context);
  62082. layer.dispatchEvent(composeEvent);
  62083. }
  62084. };
  62085. /**
  62086. * @return {!ol.Transform} Matrix.
  62087. */
  62088. ol.renderer.webgl.Layer.prototype.getTexCoordMatrix = function() {
  62089. return this.texCoordMatrix;
  62090. };
  62091. /**
  62092. * @return {WebGLTexture} Texture.
  62093. */
  62094. ol.renderer.webgl.Layer.prototype.getTexture = function() {
  62095. return this.texture;
  62096. };
  62097. /**
  62098. * @return {!ol.Transform} Matrix.
  62099. */
  62100. ol.renderer.webgl.Layer.prototype.getProjectionMatrix = function() {
  62101. return this.projectionMatrix;
  62102. };
  62103. /**
  62104. * Handle webglcontextlost.
  62105. */
  62106. ol.renderer.webgl.Layer.prototype.handleWebGLContextLost = function() {
  62107. this.texture = null;
  62108. this.framebuffer = null;
  62109. this.framebufferDimension = undefined;
  62110. };
  62111. /**
  62112. * @abstract
  62113. * @param {olx.FrameState} frameState Frame state.
  62114. * @param {ol.LayerState} layerState Layer state.
  62115. * @param {ol.webgl.Context} context Context.
  62116. * @return {boolean} whether composeFrame should be called.
  62117. */
  62118. ol.renderer.webgl.Layer.prototype.prepareFrame = function(frameState, layerState, context) {};
  62119. /**
  62120. * @abstract
  62121. * @param {ol.Pixel} pixel Pixel.
  62122. * @param {olx.FrameState} frameState FrameState.
  62123. * @param {function(this: S, ol.layer.Layer, (Uint8ClampedArray|Uint8Array)): T} callback Layer
  62124. * callback.
  62125. * @param {S} thisArg Value to use as `this` when executing `callback`.
  62126. * @return {T|undefined} Callback result.
  62127. * @template S,T,U
  62128. */
  62129. ol.renderer.webgl.Layer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {};
  62130. goog.provide('ol.renderer.webgl.ImageLayer');
  62131. goog.require('ol');
  62132. goog.require('ol.LayerType');
  62133. goog.require('ol.ViewHint');
  62134. goog.require('ol.dom');
  62135. goog.require('ol.extent');
  62136. goog.require('ol.functions');
  62137. goog.require('ol.renderer.Type');
  62138. goog.require('ol.renderer.webgl.Layer');
  62139. goog.require('ol.transform');
  62140. goog.require('ol.webgl');
  62141. goog.require('ol.webgl.Context');
  62142. /**
  62143. * @constructor
  62144. * @extends {ol.renderer.webgl.Layer}
  62145. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
  62146. * @param {ol.layer.Image} imageLayer Tile layer.
  62147. * @api
  62148. */
  62149. ol.renderer.webgl.ImageLayer = function(mapRenderer, imageLayer) {
  62150. ol.renderer.webgl.Layer.call(this, mapRenderer, imageLayer);
  62151. /**
  62152. * The last rendered image.
  62153. * @private
  62154. * @type {?ol.ImageBase}
  62155. */
  62156. this.image_ = null;
  62157. /**
  62158. * @private
  62159. * @type {CanvasRenderingContext2D}
  62160. */
  62161. this.hitCanvasContext_ = null;
  62162. /**
  62163. * @private
  62164. * @type {?ol.Transform}
  62165. */
  62166. this.hitTransformationMatrix_ = null;
  62167. };
  62168. ol.inherits(ol.renderer.webgl.ImageLayer, ol.renderer.webgl.Layer);
  62169. /**
  62170. * Determine if this renderer handles the provided layer.
  62171. * @param {ol.renderer.Type} type The renderer type.
  62172. * @param {ol.layer.Layer} layer The candidate layer.
  62173. * @return {boolean} The renderer can render the layer.
  62174. */
  62175. ol.renderer.webgl.ImageLayer['handles'] = function(type, layer) {
  62176. return type === ol.renderer.Type.WEBGL && layer.getType() === ol.LayerType.IMAGE;
  62177. };
  62178. /**
  62179. * Create a layer renderer.
  62180. * @param {ol.renderer.Map} mapRenderer The map renderer.
  62181. * @param {ol.layer.Layer} layer The layer to be rendererd.
  62182. * @return {ol.renderer.webgl.ImageLayer} The layer renderer.
  62183. */
  62184. ol.renderer.webgl.ImageLayer['create'] = function(mapRenderer, layer) {
  62185. return new ol.renderer.webgl.ImageLayer(
  62186. /** @type {ol.renderer.webgl.Map} */ (mapRenderer),
  62187. /** @type {ol.layer.Image} */ (layer)
  62188. );
  62189. };
  62190. /**
  62191. * @param {ol.ImageBase} image Image.
  62192. * @private
  62193. * @return {WebGLTexture} Texture.
  62194. */
  62195. ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
  62196. // We meet the conditions to work with non-power of two textures.
  62197. // http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support
  62198. // http://learningwebgl.com/blog/?p=2101
  62199. var imageElement = image.getImage();
  62200. var gl = this.mapRenderer.getGL();
  62201. return ol.webgl.Context.createTexture(
  62202. gl, imageElement, ol.webgl.CLAMP_TO_EDGE, ol.webgl.CLAMP_TO_EDGE);
  62203. };
  62204. /**
  62205. * @inheritDoc
  62206. */
  62207. ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
  62208. var layer = this.getLayer();
  62209. var source = layer.getSource();
  62210. var resolution = frameState.viewState.resolution;
  62211. var rotation = frameState.viewState.rotation;
  62212. var skippedFeatureUids = frameState.skippedFeatureUids;
  62213. return source.forEachFeatureAtCoordinate(
  62214. coordinate, resolution, rotation, hitTolerance, skippedFeatureUids,
  62215. /**
  62216. * @param {ol.Feature|ol.render.Feature} feature Feature.
  62217. * @return {?} Callback result.
  62218. */
  62219. function(feature) {
  62220. return callback.call(thisArg, feature, layer);
  62221. });
  62222. };
  62223. /**
  62224. * @inheritDoc
  62225. */
  62226. ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layerState, context) {
  62227. var gl = this.mapRenderer.getGL();
  62228. var pixelRatio = frameState.pixelRatio;
  62229. var viewState = frameState.viewState;
  62230. var viewCenter = viewState.center;
  62231. var viewResolution = viewState.resolution;
  62232. var viewRotation = viewState.rotation;
  62233. var image = this.image_;
  62234. var texture = this.texture;
  62235. var imageLayer = /** @type {ol.layer.Image} */ (this.getLayer());
  62236. var imageSource = imageLayer.getSource();
  62237. var hints = frameState.viewHints;
  62238. var renderedExtent = frameState.extent;
  62239. if (layerState.extent !== undefined) {
  62240. renderedExtent = ol.extent.getIntersection(
  62241. renderedExtent, layerState.extent);
  62242. }
  62243. if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING] &&
  62244. !ol.extent.isEmpty(renderedExtent)) {
  62245. var projection = viewState.projection;
  62246. if (!ol.ENABLE_RASTER_REPROJECTION) {
  62247. var sourceProjection = imageSource.getProjection();
  62248. if (sourceProjection) {
  62249. projection = sourceProjection;
  62250. }
  62251. }
  62252. var image_ = imageSource.getImage(renderedExtent, viewResolution,
  62253. pixelRatio, projection);
  62254. if (image_) {
  62255. var loaded = this.loadImage(image_);
  62256. if (loaded) {
  62257. image = image_;
  62258. texture = this.createTexture_(image_);
  62259. if (this.texture) {
  62260. /**
  62261. * @param {WebGLRenderingContext} gl GL.
  62262. * @param {WebGLTexture} texture Texture.
  62263. */
  62264. var postRenderFunction = function(gl, texture) {
  62265. if (!gl.isContextLost()) {
  62266. gl.deleteTexture(texture);
  62267. }
  62268. }.bind(null, gl, this.texture);
  62269. frameState.postRenderFunctions.push(
  62270. /** @type {ol.PostRenderFunction} */ (postRenderFunction)
  62271. );
  62272. }
  62273. }
  62274. }
  62275. }
  62276. if (image) {
  62277. var canvas = this.mapRenderer.getContext().getCanvas();
  62278. this.updateProjectionMatrix_(canvas.width, canvas.height,
  62279. pixelRatio, viewCenter, viewResolution, viewRotation,
  62280. image.getExtent());
  62281. this.hitTransformationMatrix_ = null;
  62282. // Translate and scale to flip the Y coord.
  62283. var texCoordMatrix = this.texCoordMatrix;
  62284. ol.transform.reset(texCoordMatrix);
  62285. ol.transform.scale(texCoordMatrix, 1, -1);
  62286. ol.transform.translate(texCoordMatrix, 0, -1);
  62287. this.image_ = image;
  62288. this.texture = texture;
  62289. this.updateLogos(frameState, imageSource);
  62290. }
  62291. return !!image;
  62292. };
  62293. /**
  62294. * @param {number} canvasWidth Canvas width.
  62295. * @param {number} canvasHeight Canvas height.
  62296. * @param {number} pixelRatio Pixel ratio.
  62297. * @param {ol.Coordinate} viewCenter View center.
  62298. * @param {number} viewResolution View resolution.
  62299. * @param {number} viewRotation View rotation.
  62300. * @param {ol.Extent} imageExtent Image extent.
  62301. * @private
  62302. */
  62303. ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ = function(canvasWidth, canvasHeight, pixelRatio,
  62304. viewCenter, viewResolution, viewRotation, imageExtent) {
  62305. var canvasExtentWidth = canvasWidth * viewResolution;
  62306. var canvasExtentHeight = canvasHeight * viewResolution;
  62307. var projectionMatrix = this.projectionMatrix;
  62308. ol.transform.reset(projectionMatrix);
  62309. ol.transform.scale(projectionMatrix,
  62310. pixelRatio * 2 / canvasExtentWidth,
  62311. pixelRatio * 2 / canvasExtentHeight);
  62312. ol.transform.rotate(projectionMatrix, -viewRotation);
  62313. ol.transform.translate(projectionMatrix,
  62314. imageExtent[0] - viewCenter[0],
  62315. imageExtent[1] - viewCenter[1]);
  62316. ol.transform.scale(projectionMatrix,
  62317. (imageExtent[2] - imageExtent[0]) / 2,
  62318. (imageExtent[3] - imageExtent[1]) / 2);
  62319. ol.transform.translate(projectionMatrix, 1, 1);
  62320. };
  62321. /**
  62322. * @inheritDoc
  62323. */
  62324. ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) {
  62325. var hasFeature = this.forEachFeatureAtCoordinate(
  62326. coordinate, frameState, 0, ol.functions.TRUE, this);
  62327. return hasFeature !== undefined;
  62328. };
  62329. /**
  62330. * @inheritDoc
  62331. */
  62332. ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
  62333. if (!this.image_ || !this.image_.getImage()) {
  62334. return undefined;
  62335. }
  62336. if (this.getLayer().getSource().forEachFeatureAtCoordinate !== ol.nullFunction) {
  62337. // for ImageCanvas sources use the original hit-detection logic,
  62338. // so that for example also transparent polygons are detected
  62339. var coordinate = ol.transform.apply(
  62340. frameState.pixelToCoordinateTransform, pixel.slice());
  62341. var hasFeature = this.forEachFeatureAtCoordinate(
  62342. coordinate, frameState, 0, ol.functions.TRUE, this);
  62343. if (hasFeature) {
  62344. return callback.call(thisArg, this.getLayer(), null);
  62345. } else {
  62346. return undefined;
  62347. }
  62348. } else {
  62349. var imageSize =
  62350. [this.image_.getImage().width, this.image_.getImage().height];
  62351. if (!this.hitTransformationMatrix_) {
  62352. this.hitTransformationMatrix_ = this.getHitTransformationMatrix_(
  62353. frameState.size, imageSize);
  62354. }
  62355. var pixelOnFrameBuffer = ol.transform.apply(
  62356. this.hitTransformationMatrix_, pixel.slice());
  62357. if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
  62358. pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {
  62359. // outside the image, no need to check
  62360. return undefined;
  62361. }
  62362. if (!this.hitCanvasContext_) {
  62363. this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);
  62364. }
  62365. this.hitCanvasContext_.clearRect(0, 0, 1, 1);
  62366. this.hitCanvasContext_.drawImage(this.image_.getImage(),
  62367. pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1);
  62368. var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
  62369. if (imageData[3] > 0) {
  62370. return callback.call(thisArg, this.getLayer(), imageData);
  62371. } else {
  62372. return undefined;
  62373. }
  62374. }
  62375. };
  62376. /**
  62377. * The transformation matrix to get the pixel on the image for a
  62378. * pixel on the map.
  62379. * @param {ol.Size} mapSize The map size.
  62380. * @param {ol.Size} imageSize The image size.
  62381. * @return {ol.Transform} The transformation matrix.
  62382. * @private
  62383. */
  62384. ol.renderer.webgl.ImageLayer.prototype.getHitTransformationMatrix_ = function(mapSize, imageSize) {
  62385. // the first matrix takes a map pixel, flips the y-axis and scales to
  62386. // a range between -1 ... 1
  62387. var mapCoordTransform = ol.transform.create();
  62388. ol.transform.translate(mapCoordTransform, -1, -1);
  62389. ol.transform.scale(mapCoordTransform, 2 / mapSize[0], 2 / mapSize[1]);
  62390. ol.transform.translate(mapCoordTransform, 0, mapSize[1]);
  62391. ol.transform.scale(mapCoordTransform, 1, -1);
  62392. // the second matrix is the inverse of the projection matrix used in the
  62393. // shader for drawing
  62394. var projectionMatrixInv = ol.transform.invert(this.projectionMatrix.slice());
  62395. // the third matrix scales to the image dimensions and flips the y-axis again
  62396. var transform = ol.transform.create();
  62397. ol.transform.translate(transform, 0, imageSize[1]);
  62398. ol.transform.scale(transform, 1, -1);
  62399. ol.transform.scale(transform, imageSize[0] / 2, imageSize[1] / 2);
  62400. ol.transform.translate(transform, 1, 1);
  62401. ol.transform.multiply(transform, projectionMatrixInv);
  62402. ol.transform.multiply(transform, mapCoordTransform);
  62403. return transform;
  62404. };
  62405. // FIXME check against gl.getParameter(webgl.MAX_TEXTURE_SIZE)
  62406. goog.provide('ol.renderer.webgl.Map');
  62407. goog.require('ol');
  62408. goog.require('ol.array');
  62409. goog.require('ol.css');
  62410. goog.require('ol.dom');
  62411. goog.require('ol.events');
  62412. goog.require('ol.has');
  62413. goog.require('ol.layer.Layer');
  62414. goog.require('ol.render.Event');
  62415. goog.require('ol.render.EventType');
  62416. goog.require('ol.render.webgl.Immediate');
  62417. goog.require('ol.renderer.Map');
  62418. goog.require('ol.renderer.Type');
  62419. goog.require('ol.source.State');
  62420. goog.require('ol.structs.LRUCache');
  62421. goog.require('ol.structs.PriorityQueue');
  62422. goog.require('ol.webgl');
  62423. goog.require('ol.webgl.Context');
  62424. goog.require('ol.webgl.ContextEventType');
  62425. /**
  62426. * @constructor
  62427. * @extends {ol.renderer.Map}
  62428. * @param {Element} container Container.
  62429. * @param {ol.PluggableMap} map Map.
  62430. * @api
  62431. */
  62432. ol.renderer.webgl.Map = function(container, map) {
  62433. ol.renderer.Map.call(this, container, map);
  62434. /**
  62435. * @private
  62436. * @type {HTMLCanvasElement}
  62437. */
  62438. this.canvas_ = /** @type {HTMLCanvasElement} */
  62439. (document.createElement('CANVAS'));
  62440. this.canvas_.style.width = '100%';
  62441. this.canvas_.style.height = '100%';
  62442. this.canvas_.style.display = 'block';
  62443. this.canvas_.className = ol.css.CLASS_UNSELECTABLE;
  62444. container.insertBefore(this.canvas_, container.childNodes[0] || null);
  62445. /**
  62446. * @private
  62447. * @type {number}
  62448. */
  62449. this.clipTileCanvasWidth_ = 0;
  62450. /**
  62451. * @private
  62452. * @type {number}
  62453. */
  62454. this.clipTileCanvasHeight_ = 0;
  62455. /**
  62456. * @private
  62457. * @type {CanvasRenderingContext2D}
  62458. */
  62459. this.clipTileContext_ = ol.dom.createCanvasContext2D();
  62460. /**
  62461. * @private
  62462. * @type {boolean}
  62463. */
  62464. this.renderedVisible_ = true;
  62465. /**
  62466. * @private
  62467. * @type {WebGLRenderingContext}
  62468. */
  62469. this.gl_ = ol.webgl.getContext(this.canvas_, {
  62470. antialias: true,
  62471. depth: true,
  62472. failIfMajorPerformanceCaveat: true,
  62473. preserveDrawingBuffer: false,
  62474. stencil: true
  62475. });
  62476. /**
  62477. * @private
  62478. * @type {ol.webgl.Context}
  62479. */
  62480. this.context_ = new ol.webgl.Context(this.canvas_, this.gl_);
  62481. ol.events.listen(this.canvas_, ol.webgl.ContextEventType.LOST,
  62482. this.handleWebGLContextLost, this);
  62483. ol.events.listen(this.canvas_, ol.webgl.ContextEventType.RESTORED,
  62484. this.handleWebGLContextRestored, this);
  62485. /**
  62486. * @private
  62487. * @type {ol.structs.LRUCache.<ol.WebglTextureCacheEntry|null>}
  62488. */
  62489. this.textureCache_ = new ol.structs.LRUCache();
  62490. /**
  62491. * @private
  62492. * @type {ol.Coordinate}
  62493. */
  62494. this.focus_ = null;
  62495. /**
  62496. * @private
  62497. * @type {ol.structs.PriorityQueue.<Array>}
  62498. */
  62499. this.tileTextureQueue_ = new ol.structs.PriorityQueue(
  62500. /**
  62501. * @param {Array.<*>} element Element.
  62502. * @return {number} Priority.
  62503. * @this {ol.renderer.webgl.Map}
  62504. */
  62505. (function(element) {
  62506. var tileCenter = /** @type {ol.Coordinate} */ (element[1]);
  62507. var tileResolution = /** @type {number} */ (element[2]);
  62508. var deltaX = tileCenter[0] - this.focus_[0];
  62509. var deltaY = tileCenter[1] - this.focus_[1];
  62510. return 65536 * Math.log(tileResolution) +
  62511. Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
  62512. }).bind(this),
  62513. /**
  62514. * @param {Array.<*>} element Element.
  62515. * @return {string} Key.
  62516. */
  62517. function(element) {
  62518. return /** @type {ol.Tile} */ (element[0]).getKey();
  62519. });
  62520. /**
  62521. * @param {ol.PluggableMap} map Map.
  62522. * @param {?olx.FrameState} frameState Frame state.
  62523. * @return {boolean} false.
  62524. * @this {ol.renderer.webgl.Map}
  62525. */
  62526. this.loadNextTileTexture_ =
  62527. function(map, frameState) {
  62528. if (!this.tileTextureQueue_.isEmpty()) {
  62529. this.tileTextureQueue_.reprioritize();
  62530. var element = this.tileTextureQueue_.dequeue();
  62531. var tile = /** @type {ol.Tile} */ (element[0]);
  62532. var tileSize = /** @type {ol.Size} */ (element[3]);
  62533. var tileGutter = /** @type {number} */ (element[4]);
  62534. this.bindTileTexture(
  62535. tile, tileSize, tileGutter, ol.webgl.LINEAR, ol.webgl.LINEAR);
  62536. }
  62537. return false;
  62538. }.bind(this);
  62539. /**
  62540. * @private
  62541. * @type {number}
  62542. */
  62543. this.textureCacheFrameMarkerCount_ = 0;
  62544. this.initializeGL_();
  62545. };
  62546. ol.inherits(ol.renderer.webgl.Map, ol.renderer.Map);
  62547. /**
  62548. * Determine if this renderer handles the provided layer.
  62549. * @param {ol.renderer.Type} type The renderer type.
  62550. * @return {boolean} The renderer can render the layer.
  62551. */
  62552. ol.renderer.webgl.Map['handles'] = function(type) {
  62553. return ol.has.WEBGL && type === ol.renderer.Type.WEBGL;
  62554. };
  62555. /**
  62556. * Create the map renderer.
  62557. * @param {Element} container Container.
  62558. * @param {ol.PluggableMap} map Map.
  62559. * @return {ol.renderer.webgl.Map} The map renderer.
  62560. */
  62561. ol.renderer.webgl.Map['create'] = function(container, map) {
  62562. return new ol.renderer.webgl.Map(container, map);
  62563. };
  62564. /**
  62565. * @param {ol.Tile} tile Tile.
  62566. * @param {ol.Size} tileSize Tile size.
  62567. * @param {number} tileGutter Tile gutter.
  62568. * @param {number} magFilter Mag filter.
  62569. * @param {number} minFilter Min filter.
  62570. */
  62571. ol.renderer.webgl.Map.prototype.bindTileTexture = function(tile, tileSize, tileGutter, magFilter, minFilter) {
  62572. var gl = this.getGL();
  62573. var tileKey = tile.getKey();
  62574. if (this.textureCache_.containsKey(tileKey)) {
  62575. var textureCacheEntry = this.textureCache_.get(tileKey);
  62576. gl.bindTexture(ol.webgl.TEXTURE_2D, textureCacheEntry.texture);
  62577. if (textureCacheEntry.magFilter != magFilter) {
  62578. gl.texParameteri(
  62579. ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_MAG_FILTER, magFilter);
  62580. textureCacheEntry.magFilter = magFilter;
  62581. }
  62582. if (textureCacheEntry.minFilter != minFilter) {
  62583. gl.texParameteri(
  62584. ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_MIN_FILTER, minFilter);
  62585. textureCacheEntry.minFilter = minFilter;
  62586. }
  62587. } else {
  62588. var texture = gl.createTexture();
  62589. gl.bindTexture(ol.webgl.TEXTURE_2D, texture);
  62590. if (tileGutter > 0) {
  62591. var clipTileCanvas = this.clipTileContext_.canvas;
  62592. var clipTileContext = this.clipTileContext_;
  62593. if (this.clipTileCanvasWidth_ !== tileSize[0] ||
  62594. this.clipTileCanvasHeight_ !== tileSize[1]) {
  62595. clipTileCanvas.width = tileSize[0];
  62596. clipTileCanvas.height = tileSize[1];
  62597. this.clipTileCanvasWidth_ = tileSize[0];
  62598. this.clipTileCanvasHeight_ = tileSize[1];
  62599. } else {
  62600. clipTileContext.clearRect(0, 0, tileSize[0], tileSize[1]);
  62601. }
  62602. clipTileContext.drawImage(tile.getImage(), tileGutter, tileGutter,
  62603. tileSize[0], tileSize[1], 0, 0, tileSize[0], tileSize[1]);
  62604. gl.texImage2D(ol.webgl.TEXTURE_2D, 0,
  62605. ol.webgl.RGBA, ol.webgl.RGBA,
  62606. ol.webgl.UNSIGNED_BYTE, clipTileCanvas);
  62607. } else {
  62608. gl.texImage2D(ol.webgl.TEXTURE_2D, 0,
  62609. ol.webgl.RGBA, ol.webgl.RGBA,
  62610. ol.webgl.UNSIGNED_BYTE, tile.getImage());
  62611. }
  62612. gl.texParameteri(
  62613. ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_MAG_FILTER, magFilter);
  62614. gl.texParameteri(
  62615. ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_MIN_FILTER, minFilter);
  62616. gl.texParameteri(ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_WRAP_S,
  62617. ol.webgl.CLAMP_TO_EDGE);
  62618. gl.texParameteri(ol.webgl.TEXTURE_2D, ol.webgl.TEXTURE_WRAP_T,
  62619. ol.webgl.CLAMP_TO_EDGE);
  62620. this.textureCache_.set(tileKey, {
  62621. texture: texture,
  62622. magFilter: magFilter,
  62623. minFilter: minFilter
  62624. });
  62625. }
  62626. };
  62627. /**
  62628. * @param {ol.render.EventType} type Event type.
  62629. * @param {olx.FrameState} frameState Frame state.
  62630. * @private
  62631. */
  62632. ol.renderer.webgl.Map.prototype.dispatchComposeEvent_ = function(type, frameState) {
  62633. var map = this.getMap();
  62634. if (map.hasListener(type)) {
  62635. var context = this.context_;
  62636. var extent = frameState.extent;
  62637. var size = frameState.size;
  62638. var viewState = frameState.viewState;
  62639. var pixelRatio = frameState.pixelRatio;
  62640. var resolution = viewState.resolution;
  62641. var center = viewState.center;
  62642. var rotation = viewState.rotation;
  62643. var vectorContext = new ol.render.webgl.Immediate(context,
  62644. center, resolution, rotation, size, extent, pixelRatio);
  62645. var composeEvent = new ol.render.Event(type, vectorContext,
  62646. frameState, null, context);
  62647. map.dispatchEvent(composeEvent);
  62648. }
  62649. };
  62650. /**
  62651. * @inheritDoc
  62652. */
  62653. ol.renderer.webgl.Map.prototype.disposeInternal = function() {
  62654. var gl = this.getGL();
  62655. if (!gl.isContextLost()) {
  62656. this.textureCache_.forEach(
  62657. /**
  62658. * @param {?ol.WebglTextureCacheEntry} textureCacheEntry
  62659. * Texture cache entry.
  62660. */
  62661. function(textureCacheEntry) {
  62662. if (textureCacheEntry) {
  62663. gl.deleteTexture(textureCacheEntry.texture);
  62664. }
  62665. });
  62666. }
  62667. this.context_.dispose();
  62668. ol.renderer.Map.prototype.disposeInternal.call(this);
  62669. };
  62670. /**
  62671. * @param {ol.PluggableMap} map Map.
  62672. * @param {olx.FrameState} frameState Frame state.
  62673. * @private
  62674. */
  62675. ol.renderer.webgl.Map.prototype.expireCache_ = function(map, frameState) {
  62676. var gl = this.getGL();
  62677. var textureCacheEntry;
  62678. while (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ >
  62679. ol.WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK) {
  62680. textureCacheEntry = this.textureCache_.peekLast();
  62681. if (!textureCacheEntry) {
  62682. if (+this.textureCache_.peekLastKey() == frameState.index) {
  62683. break;
  62684. } else {
  62685. --this.textureCacheFrameMarkerCount_;
  62686. }
  62687. } else {
  62688. gl.deleteTexture(textureCacheEntry.texture);
  62689. }
  62690. this.textureCache_.pop();
  62691. }
  62692. };
  62693. /**
  62694. * @return {ol.webgl.Context} The context.
  62695. */
  62696. ol.renderer.webgl.Map.prototype.getContext = function() {
  62697. return this.context_;
  62698. };
  62699. /**
  62700. * @return {WebGLRenderingContext} GL.
  62701. */
  62702. ol.renderer.webgl.Map.prototype.getGL = function() {
  62703. return this.gl_;
  62704. };
  62705. /**
  62706. * @return {ol.structs.PriorityQueue.<Array>} Tile texture queue.
  62707. */
  62708. ol.renderer.webgl.Map.prototype.getTileTextureQueue = function() {
  62709. return this.tileTextureQueue_;
  62710. };
  62711. /**
  62712. * @inheritDoc
  62713. */
  62714. ol.renderer.webgl.Map.prototype.getType = function() {
  62715. return ol.renderer.Type.WEBGL;
  62716. };
  62717. /**
  62718. * @param {ol.events.Event} event Event.
  62719. * @protected
  62720. */
  62721. ol.renderer.webgl.Map.prototype.handleWebGLContextLost = function(event) {
  62722. event.preventDefault();
  62723. this.textureCache_.clear();
  62724. this.textureCacheFrameMarkerCount_ = 0;
  62725. var renderers = this.getLayerRenderers();
  62726. for (var id in renderers) {
  62727. var renderer = /** @type {ol.renderer.webgl.Layer} */ (renderers[id]);
  62728. renderer.handleWebGLContextLost();
  62729. }
  62730. };
  62731. /**
  62732. * @protected
  62733. */
  62734. ol.renderer.webgl.Map.prototype.handleWebGLContextRestored = function() {
  62735. this.initializeGL_();
  62736. this.getMap().render();
  62737. };
  62738. /**
  62739. * @private
  62740. */
  62741. ol.renderer.webgl.Map.prototype.initializeGL_ = function() {
  62742. var gl = this.gl_;
  62743. gl.activeTexture(ol.webgl.TEXTURE0);
  62744. gl.blendFuncSeparate(
  62745. ol.webgl.SRC_ALPHA, ol.webgl.ONE_MINUS_SRC_ALPHA,
  62746. ol.webgl.ONE, ol.webgl.ONE_MINUS_SRC_ALPHA);
  62747. gl.disable(ol.webgl.CULL_FACE);
  62748. gl.disable(ol.webgl.DEPTH_TEST);
  62749. gl.disable(ol.webgl.SCISSOR_TEST);
  62750. gl.disable(ol.webgl.STENCIL_TEST);
  62751. };
  62752. /**
  62753. * @param {ol.Tile} tile Tile.
  62754. * @return {boolean} Is tile texture loaded.
  62755. */
  62756. ol.renderer.webgl.Map.prototype.isTileTextureLoaded = function(tile) {
  62757. return this.textureCache_.containsKey(tile.getKey());
  62758. };
  62759. /**
  62760. * @inheritDoc
  62761. */
  62762. ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
  62763. var context = this.getContext();
  62764. var gl = this.getGL();
  62765. if (gl.isContextLost()) {
  62766. return false;
  62767. }
  62768. if (!frameState) {
  62769. if (this.renderedVisible_) {
  62770. this.canvas_.style.display = 'none';
  62771. this.renderedVisible_ = false;
  62772. }
  62773. return false;
  62774. }
  62775. this.focus_ = frameState.focus;
  62776. this.textureCache_.set((-frameState.index).toString(), null);
  62777. ++this.textureCacheFrameMarkerCount_;
  62778. this.dispatchComposeEvent_(ol.render.EventType.PRECOMPOSE, frameState);
  62779. /** @type {Array.<ol.LayerState>} */
  62780. var layerStatesToDraw = [];
  62781. var layerStatesArray = frameState.layerStatesArray;
  62782. ol.array.stableSort(layerStatesArray, ol.renderer.Map.sortByZIndex);
  62783. var viewResolution = frameState.viewState.resolution;
  62784. var i, ii, layerRenderer, layerState;
  62785. for (i = 0, ii = layerStatesArray.length; i < ii; ++i) {
  62786. layerState = layerStatesArray[i];
  62787. if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
  62788. layerState.sourceState == ol.source.State.READY) {
  62789. layerRenderer = /** @type {ol.renderer.webgl.Layer} */ (this.getLayerRenderer(layerState.layer));
  62790. if (layerRenderer.prepareFrame(frameState, layerState, context)) {
  62791. layerStatesToDraw.push(layerState);
  62792. }
  62793. }
  62794. }
  62795. var width = frameState.size[0] * frameState.pixelRatio;
  62796. var height = frameState.size[1] * frameState.pixelRatio;
  62797. if (this.canvas_.width != width || this.canvas_.height != height) {
  62798. this.canvas_.width = width;
  62799. this.canvas_.height = height;
  62800. }
  62801. gl.bindFramebuffer(ol.webgl.FRAMEBUFFER, null);
  62802. gl.clearColor(0, 0, 0, 0);
  62803. gl.clear(ol.webgl.COLOR_BUFFER_BIT);
  62804. gl.enable(ol.webgl.BLEND);
  62805. gl.viewport(0, 0, this.canvas_.width, this.canvas_.height);
  62806. for (i = 0, ii = layerStatesToDraw.length; i < ii; ++i) {
  62807. layerState = layerStatesToDraw[i];
  62808. layerRenderer = /** @type {ol.renderer.webgl.Layer} */ (this.getLayerRenderer(layerState.layer));
  62809. layerRenderer.composeFrame(frameState, layerState, context);
  62810. }
  62811. if (!this.renderedVisible_) {
  62812. this.canvas_.style.display = '';
  62813. this.renderedVisible_ = true;
  62814. }
  62815. this.calculateMatrices2D(frameState);
  62816. if (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ >
  62817. ol.WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK) {
  62818. frameState.postRenderFunctions.push(
  62819. /** @type {ol.PostRenderFunction} */ (this.expireCache_.bind(this))
  62820. );
  62821. }
  62822. if (!this.tileTextureQueue_.isEmpty()) {
  62823. frameState.postRenderFunctions.push(this.loadNextTileTexture_);
  62824. frameState.animate = true;
  62825. }
  62826. this.dispatchComposeEvent_(ol.render.EventType.POSTCOMPOSE, frameState);
  62827. this.scheduleRemoveUnusedLayerRenderers(frameState);
  62828. this.scheduleExpireIconCache(frameState);
  62829. };
  62830. /**
  62831. * @inheritDoc
  62832. */
  62833. ol.renderer.webgl.Map.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg,
  62834. layerFilter, thisArg2) {
  62835. var result;
  62836. if (this.getGL().isContextLost()) {
  62837. return false;
  62838. }
  62839. var viewState = frameState.viewState;
  62840. var layerStates = frameState.layerStatesArray;
  62841. var numLayers = layerStates.length;
  62842. var i;
  62843. for (i = numLayers - 1; i >= 0; --i) {
  62844. var layerState = layerStates[i];
  62845. var layer = layerState.layer;
  62846. if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
  62847. layerFilter.call(thisArg2, layer)) {
  62848. var layerRenderer = this.getLayerRenderer(layer);
  62849. result = layerRenderer.forEachFeatureAtCoordinate(
  62850. coordinate, frameState, hitTolerance, callback, thisArg);
  62851. if (result) {
  62852. return result;
  62853. }
  62854. }
  62855. }
  62856. return undefined;
  62857. };
  62858. /**
  62859. * @inheritDoc
  62860. */
  62861. ol.renderer.webgl.Map.prototype.hasFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, layerFilter, thisArg) {
  62862. var hasFeature = false;
  62863. if (this.getGL().isContextLost()) {
  62864. return false;
  62865. }
  62866. var viewState = frameState.viewState;
  62867. var layerStates = frameState.layerStatesArray;
  62868. var numLayers = layerStates.length;
  62869. var i;
  62870. for (i = numLayers - 1; i >= 0; --i) {
  62871. var layerState = layerStates[i];
  62872. var layer = layerState.layer;
  62873. if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
  62874. layerFilter.call(thisArg, layer)) {
  62875. var layerRenderer = this.getLayerRenderer(layer);
  62876. hasFeature =
  62877. layerRenderer.hasFeatureAtCoordinate(coordinate, frameState);
  62878. if (hasFeature) {
  62879. return true;
  62880. }
  62881. }
  62882. }
  62883. return hasFeature;
  62884. };
  62885. /**
  62886. * @inheritDoc
  62887. */
  62888. ol.renderer.webgl.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg,
  62889. layerFilter, thisArg2) {
  62890. if (this.getGL().isContextLost()) {
  62891. return false;
  62892. }
  62893. var viewState = frameState.viewState;
  62894. var result;
  62895. var layerStates = frameState.layerStatesArray;
  62896. var numLayers = layerStates.length;
  62897. var i;
  62898. for (i = numLayers - 1; i >= 0; --i) {
  62899. var layerState = layerStates[i];
  62900. var layer = layerState.layer;
  62901. if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
  62902. layerFilter.call(thisArg, layer)) {
  62903. var layerRenderer = /** @type {ol.renderer.webgl.Layer} */ (this.getLayerRenderer(layer));
  62904. result = layerRenderer.forEachLayerAtPixel(
  62905. pixel, frameState, callback, thisArg);
  62906. if (result) {
  62907. return result;
  62908. }
  62909. }
  62910. }
  62911. return undefined;
  62912. };
  62913. // This file is automatically generated, do not edit
  62914. goog.provide('ol.renderer.webgl.tilelayershader');
  62915. goog.require('ol');
  62916. goog.require('ol.webgl.Fragment');
  62917. goog.require('ol.webgl.Vertex');
  62918. ol.renderer.webgl.tilelayershader.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
  62919. 'precision mediump float;\nvarying vec2 v_texCoord;\n\n\nuniform sampler2D u_texture;\n\nvoid main(void) {\n gl_FragColor = texture2D(u_texture, v_texCoord);\n}\n' :
  62920. 'precision mediump float;varying vec2 a;uniform sampler2D e;void main(void){gl_FragColor=texture2D(e,a);}');
  62921. ol.renderer.webgl.tilelayershader.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
  62922. 'varying vec2 v_texCoord;\n\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nuniform vec4 u_tileOffset;\n\nvoid main(void) {\n gl_Position = vec4(a_position * u_tileOffset.xy + u_tileOffset.zw, 0., 1.);\n v_texCoord = a_texCoord;\n}\n\n\n' :
  62923. 'varying vec2 a;attribute vec2 b;attribute vec2 c;uniform vec4 d;void main(void){gl_Position=vec4(b*d.xy+d.zw,0.,1.);a=c;}');
  62924. // This file is automatically generated, do not edit
  62925. goog.provide('ol.renderer.webgl.tilelayershader.Locations');
  62926. goog.require('ol');
  62927. /**
  62928. * @constructor
  62929. * @param {WebGLRenderingContext} gl GL.
  62930. * @param {WebGLProgram} program Program.
  62931. * @struct
  62932. */
  62933. ol.renderer.webgl.tilelayershader.Locations = function(gl, program) {
  62934. /**
  62935. * @type {WebGLUniformLocation}
  62936. */
  62937. this.u_tileOffset = gl.getUniformLocation(
  62938. program, ol.DEBUG_WEBGL ? 'u_tileOffset' : 'd');
  62939. /**
  62940. * @type {WebGLUniformLocation}
  62941. */
  62942. this.u_texture = gl.getUniformLocation(
  62943. program, ol.DEBUG_WEBGL ? 'u_texture' : 'e');
  62944. /**
  62945. * @type {number}
  62946. */
  62947. this.a_position = gl.getAttribLocation(
  62948. program, ol.DEBUG_WEBGL ? 'a_position' : 'b');
  62949. /**
  62950. * @type {number}
  62951. */
  62952. this.a_texCoord = gl.getAttribLocation(
  62953. program, ol.DEBUG_WEBGL ? 'a_texCoord' : 'c');
  62954. };
  62955. // FIXME large resolutions lead to too large framebuffers :-(
  62956. // FIXME animated shaders! check in redraw
  62957. goog.provide('ol.renderer.webgl.TileLayer');
  62958. goog.require('ol');
  62959. goog.require('ol.LayerType');
  62960. goog.require('ol.TileRange');
  62961. goog.require('ol.TileState');
  62962. goog.require('ol.array');
  62963. goog.require('ol.extent');
  62964. goog.require('ol.math');
  62965. goog.require('ol.renderer.Type');
  62966. goog.require('ol.renderer.webgl.Layer');
  62967. goog.require('ol.renderer.webgl.tilelayershader');
  62968. goog.require('ol.renderer.webgl.tilelayershader.Locations');
  62969. goog.require('ol.size');
  62970. goog.require('ol.transform');
  62971. goog.require('ol.webgl');
  62972. goog.require('ol.webgl.Buffer');
  62973. /**
  62974. * @constructor
  62975. * @extends {ol.renderer.webgl.Layer}
  62976. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
  62977. * @param {ol.layer.Tile} tileLayer Tile layer.
  62978. * @api
  62979. */
  62980. ol.renderer.webgl.TileLayer = function(mapRenderer, tileLayer) {
  62981. ol.renderer.webgl.Layer.call(this, mapRenderer, tileLayer);
  62982. /**
  62983. * @private
  62984. * @type {ol.webgl.Fragment}
  62985. */
  62986. this.fragmentShader_ = ol.renderer.webgl.tilelayershader.fragment;
  62987. /**
  62988. * @private
  62989. * @type {ol.webgl.Vertex}
  62990. */
  62991. this.vertexShader_ = ol.renderer.webgl.tilelayershader.vertex;
  62992. /**
  62993. * @private
  62994. * @type {ol.renderer.webgl.tilelayershader.Locations}
  62995. */
  62996. this.locations_ = null;
  62997. /**
  62998. * @private
  62999. * @type {ol.webgl.Buffer}
  63000. */
  63001. this.renderArrayBuffer_ = new ol.webgl.Buffer([
  63002. 0, 0, 0, 1,
  63003. 1, 0, 1, 1,
  63004. 0, 1, 0, 0,
  63005. 1, 1, 1, 0
  63006. ]);
  63007. /**
  63008. * @private
  63009. * @type {ol.TileRange}
  63010. */
  63011. this.renderedTileRange_ = null;
  63012. /**
  63013. * @private
  63014. * @type {ol.Extent}
  63015. */
  63016. this.renderedFramebufferExtent_ = null;
  63017. /**
  63018. * @private
  63019. * @type {number}
  63020. */
  63021. this.renderedRevision_ = -1;
  63022. /**
  63023. * @private
  63024. * @type {ol.Size}
  63025. */
  63026. this.tmpSize_ = [0, 0];
  63027. };
  63028. ol.inherits(ol.renderer.webgl.TileLayer, ol.renderer.webgl.Layer);
  63029. /**
  63030. * Determine if this renderer handles the provided layer.
  63031. * @param {ol.renderer.Type} type The renderer type.
  63032. * @param {ol.layer.Layer} layer The candidate layer.
  63033. * @return {boolean} The renderer can render the layer.
  63034. */
  63035. ol.renderer.webgl.TileLayer['handles'] = function(type, layer) {
  63036. return type === ol.renderer.Type.WEBGL && layer.getType() === ol.LayerType.TILE;
  63037. };
  63038. /**
  63039. * Create a layer renderer.
  63040. * @param {ol.renderer.Map} mapRenderer The map renderer.
  63041. * @param {ol.layer.Layer} layer The layer to be rendererd.
  63042. * @return {ol.renderer.webgl.TileLayer} The layer renderer.
  63043. */
  63044. ol.renderer.webgl.TileLayer['create'] = function(mapRenderer, layer) {
  63045. return new ol.renderer.webgl.TileLayer(
  63046. /** @type {ol.renderer.webgl.Map} */ (mapRenderer),
  63047. /** @type {ol.layer.Tile} */ (layer)
  63048. );
  63049. };
  63050. /**
  63051. * @inheritDoc
  63052. */
  63053. ol.renderer.webgl.TileLayer.prototype.disposeInternal = function() {
  63054. var context = this.mapRenderer.getContext();
  63055. context.deleteBuffer(this.renderArrayBuffer_);
  63056. ol.renderer.webgl.Layer.prototype.disposeInternal.call(this);
  63057. };
  63058. /**
  63059. * @inheritDoc
  63060. */
  63061. ol.renderer.webgl.TileLayer.prototype.createLoadedTileFinder = function(source, projection, tiles) {
  63062. var mapRenderer = this.mapRenderer;
  63063. return (
  63064. /**
  63065. * @param {number} zoom Zoom level.
  63066. * @param {ol.TileRange} tileRange Tile range.
  63067. * @return {boolean} The tile range is fully loaded.
  63068. */
  63069. function(zoom, tileRange) {
  63070. function callback(tile) {
  63071. var loaded = mapRenderer.isTileTextureLoaded(tile);
  63072. if (loaded) {
  63073. if (!tiles[zoom]) {
  63074. tiles[zoom] = {};
  63075. }
  63076. tiles[zoom][tile.tileCoord.toString()] = tile;
  63077. }
  63078. return loaded;
  63079. }
  63080. return source.forEachLoadedTile(projection, zoom, tileRange, callback);
  63081. });
  63082. };
  63083. /**
  63084. * @inheritDoc
  63085. */
  63086. ol.renderer.webgl.TileLayer.prototype.handleWebGLContextLost = function() {
  63087. ol.renderer.webgl.Layer.prototype.handleWebGLContextLost.call(this);
  63088. this.locations_ = null;
  63089. };
  63090. /**
  63091. * @inheritDoc
  63092. */
  63093. ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerState, context) {
  63094. var mapRenderer = this.mapRenderer;
  63095. var gl = context.getGL();
  63096. var viewState = frameState.viewState;
  63097. var projection = viewState.projection;
  63098. var tileLayer = /** @type {ol.layer.Tile} */ (this.getLayer());
  63099. var tileSource = tileLayer.getSource();
  63100. var tileGrid = tileSource.getTileGridForProjection(projection);
  63101. var z = tileGrid.getZForResolution(viewState.resolution);
  63102. var tileResolution = tileGrid.getResolution(z);
  63103. var tilePixelSize =
  63104. tileSource.getTilePixelSize(z, frameState.pixelRatio, projection);
  63105. var pixelRatio = tilePixelSize[0] /
  63106. ol.size.toSize(tileGrid.getTileSize(z), this.tmpSize_)[0];
  63107. var tilePixelResolution = tileResolution / pixelRatio;
  63108. var tileGutter = tileSource.getTilePixelRatio(pixelRatio) * tileSource.getGutter(projection);
  63109. var center = viewState.center;
  63110. var extent = frameState.extent;
  63111. var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
  63112. var framebufferExtent;
  63113. if (this.renderedTileRange_ &&
  63114. this.renderedTileRange_.equals(tileRange) &&
  63115. this.renderedRevision_ == tileSource.getRevision()) {
  63116. framebufferExtent = this.renderedFramebufferExtent_;
  63117. } else {
  63118. var tileRangeSize = tileRange.getSize();
  63119. var maxDimension = Math.max(
  63120. tileRangeSize[0] * tilePixelSize[0],
  63121. tileRangeSize[1] * tilePixelSize[1]);
  63122. var framebufferDimension = ol.math.roundUpToPowerOfTwo(maxDimension);
  63123. var framebufferExtentDimension = tilePixelResolution * framebufferDimension;
  63124. var origin = tileGrid.getOrigin(z);
  63125. var minX = origin[0] +
  63126. tileRange.minX * tilePixelSize[0] * tilePixelResolution;
  63127. var minY = origin[1] +
  63128. tileRange.minY * tilePixelSize[1] * tilePixelResolution;
  63129. framebufferExtent = [
  63130. minX, minY,
  63131. minX + framebufferExtentDimension, minY + framebufferExtentDimension
  63132. ];
  63133. this.bindFramebuffer(frameState, framebufferDimension);
  63134. gl.viewport(0, 0, framebufferDimension, framebufferDimension);
  63135. gl.clearColor(0, 0, 0, 0);
  63136. gl.clear(ol.webgl.COLOR_BUFFER_BIT);
  63137. gl.disable(ol.webgl.BLEND);
  63138. var program = context.getProgram(this.fragmentShader_, this.vertexShader_);
  63139. context.useProgram(program);
  63140. if (!this.locations_) {
  63141. this.locations_ = new ol.renderer.webgl.tilelayershader.Locations(gl, program);
  63142. }
  63143. context.bindBuffer(ol.webgl.ARRAY_BUFFER, this.renderArrayBuffer_);
  63144. gl.enableVertexAttribArray(this.locations_.a_position);
  63145. gl.vertexAttribPointer(
  63146. this.locations_.a_position, 2, ol.webgl.FLOAT, false, 16, 0);
  63147. gl.enableVertexAttribArray(this.locations_.a_texCoord);
  63148. gl.vertexAttribPointer(
  63149. this.locations_.a_texCoord, 2, ol.webgl.FLOAT, false, 16, 8);
  63150. gl.uniform1i(this.locations_.u_texture, 0);
  63151. /**
  63152. * @type {Object.<number, Object.<string, ol.Tile>>}
  63153. */
  63154. var tilesToDrawByZ = {};
  63155. tilesToDrawByZ[z] = {};
  63156. var findLoadedTiles = this.createLoadedTileFinder(
  63157. tileSource, projection, tilesToDrawByZ);
  63158. var useInterimTilesOnError = tileLayer.getUseInterimTilesOnError();
  63159. var allTilesLoaded = true;
  63160. var tmpExtent = ol.extent.createEmpty();
  63161. var tmpTileRange = new ol.TileRange(0, 0, 0, 0);
  63162. var childTileRange, drawable, fullyLoaded, tile, tileState;
  63163. var x, y, tileExtent;
  63164. for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
  63165. for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
  63166. tile = tileSource.getTile(z, x, y, pixelRatio, projection);
  63167. if (layerState.extent !== undefined) {
  63168. // ignore tiles outside layer extent
  63169. tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent);
  63170. if (!ol.extent.intersects(tileExtent, layerState.extent)) {
  63171. continue;
  63172. }
  63173. }
  63174. tileState = tile.getState();
  63175. drawable = tileState == ol.TileState.LOADED ||
  63176. tileState == ol.TileState.EMPTY ||
  63177. tileState == ol.TileState.ERROR && !useInterimTilesOnError;
  63178. if (!drawable) {
  63179. tile = tile.getInterimTile();
  63180. }
  63181. tileState = tile.getState();
  63182. if (tileState == ol.TileState.LOADED) {
  63183. if (mapRenderer.isTileTextureLoaded(tile)) {
  63184. tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
  63185. continue;
  63186. }
  63187. } else if (tileState == ol.TileState.EMPTY ||
  63188. (tileState == ol.TileState.ERROR &&
  63189. !useInterimTilesOnError)) {
  63190. continue;
  63191. }
  63192. allTilesLoaded = false;
  63193. fullyLoaded = tileGrid.forEachTileCoordParentTileRange(
  63194. tile.tileCoord, findLoadedTiles, null, tmpTileRange, tmpExtent);
  63195. if (!fullyLoaded) {
  63196. childTileRange = tileGrid.getTileCoordChildTileRange(
  63197. tile.tileCoord, tmpTileRange, tmpExtent);
  63198. if (childTileRange) {
  63199. findLoadedTiles(z + 1, childTileRange);
  63200. }
  63201. }
  63202. }
  63203. }
  63204. /** @type {Array.<number>} */
  63205. var zs = Object.keys(tilesToDrawByZ).map(Number);
  63206. zs.sort(ol.array.numberSafeCompareFunction);
  63207. var u_tileOffset = new Float32Array(4);
  63208. var i, ii, tileKey, tilesToDraw;
  63209. for (i = 0, ii = zs.length; i < ii; ++i) {
  63210. tilesToDraw = tilesToDrawByZ[zs[i]];
  63211. for (tileKey in tilesToDraw) {
  63212. tile = tilesToDraw[tileKey];
  63213. tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent);
  63214. u_tileOffset[0] = 2 * (tileExtent[2] - tileExtent[0]) /
  63215. framebufferExtentDimension;
  63216. u_tileOffset[1] = 2 * (tileExtent[3] - tileExtent[1]) /
  63217. framebufferExtentDimension;
  63218. u_tileOffset[2] = 2 * (tileExtent[0] - framebufferExtent[0]) /
  63219. framebufferExtentDimension - 1;
  63220. u_tileOffset[3] = 2 * (tileExtent[1] - framebufferExtent[1]) /
  63221. framebufferExtentDimension - 1;
  63222. gl.uniform4fv(this.locations_.u_tileOffset, u_tileOffset);
  63223. mapRenderer.bindTileTexture(tile, tilePixelSize,
  63224. tileGutter * pixelRatio, ol.webgl.LINEAR, ol.webgl.LINEAR);
  63225. gl.drawArrays(ol.webgl.TRIANGLE_STRIP, 0, 4);
  63226. }
  63227. }
  63228. if (allTilesLoaded) {
  63229. this.renderedTileRange_ = tileRange;
  63230. this.renderedFramebufferExtent_ = framebufferExtent;
  63231. this.renderedRevision_ = tileSource.getRevision();
  63232. } else {
  63233. this.renderedTileRange_ = null;
  63234. this.renderedFramebufferExtent_ = null;
  63235. this.renderedRevision_ = -1;
  63236. frameState.animate = true;
  63237. }
  63238. }
  63239. this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
  63240. var tileTextureQueue = mapRenderer.getTileTextureQueue();
  63241. this.manageTilePyramid(
  63242. frameState, tileSource, tileGrid, pixelRatio, projection, extent, z,
  63243. tileLayer.getPreload(),
  63244. /**
  63245. * @param {ol.Tile} tile Tile.
  63246. */
  63247. function(tile) {
  63248. if (tile.getState() == ol.TileState.LOADED &&
  63249. !mapRenderer.isTileTextureLoaded(tile) &&
  63250. !tileTextureQueue.isKeyQueued(tile.getKey())) {
  63251. tileTextureQueue.enqueue([
  63252. tile,
  63253. tileGrid.getTileCoordCenter(tile.tileCoord),
  63254. tileGrid.getResolution(tile.tileCoord[0]),
  63255. tilePixelSize, tileGutter * pixelRatio
  63256. ]);
  63257. }
  63258. }, this);
  63259. this.scheduleExpireCache(frameState, tileSource);
  63260. this.updateLogos(frameState, tileSource);
  63261. var texCoordMatrix = this.texCoordMatrix;
  63262. ol.transform.reset(texCoordMatrix);
  63263. ol.transform.translate(texCoordMatrix,
  63264. (Math.round(center[0] / tileResolution) * tileResolution - framebufferExtent[0]) /
  63265. (framebufferExtent[2] - framebufferExtent[0]),
  63266. (Math.round(center[1] / tileResolution) * tileResolution - framebufferExtent[1]) /
  63267. (framebufferExtent[3] - framebufferExtent[1]));
  63268. if (viewState.rotation !== 0) {
  63269. ol.transform.rotate(texCoordMatrix, viewState.rotation);
  63270. }
  63271. ol.transform.scale(texCoordMatrix,
  63272. frameState.size[0] * viewState.resolution /
  63273. (framebufferExtent[2] - framebufferExtent[0]),
  63274. frameState.size[1] * viewState.resolution /
  63275. (framebufferExtent[3] - framebufferExtent[1]));
  63276. ol.transform.translate(texCoordMatrix, -0.5, -0.5);
  63277. return true;
  63278. };
  63279. /**
  63280. * @inheritDoc
  63281. */
  63282. ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
  63283. if (!this.framebuffer) {
  63284. return undefined;
  63285. }
  63286. var pixelOnMapScaled = [
  63287. pixel[0] / frameState.size[0],
  63288. (frameState.size[1] - pixel[1]) / frameState.size[1]];
  63289. var pixelOnFrameBufferScaled = ol.transform.apply(
  63290. this.texCoordMatrix, pixelOnMapScaled.slice());
  63291. var pixelOnFrameBuffer = [
  63292. pixelOnFrameBufferScaled[0] * this.framebufferDimension,
  63293. pixelOnFrameBufferScaled[1] * this.framebufferDimension];
  63294. var gl = this.mapRenderer.getContext().getGL();
  63295. gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
  63296. var imageData = new Uint8Array(4);
  63297. gl.readPixels(pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1,
  63298. gl.RGBA, gl.UNSIGNED_BYTE, imageData);
  63299. if (imageData[3] > 0) {
  63300. return callback.call(thisArg, this.getLayer(), imageData);
  63301. } else {
  63302. return undefined;
  63303. }
  63304. };
  63305. goog.provide('ol.renderer.webgl.VectorLayer');
  63306. goog.require('ol');
  63307. goog.require('ol.LayerType');
  63308. goog.require('ol.ViewHint');
  63309. goog.require('ol.extent');
  63310. goog.require('ol.render.webgl.ReplayGroup');
  63311. goog.require('ol.renderer.Type');
  63312. goog.require('ol.renderer.vector');
  63313. goog.require('ol.renderer.webgl.Layer');
  63314. goog.require('ol.transform');
  63315. /**
  63316. * @constructor
  63317. * @extends {ol.renderer.webgl.Layer}
  63318. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
  63319. * @param {ol.layer.Vector} vectorLayer Vector layer.
  63320. * @api
  63321. */
  63322. ol.renderer.webgl.VectorLayer = function(mapRenderer, vectorLayer) {
  63323. ol.renderer.webgl.Layer.call(this, mapRenderer, vectorLayer);
  63324. /**
  63325. * @private
  63326. * @type {boolean}
  63327. */
  63328. this.dirty_ = false;
  63329. /**
  63330. * @private
  63331. * @type {number}
  63332. */
  63333. this.renderedRevision_ = -1;
  63334. /**
  63335. * @private
  63336. * @type {number}
  63337. */
  63338. this.renderedResolution_ = NaN;
  63339. /**
  63340. * @private
  63341. * @type {ol.Extent}
  63342. */
  63343. this.renderedExtent_ = ol.extent.createEmpty();
  63344. /**
  63345. * @private
  63346. * @type {function(ol.Feature, ol.Feature): number|null}
  63347. */
  63348. this.renderedRenderOrder_ = null;
  63349. /**
  63350. * @private
  63351. * @type {ol.render.webgl.ReplayGroup}
  63352. */
  63353. this.replayGroup_ = null;
  63354. /**
  63355. * The last layer state.
  63356. * @private
  63357. * @type {?ol.LayerState}
  63358. */
  63359. this.layerState_ = null;
  63360. };
  63361. ol.inherits(ol.renderer.webgl.VectorLayer, ol.renderer.webgl.Layer);
  63362. /**
  63363. * Determine if this renderer handles the provided layer.
  63364. * @param {ol.renderer.Type} type The renderer type.
  63365. * @param {ol.layer.Layer} layer The candidate layer.
  63366. * @return {boolean} The renderer can render the layer.
  63367. */
  63368. ol.renderer.webgl.VectorLayer['handles'] = function(type, layer) {
  63369. return type === ol.renderer.Type.WEBGL && layer.getType() === ol.LayerType.VECTOR;
  63370. };
  63371. /**
  63372. * Create a layer renderer.
  63373. * @param {ol.renderer.Map} mapRenderer The map renderer.
  63374. * @param {ol.layer.Layer} layer The layer to be rendererd.
  63375. * @return {ol.renderer.webgl.VectorLayer} The layer renderer.
  63376. */
  63377. ol.renderer.webgl.VectorLayer['create'] = function(mapRenderer, layer) {
  63378. return new ol.renderer.webgl.VectorLayer(
  63379. /** @type {ol.renderer.webgl.Map} */ (mapRenderer),
  63380. /** @type {ol.layer.Vector} */ (layer)
  63381. );
  63382. };
  63383. /**
  63384. * @inheritDoc
  63385. */
  63386. ol.renderer.webgl.VectorLayer.prototype.composeFrame = function(frameState, layerState, context) {
  63387. this.layerState_ = layerState;
  63388. var viewState = frameState.viewState;
  63389. var replayGroup = this.replayGroup_;
  63390. var size = frameState.size;
  63391. var pixelRatio = frameState.pixelRatio;
  63392. var gl = this.mapRenderer.getGL();
  63393. if (replayGroup && !replayGroup.isEmpty()) {
  63394. gl.enable(gl.SCISSOR_TEST);
  63395. gl.scissor(0, 0, size[0] * pixelRatio, size[1] * pixelRatio);
  63396. replayGroup.replay(context,
  63397. viewState.center, viewState.resolution, viewState.rotation,
  63398. size, pixelRatio, layerState.opacity,
  63399. layerState.managed ? frameState.skippedFeatureUids : {});
  63400. gl.disable(gl.SCISSOR_TEST);
  63401. }
  63402. };
  63403. /**
  63404. * @inheritDoc
  63405. */
  63406. ol.renderer.webgl.VectorLayer.prototype.disposeInternal = function() {
  63407. var replayGroup = this.replayGroup_;
  63408. if (replayGroup) {
  63409. var context = this.mapRenderer.getContext();
  63410. replayGroup.getDeleteResourcesFunction(context)();
  63411. this.replayGroup_ = null;
  63412. }
  63413. ol.renderer.webgl.Layer.prototype.disposeInternal.call(this);
  63414. };
  63415. /**
  63416. * @inheritDoc
  63417. */
  63418. ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
  63419. if (!this.replayGroup_ || !this.layerState_) {
  63420. return undefined;
  63421. } else {
  63422. var context = this.mapRenderer.getContext();
  63423. var viewState = frameState.viewState;
  63424. var layer = this.getLayer();
  63425. var layerState = this.layerState_;
  63426. /** @type {Object.<string, boolean>} */
  63427. var features = {};
  63428. return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
  63429. context, viewState.center, viewState.resolution, viewState.rotation,
  63430. frameState.size, frameState.pixelRatio, layerState.opacity,
  63431. {},
  63432. /**
  63433. * @param {ol.Feature|ol.render.Feature} feature Feature.
  63434. * @return {?} Callback result.
  63435. */
  63436. function(feature) {
  63437. var key = ol.getUid(feature).toString();
  63438. if (!(key in features)) {
  63439. features[key] = true;
  63440. return callback.call(thisArg, feature, layer);
  63441. }
  63442. });
  63443. }
  63444. };
  63445. /**
  63446. * @inheritDoc
  63447. */
  63448. ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) {
  63449. if (!this.replayGroup_ || !this.layerState_) {
  63450. return false;
  63451. } else {
  63452. var context = this.mapRenderer.getContext();
  63453. var viewState = frameState.viewState;
  63454. var layerState = this.layerState_;
  63455. return this.replayGroup_.hasFeatureAtCoordinate(coordinate,
  63456. context, viewState.center, viewState.resolution, viewState.rotation,
  63457. frameState.size, frameState.pixelRatio, layerState.opacity,
  63458. frameState.skippedFeatureUids);
  63459. }
  63460. };
  63461. /**
  63462. * @inheritDoc
  63463. */
  63464. ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
  63465. var coordinate = ol.transform.apply(
  63466. frameState.pixelToCoordinateTransform, pixel.slice());
  63467. var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);
  63468. if (hasFeature) {
  63469. return callback.call(thisArg, this.getLayer(), null);
  63470. } else {
  63471. return undefined;
  63472. }
  63473. };
  63474. /**
  63475. * Handle changes in image style state.
  63476. * @param {ol.events.Event} event Image style change event.
  63477. * @private
  63478. */
  63479. ol.renderer.webgl.VectorLayer.prototype.handleStyleImageChange_ = function(event) {
  63480. this.renderIfReadyAndVisible();
  63481. };
  63482. /**
  63483. * @inheritDoc
  63484. */
  63485. ol.renderer.webgl.VectorLayer.prototype.prepareFrame = function(frameState, layerState, context) {
  63486. var vectorLayer = /** @type {ol.layer.Vector} */ (this.getLayer());
  63487. var vectorSource = vectorLayer.getSource();
  63488. this.updateLogos(frameState, vectorSource);
  63489. var animating = frameState.viewHints[ol.ViewHint.ANIMATING];
  63490. var interacting = frameState.viewHints[ol.ViewHint.INTERACTING];
  63491. var updateWhileAnimating = vectorLayer.getUpdateWhileAnimating();
  63492. var updateWhileInteracting = vectorLayer.getUpdateWhileInteracting();
  63493. if (!this.dirty_ && (!updateWhileAnimating && animating) ||
  63494. (!updateWhileInteracting && interacting)) {
  63495. return true;
  63496. }
  63497. var frameStateExtent = frameState.extent;
  63498. var viewState = frameState.viewState;
  63499. var projection = viewState.projection;
  63500. var resolution = viewState.resolution;
  63501. var pixelRatio = frameState.pixelRatio;
  63502. var vectorLayerRevision = vectorLayer.getRevision();
  63503. var vectorLayerRenderBuffer = vectorLayer.getRenderBuffer();
  63504. var vectorLayerRenderOrder = vectorLayer.getRenderOrder();
  63505. if (vectorLayerRenderOrder === undefined) {
  63506. vectorLayerRenderOrder = ol.renderer.vector.defaultOrder;
  63507. }
  63508. var extent = ol.extent.buffer(frameStateExtent,
  63509. vectorLayerRenderBuffer * resolution);
  63510. if (!this.dirty_ &&
  63511. this.renderedResolution_ == resolution &&
  63512. this.renderedRevision_ == vectorLayerRevision &&
  63513. this.renderedRenderOrder_ == vectorLayerRenderOrder &&
  63514. ol.extent.containsExtent(this.renderedExtent_, extent)) {
  63515. return true;
  63516. }
  63517. if (this.replayGroup_) {
  63518. frameState.postRenderFunctions.push(
  63519. this.replayGroup_.getDeleteResourcesFunction(context));
  63520. }
  63521. this.dirty_ = false;
  63522. var replayGroup = new ol.render.webgl.ReplayGroup(
  63523. ol.renderer.vector.getTolerance(resolution, pixelRatio),
  63524. extent, vectorLayer.getRenderBuffer());
  63525. vectorSource.loadFeatures(extent, resolution, projection);
  63526. /**
  63527. * @param {ol.Feature} feature Feature.
  63528. * @this {ol.renderer.webgl.VectorLayer}
  63529. */
  63530. var renderFeature = function(feature) {
  63531. var styles;
  63532. var styleFunction = feature.getStyleFunction();
  63533. if (styleFunction) {
  63534. styles = styleFunction.call(feature, resolution);
  63535. } else {
  63536. styleFunction = vectorLayer.getStyleFunction();
  63537. if (styleFunction) {
  63538. styles = styleFunction(feature, resolution);
  63539. }
  63540. }
  63541. if (styles) {
  63542. var dirty = this.renderFeature(
  63543. feature, resolution, pixelRatio, styles, replayGroup);
  63544. this.dirty_ = this.dirty_ || dirty;
  63545. }
  63546. };
  63547. if (vectorLayerRenderOrder) {
  63548. /** @type {Array.<ol.Feature>} */
  63549. var features = [];
  63550. vectorSource.forEachFeatureInExtent(extent,
  63551. /**
  63552. * @param {ol.Feature} feature Feature.
  63553. */
  63554. function(feature) {
  63555. features.push(feature);
  63556. }, this);
  63557. features.sort(vectorLayerRenderOrder);
  63558. features.forEach(renderFeature, this);
  63559. } else {
  63560. vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
  63561. }
  63562. replayGroup.finish(context);
  63563. this.renderedResolution_ = resolution;
  63564. this.renderedRevision_ = vectorLayerRevision;
  63565. this.renderedRenderOrder_ = vectorLayerRenderOrder;
  63566. this.renderedExtent_ = extent;
  63567. this.replayGroup_ = replayGroup;
  63568. return true;
  63569. };
  63570. /**
  63571. * @param {ol.Feature} feature Feature.
  63572. * @param {number} resolution Resolution.
  63573. * @param {number} pixelRatio Pixel ratio.
  63574. * @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
  63575. * styles.
  63576. * @param {ol.render.webgl.ReplayGroup} replayGroup Replay group.
  63577. * @return {boolean} `true` if an image is loading.
  63578. */
  63579. ol.renderer.webgl.VectorLayer.prototype.renderFeature = function(feature, resolution, pixelRatio, styles, replayGroup) {
  63580. if (!styles) {
  63581. return false;
  63582. }
  63583. var loading = false;
  63584. if (Array.isArray(styles)) {
  63585. for (var i = styles.length - 1, ii = 0; i >= ii; --i) {
  63586. loading = ol.renderer.vector.renderFeature(
  63587. replayGroup, feature, styles[i],
  63588. ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
  63589. this.handleStyleImageChange_, this) || loading;
  63590. }
  63591. } else {
  63592. loading = ol.renderer.vector.renderFeature(
  63593. replayGroup, feature, styles,
  63594. ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
  63595. this.handleStyleImageChange_, this) || loading;
  63596. }
  63597. return loading;
  63598. };
  63599. goog.provide('ol.Map');
  63600. goog.require('ol');
  63601. goog.require('ol.PluggableMap');
  63602. goog.require('ol.PluginType');
  63603. goog.require('ol.control');
  63604. goog.require('ol.interaction');
  63605. goog.require('ol.obj');
  63606. goog.require('ol.plugins');
  63607. goog.require('ol.renderer.canvas.ImageLayer');
  63608. goog.require('ol.renderer.canvas.Map');
  63609. goog.require('ol.renderer.canvas.TileLayer');
  63610. goog.require('ol.renderer.canvas.VectorLayer');
  63611. goog.require('ol.renderer.canvas.VectorTileLayer');
  63612. goog.require('ol.renderer.webgl.ImageLayer');
  63613. goog.require('ol.renderer.webgl.Map');
  63614. goog.require('ol.renderer.webgl.TileLayer');
  63615. goog.require('ol.renderer.webgl.VectorLayer');
  63616. if (ol.ENABLE_CANVAS) {
  63617. ol.plugins.register(ol.PluginType.MAP_RENDERER, ol.renderer.canvas.Map);
  63618. ol.plugins.registerMultiple(ol.PluginType.LAYER_RENDERER, [
  63619. ol.renderer.canvas.ImageLayer,
  63620. ol.renderer.canvas.TileLayer,
  63621. ol.renderer.canvas.VectorLayer,
  63622. ol.renderer.canvas.VectorTileLayer
  63623. ]);
  63624. }
  63625. if (ol.ENABLE_WEBGL) {
  63626. ol.plugins.register(ol.PluginType.MAP_RENDERER, ol.renderer.webgl.Map);
  63627. ol.plugins.registerMultiple(ol.PluginType.LAYER_RENDERER, [
  63628. ol.renderer.webgl.ImageLayer,
  63629. ol.renderer.webgl.TileLayer,
  63630. ol.renderer.webgl.VectorLayer
  63631. ]);
  63632. }
  63633. /**
  63634. * @classdesc
  63635. * The map is the core component of OpenLayers. For a map to render, a view,
  63636. * one or more layers, and a target container are needed:
  63637. *
  63638. * var map = new ol.Map({
  63639. * view: new ol.View({
  63640. * center: [0, 0],
  63641. * zoom: 1
  63642. * }),
  63643. * layers: [
  63644. * new ol.layer.Tile({
  63645. * source: new ol.source.OSM()
  63646. * })
  63647. * ],
  63648. * target: 'map'
  63649. * });
  63650. *
  63651. * The above snippet creates a map using a {@link ol.layer.Tile} to display
  63652. * {@link ol.source.OSM} OSM data and render it to a DOM element with the
  63653. * id `map`.
  63654. *
  63655. * The constructor places a viewport container (with CSS class name
  63656. * `ol-viewport`) in the target element (see `getViewport()`), and then two
  63657. * further elements within the viewport: one with CSS class name
  63658. * `ol-overlaycontainer-stopevent` for controls and some overlays, and one with
  63659. * CSS class name `ol-overlaycontainer` for other overlays (see the `stopEvent`
  63660. * option of {@link ol.Overlay} for the difference). The map itself is placed in
  63661. * a further element within the viewport.
  63662. *
  63663. * Layers are stored as a `ol.Collection` in layerGroups. A top-level group is
  63664. * provided by the library. This is what is accessed by `getLayerGroup` and
  63665. * `setLayerGroup`. Layers entered in the options are added to this group, and
  63666. * `addLayer` and `removeLayer` change the layer collection in the group.
  63667. * `getLayers` is a convenience function for `getLayerGroup().getLayers()`.
  63668. * Note that `ol.layer.Group` is a subclass of `ol.layer.Base`, so layers
  63669. * entered in the options or added with `addLayer` can be groups, which can
  63670. * contain further groups, and so on.
  63671. *
  63672. * @constructor
  63673. * @extends {ol.PluggableMap}
  63674. * @param {olx.MapOptions} options Map options.
  63675. * @fires ol.MapBrowserEvent
  63676. * @fires ol.MapEvent
  63677. * @fires ol.render.Event#postcompose
  63678. * @fires ol.render.Event#precompose
  63679. * @api
  63680. */
  63681. ol.Map = function(options) {
  63682. options = ol.obj.assign({}, options);
  63683. if (!options.controls) {
  63684. options.controls = ol.control.defaults();
  63685. }
  63686. if (!options.interactions) {
  63687. options.interactions = ol.interaction.defaults();
  63688. }
  63689. ol.PluggableMap.call(this, options);
  63690. };
  63691. ol.inherits(ol.Map, ol.PluggableMap);
  63692. goog.provide('ol.net');
  63693. goog.require('ol');
  63694. /**
  63695. * Simple JSONP helper. Supports error callbacks and a custom callback param.
  63696. * The error callback will be called when no JSONP is executed after 10 seconds.
  63697. *
  63698. * @param {string} url Request url. A 'callback' query parameter will be
  63699. * appended.
  63700. * @param {Function} callback Callback on success.
  63701. * @param {function()=} opt_errback Callback on error.
  63702. * @param {string=} opt_callbackParam Custom query parameter for the JSONP
  63703. * callback. Default is 'callback'.
  63704. */
  63705. ol.net.jsonp = function(url, callback, opt_errback, opt_callbackParam) {
  63706. var script = document.createElement('script');
  63707. var key = 'olc_' + ol.getUid(callback);
  63708. function cleanup() {
  63709. delete window[key];
  63710. script.parentNode.removeChild(script);
  63711. }
  63712. script.async = true;
  63713. script.src = url + (url.indexOf('?') == -1 ? '?' : '&') +
  63714. (opt_callbackParam || 'callback') + '=' + key;
  63715. var timer = setTimeout(function() {
  63716. cleanup();
  63717. if (opt_errback) {
  63718. opt_errback();
  63719. }
  63720. }, 10000);
  63721. window[key] = function(data) {
  63722. clearTimeout(timer);
  63723. cleanup();
  63724. callback(data);
  63725. };
  63726. document.getElementsByTagName('head')[0].appendChild(script);
  63727. };
  63728. goog.provide('ol.proj.common');
  63729. goog.require('ol.proj');
  63730. /**
  63731. * Deprecated. Transforms between EPSG:4326 and EPSG:3857 are now included by
  63732. * default. There is no need to call this function in application code and it
  63733. * will be removed in a future major release.
  63734. * @deprecated This function is no longer necessary.
  63735. * @api
  63736. */
  63737. ol.proj.common.add = ol.proj.addCommon;
  63738. goog.provide('ol.render');
  63739. goog.require('ol.has');
  63740. goog.require('ol.transform');
  63741. goog.require('ol.render.canvas.Immediate');
  63742. /**
  63743. * Binds a Canvas Immediate API to a canvas context, to allow drawing geometries
  63744. * to the context's canvas.
  63745. *
  63746. * The units for geometry coordinates are css pixels relative to the top left
  63747. * corner of the canvas element.
  63748. * ```js
  63749. * var canvas = document.createElement('canvas');
  63750. * var render = ol.render.toContext(canvas.getContext('2d'),
  63751. * { size: [100, 100] });
  63752. * render.setFillStrokeStyle(new ol.style.Fill({ color: blue }));
  63753. * render.drawPolygon(
  63754. * new ol.geom.Polygon([[[0, 0], [100, 100], [100, 0], [0, 0]]]));
  63755. * ```
  63756. *
  63757. * @param {CanvasRenderingContext2D} context Canvas context.
  63758. * @param {olx.render.ToContextOptions=} opt_options Options.
  63759. * @return {ol.render.canvas.Immediate} Canvas Immediate.
  63760. * @api
  63761. */
  63762. ol.render.toContext = function(context, opt_options) {
  63763. var canvas = context.canvas;
  63764. var options = opt_options ? opt_options : {};
  63765. var pixelRatio = options.pixelRatio || ol.has.DEVICE_PIXEL_RATIO;
  63766. var size = options.size;
  63767. if (size) {
  63768. canvas.width = size[0] * pixelRatio;
  63769. canvas.height = size[1] * pixelRatio;
  63770. canvas.style.width = size[0] + 'px';
  63771. canvas.style.height = size[1] + 'px';
  63772. }
  63773. var extent = [0, 0, canvas.width, canvas.height];
  63774. var transform = ol.transform.scale(ol.transform.create(), pixelRatio, pixelRatio);
  63775. return new ol.render.canvas.Immediate(context, pixelRatio, extent, transform,
  63776. 0);
  63777. };
  63778. goog.provide('ol.reproj');
  63779. goog.require('ol.dom');
  63780. goog.require('ol.extent');
  63781. goog.require('ol.math');
  63782. goog.require('ol.proj');
  63783. /**
  63784. * Calculates ideal resolution to use from the source in order to achieve
  63785. * pixel mapping as close as possible to 1:1 during reprojection.
  63786. * The resolution is calculated regardless of what resolutions
  63787. * are actually available in the dataset (TileGrid, Image, ...).
  63788. *
  63789. * @param {ol.proj.Projection} sourceProj Source projection.
  63790. * @param {ol.proj.Projection} targetProj Target projection.
  63791. * @param {ol.Coordinate} targetCenter Target center.
  63792. * @param {number} targetResolution Target resolution.
  63793. * @return {number} The best resolution to use. Can be +-Infinity, NaN or 0.
  63794. */
  63795. ol.reproj.calculateSourceResolution = function(sourceProj, targetProj,
  63796. targetCenter, targetResolution) {
  63797. var sourceCenter = ol.proj.transform(targetCenter, targetProj, sourceProj);
  63798. // calculate the ideal resolution of the source data
  63799. var sourceResolution =
  63800. ol.proj.getPointResolution(targetProj, targetResolution, targetCenter);
  63801. var targetMetersPerUnit = targetProj.getMetersPerUnit();
  63802. if (targetMetersPerUnit !== undefined) {
  63803. sourceResolution *= targetMetersPerUnit;
  63804. }
  63805. var sourceMetersPerUnit = sourceProj.getMetersPerUnit();
  63806. if (sourceMetersPerUnit !== undefined) {
  63807. sourceResolution /= sourceMetersPerUnit;
  63808. }
  63809. // Based on the projection properties, the point resolution at the specified
  63810. // coordinates may be slightly different. We need to reverse-compensate this
  63811. // in order to achieve optimal results.
  63812. var sourceExtent = sourceProj.getExtent();
  63813. if (!sourceExtent || ol.extent.containsCoordinate(sourceExtent, sourceCenter)) {
  63814. var compensationFactor =
  63815. ol.proj.getPointResolution(sourceProj, sourceResolution, sourceCenter) /
  63816. sourceResolution;
  63817. if (isFinite(compensationFactor) && compensationFactor > 0) {
  63818. sourceResolution /= compensationFactor;
  63819. }
  63820. }
  63821. return sourceResolution;
  63822. };
  63823. /**
  63824. * Enlarge the clipping triangle point by 1 pixel to ensure the edges overlap
  63825. * in order to mask gaps caused by antialiasing.
  63826. *
  63827. * @param {number} centroidX Centroid of the triangle (x coordinate in pixels).
  63828. * @param {number} centroidY Centroid of the triangle (y coordinate in pixels).
  63829. * @param {number} x X coordinate of the point (in pixels).
  63830. * @param {number} y Y coordinate of the point (in pixels).
  63831. * @return {ol.Coordinate} New point 1 px farther from the centroid.
  63832. * @private
  63833. */
  63834. ol.reproj.enlargeClipPoint_ = function(centroidX, centroidY, x, y) {
  63835. var dX = x - centroidX, dY = y - centroidY;
  63836. var distance = Math.sqrt(dX * dX + dY * dY);
  63837. return [Math.round(x + dX / distance), Math.round(y + dY / distance)];
  63838. };
  63839. /**
  63840. * Renders the source data into new canvas based on the triangulation.
  63841. *
  63842. * @param {number} width Width of the canvas.
  63843. * @param {number} height Height of the canvas.
  63844. * @param {number} pixelRatio Pixel ratio.
  63845. * @param {number} sourceResolution Source resolution.
  63846. * @param {ol.Extent} sourceExtent Extent of the data source.
  63847. * @param {number} targetResolution Target resolution.
  63848. * @param {ol.Extent} targetExtent Target extent.
  63849. * @param {ol.reproj.Triangulation} triangulation Calculated triangulation.
  63850. * @param {Array.<{extent: ol.Extent,
  63851. * image: (HTMLCanvasElement|Image|HTMLVideoElement)}>} sources
  63852. * Array of sources.
  63853. * @param {number} gutter Gutter of the sources.
  63854. * @param {boolean=} opt_renderEdges Render reprojection edges.
  63855. * @return {HTMLCanvasElement} Canvas with reprojected data.
  63856. */
  63857. ol.reproj.render = function(width, height, pixelRatio,
  63858. sourceResolution, sourceExtent, targetResolution, targetExtent,
  63859. triangulation, sources, gutter, opt_renderEdges) {
  63860. var context = ol.dom.createCanvasContext2D(Math.round(pixelRatio * width),
  63861. Math.round(pixelRatio * height));
  63862. if (sources.length === 0) {
  63863. return context.canvas;
  63864. }
  63865. context.scale(pixelRatio, pixelRatio);
  63866. var sourceDataExtent = ol.extent.createEmpty();
  63867. sources.forEach(function(src, i, arr) {
  63868. ol.extent.extend(sourceDataExtent, src.extent);
  63869. });
  63870. var canvasWidthInUnits = ol.extent.getWidth(sourceDataExtent);
  63871. var canvasHeightInUnits = ol.extent.getHeight(sourceDataExtent);
  63872. var stitchContext = ol.dom.createCanvasContext2D(
  63873. Math.round(pixelRatio * canvasWidthInUnits / sourceResolution),
  63874. Math.round(pixelRatio * canvasHeightInUnits / sourceResolution));
  63875. var stitchScale = pixelRatio / sourceResolution;
  63876. sources.forEach(function(src, i, arr) {
  63877. var xPos = src.extent[0] - sourceDataExtent[0];
  63878. var yPos = -(src.extent[3] - sourceDataExtent[3]);
  63879. var srcWidth = ol.extent.getWidth(src.extent);
  63880. var srcHeight = ol.extent.getHeight(src.extent);
  63881. stitchContext.drawImage(
  63882. src.image,
  63883. gutter, gutter,
  63884. src.image.width - 2 * gutter, src.image.height - 2 * gutter,
  63885. xPos * stitchScale, yPos * stitchScale,
  63886. srcWidth * stitchScale, srcHeight * stitchScale);
  63887. });
  63888. var targetTopLeft = ol.extent.getTopLeft(targetExtent);
  63889. triangulation.getTriangles().forEach(function(triangle, i, arr) {
  63890. /* Calculate affine transform (src -> dst)
  63891. * Resulting matrix can be used to transform coordinate
  63892. * from `sourceProjection` to destination pixels.
  63893. *
  63894. * To optimize number of context calls and increase numerical stability,
  63895. * we also do the following operations:
  63896. * trans(-topLeftExtentCorner), scale(1 / targetResolution), scale(1, -1)
  63897. * here before solving the linear system so [ui, vi] are pixel coordinates.
  63898. *
  63899. * Src points: xi, yi
  63900. * Dst points: ui, vi
  63901. * Affine coefficients: aij
  63902. *
  63903. * | x0 y0 1 0 0 0 | |a00| |u0|
  63904. * | x1 y1 1 0 0 0 | |a01| |u1|
  63905. * | x2 y2 1 0 0 0 | x |a02| = |u2|
  63906. * | 0 0 0 x0 y0 1 | |a10| |v0|
  63907. * | 0 0 0 x1 y1 1 | |a11| |v1|
  63908. * | 0 0 0 x2 y2 1 | |a12| |v2|
  63909. */
  63910. var source = triangle.source, target = triangle.target;
  63911. var x0 = source[0][0], y0 = source[0][1],
  63912. x1 = source[1][0], y1 = source[1][1],
  63913. x2 = source[2][0], y2 = source[2][1];
  63914. var u0 = (target[0][0] - targetTopLeft[0]) / targetResolution,
  63915. v0 = -(target[0][1] - targetTopLeft[1]) / targetResolution;
  63916. var u1 = (target[1][0] - targetTopLeft[0]) / targetResolution,
  63917. v1 = -(target[1][1] - targetTopLeft[1]) / targetResolution;
  63918. var u2 = (target[2][0] - targetTopLeft[0]) / targetResolution,
  63919. v2 = -(target[2][1] - targetTopLeft[1]) / targetResolution;
  63920. // Shift all the source points to improve numerical stability
  63921. // of all the subsequent calculations. The [x0, y0] is used here.
  63922. // This is also used to simplify the linear system.
  63923. var sourceNumericalShiftX = x0, sourceNumericalShiftY = y0;
  63924. x0 = 0;
  63925. y0 = 0;
  63926. x1 -= sourceNumericalShiftX;
  63927. y1 -= sourceNumericalShiftY;
  63928. x2 -= sourceNumericalShiftX;
  63929. y2 -= sourceNumericalShiftY;
  63930. var augmentedMatrix = [
  63931. [x1, y1, 0, 0, u1 - u0],
  63932. [x2, y2, 0, 0, u2 - u0],
  63933. [0, 0, x1, y1, v1 - v0],
  63934. [0, 0, x2, y2, v2 - v0]
  63935. ];
  63936. var affineCoefs = ol.math.solveLinearSystem(augmentedMatrix);
  63937. if (!affineCoefs) {
  63938. return;
  63939. }
  63940. context.save();
  63941. context.beginPath();
  63942. var centroidX = (u0 + u1 + u2) / 3, centroidY = (v0 + v1 + v2) / 3;
  63943. var p0 = ol.reproj.enlargeClipPoint_(centroidX, centroidY, u0, v0);
  63944. var p1 = ol.reproj.enlargeClipPoint_(centroidX, centroidY, u1, v1);
  63945. var p2 = ol.reproj.enlargeClipPoint_(centroidX, centroidY, u2, v2);
  63946. context.moveTo(p1[0], p1[1]);
  63947. context.lineTo(p0[0], p0[1]);
  63948. context.lineTo(p2[0], p2[1]);
  63949. context.clip();
  63950. context.transform(
  63951. affineCoefs[0], affineCoefs[2], affineCoefs[1], affineCoefs[3], u0, v0);
  63952. context.translate(sourceDataExtent[0] - sourceNumericalShiftX,
  63953. sourceDataExtent[3] - sourceNumericalShiftY);
  63954. context.scale(sourceResolution / pixelRatio,
  63955. -sourceResolution / pixelRatio);
  63956. context.drawImage(stitchContext.canvas, 0, 0);
  63957. context.restore();
  63958. });
  63959. if (opt_renderEdges) {
  63960. context.save();
  63961. context.strokeStyle = 'black';
  63962. context.lineWidth = 1;
  63963. triangulation.getTriangles().forEach(function(triangle, i, arr) {
  63964. var target = triangle.target;
  63965. var u0 = (target[0][0] - targetTopLeft[0]) / targetResolution,
  63966. v0 = -(target[0][1] - targetTopLeft[1]) / targetResolution;
  63967. var u1 = (target[1][0] - targetTopLeft[0]) / targetResolution,
  63968. v1 = -(target[1][1] - targetTopLeft[1]) / targetResolution;
  63969. var u2 = (target[2][0] - targetTopLeft[0]) / targetResolution,
  63970. v2 = -(target[2][1] - targetTopLeft[1]) / targetResolution;
  63971. context.beginPath();
  63972. context.moveTo(u1, v1);
  63973. context.lineTo(u0, v0);
  63974. context.lineTo(u2, v2);
  63975. context.closePath();
  63976. context.stroke();
  63977. });
  63978. context.restore();
  63979. }
  63980. return context.canvas;
  63981. };
  63982. goog.provide('ol.reproj.Triangulation');
  63983. goog.require('ol');
  63984. goog.require('ol.extent');
  63985. goog.require('ol.math');
  63986. goog.require('ol.proj');
  63987. /**
  63988. * @classdesc
  63989. * Class containing triangulation of the given target extent.
  63990. * Used for determining source data and the reprojection itself.
  63991. *
  63992. * @param {ol.proj.Projection} sourceProj Source projection.
  63993. * @param {ol.proj.Projection} targetProj Target projection.
  63994. * @param {ol.Extent} targetExtent Target extent to triangulate.
  63995. * @param {ol.Extent} maxSourceExtent Maximal source extent that can be used.
  63996. * @param {number} errorThreshold Acceptable error (in source units).
  63997. * @constructor
  63998. */
  63999. ol.reproj.Triangulation = function(sourceProj, targetProj, targetExtent,
  64000. maxSourceExtent, errorThreshold) {
  64001. /**
  64002. * @type {ol.proj.Projection}
  64003. * @private
  64004. */
  64005. this.sourceProj_ = sourceProj;
  64006. /**
  64007. * @type {ol.proj.Projection}
  64008. * @private
  64009. */
  64010. this.targetProj_ = targetProj;
  64011. /** @type {!Object.<string, ol.Coordinate>} */
  64012. var transformInvCache = {};
  64013. var transformInv = ol.proj.getTransform(this.targetProj_, this.sourceProj_);
  64014. /**
  64015. * @param {ol.Coordinate} c A coordinate.
  64016. * @return {ol.Coordinate} Transformed coordinate.
  64017. * @private
  64018. */
  64019. this.transformInv_ = function(c) {
  64020. var key = c[0] + '/' + c[1];
  64021. if (!transformInvCache[key]) {
  64022. transformInvCache[key] = transformInv(c);
  64023. }
  64024. return transformInvCache[key];
  64025. };
  64026. /**
  64027. * @type {ol.Extent}
  64028. * @private
  64029. */
  64030. this.maxSourceExtent_ = maxSourceExtent;
  64031. /**
  64032. * @type {number}
  64033. * @private
  64034. */
  64035. this.errorThresholdSquared_ = errorThreshold * errorThreshold;
  64036. /**
  64037. * @type {Array.<ol.ReprojTriangle>}
  64038. * @private
  64039. */
  64040. this.triangles_ = [];
  64041. /**
  64042. * Indicates that the triangulation crosses edge of the source projection.
  64043. * @type {boolean}
  64044. * @private
  64045. */
  64046. this.wrapsXInSource_ = false;
  64047. /**
  64048. * @type {boolean}
  64049. * @private
  64050. */
  64051. this.canWrapXInSource_ = this.sourceProj_.canWrapX() &&
  64052. !!maxSourceExtent &&
  64053. !!this.sourceProj_.getExtent() &&
  64054. (ol.extent.getWidth(maxSourceExtent) ==
  64055. ol.extent.getWidth(this.sourceProj_.getExtent()));
  64056. /**
  64057. * @type {?number}
  64058. * @private
  64059. */
  64060. this.sourceWorldWidth_ = this.sourceProj_.getExtent() ?
  64061. ol.extent.getWidth(this.sourceProj_.getExtent()) : null;
  64062. /**
  64063. * @type {?number}
  64064. * @private
  64065. */
  64066. this.targetWorldWidth_ = this.targetProj_.getExtent() ?
  64067. ol.extent.getWidth(this.targetProj_.getExtent()) : null;
  64068. var destinationTopLeft = ol.extent.getTopLeft(targetExtent);
  64069. var destinationTopRight = ol.extent.getTopRight(targetExtent);
  64070. var destinationBottomRight = ol.extent.getBottomRight(targetExtent);
  64071. var destinationBottomLeft = ol.extent.getBottomLeft(targetExtent);
  64072. var sourceTopLeft = this.transformInv_(destinationTopLeft);
  64073. var sourceTopRight = this.transformInv_(destinationTopRight);
  64074. var sourceBottomRight = this.transformInv_(destinationBottomRight);
  64075. var sourceBottomLeft = this.transformInv_(destinationBottomLeft);
  64076. this.addQuad_(
  64077. destinationTopLeft, destinationTopRight,
  64078. destinationBottomRight, destinationBottomLeft,
  64079. sourceTopLeft, sourceTopRight, sourceBottomRight, sourceBottomLeft,
  64080. ol.RASTER_REPROJECTION_MAX_SUBDIVISION);
  64081. if (this.wrapsXInSource_) {
  64082. var leftBound = Infinity;
  64083. this.triangles_.forEach(function(triangle, i, arr) {
  64084. leftBound = Math.min(leftBound,
  64085. triangle.source[0][0], triangle.source[1][0], triangle.source[2][0]);
  64086. });
  64087. // Shift triangles to be as close to `leftBound` as possible
  64088. // (if the distance is more than `worldWidth / 2` it can be closer.
  64089. this.triangles_.forEach(function(triangle) {
  64090. if (Math.max(triangle.source[0][0], triangle.source[1][0],
  64091. triangle.source[2][0]) - leftBound > this.sourceWorldWidth_ / 2) {
  64092. var newTriangle = [[triangle.source[0][0], triangle.source[0][1]],
  64093. [triangle.source[1][0], triangle.source[1][1]],
  64094. [triangle.source[2][0], triangle.source[2][1]]];
  64095. if ((newTriangle[0][0] - leftBound) > this.sourceWorldWidth_ / 2) {
  64096. newTriangle[0][0] -= this.sourceWorldWidth_;
  64097. }
  64098. if ((newTriangle[1][0] - leftBound) > this.sourceWorldWidth_ / 2) {
  64099. newTriangle[1][0] -= this.sourceWorldWidth_;
  64100. }
  64101. if ((newTriangle[2][0] - leftBound) > this.sourceWorldWidth_ / 2) {
  64102. newTriangle[2][0] -= this.sourceWorldWidth_;
  64103. }
  64104. // Rarely (if the extent contains both the dateline and prime meridian)
  64105. // the shift can in turn break some triangles.
  64106. // Detect this here and don't shift in such cases.
  64107. var minX = Math.min(
  64108. newTriangle[0][0], newTriangle[1][0], newTriangle[2][0]);
  64109. var maxX = Math.max(
  64110. newTriangle[0][0], newTriangle[1][0], newTriangle[2][0]);
  64111. if ((maxX - minX) < this.sourceWorldWidth_ / 2) {
  64112. triangle.source = newTriangle;
  64113. }
  64114. }
  64115. }, this);
  64116. }
  64117. transformInvCache = {};
  64118. };
  64119. /**
  64120. * Adds triangle to the triangulation.
  64121. * @param {ol.Coordinate} a The target a coordinate.
  64122. * @param {ol.Coordinate} b The target b coordinate.
  64123. * @param {ol.Coordinate} c The target c coordinate.
  64124. * @param {ol.Coordinate} aSrc The source a coordinate.
  64125. * @param {ol.Coordinate} bSrc The source b coordinate.
  64126. * @param {ol.Coordinate} cSrc The source c coordinate.
  64127. * @private
  64128. */
  64129. ol.reproj.Triangulation.prototype.addTriangle_ = function(a, b, c,
  64130. aSrc, bSrc, cSrc) {
  64131. this.triangles_.push({
  64132. source: [aSrc, bSrc, cSrc],
  64133. target: [a, b, c]
  64134. });
  64135. };
  64136. /**
  64137. * Adds quad (points in clock-wise order) to the triangulation
  64138. * (and reprojects the vertices) if valid.
  64139. * Performs quad subdivision if needed to increase precision.
  64140. *
  64141. * @param {ol.Coordinate} a The target a coordinate.
  64142. * @param {ol.Coordinate} b The target b coordinate.
  64143. * @param {ol.Coordinate} c The target c coordinate.
  64144. * @param {ol.Coordinate} d The target d coordinate.
  64145. * @param {ol.Coordinate} aSrc The source a coordinate.
  64146. * @param {ol.Coordinate} bSrc The source b coordinate.
  64147. * @param {ol.Coordinate} cSrc The source c coordinate.
  64148. * @param {ol.Coordinate} dSrc The source d coordinate.
  64149. * @param {number} maxSubdivision Maximal allowed subdivision of the quad.
  64150. * @private
  64151. */
  64152. ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
  64153. aSrc, bSrc, cSrc, dSrc, maxSubdivision) {
  64154. var sourceQuadExtent = ol.extent.boundingExtent([aSrc, bSrc, cSrc, dSrc]);
  64155. var sourceCoverageX = this.sourceWorldWidth_ ?
  64156. ol.extent.getWidth(sourceQuadExtent) / this.sourceWorldWidth_ : null;
  64157. var sourceWorldWidth = /** @type {number} */ (this.sourceWorldWidth_);
  64158. // when the quad is wrapped in the source projection
  64159. // it covers most of the projection extent, but not fully
  64160. var wrapsX = this.sourceProj_.canWrapX() &&
  64161. sourceCoverageX > 0.5 && sourceCoverageX < 1;
  64162. var needsSubdivision = false;
  64163. if (maxSubdivision > 0) {
  64164. if (this.targetProj_.isGlobal() && this.targetWorldWidth_) {
  64165. var targetQuadExtent = ol.extent.boundingExtent([a, b, c, d]);
  64166. var targetCoverageX =
  64167. ol.extent.getWidth(targetQuadExtent) / this.targetWorldWidth_;
  64168. needsSubdivision |=
  64169. targetCoverageX > ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH;
  64170. }
  64171. if (!wrapsX && this.sourceProj_.isGlobal() && sourceCoverageX) {
  64172. needsSubdivision |=
  64173. sourceCoverageX > ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH;
  64174. }
  64175. }
  64176. if (!needsSubdivision && this.maxSourceExtent_) {
  64177. if (!ol.extent.intersects(sourceQuadExtent, this.maxSourceExtent_)) {
  64178. // whole quad outside source projection extent -> ignore
  64179. return;
  64180. }
  64181. }
  64182. if (!needsSubdivision) {
  64183. if (!isFinite(aSrc[0]) || !isFinite(aSrc[1]) ||
  64184. !isFinite(bSrc[0]) || !isFinite(bSrc[1]) ||
  64185. !isFinite(cSrc[0]) || !isFinite(cSrc[1]) ||
  64186. !isFinite(dSrc[0]) || !isFinite(dSrc[1])) {
  64187. if (maxSubdivision > 0) {
  64188. needsSubdivision = true;
  64189. } else {
  64190. return;
  64191. }
  64192. }
  64193. }
  64194. if (maxSubdivision > 0) {
  64195. if (!needsSubdivision) {
  64196. var center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
  64197. var centerSrc = this.transformInv_(center);
  64198. var dx;
  64199. if (wrapsX) {
  64200. var centerSrcEstimX =
  64201. (ol.math.modulo(aSrc[0], sourceWorldWidth) +
  64202. ol.math.modulo(cSrc[0], sourceWorldWidth)) / 2;
  64203. dx = centerSrcEstimX -
  64204. ol.math.modulo(centerSrc[0], sourceWorldWidth);
  64205. } else {
  64206. dx = (aSrc[0] + cSrc[0]) / 2 - centerSrc[0];
  64207. }
  64208. var dy = (aSrc[1] + cSrc[1]) / 2 - centerSrc[1];
  64209. var centerSrcErrorSquared = dx * dx + dy * dy;
  64210. needsSubdivision = centerSrcErrorSquared > this.errorThresholdSquared_;
  64211. }
  64212. if (needsSubdivision) {
  64213. if (Math.abs(a[0] - c[0]) <= Math.abs(a[1] - c[1])) {
  64214. // split horizontally (top & bottom)
  64215. var bc = [(b[0] + c[0]) / 2, (b[1] + c[1]) / 2];
  64216. var bcSrc = this.transformInv_(bc);
  64217. var da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
  64218. var daSrc = this.transformInv_(da);
  64219. this.addQuad_(
  64220. a, b, bc, da, aSrc, bSrc, bcSrc, daSrc, maxSubdivision - 1);
  64221. this.addQuad_(
  64222. da, bc, c, d, daSrc, bcSrc, cSrc, dSrc, maxSubdivision - 1);
  64223. } else {
  64224. // split vertically (left & right)
  64225. var ab = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
  64226. var abSrc = this.transformInv_(ab);
  64227. var cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
  64228. var cdSrc = this.transformInv_(cd);
  64229. this.addQuad_(
  64230. a, ab, cd, d, aSrc, abSrc, cdSrc, dSrc, maxSubdivision - 1);
  64231. this.addQuad_(
  64232. ab, b, c, cd, abSrc, bSrc, cSrc, cdSrc, maxSubdivision - 1);
  64233. }
  64234. return;
  64235. }
  64236. }
  64237. if (wrapsX) {
  64238. if (!this.canWrapXInSource_) {
  64239. return;
  64240. }
  64241. this.wrapsXInSource_ = true;
  64242. }
  64243. this.addTriangle_(a, c, d, aSrc, cSrc, dSrc);
  64244. this.addTriangle_(a, b, c, aSrc, bSrc, cSrc);
  64245. };
  64246. /**
  64247. * Calculates extent of the 'source' coordinates from all the triangles.
  64248. *
  64249. * @return {ol.Extent} Calculated extent.
  64250. */
  64251. ol.reproj.Triangulation.prototype.calculateSourceExtent = function() {
  64252. var extent = ol.extent.createEmpty();
  64253. this.triangles_.forEach(function(triangle, i, arr) {
  64254. var src = triangle.source;
  64255. ol.extent.extendCoordinate(extent, src[0]);
  64256. ol.extent.extendCoordinate(extent, src[1]);
  64257. ol.extent.extendCoordinate(extent, src[2]);
  64258. });
  64259. return extent;
  64260. };
  64261. /**
  64262. * @return {Array.<ol.ReprojTriangle>} Array of the calculated triangles.
  64263. */
  64264. ol.reproj.Triangulation.prototype.getTriangles = function() {
  64265. return this.triangles_;
  64266. };
  64267. goog.provide('ol.reproj.Image');
  64268. goog.require('ol');
  64269. goog.require('ol.ImageBase');
  64270. goog.require('ol.ImageState');
  64271. goog.require('ol.events');
  64272. goog.require('ol.events.EventType');
  64273. goog.require('ol.extent');
  64274. goog.require('ol.reproj');
  64275. goog.require('ol.reproj.Triangulation');
  64276. /**
  64277. * @classdesc
  64278. * Class encapsulating single reprojected image.
  64279. * See {@link ol.source.Image}.
  64280. *
  64281. * @constructor
  64282. * @extends {ol.ImageBase}
  64283. * @param {ol.proj.Projection} sourceProj Source projection (of the data).
  64284. * @param {ol.proj.Projection} targetProj Target projection.
  64285. * @param {ol.Extent} targetExtent Target extent.
  64286. * @param {number} targetResolution Target resolution.
  64287. * @param {number} pixelRatio Pixel ratio.
  64288. * @param {ol.ReprojImageFunctionType} getImageFunction
  64289. * Function returning source images (extent, resolution, pixelRatio).
  64290. */
  64291. ol.reproj.Image = function(sourceProj, targetProj,
  64292. targetExtent, targetResolution, pixelRatio, getImageFunction) {
  64293. /**
  64294. * @private
  64295. * @type {ol.proj.Projection}
  64296. */
  64297. this.targetProj_ = targetProj;
  64298. /**
  64299. * @private
  64300. * @type {ol.Extent}
  64301. */
  64302. this.maxSourceExtent_ = sourceProj.getExtent();
  64303. var maxTargetExtent = targetProj.getExtent();
  64304. var limitedTargetExtent = maxTargetExtent ?
  64305. ol.extent.getIntersection(targetExtent, maxTargetExtent) : targetExtent;
  64306. var targetCenter = ol.extent.getCenter(limitedTargetExtent);
  64307. var sourceResolution = ol.reproj.calculateSourceResolution(
  64308. sourceProj, targetProj, targetCenter, targetResolution);
  64309. var errorThresholdInPixels = ol.DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD;
  64310. /**
  64311. * @private
  64312. * @type {!ol.reproj.Triangulation}
  64313. */
  64314. this.triangulation_ = new ol.reproj.Triangulation(
  64315. sourceProj, targetProj, limitedTargetExtent, this.maxSourceExtent_,
  64316. sourceResolution * errorThresholdInPixels);
  64317. /**
  64318. * @private
  64319. * @type {number}
  64320. */
  64321. this.targetResolution_ = targetResolution;
  64322. /**
  64323. * @private
  64324. * @type {ol.Extent}
  64325. */
  64326. this.targetExtent_ = targetExtent;
  64327. var sourceExtent = this.triangulation_.calculateSourceExtent();
  64328. /**
  64329. * @private
  64330. * @type {ol.ImageBase}
  64331. */
  64332. this.sourceImage_ =
  64333. getImageFunction(sourceExtent, sourceResolution, pixelRatio);
  64334. /**
  64335. * @private
  64336. * @type {number}
  64337. */
  64338. this.sourcePixelRatio_ =
  64339. this.sourceImage_ ? this.sourceImage_.getPixelRatio() : 1;
  64340. /**
  64341. * @private
  64342. * @type {HTMLCanvasElement}
  64343. */
  64344. this.canvas_ = null;
  64345. /**
  64346. * @private
  64347. * @type {?ol.EventsKey}
  64348. */
  64349. this.sourceListenerKey_ = null;
  64350. var state = ol.ImageState.LOADED;
  64351. if (this.sourceImage_) {
  64352. state = ol.ImageState.IDLE;
  64353. }
  64354. ol.ImageBase.call(this, targetExtent, targetResolution, this.sourcePixelRatio_, state);
  64355. };
  64356. ol.inherits(ol.reproj.Image, ol.ImageBase);
  64357. /**
  64358. * @inheritDoc
  64359. */
  64360. ol.reproj.Image.prototype.disposeInternal = function() {
  64361. if (this.state == ol.ImageState.LOADING) {
  64362. this.unlistenSource_();
  64363. }
  64364. ol.ImageBase.prototype.disposeInternal.call(this);
  64365. };
  64366. /**
  64367. * @inheritDoc
  64368. */
  64369. ol.reproj.Image.prototype.getImage = function() {
  64370. return this.canvas_;
  64371. };
  64372. /**
  64373. * @return {ol.proj.Projection} Projection.
  64374. */
  64375. ol.reproj.Image.prototype.getProjection = function() {
  64376. return this.targetProj_;
  64377. };
  64378. /**
  64379. * @private
  64380. */
  64381. ol.reproj.Image.prototype.reproject_ = function() {
  64382. var sourceState = this.sourceImage_.getState();
  64383. if (sourceState == ol.ImageState.LOADED) {
  64384. var width = ol.extent.getWidth(this.targetExtent_) / this.targetResolution_;
  64385. var height =
  64386. ol.extent.getHeight(this.targetExtent_) / this.targetResolution_;
  64387. this.canvas_ = ol.reproj.render(width, height, this.sourcePixelRatio_,
  64388. this.sourceImage_.getResolution(), this.maxSourceExtent_,
  64389. this.targetResolution_, this.targetExtent_, this.triangulation_, [{
  64390. extent: this.sourceImage_.getExtent(),
  64391. image: this.sourceImage_.getImage()
  64392. }], 0);
  64393. }
  64394. this.state = sourceState;
  64395. this.changed();
  64396. };
  64397. /**
  64398. * @inheritDoc
  64399. */
  64400. ol.reproj.Image.prototype.load = function() {
  64401. if (this.state == ol.ImageState.IDLE) {
  64402. this.state = ol.ImageState.LOADING;
  64403. this.changed();
  64404. var sourceState = this.sourceImage_.getState();
  64405. if (sourceState == ol.ImageState.LOADED ||
  64406. sourceState == ol.ImageState.ERROR) {
  64407. this.reproject_();
  64408. } else {
  64409. this.sourceListenerKey_ = ol.events.listen(this.sourceImage_,
  64410. ol.events.EventType.CHANGE, function(e) {
  64411. var sourceState = this.sourceImage_.getState();
  64412. if (sourceState == ol.ImageState.LOADED ||
  64413. sourceState == ol.ImageState.ERROR) {
  64414. this.unlistenSource_();
  64415. this.reproject_();
  64416. }
  64417. }, this);
  64418. this.sourceImage_.load();
  64419. }
  64420. }
  64421. };
  64422. /**
  64423. * @private
  64424. */
  64425. ol.reproj.Image.prototype.unlistenSource_ = function() {
  64426. ol.events.unlistenByKey(/** @type {!ol.EventsKey} */ (this.sourceListenerKey_));
  64427. this.sourceListenerKey_ = null;
  64428. };
  64429. goog.provide('ol.reproj.Tile');
  64430. goog.require('ol');
  64431. goog.require('ol.Tile');
  64432. goog.require('ol.TileState');
  64433. goog.require('ol.events');
  64434. goog.require('ol.events.EventType');
  64435. goog.require('ol.extent');
  64436. goog.require('ol.math');
  64437. goog.require('ol.reproj');
  64438. goog.require('ol.reproj.Triangulation');
  64439. /**
  64440. * @classdesc
  64441. * Class encapsulating single reprojected tile.
  64442. * See {@link ol.source.TileImage}.
  64443. *
  64444. * @constructor
  64445. * @extends {ol.Tile}
  64446. * @param {ol.proj.Projection} sourceProj Source projection.
  64447. * @param {ol.tilegrid.TileGrid} sourceTileGrid Source tile grid.
  64448. * @param {ol.proj.Projection} targetProj Target projection.
  64449. * @param {ol.tilegrid.TileGrid} targetTileGrid Target tile grid.
  64450. * @param {ol.TileCoord} tileCoord Coordinate of the tile.
  64451. * @param {ol.TileCoord} wrappedTileCoord Coordinate of the tile wrapped in X.
  64452. * @param {number} pixelRatio Pixel ratio.
  64453. * @param {number} gutter Gutter of the source tiles.
  64454. * @param {ol.ReprojTileFunctionType} getTileFunction
  64455. * Function returning source tiles (z, x, y, pixelRatio).
  64456. * @param {number=} opt_errorThreshold Acceptable reprojection error (in px).
  64457. * @param {boolean=} opt_renderEdges Render reprojection edges.
  64458. */
  64459. ol.reproj.Tile = function(sourceProj, sourceTileGrid,
  64460. targetProj, targetTileGrid, tileCoord, wrappedTileCoord,
  64461. pixelRatio, gutter, getTileFunction,
  64462. opt_errorThreshold, opt_renderEdges) {
  64463. ol.Tile.call(this, tileCoord, ol.TileState.IDLE);
  64464. /**
  64465. * @private
  64466. * @type {boolean}
  64467. */
  64468. this.renderEdges_ = opt_renderEdges !== undefined ? opt_renderEdges : false;
  64469. /**
  64470. * @private
  64471. * @type {number}
  64472. */
  64473. this.pixelRatio_ = pixelRatio;
  64474. /**
  64475. * @private
  64476. * @type {number}
  64477. */
  64478. this.gutter_ = gutter;
  64479. /**
  64480. * @private
  64481. * @type {HTMLCanvasElement}
  64482. */
  64483. this.canvas_ = null;
  64484. /**
  64485. * @private
  64486. * @type {ol.tilegrid.TileGrid}
  64487. */
  64488. this.sourceTileGrid_ = sourceTileGrid;
  64489. /**
  64490. * @private
  64491. * @type {ol.tilegrid.TileGrid}
  64492. */
  64493. this.targetTileGrid_ = targetTileGrid;
  64494. /**
  64495. * @private
  64496. * @type {ol.TileCoord}
  64497. */
  64498. this.wrappedTileCoord_ = wrappedTileCoord ? wrappedTileCoord : tileCoord;
  64499. /**
  64500. * @private
  64501. * @type {!Array.<ol.Tile>}
  64502. */
  64503. this.sourceTiles_ = [];
  64504. /**
  64505. * @private
  64506. * @type {Array.<ol.EventsKey>}
  64507. */
  64508. this.sourcesListenerKeys_ = null;
  64509. /**
  64510. * @private
  64511. * @type {number}
  64512. */
  64513. this.sourceZ_ = 0;
  64514. var targetExtent = targetTileGrid.getTileCoordExtent(this.wrappedTileCoord_);
  64515. var maxTargetExtent = this.targetTileGrid_.getExtent();
  64516. var maxSourceExtent = this.sourceTileGrid_.getExtent();
  64517. var limitedTargetExtent = maxTargetExtent ?
  64518. ol.extent.getIntersection(targetExtent, maxTargetExtent) : targetExtent;
  64519. if (ol.extent.getArea(limitedTargetExtent) === 0) {
  64520. // Tile is completely outside range -> EMPTY
  64521. // TODO: is it actually correct that the source even creates the tile ?
  64522. this.state = ol.TileState.EMPTY;
  64523. return;
  64524. }
  64525. var sourceProjExtent = sourceProj.getExtent();
  64526. if (sourceProjExtent) {
  64527. if (!maxSourceExtent) {
  64528. maxSourceExtent = sourceProjExtent;
  64529. } else {
  64530. maxSourceExtent = ol.extent.getIntersection(
  64531. maxSourceExtent, sourceProjExtent);
  64532. }
  64533. }
  64534. var targetResolution = targetTileGrid.getResolution(
  64535. this.wrappedTileCoord_[0]);
  64536. var targetCenter = ol.extent.getCenter(limitedTargetExtent);
  64537. var sourceResolution = ol.reproj.calculateSourceResolution(
  64538. sourceProj, targetProj, targetCenter, targetResolution);
  64539. if (!isFinite(sourceResolution) || sourceResolution <= 0) {
  64540. // invalid sourceResolution -> EMPTY
  64541. // probably edges of the projections when no extent is defined
  64542. this.state = ol.TileState.EMPTY;
  64543. return;
  64544. }
  64545. var errorThresholdInPixels = opt_errorThreshold !== undefined ?
  64546. opt_errorThreshold : ol.DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD;
  64547. /**
  64548. * @private
  64549. * @type {!ol.reproj.Triangulation}
  64550. */
  64551. this.triangulation_ = new ol.reproj.Triangulation(
  64552. sourceProj, targetProj, limitedTargetExtent, maxSourceExtent,
  64553. sourceResolution * errorThresholdInPixels);
  64554. if (this.triangulation_.getTriangles().length === 0) {
  64555. // no valid triangles -> EMPTY
  64556. this.state = ol.TileState.EMPTY;
  64557. return;
  64558. }
  64559. this.sourceZ_ = sourceTileGrid.getZForResolution(sourceResolution);
  64560. var sourceExtent = this.triangulation_.calculateSourceExtent();
  64561. if (maxSourceExtent) {
  64562. if (sourceProj.canWrapX()) {
  64563. sourceExtent[1] = ol.math.clamp(
  64564. sourceExtent[1], maxSourceExtent[1], maxSourceExtent[3]);
  64565. sourceExtent[3] = ol.math.clamp(
  64566. sourceExtent[3], maxSourceExtent[1], maxSourceExtent[3]);
  64567. } else {
  64568. sourceExtent = ol.extent.getIntersection(sourceExtent, maxSourceExtent);
  64569. }
  64570. }
  64571. if (!ol.extent.getArea(sourceExtent)) {
  64572. this.state = ol.TileState.EMPTY;
  64573. } else {
  64574. var sourceRange = sourceTileGrid.getTileRangeForExtentAndZ(
  64575. sourceExtent, this.sourceZ_);
  64576. for (var srcX = sourceRange.minX; srcX <= sourceRange.maxX; srcX++) {
  64577. for (var srcY = sourceRange.minY; srcY <= sourceRange.maxY; srcY++) {
  64578. var tile = getTileFunction(this.sourceZ_, srcX, srcY, pixelRatio);
  64579. if (tile) {
  64580. this.sourceTiles_.push(tile);
  64581. }
  64582. }
  64583. }
  64584. if (this.sourceTiles_.length === 0) {
  64585. this.state = ol.TileState.EMPTY;
  64586. }
  64587. }
  64588. };
  64589. ol.inherits(ol.reproj.Tile, ol.Tile);
  64590. /**
  64591. * @inheritDoc
  64592. */
  64593. ol.reproj.Tile.prototype.disposeInternal = function() {
  64594. if (this.state == ol.TileState.LOADING) {
  64595. this.unlistenSources_();
  64596. }
  64597. ol.Tile.prototype.disposeInternal.call(this);
  64598. };
  64599. /**
  64600. * Get the HTML Canvas element for this tile.
  64601. * @return {HTMLCanvasElement} Canvas.
  64602. */
  64603. ol.reproj.Tile.prototype.getImage = function() {
  64604. return this.canvas_;
  64605. };
  64606. /**
  64607. * @private
  64608. */
  64609. ol.reproj.Tile.prototype.reproject_ = function() {
  64610. var sources = [];
  64611. this.sourceTiles_.forEach(function(tile, i, arr) {
  64612. if (tile && tile.getState() == ol.TileState.LOADED) {
  64613. sources.push({
  64614. extent: this.sourceTileGrid_.getTileCoordExtent(tile.tileCoord),
  64615. image: tile.getImage()
  64616. });
  64617. }
  64618. }, this);
  64619. this.sourceTiles_.length = 0;
  64620. if (sources.length === 0) {
  64621. this.state = ol.TileState.ERROR;
  64622. } else {
  64623. var z = this.wrappedTileCoord_[0];
  64624. var size = this.targetTileGrid_.getTileSize(z);
  64625. var width = typeof size === 'number' ? size : size[0];
  64626. var height = typeof size === 'number' ? size : size[1];
  64627. var targetResolution = this.targetTileGrid_.getResolution(z);
  64628. var sourceResolution = this.sourceTileGrid_.getResolution(this.sourceZ_);
  64629. var targetExtent = this.targetTileGrid_.getTileCoordExtent(
  64630. this.wrappedTileCoord_);
  64631. this.canvas_ = ol.reproj.render(width, height, this.pixelRatio_,
  64632. sourceResolution, this.sourceTileGrid_.getExtent(),
  64633. targetResolution, targetExtent, this.triangulation_, sources,
  64634. this.gutter_, this.renderEdges_);
  64635. this.state = ol.TileState.LOADED;
  64636. }
  64637. this.changed();
  64638. };
  64639. /**
  64640. * @inheritDoc
  64641. */
  64642. ol.reproj.Tile.prototype.load = function() {
  64643. if (this.state == ol.TileState.IDLE) {
  64644. this.state = ol.TileState.LOADING;
  64645. this.changed();
  64646. var leftToLoad = 0;
  64647. this.sourcesListenerKeys_ = [];
  64648. this.sourceTiles_.forEach(function(tile, i, arr) {
  64649. var state = tile.getState();
  64650. if (state == ol.TileState.IDLE || state == ol.TileState.LOADING) {
  64651. leftToLoad++;
  64652. var sourceListenKey;
  64653. sourceListenKey = ol.events.listen(tile, ol.events.EventType.CHANGE,
  64654. function(e) {
  64655. var state = tile.getState();
  64656. if (state == ol.TileState.LOADED ||
  64657. state == ol.TileState.ERROR ||
  64658. state == ol.TileState.EMPTY) {
  64659. ol.events.unlistenByKey(sourceListenKey);
  64660. leftToLoad--;
  64661. if (leftToLoad === 0) {
  64662. this.unlistenSources_();
  64663. this.reproject_();
  64664. }
  64665. }
  64666. }, this);
  64667. this.sourcesListenerKeys_.push(sourceListenKey);
  64668. }
  64669. }, this);
  64670. this.sourceTiles_.forEach(function(tile, i, arr) {
  64671. var state = tile.getState();
  64672. if (state == ol.TileState.IDLE) {
  64673. tile.load();
  64674. }
  64675. });
  64676. if (leftToLoad === 0) {
  64677. setTimeout(this.reproject_.bind(this), 0);
  64678. }
  64679. }
  64680. };
  64681. /**
  64682. * @private
  64683. */
  64684. ol.reproj.Tile.prototype.unlistenSources_ = function() {
  64685. this.sourcesListenerKeys_.forEach(ol.events.unlistenByKey);
  64686. this.sourcesListenerKeys_ = null;
  64687. };
  64688. goog.provide('ol.TileUrlFunction');
  64689. goog.require('ol.asserts');
  64690. goog.require('ol.math');
  64691. goog.require('ol.tilecoord');
  64692. /**
  64693. * @param {string} template Template.
  64694. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
  64695. * @return {ol.TileUrlFunctionType} Tile URL function.
  64696. */
  64697. ol.TileUrlFunction.createFromTemplate = function(template, tileGrid) {
  64698. var zRegEx = /\{z\}/g;
  64699. var xRegEx = /\{x\}/g;
  64700. var yRegEx = /\{y\}/g;
  64701. var dashYRegEx = /\{-y\}/g;
  64702. return (
  64703. /**
  64704. * @param {ol.TileCoord} tileCoord Tile Coordinate.
  64705. * @param {number} pixelRatio Pixel ratio.
  64706. * @param {ol.proj.Projection} projection Projection.
  64707. * @return {string|undefined} Tile URL.
  64708. */
  64709. function(tileCoord, pixelRatio, projection) {
  64710. if (!tileCoord) {
  64711. return undefined;
  64712. } else {
  64713. return template.replace(zRegEx, tileCoord[0].toString())
  64714. .replace(xRegEx, tileCoord[1].toString())
  64715. .replace(yRegEx, function() {
  64716. var y = -tileCoord[2] - 1;
  64717. return y.toString();
  64718. })
  64719. .replace(dashYRegEx, function() {
  64720. var z = tileCoord[0];
  64721. var range = tileGrid.getFullTileRange(z);
  64722. ol.asserts.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
  64723. var y = range.getHeight() + tileCoord[2];
  64724. return y.toString();
  64725. });
  64726. }
  64727. });
  64728. };
  64729. /**
  64730. * @param {Array.<string>} templates Templates.
  64731. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
  64732. * @return {ol.TileUrlFunctionType} Tile URL function.
  64733. */
  64734. ol.TileUrlFunction.createFromTemplates = function(templates, tileGrid) {
  64735. var len = templates.length;
  64736. var tileUrlFunctions = new Array(len);
  64737. for (var i = 0; i < len; ++i) {
  64738. tileUrlFunctions[i] = ol.TileUrlFunction.createFromTemplate(
  64739. templates[i], tileGrid);
  64740. }
  64741. return ol.TileUrlFunction.createFromTileUrlFunctions(tileUrlFunctions);
  64742. };
  64743. /**
  64744. * @param {Array.<ol.TileUrlFunctionType>} tileUrlFunctions Tile URL Functions.
  64745. * @return {ol.TileUrlFunctionType} Tile URL function.
  64746. */
  64747. ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
  64748. if (tileUrlFunctions.length === 1) {
  64749. return tileUrlFunctions[0];
  64750. }
  64751. return (
  64752. /**
  64753. * @param {ol.TileCoord} tileCoord Tile Coordinate.
  64754. * @param {number} pixelRatio Pixel ratio.
  64755. * @param {ol.proj.Projection} projection Projection.
  64756. * @return {string|undefined} Tile URL.
  64757. */
  64758. function(tileCoord, pixelRatio, projection) {
  64759. if (!tileCoord) {
  64760. return undefined;
  64761. } else {
  64762. var h = ol.tilecoord.hash(tileCoord);
  64763. var index = ol.math.modulo(h, tileUrlFunctions.length);
  64764. return tileUrlFunctions[index](tileCoord, pixelRatio, projection);
  64765. }
  64766. });
  64767. };
  64768. /**
  64769. * @param {ol.TileCoord} tileCoord Tile coordinate.
  64770. * @param {number} pixelRatio Pixel ratio.
  64771. * @param {ol.proj.Projection} projection Projection.
  64772. * @return {string|undefined} Tile URL.
  64773. */
  64774. ol.TileUrlFunction.nullTileUrlFunction = function(tileCoord, pixelRatio, projection) {
  64775. return undefined;
  64776. };
  64777. /**
  64778. * @param {string} url URL.
  64779. * @return {Array.<string>} Array of urls.
  64780. */
  64781. ol.TileUrlFunction.expandUrl = function(url) {
  64782. var urls = [];
  64783. var match = /\{([a-z])-([a-z])\}/.exec(url);
  64784. if (match) {
  64785. // char range
  64786. var startCharCode = match[1].charCodeAt(0);
  64787. var stopCharCode = match[2].charCodeAt(0);
  64788. var charCode;
  64789. for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
  64790. urls.push(url.replace(match[0], String.fromCharCode(charCode)));
  64791. }
  64792. return urls;
  64793. }
  64794. match = match = /\{(\d+)-(\d+)\}/.exec(url);
  64795. if (match) {
  64796. // number range
  64797. var stop = parseInt(match[2], 10);
  64798. for (var i = parseInt(match[1], 10); i <= stop; i++) {
  64799. urls.push(url.replace(match[0], i.toString()));
  64800. }
  64801. return urls;
  64802. }
  64803. urls.push(url);
  64804. return urls;
  64805. };
  64806. goog.provide('ol.TileCache');
  64807. goog.require('ol');
  64808. goog.require('ol.structs.LRUCache');
  64809. goog.require('ol.tilecoord');
  64810. /**
  64811. * @constructor
  64812. * @extends {ol.structs.LRUCache.<ol.Tile>}
  64813. * @param {number=} opt_highWaterMark High water mark.
  64814. * @struct
  64815. */
  64816. ol.TileCache = function(opt_highWaterMark) {
  64817. ol.structs.LRUCache.call(this, opt_highWaterMark);
  64818. };
  64819. ol.inherits(ol.TileCache, ol.structs.LRUCache);
  64820. /**
  64821. * @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
  64822. */
  64823. ol.TileCache.prototype.expireCache = function(usedTiles) {
  64824. var tile, zKey;
  64825. while (this.canExpireCache()) {
  64826. tile = this.peekLast();
  64827. zKey = tile.tileCoord[0].toString();
  64828. if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) {
  64829. break;
  64830. } else {
  64831. this.pop().dispose();
  64832. }
  64833. }
  64834. };
  64835. /**
  64836. * Prune all tiles from the cache that don't have the same z as the newest tile.
  64837. */
  64838. ol.TileCache.prototype.pruneExceptNewestZ = function() {
  64839. if (this.getCount() === 0) {
  64840. return;
  64841. }
  64842. var key = this.peekFirstKey();
  64843. var tileCoord = ol.tilecoord.fromKey(key);
  64844. var z = tileCoord[0];
  64845. this.forEach(function(tile) {
  64846. if (tile.tileCoord[0] !== z) {
  64847. this.remove(ol.tilecoord.getKey(tile.tileCoord));
  64848. tile.dispose();
  64849. }
  64850. }, this);
  64851. };
  64852. goog.provide('ol.source.Tile');
  64853. goog.require('ol');
  64854. goog.require('ol.TileCache');
  64855. goog.require('ol.TileState');
  64856. goog.require('ol.events.Event');
  64857. goog.require('ol.proj');
  64858. goog.require('ol.size');
  64859. goog.require('ol.source.Source');
  64860. goog.require('ol.tilecoord');
  64861. goog.require('ol.tilegrid');
  64862. /**
  64863. * @classdesc
  64864. * Abstract base class; normally only used for creating subclasses and not
  64865. * instantiated in apps.
  64866. * Base class for sources providing images divided into a tile grid.
  64867. *
  64868. * @constructor
  64869. * @abstract
  64870. * @extends {ol.source.Source}
  64871. * @param {ol.SourceTileOptions} options Tile source options.
  64872. * @api
  64873. */
  64874. ol.source.Tile = function(options) {
  64875. ol.source.Source.call(this, {
  64876. attributions: options.attributions,
  64877. extent: options.extent,
  64878. logo: options.logo,
  64879. projection: options.projection,
  64880. state: options.state,
  64881. wrapX: options.wrapX
  64882. });
  64883. /**
  64884. * @private
  64885. * @type {boolean}
  64886. */
  64887. this.opaque_ = options.opaque !== undefined ? options.opaque : false;
  64888. /**
  64889. * @private
  64890. * @type {number}
  64891. */
  64892. this.tilePixelRatio_ = options.tilePixelRatio !== undefined ?
  64893. options.tilePixelRatio : 1;
  64894. /**
  64895. * @protected
  64896. * @type {ol.tilegrid.TileGrid}
  64897. */
  64898. this.tileGrid = options.tileGrid !== undefined ? options.tileGrid : null;
  64899. /**
  64900. * @protected
  64901. * @type {ol.TileCache}
  64902. */
  64903. this.tileCache = new ol.TileCache(options.cacheSize);
  64904. /**
  64905. * @protected
  64906. * @type {ol.Size}
  64907. */
  64908. this.tmpSize = [0, 0];
  64909. /**
  64910. * @private
  64911. * @type {string}
  64912. */
  64913. this.key_ = '';
  64914. /**
  64915. * @protected
  64916. * @type {olx.TileOptions}
  64917. */
  64918. this.tileOptions = {transition: options.transition};
  64919. };
  64920. ol.inherits(ol.source.Tile, ol.source.Source);
  64921. /**
  64922. * @return {boolean} Can expire cache.
  64923. */
  64924. ol.source.Tile.prototype.canExpireCache = function() {
  64925. return this.tileCache.canExpireCache();
  64926. };
  64927. /**
  64928. * @param {ol.proj.Projection} projection Projection.
  64929. * @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
  64930. */
  64931. ol.source.Tile.prototype.expireCache = function(projection, usedTiles) {
  64932. var tileCache = this.getTileCacheForProjection(projection);
  64933. if (tileCache) {
  64934. tileCache.expireCache(usedTiles);
  64935. }
  64936. };
  64937. /**
  64938. * @param {ol.proj.Projection} projection Projection.
  64939. * @param {number} z Zoom level.
  64940. * @param {ol.TileRange} tileRange Tile range.
  64941. * @param {function(ol.Tile):(boolean|undefined)} callback Called with each
  64942. * loaded tile. If the callback returns `false`, the tile will not be
  64943. * considered loaded.
  64944. * @return {boolean} The tile range is fully covered with loaded tiles.
  64945. */
  64946. ol.source.Tile.prototype.forEachLoadedTile = function(projection, z, tileRange, callback) {
  64947. var tileCache = this.getTileCacheForProjection(projection);
  64948. if (!tileCache) {
  64949. return false;
  64950. }
  64951. var covered = true;
  64952. var tile, tileCoordKey, loaded;
  64953. for (var x = tileRange.minX; x <= tileRange.maxX; ++x) {
  64954. for (var y = tileRange.minY; y <= tileRange.maxY; ++y) {
  64955. tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  64956. loaded = false;
  64957. if (tileCache.containsKey(tileCoordKey)) {
  64958. tile = /** @type {!ol.Tile} */ (tileCache.get(tileCoordKey));
  64959. loaded = tile.getState() === ol.TileState.LOADED;
  64960. if (loaded) {
  64961. loaded = (callback(tile) !== false);
  64962. }
  64963. }
  64964. if (!loaded) {
  64965. covered = false;
  64966. }
  64967. }
  64968. }
  64969. return covered;
  64970. };
  64971. /**
  64972. * @param {ol.proj.Projection} projection Projection.
  64973. * @return {number} Gutter.
  64974. */
  64975. ol.source.Tile.prototype.getGutter = function(projection) {
  64976. return 0;
  64977. };
  64978. /**
  64979. * Return the key to be used for all tiles in the source.
  64980. * @return {string} The key for all tiles.
  64981. * @protected
  64982. */
  64983. ol.source.Tile.prototype.getKey = function() {
  64984. return this.key_;
  64985. };
  64986. /**
  64987. * Set the value to be used as the key for all tiles in the source.
  64988. * @param {string} key The key for tiles.
  64989. * @protected
  64990. */
  64991. ol.source.Tile.prototype.setKey = function(key) {
  64992. if (this.key_ !== key) {
  64993. this.key_ = key;
  64994. this.changed();
  64995. }
  64996. };
  64997. /**
  64998. * @param {ol.proj.Projection} projection Projection.
  64999. * @return {boolean} Opaque.
  65000. */
  65001. ol.source.Tile.prototype.getOpaque = function(projection) {
  65002. return this.opaque_;
  65003. };
  65004. /**
  65005. * @inheritDoc
  65006. */
  65007. ol.source.Tile.prototype.getResolutions = function() {
  65008. return this.tileGrid.getResolutions();
  65009. };
  65010. /**
  65011. * @abstract
  65012. * @param {number} z Tile coordinate z.
  65013. * @param {number} x Tile coordinate x.
  65014. * @param {number} y Tile coordinate y.
  65015. * @param {number} pixelRatio Pixel ratio.
  65016. * @param {ol.proj.Projection} projection Projection.
  65017. * @return {!ol.Tile} Tile.
  65018. */
  65019. ol.source.Tile.prototype.getTile = function(z, x, y, pixelRatio, projection) {};
  65020. /**
  65021. * Return the tile grid of the tile source.
  65022. * @return {ol.tilegrid.TileGrid} Tile grid.
  65023. * @api
  65024. */
  65025. ol.source.Tile.prototype.getTileGrid = function() {
  65026. return this.tileGrid;
  65027. };
  65028. /**
  65029. * @param {ol.proj.Projection} projection Projection.
  65030. * @return {!ol.tilegrid.TileGrid} Tile grid.
  65031. */
  65032. ol.source.Tile.prototype.getTileGridForProjection = function(projection) {
  65033. if (!this.tileGrid) {
  65034. return ol.tilegrid.getForProjection(projection);
  65035. } else {
  65036. return this.tileGrid;
  65037. }
  65038. };
  65039. /**
  65040. * @param {ol.proj.Projection} projection Projection.
  65041. * @return {ol.TileCache} Tile cache.
  65042. * @protected
  65043. */
  65044. ol.source.Tile.prototype.getTileCacheForProjection = function(projection) {
  65045. var thisProj = this.getProjection();
  65046. if (thisProj && !ol.proj.equivalent(thisProj, projection)) {
  65047. return null;
  65048. } else {
  65049. return this.tileCache;
  65050. }
  65051. };
  65052. /**
  65053. * Get the tile pixel ratio for this source. Subclasses may override this
  65054. * method, which is meant to return a supported pixel ratio that matches the
  65055. * provided `pixelRatio` as close as possible.
  65056. * @param {number} pixelRatio Pixel ratio.
  65057. * @return {number} Tile pixel ratio.
  65058. */
  65059. ol.source.Tile.prototype.getTilePixelRatio = function(pixelRatio) {
  65060. return this.tilePixelRatio_;
  65061. };
  65062. /**
  65063. * @param {number} z Z.
  65064. * @param {number} pixelRatio Pixel ratio.
  65065. * @param {ol.proj.Projection} projection Projection.
  65066. * @return {ol.Size} Tile size.
  65067. */
  65068. ol.source.Tile.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
  65069. var tileGrid = this.getTileGridForProjection(projection);
  65070. var tilePixelRatio = this.getTilePixelRatio(pixelRatio);
  65071. var tileSize = ol.size.toSize(tileGrid.getTileSize(z), this.tmpSize);
  65072. if (tilePixelRatio == 1) {
  65073. return tileSize;
  65074. } else {
  65075. return ol.size.scale(tileSize, tilePixelRatio, this.tmpSize);
  65076. }
  65077. };
  65078. /**
  65079. * Returns a tile coordinate wrapped around the x-axis. When the tile coordinate
  65080. * is outside the resolution and extent range of the tile grid, `null` will be
  65081. * returned.
  65082. * @param {ol.TileCoord} tileCoord Tile coordinate.
  65083. * @param {ol.proj.Projection=} opt_projection Projection.
  65084. * @return {ol.TileCoord} Tile coordinate to be passed to the tileUrlFunction or
  65085. * null if no tile URL should be created for the passed `tileCoord`.
  65086. */
  65087. ol.source.Tile.prototype.getTileCoordForTileUrlFunction = function(tileCoord, opt_projection) {
  65088. var projection = opt_projection !== undefined ?
  65089. opt_projection : this.getProjection();
  65090. var tileGrid = this.getTileGridForProjection(projection);
  65091. if (this.getWrapX() && projection.isGlobal()) {
  65092. tileCoord = ol.tilegrid.wrapX(tileGrid, tileCoord, projection);
  65093. }
  65094. return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
  65095. };
  65096. /**
  65097. * @inheritDoc
  65098. */
  65099. ol.source.Tile.prototype.refresh = function() {
  65100. this.tileCache.clear();
  65101. this.changed();
  65102. };
  65103. /**
  65104. * Marks a tile coord as being used, without triggering a load.
  65105. * @param {number} z Tile coordinate z.
  65106. * @param {number} x Tile coordinate x.
  65107. * @param {number} y Tile coordinate y.
  65108. * @param {ol.proj.Projection} projection Projection.
  65109. */
  65110. ol.source.Tile.prototype.useTile = ol.nullFunction;
  65111. /**
  65112. * @classdesc
  65113. * Events emitted by {@link ol.source.Tile} instances are instances of this
  65114. * type.
  65115. *
  65116. * @constructor
  65117. * @extends {ol.events.Event}
  65118. * @implements {oli.source.Tile.Event}
  65119. * @param {string} type Type.
  65120. * @param {ol.Tile} tile The tile.
  65121. */
  65122. ol.source.Tile.Event = function(type, tile) {
  65123. ol.events.Event.call(this, type);
  65124. /**
  65125. * The tile related to the event.
  65126. * @type {ol.Tile}
  65127. * @api
  65128. */
  65129. this.tile = tile;
  65130. };
  65131. ol.inherits(ol.source.Tile.Event, ol.events.Event);
  65132. goog.provide('ol.source.TileEventType');
  65133. /**
  65134. * @enum {string}
  65135. */
  65136. ol.source.TileEventType = {
  65137. /**
  65138. * Triggered when a tile starts loading.
  65139. * @event ol.source.Tile.Event#tileloadstart
  65140. * @api
  65141. */
  65142. TILELOADSTART: 'tileloadstart',
  65143. /**
  65144. * Triggered when a tile finishes loading, either when its data is loaded,
  65145. * or when loading was aborted because the tile is no longer needed.
  65146. * @event ol.source.Tile.Event#tileloadend
  65147. * @api
  65148. */
  65149. TILELOADEND: 'tileloadend',
  65150. /**
  65151. * Triggered if tile loading results in an error.
  65152. * @event ol.source.Tile.Event#tileloaderror
  65153. * @api
  65154. */
  65155. TILELOADERROR: 'tileloaderror'
  65156. };
  65157. goog.provide('ol.source.UrlTile');
  65158. goog.require('ol');
  65159. goog.require('ol.TileState');
  65160. goog.require('ol.TileUrlFunction');
  65161. goog.require('ol.source.Tile');
  65162. goog.require('ol.source.TileEventType');
  65163. goog.require('ol.tilecoord');
  65164. /**
  65165. * @classdesc
  65166. * Base class for sources providing tiles divided into a tile grid over http.
  65167. *
  65168. * @constructor
  65169. * @abstract
  65170. * @fires ol.source.Tile.Event
  65171. * @extends {ol.source.Tile}
  65172. * @param {ol.SourceUrlTileOptions} options Image tile options.
  65173. */
  65174. ol.source.UrlTile = function(options) {
  65175. ol.source.Tile.call(this, {
  65176. attributions: options.attributions,
  65177. cacheSize: options.cacheSize,
  65178. extent: options.extent,
  65179. logo: options.logo,
  65180. opaque: options.opaque,
  65181. projection: options.projection,
  65182. state: options.state,
  65183. tileGrid: options.tileGrid,
  65184. tilePixelRatio: options.tilePixelRatio,
  65185. wrapX: options.wrapX,
  65186. transition: options.transition
  65187. });
  65188. /**
  65189. * @protected
  65190. * @type {ol.TileLoadFunctionType}
  65191. */
  65192. this.tileLoadFunction = options.tileLoadFunction;
  65193. /**
  65194. * @protected
  65195. * @type {ol.TileUrlFunctionType}
  65196. */
  65197. this.tileUrlFunction = this.fixedTileUrlFunction ?
  65198. this.fixedTileUrlFunction.bind(this) :
  65199. ol.TileUrlFunction.nullTileUrlFunction;
  65200. /**
  65201. * @protected
  65202. * @type {!Array.<string>|null}
  65203. */
  65204. this.urls = null;
  65205. if (options.urls) {
  65206. this.setUrls(options.urls);
  65207. } else if (options.url) {
  65208. this.setUrl(options.url);
  65209. }
  65210. if (options.tileUrlFunction) {
  65211. this.setTileUrlFunction(options.tileUrlFunction);
  65212. }
  65213. /**
  65214. * @private
  65215. * @type {Object.<number, boolean>}
  65216. */
  65217. this.tileLoadingKeys_ = {};
  65218. };
  65219. ol.inherits(ol.source.UrlTile, ol.source.Tile);
  65220. /**
  65221. * @type {ol.TileUrlFunctionType|undefined}
  65222. * @protected
  65223. */
  65224. ol.source.UrlTile.prototype.fixedTileUrlFunction;
  65225. /**
  65226. * Return the tile load function of the source.
  65227. * @return {ol.TileLoadFunctionType} TileLoadFunction
  65228. * @api
  65229. */
  65230. ol.source.UrlTile.prototype.getTileLoadFunction = function() {
  65231. return this.tileLoadFunction;
  65232. };
  65233. /**
  65234. * Return the tile URL function of the source.
  65235. * @return {ol.TileUrlFunctionType} TileUrlFunction
  65236. * @api
  65237. */
  65238. ol.source.UrlTile.prototype.getTileUrlFunction = function() {
  65239. return this.tileUrlFunction;
  65240. };
  65241. /**
  65242. * Return the URLs used for this source.
  65243. * When a tileUrlFunction is used instead of url or urls,
  65244. * null will be returned.
  65245. * @return {!Array.<string>|null} URLs.
  65246. * @api
  65247. */
  65248. ol.source.UrlTile.prototype.getUrls = function() {
  65249. return this.urls;
  65250. };
  65251. /**
  65252. * Handle tile change events.
  65253. * @param {ol.events.Event} event Event.
  65254. * @protected
  65255. */
  65256. ol.source.UrlTile.prototype.handleTileChange = function(event) {
  65257. var tile = /** @type {ol.Tile} */ (event.target);
  65258. var uid = ol.getUid(tile);
  65259. var tileState = tile.getState();
  65260. var type;
  65261. if (tileState == ol.TileState.LOADING) {
  65262. this.tileLoadingKeys_[uid] = true;
  65263. type = ol.source.TileEventType.TILELOADSTART;
  65264. } else if (uid in this.tileLoadingKeys_) {
  65265. delete this.tileLoadingKeys_[uid];
  65266. type = tileState == ol.TileState.ERROR ? ol.source.TileEventType.TILELOADERROR :
  65267. (tileState == ol.TileState.LOADED || tileState == ol.TileState.ABORT) ?
  65268. ol.source.TileEventType.TILELOADEND : undefined;
  65269. }
  65270. if (type != undefined) {
  65271. this.dispatchEvent(new ol.source.Tile.Event(type, tile));
  65272. }
  65273. };
  65274. /**
  65275. * Set the tile load function of the source.
  65276. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
  65277. * @api
  65278. */
  65279. ol.source.UrlTile.prototype.setTileLoadFunction = function(tileLoadFunction) {
  65280. this.tileCache.clear();
  65281. this.tileLoadFunction = tileLoadFunction;
  65282. this.changed();
  65283. };
  65284. /**
  65285. * Set the tile URL function of the source.
  65286. * @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
  65287. * @param {string=} opt_key Optional new tile key for the source.
  65288. * @api
  65289. */
  65290. ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction, opt_key) {
  65291. this.tileUrlFunction = tileUrlFunction;
  65292. this.tileCache.pruneExceptNewestZ();
  65293. if (typeof opt_key !== 'undefined') {
  65294. this.setKey(opt_key);
  65295. } else {
  65296. this.changed();
  65297. }
  65298. };
  65299. /**
  65300. * Set the URL to use for requests.
  65301. * @param {string} url URL.
  65302. * @api
  65303. */
  65304. ol.source.UrlTile.prototype.setUrl = function(url) {
  65305. var urls = this.urls = ol.TileUrlFunction.expandUrl(url);
  65306. this.setTileUrlFunction(this.fixedTileUrlFunction ?
  65307. this.fixedTileUrlFunction.bind(this) :
  65308. ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid), url);
  65309. };
  65310. /**
  65311. * Set the URLs to use for requests.
  65312. * @param {Array.<string>} urls URLs.
  65313. * @api
  65314. */
  65315. ol.source.UrlTile.prototype.setUrls = function(urls) {
  65316. this.urls = urls;
  65317. var key = urls.join('\n');
  65318. this.setTileUrlFunction(this.fixedTileUrlFunction ?
  65319. this.fixedTileUrlFunction.bind(this) :
  65320. ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid), key);
  65321. };
  65322. /**
  65323. * @inheritDoc
  65324. */
  65325. ol.source.UrlTile.prototype.useTile = function(z, x, y) {
  65326. var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  65327. if (this.tileCache.containsKey(tileCoordKey)) {
  65328. this.tileCache.get(tileCoordKey);
  65329. }
  65330. };
  65331. goog.provide('ol.source.TileImage');
  65332. goog.require('ol');
  65333. goog.require('ol.ImageTile');
  65334. goog.require('ol.TileCache');
  65335. goog.require('ol.TileState');
  65336. goog.require('ol.events');
  65337. goog.require('ol.events.EventType');
  65338. goog.require('ol.proj');
  65339. goog.require('ol.reproj.Tile');
  65340. goog.require('ol.source.UrlTile');
  65341. goog.require('ol.tilecoord');
  65342. goog.require('ol.tilegrid');
  65343. /**
  65344. * @classdesc
  65345. * Base class for sources providing images divided into a tile grid.
  65346. *
  65347. * @constructor
  65348. * @fires ol.source.Tile.Event
  65349. * @extends {ol.source.UrlTile}
  65350. * @param {olx.source.TileImageOptions} options Image tile options.
  65351. * @api
  65352. */
  65353. ol.source.TileImage = function(options) {
  65354. ol.source.UrlTile.call(this, {
  65355. attributions: options.attributions,
  65356. cacheSize: options.cacheSize,
  65357. extent: options.extent,
  65358. logo: options.logo,
  65359. opaque: options.opaque,
  65360. projection: options.projection,
  65361. state: options.state,
  65362. tileGrid: options.tileGrid,
  65363. tileLoadFunction: options.tileLoadFunction ?
  65364. options.tileLoadFunction : ol.source.TileImage.defaultTileLoadFunction,
  65365. tilePixelRatio: options.tilePixelRatio,
  65366. tileUrlFunction: options.tileUrlFunction,
  65367. url: options.url,
  65368. urls: options.urls,
  65369. wrapX: options.wrapX,
  65370. transition: options.transition
  65371. });
  65372. /**
  65373. * @protected
  65374. * @type {?string}
  65375. */
  65376. this.crossOrigin =
  65377. options.crossOrigin !== undefined ? options.crossOrigin : null;
  65378. /**
  65379. * @protected
  65380. * @type {function(new: ol.ImageTile, ol.TileCoord, ol.TileState, string,
  65381. * ?string, ol.TileLoadFunctionType, olx.TileOptions=)}
  65382. */
  65383. this.tileClass = options.tileClass !== undefined ?
  65384. options.tileClass : ol.ImageTile;
  65385. /**
  65386. * @protected
  65387. * @type {Object.<string, ol.TileCache>}
  65388. */
  65389. this.tileCacheForProjection = {};
  65390. /**
  65391. * @protected
  65392. * @type {Object.<string, ol.tilegrid.TileGrid>}
  65393. */
  65394. this.tileGridForProjection = {};
  65395. /**
  65396. * @private
  65397. * @type {number|undefined}
  65398. */
  65399. this.reprojectionErrorThreshold_ = options.reprojectionErrorThreshold;
  65400. /**
  65401. * @private
  65402. * @type {boolean}
  65403. */
  65404. this.renderReprojectionEdges_ = false;
  65405. };
  65406. ol.inherits(ol.source.TileImage, ol.source.UrlTile);
  65407. /**
  65408. * @inheritDoc
  65409. */
  65410. ol.source.TileImage.prototype.canExpireCache = function() {
  65411. if (!ol.ENABLE_RASTER_REPROJECTION) {
  65412. return ol.source.UrlTile.prototype.canExpireCache.call(this);
  65413. }
  65414. if (this.tileCache.canExpireCache()) {
  65415. return true;
  65416. } else {
  65417. for (var key in this.tileCacheForProjection) {
  65418. if (this.tileCacheForProjection[key].canExpireCache()) {
  65419. return true;
  65420. }
  65421. }
  65422. }
  65423. return false;
  65424. };
  65425. /**
  65426. * @inheritDoc
  65427. */
  65428. ol.source.TileImage.prototype.expireCache = function(projection, usedTiles) {
  65429. if (!ol.ENABLE_RASTER_REPROJECTION) {
  65430. ol.source.UrlTile.prototype.expireCache.call(this, projection, usedTiles);
  65431. return;
  65432. }
  65433. var usedTileCache = this.getTileCacheForProjection(projection);
  65434. this.tileCache.expireCache(this.tileCache == usedTileCache ? usedTiles : {});
  65435. for (var id in this.tileCacheForProjection) {
  65436. var tileCache = this.tileCacheForProjection[id];
  65437. tileCache.expireCache(tileCache == usedTileCache ? usedTiles : {});
  65438. }
  65439. };
  65440. /**
  65441. * @inheritDoc
  65442. */
  65443. ol.source.TileImage.prototype.getGutter = function(projection) {
  65444. if (ol.ENABLE_RASTER_REPROJECTION &&
  65445. this.getProjection() && projection &&
  65446. !ol.proj.equivalent(this.getProjection(), projection)) {
  65447. return 0;
  65448. } else {
  65449. return this.getGutterInternal();
  65450. }
  65451. };
  65452. /**
  65453. * @protected
  65454. * @return {number} Gutter.
  65455. */
  65456. ol.source.TileImage.prototype.getGutterInternal = function() {
  65457. return 0;
  65458. };
  65459. /**
  65460. * @inheritDoc
  65461. */
  65462. ol.source.TileImage.prototype.getOpaque = function(projection) {
  65463. if (ol.ENABLE_RASTER_REPROJECTION &&
  65464. this.getProjection() && projection &&
  65465. !ol.proj.equivalent(this.getProjection(), projection)) {
  65466. return false;
  65467. } else {
  65468. return ol.source.UrlTile.prototype.getOpaque.call(this, projection);
  65469. }
  65470. };
  65471. /**
  65472. * @inheritDoc
  65473. */
  65474. ol.source.TileImage.prototype.getTileGridForProjection = function(projection) {
  65475. if (!ol.ENABLE_RASTER_REPROJECTION) {
  65476. return ol.source.UrlTile.prototype.getTileGridForProjection.call(this, projection);
  65477. }
  65478. var thisProj = this.getProjection();
  65479. if (this.tileGrid &&
  65480. (!thisProj || ol.proj.equivalent(thisProj, projection))) {
  65481. return this.tileGrid;
  65482. } else {
  65483. var projKey = ol.getUid(projection).toString();
  65484. if (!(projKey in this.tileGridForProjection)) {
  65485. this.tileGridForProjection[projKey] =
  65486. ol.tilegrid.getForProjection(projection);
  65487. }
  65488. return /** @type {!ol.tilegrid.TileGrid} */ (this.tileGridForProjection[projKey]);
  65489. }
  65490. };
  65491. /**
  65492. * @inheritDoc
  65493. */
  65494. ol.source.TileImage.prototype.getTileCacheForProjection = function(projection) {
  65495. if (!ol.ENABLE_RASTER_REPROJECTION) {
  65496. return ol.source.UrlTile.prototype.getTileCacheForProjection.call(this, projection);
  65497. }
  65498. var thisProj = this.getProjection();
  65499. if (!thisProj || ol.proj.equivalent(thisProj, projection)) {
  65500. return this.tileCache;
  65501. } else {
  65502. var projKey = ol.getUid(projection).toString();
  65503. if (!(projKey in this.tileCacheForProjection)) {
  65504. this.tileCacheForProjection[projKey] = new ol.TileCache(this.tileCache.highWaterMark);
  65505. }
  65506. return this.tileCacheForProjection[projKey];
  65507. }
  65508. };
  65509. /**
  65510. * @param {number} z Tile coordinate z.
  65511. * @param {number} x Tile coordinate x.
  65512. * @param {number} y Tile coordinate y.
  65513. * @param {number} pixelRatio Pixel ratio.
  65514. * @param {ol.proj.Projection} projection Projection.
  65515. * @param {string} key The key set on the tile.
  65516. * @return {!ol.Tile} Tile.
  65517. * @private
  65518. */
  65519. ol.source.TileImage.prototype.createTile_ = function(z, x, y, pixelRatio, projection, key) {
  65520. var tileCoord = [z, x, y];
  65521. var urlTileCoord = this.getTileCoordForTileUrlFunction(
  65522. tileCoord, projection);
  65523. var tileUrl = urlTileCoord ?
  65524. this.tileUrlFunction(urlTileCoord, pixelRatio, projection) : undefined;
  65525. var tile = new this.tileClass(
  65526. tileCoord,
  65527. tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY,
  65528. tileUrl !== undefined ? tileUrl : '',
  65529. this.crossOrigin,
  65530. this.tileLoadFunction,
  65531. this.tileOptions);
  65532. tile.key = key;
  65533. ol.events.listen(tile, ol.events.EventType.CHANGE,
  65534. this.handleTileChange, this);
  65535. return tile;
  65536. };
  65537. /**
  65538. * @inheritDoc
  65539. */
  65540. ol.source.TileImage.prototype.getTile = function(z, x, y, pixelRatio, projection) {
  65541. var sourceProjection = /** @type {!ol.proj.Projection} */ (this.getProjection());
  65542. if (!ol.ENABLE_RASTER_REPROJECTION ||
  65543. !sourceProjection || !projection ||
  65544. ol.proj.equivalent(sourceProjection, projection)) {
  65545. return this.getTileInternal(z, x, y, pixelRatio, sourceProjection || projection);
  65546. } else {
  65547. var cache = this.getTileCacheForProjection(projection);
  65548. var tileCoord = [z, x, y];
  65549. var tile;
  65550. var tileCoordKey = ol.tilecoord.getKey(tileCoord);
  65551. if (cache.containsKey(tileCoordKey)) {
  65552. tile = /** @type {!ol.Tile} */ (cache.get(tileCoordKey));
  65553. }
  65554. var key = this.getKey();
  65555. if (tile && tile.key == key) {
  65556. return tile;
  65557. } else {
  65558. var sourceTileGrid = this.getTileGridForProjection(sourceProjection);
  65559. var targetTileGrid = this.getTileGridForProjection(projection);
  65560. var wrappedTileCoord =
  65561. this.getTileCoordForTileUrlFunction(tileCoord, projection);
  65562. var newTile = new ol.reproj.Tile(
  65563. sourceProjection, sourceTileGrid,
  65564. projection, targetTileGrid,
  65565. tileCoord, wrappedTileCoord, this.getTilePixelRatio(pixelRatio),
  65566. this.getGutterInternal(),
  65567. function(z, x, y, pixelRatio) {
  65568. return this.getTileInternal(z, x, y, pixelRatio, sourceProjection);
  65569. }.bind(this), this.reprojectionErrorThreshold_,
  65570. this.renderReprojectionEdges_);
  65571. newTile.key = key;
  65572. if (tile) {
  65573. newTile.interimTile = tile;
  65574. newTile.refreshInterimChain();
  65575. cache.replace(tileCoordKey, newTile);
  65576. } else {
  65577. cache.set(tileCoordKey, newTile);
  65578. }
  65579. return newTile;
  65580. }
  65581. }
  65582. };
  65583. /**
  65584. * @param {number} z Tile coordinate z.
  65585. * @param {number} x Tile coordinate x.
  65586. * @param {number} y Tile coordinate y.
  65587. * @param {number} pixelRatio Pixel ratio.
  65588. * @param {!ol.proj.Projection} projection Projection.
  65589. * @return {!ol.Tile} Tile.
  65590. * @protected
  65591. */
  65592. ol.source.TileImage.prototype.getTileInternal = function(z, x, y, pixelRatio, projection) {
  65593. var tile = null;
  65594. var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  65595. var key = this.getKey();
  65596. if (!this.tileCache.containsKey(tileCoordKey)) {
  65597. tile = this.createTile_(z, x, y, pixelRatio, projection, key);
  65598. this.tileCache.set(tileCoordKey, tile);
  65599. } else {
  65600. tile = this.tileCache.get(tileCoordKey);
  65601. if (tile.key != key) {
  65602. // The source's params changed. If the tile has an interim tile and if we
  65603. // can use it then we use it. Otherwise we create a new tile. In both
  65604. // cases we attempt to assign an interim tile to the new tile.
  65605. var interimTile = tile;
  65606. tile = this.createTile_(z, x, y, pixelRatio, projection, key);
  65607. //make the new tile the head of the list,
  65608. if (interimTile.getState() == ol.TileState.IDLE) {
  65609. //the old tile hasn't begun loading yet, and is now outdated, so we can simply discard it
  65610. tile.interimTile = interimTile.interimTile;
  65611. } else {
  65612. tile.interimTile = interimTile;
  65613. }
  65614. tile.refreshInterimChain();
  65615. this.tileCache.replace(tileCoordKey, tile);
  65616. }
  65617. }
  65618. return tile;
  65619. };
  65620. /**
  65621. * Sets whether to render reprojection edges or not (usually for debugging).
  65622. * @param {boolean} render Render the edges.
  65623. * @api
  65624. */
  65625. ol.source.TileImage.prototype.setRenderReprojectionEdges = function(render) {
  65626. if (!ol.ENABLE_RASTER_REPROJECTION ||
  65627. this.renderReprojectionEdges_ == render) {
  65628. return;
  65629. }
  65630. this.renderReprojectionEdges_ = render;
  65631. for (var id in this.tileCacheForProjection) {
  65632. this.tileCacheForProjection[id].clear();
  65633. }
  65634. this.changed();
  65635. };
  65636. /**
  65637. * Sets the tile grid to use when reprojecting the tiles to the given
  65638. * projection instead of the default tile grid for the projection.
  65639. *
  65640. * This can be useful when the default tile grid cannot be created
  65641. * (e.g. projection has no extent defined) or
  65642. * for optimization reasons (custom tile size, resolutions, ...).
  65643. *
  65644. * @param {ol.ProjectionLike} projection Projection.
  65645. * @param {ol.tilegrid.TileGrid} tilegrid Tile grid to use for the projection.
  65646. * @api
  65647. */
  65648. ol.source.TileImage.prototype.setTileGridForProjection = function(projection, tilegrid) {
  65649. if (ol.ENABLE_RASTER_REPROJECTION) {
  65650. var proj = ol.proj.get(projection);
  65651. if (proj) {
  65652. var projKey = ol.getUid(proj).toString();
  65653. if (!(projKey in this.tileGridForProjection)) {
  65654. this.tileGridForProjection[projKey] = tilegrid;
  65655. }
  65656. }
  65657. }
  65658. };
  65659. /**
  65660. * @param {ol.ImageTile} imageTile Image tile.
  65661. * @param {string} src Source.
  65662. */
  65663. ol.source.TileImage.defaultTileLoadFunction = function(imageTile, src) {
  65664. imageTile.getImage().src = src;
  65665. };
  65666. goog.provide('ol.source.BingMaps');
  65667. goog.require('ol');
  65668. goog.require('ol.TileUrlFunction');
  65669. goog.require('ol.extent');
  65670. goog.require('ol.net');
  65671. goog.require('ol.proj');
  65672. goog.require('ol.source.State');
  65673. goog.require('ol.source.TileImage');
  65674. goog.require('ol.tilecoord');
  65675. goog.require('ol.tilegrid');
  65676. /**
  65677. * @classdesc
  65678. * Layer source for Bing Maps tile data.
  65679. *
  65680. * @constructor
  65681. * @extends {ol.source.TileImage}
  65682. * @param {olx.source.BingMapsOptions} options Bing Maps options.
  65683. * @api
  65684. */
  65685. ol.source.BingMaps = function(options) {
  65686. /**
  65687. * @private
  65688. * @type {boolean}
  65689. */
  65690. this.hidpi_ = options.hidpi !== undefined ? options.hidpi : false;
  65691. ol.source.TileImage.call(this, {
  65692. cacheSize: options.cacheSize,
  65693. crossOrigin: 'anonymous',
  65694. opaque: true,
  65695. projection: ol.proj.get('EPSG:3857'),
  65696. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  65697. state: ol.source.State.LOADING,
  65698. tileLoadFunction: options.tileLoadFunction,
  65699. tilePixelRatio: this.hidpi_ ? 2 : 1,
  65700. wrapX: options.wrapX !== undefined ? options.wrapX : true,
  65701. transition: options.transition
  65702. });
  65703. /**
  65704. * @private
  65705. * @type {string}
  65706. */
  65707. this.culture_ = options.culture !== undefined ? options.culture : 'en-us';
  65708. /**
  65709. * @private
  65710. * @type {number}
  65711. */
  65712. this.maxZoom_ = options.maxZoom !== undefined ? options.maxZoom : -1;
  65713. /**
  65714. * @private
  65715. * @type {string}
  65716. */
  65717. this.apiKey_ = options.key;
  65718. /**
  65719. * @private
  65720. * @type {string}
  65721. */
  65722. this.imagerySet_ = options.imagerySet;
  65723. var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
  65724. this.imagerySet_ +
  65725. '?uriScheme=https&include=ImageryProviders&key=' + this.apiKey_ +
  65726. '&c=' + this.culture_;
  65727. ol.net.jsonp(url, this.handleImageryMetadataResponse.bind(this), undefined,
  65728. 'jsonp');
  65729. };
  65730. ol.inherits(ol.source.BingMaps, ol.source.TileImage);
  65731. /**
  65732. * The attribution containing a link to the Microsoft® Bing™ Maps Platform APIs’
  65733. * Terms Of Use.
  65734. * @const
  65735. * @type {string}
  65736. * @api
  65737. */
  65738. ol.source.BingMaps.TOS_ATTRIBUTION = '<a class="ol-attribution-bing-tos" ' +
  65739. 'href="https://www.microsoft.com/maps/product/terms.html">' +
  65740. 'Terms of Use</a>';
  65741. /**
  65742. * Get the api key used for this source.
  65743. *
  65744. * @return {string} The api key.
  65745. * @api
  65746. */
  65747. ol.source.BingMaps.prototype.getApiKey = function() {
  65748. return this.apiKey_;
  65749. };
  65750. /**
  65751. * Get the imagery set associated with this source.
  65752. *
  65753. * @return {string} The imagery set.
  65754. * @api
  65755. */
  65756. ol.source.BingMaps.prototype.getImagerySet = function() {
  65757. return this.imagerySet_;
  65758. };
  65759. /**
  65760. * @param {BingMapsImageryMetadataResponse} response Response.
  65761. */
  65762. ol.source.BingMaps.prototype.handleImageryMetadataResponse = function(response) {
  65763. if (response.statusCode != 200 ||
  65764. response.statusDescription != 'OK' ||
  65765. response.authenticationResultCode != 'ValidCredentials' ||
  65766. response.resourceSets.length != 1 ||
  65767. response.resourceSets[0].resources.length != 1) {
  65768. this.setState(ol.source.State.ERROR);
  65769. return;
  65770. }
  65771. var brandLogoUri = response.brandLogoUri;
  65772. if (brandLogoUri.indexOf('https') == -1) {
  65773. brandLogoUri = brandLogoUri.replace('http', 'https');
  65774. }
  65775. //var copyright = response.copyright; // FIXME do we need to display this?
  65776. var resource = response.resourceSets[0].resources[0];
  65777. var maxZoom = this.maxZoom_ == -1 ? resource.zoomMax : this.maxZoom_;
  65778. var sourceProjection = this.getProjection();
  65779. var extent = ol.tilegrid.extentFromProjection(sourceProjection);
  65780. var tileSize = resource.imageWidth == resource.imageHeight ?
  65781. resource.imageWidth : [resource.imageWidth, resource.imageHeight];
  65782. var tileGrid = ol.tilegrid.createXYZ({
  65783. extent: extent,
  65784. minZoom: resource.zoomMin,
  65785. maxZoom: maxZoom,
  65786. tileSize: tileSize / (this.hidpi_ ? 2 : 1)
  65787. });
  65788. this.tileGrid = tileGrid;
  65789. var culture = this.culture_;
  65790. var hidpi = this.hidpi_;
  65791. this.tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
  65792. resource.imageUrlSubdomains.map(function(subdomain) {
  65793. var quadKeyTileCoord = [0, 0, 0];
  65794. var imageUrl = resource.imageUrl
  65795. .replace('{subdomain}', subdomain)
  65796. .replace('{culture}', culture);
  65797. return (
  65798. /**
  65799. * @param {ol.TileCoord} tileCoord Tile coordinate.
  65800. * @param {number} pixelRatio Pixel ratio.
  65801. * @param {ol.proj.Projection} projection Projection.
  65802. * @return {string|undefined} Tile URL.
  65803. */
  65804. function(tileCoord, pixelRatio, projection) {
  65805. if (!tileCoord) {
  65806. return undefined;
  65807. } else {
  65808. ol.tilecoord.createOrUpdate(tileCoord[0], tileCoord[1],
  65809. -tileCoord[2] - 1, quadKeyTileCoord);
  65810. var url = imageUrl;
  65811. if (hidpi) {
  65812. url += '&dpi=d1&device=mobile';
  65813. }
  65814. return url.replace('{quadkey}', ol.tilecoord.quadKey(
  65815. quadKeyTileCoord));
  65816. }
  65817. });
  65818. }));
  65819. if (resource.imageryProviders) {
  65820. var transform = ol.proj.getTransformFromProjections(
  65821. ol.proj.get('EPSG:4326'), this.getProjection());
  65822. this.setAttributions(function(frameState) {
  65823. var attributions = [];
  65824. var zoom = frameState.viewState.zoom;
  65825. resource.imageryProviders.map(function(imageryProvider) {
  65826. var intersects = false;
  65827. var coverageAreas = imageryProvider.coverageAreas;
  65828. for (var i = 0, ii = coverageAreas.length; i < ii; ++i) {
  65829. var coverageArea = coverageAreas[i];
  65830. if (zoom >= coverageArea.zoomMin && zoom <= coverageArea.zoomMax) {
  65831. var bbox = coverageArea.bbox;
  65832. var epsg4326Extent = [bbox[1], bbox[0], bbox[3], bbox[2]];
  65833. var extent = ol.extent.applyTransform(epsg4326Extent, transform);
  65834. if (ol.extent.intersects(extent, frameState.extent)) {
  65835. intersects = true;
  65836. break;
  65837. }
  65838. }
  65839. }
  65840. if (intersects) {
  65841. attributions.push(imageryProvider.attribution);
  65842. }
  65843. });
  65844. attributions.push(ol.source.BingMaps.TOS_ATTRIBUTION);
  65845. return attributions;
  65846. });
  65847. }
  65848. this.setLogo(brandLogoUri);
  65849. this.setState(ol.source.State.READY);
  65850. };
  65851. goog.provide('ol.source.XYZ');
  65852. goog.require('ol');
  65853. goog.require('ol.source.TileImage');
  65854. goog.require('ol.tilegrid');
  65855. /**
  65856. * @classdesc
  65857. * Layer source for tile data with URLs in a set XYZ format that are
  65858. * defined in a URL template. By default, this follows the widely-used
  65859. * Google grid where `x` 0 and `y` 0 are in the top left. Grids like
  65860. * TMS where `x` 0 and `y` 0 are in the bottom left can be used by
  65861. * using the `{-y}` placeholder in the URL template, so long as the
  65862. * source does not have a custom tile grid. In this case,
  65863. * {@link ol.source.TileImage} can be used with a `tileUrlFunction`
  65864. * such as:
  65865. *
  65866. * tileUrlFunction: function(coordinate) {
  65867. * return 'http://mapserver.com/' + coordinate[0] + '/' +
  65868. * coordinate[1] + '/' + coordinate[2] + '.png';
  65869. * }
  65870. *
  65871. *
  65872. * @constructor
  65873. * @extends {ol.source.TileImage}
  65874. * @param {olx.source.XYZOptions=} opt_options XYZ options.
  65875. * @api
  65876. */
  65877. ol.source.XYZ = function(opt_options) {
  65878. var options = opt_options || {};
  65879. var projection = options.projection !== undefined ?
  65880. options.projection : 'EPSG:3857';
  65881. var tileGrid = options.tileGrid !== undefined ? options.tileGrid :
  65882. ol.tilegrid.createXYZ({
  65883. extent: ol.tilegrid.extentFromProjection(projection),
  65884. maxZoom: options.maxZoom,
  65885. minZoom: options.minZoom,
  65886. tileSize: options.tileSize
  65887. });
  65888. ol.source.TileImage.call(this, {
  65889. attributions: options.attributions,
  65890. cacheSize: options.cacheSize,
  65891. crossOrigin: options.crossOrigin,
  65892. logo: options.logo,
  65893. opaque: options.opaque,
  65894. projection: projection,
  65895. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  65896. tileGrid: tileGrid,
  65897. tileLoadFunction: options.tileLoadFunction,
  65898. tilePixelRatio: options.tilePixelRatio,
  65899. tileUrlFunction: options.tileUrlFunction,
  65900. url: options.url,
  65901. urls: options.urls,
  65902. wrapX: options.wrapX !== undefined ? options.wrapX : true,
  65903. transition: options.transition
  65904. });
  65905. };
  65906. ol.inherits(ol.source.XYZ, ol.source.TileImage);
  65907. goog.provide('ol.source.CartoDB');
  65908. goog.require('ol');
  65909. goog.require('ol.obj');
  65910. goog.require('ol.source.State');
  65911. goog.require('ol.source.XYZ');
  65912. /**
  65913. * @classdesc
  65914. * Layer source for the CartoDB Maps API.
  65915. *
  65916. * @constructor
  65917. * @extends {ol.source.XYZ}
  65918. * @param {olx.source.CartoDBOptions} options CartoDB options.
  65919. * @api
  65920. */
  65921. ol.source.CartoDB = function(options) {
  65922. /**
  65923. * @type {string}
  65924. * @private
  65925. */
  65926. this.account_ = options.account;
  65927. /**
  65928. * @type {string}
  65929. * @private
  65930. */
  65931. this.mapId_ = options.map || '';
  65932. /**
  65933. * @type {!Object}
  65934. * @private
  65935. */
  65936. this.config_ = options.config || {};
  65937. /**
  65938. * @type {!Object.<string, CartoDBLayerInfo>}
  65939. * @private
  65940. */
  65941. this.templateCache_ = {};
  65942. ol.source.XYZ.call(this, {
  65943. attributions: options.attributions,
  65944. cacheSize: options.cacheSize,
  65945. crossOrigin: options.crossOrigin,
  65946. logo: options.logo,
  65947. maxZoom: options.maxZoom !== undefined ? options.maxZoom : 18,
  65948. minZoom: options.minZoom,
  65949. projection: options.projection,
  65950. state: ol.source.State.LOADING,
  65951. wrapX: options.wrapX
  65952. });
  65953. this.initializeMap_();
  65954. };
  65955. ol.inherits(ol.source.CartoDB, ol.source.XYZ);
  65956. /**
  65957. * Returns the current config.
  65958. * @return {!Object} The current configuration.
  65959. * @api
  65960. */
  65961. ol.source.CartoDB.prototype.getConfig = function() {
  65962. return this.config_;
  65963. };
  65964. /**
  65965. * Updates the carto db config.
  65966. * @param {Object} config a key-value lookup. Values will replace current values
  65967. * in the config.
  65968. * @api
  65969. */
  65970. ol.source.CartoDB.prototype.updateConfig = function(config) {
  65971. ol.obj.assign(this.config_, config);
  65972. this.initializeMap_();
  65973. };
  65974. /**
  65975. * Sets the CartoDB config
  65976. * @param {Object} config In the case of anonymous maps, a CartoDB configuration
  65977. * object.
  65978. * If using named maps, a key-value lookup with the template parameters.
  65979. * @api
  65980. */
  65981. ol.source.CartoDB.prototype.setConfig = function(config) {
  65982. this.config_ = config || {};
  65983. this.initializeMap_();
  65984. };
  65985. /**
  65986. * Issue a request to initialize the CartoDB map.
  65987. * @private
  65988. */
  65989. ol.source.CartoDB.prototype.initializeMap_ = function() {
  65990. var paramHash = JSON.stringify(this.config_);
  65991. if (this.templateCache_[paramHash]) {
  65992. this.applyTemplate_(this.templateCache_[paramHash]);
  65993. return;
  65994. }
  65995. var mapUrl = 'https://' + this.account_ + '.carto.com/api/v1/map';
  65996. if (this.mapId_) {
  65997. mapUrl += '/named/' + this.mapId_;
  65998. }
  65999. var client = new XMLHttpRequest();
  66000. client.addEventListener('load', this.handleInitResponse_.bind(this, paramHash));
  66001. client.addEventListener('error', this.handleInitError_.bind(this));
  66002. client.open('POST', mapUrl);
  66003. client.setRequestHeader('Content-type', 'application/json');
  66004. client.send(JSON.stringify(this.config_));
  66005. };
  66006. /**
  66007. * Handle map initialization response.
  66008. * @param {string} paramHash a hash representing the parameter set that was used
  66009. * for the request
  66010. * @param {Event} event Event.
  66011. * @private
  66012. */
  66013. ol.source.CartoDB.prototype.handleInitResponse_ = function(paramHash, event) {
  66014. var client = /** @type {XMLHttpRequest} */ (event.target);
  66015. // status will be 0 for file:// urls
  66016. if (!client.status || client.status >= 200 && client.status < 300) {
  66017. var response;
  66018. try {
  66019. response = /** @type {CartoDBLayerInfo} */(JSON.parse(client.responseText));
  66020. } catch (err) {
  66021. this.setState(ol.source.State.ERROR);
  66022. return;
  66023. }
  66024. this.applyTemplate_(response);
  66025. this.templateCache_[paramHash] = response;
  66026. this.setState(ol.source.State.READY);
  66027. } else {
  66028. this.setState(ol.source.State.ERROR);
  66029. }
  66030. };
  66031. /**
  66032. * @private
  66033. * @param {Event} event Event.
  66034. */
  66035. ol.source.CartoDB.prototype.handleInitError_ = function(event) {
  66036. this.setState(ol.source.State.ERROR);
  66037. };
  66038. /**
  66039. * Apply the new tile urls returned by carto db
  66040. * @param {CartoDBLayerInfo} data Result of carto db call.
  66041. * @private
  66042. */
  66043. ol.source.CartoDB.prototype.applyTemplate_ = function(data) {
  66044. var tilesUrl = 'https://' + data.cdn_url.https + '/' + this.account_ +
  66045. '/api/v1/map/' + data.layergroupid + '/{z}/{x}/{y}.png';
  66046. this.setUrl(tilesUrl);
  66047. };
  66048. // FIXME keep cluster cache by resolution ?
  66049. // FIXME distance not respected because of the centroid
  66050. goog.provide('ol.source.Cluster');
  66051. goog.require('ol');
  66052. goog.require('ol.asserts');
  66053. goog.require('ol.Feature');
  66054. goog.require('ol.coordinate');
  66055. goog.require('ol.events.EventType');
  66056. goog.require('ol.extent');
  66057. goog.require('ol.geom.Point');
  66058. goog.require('ol.source.Vector');
  66059. /**
  66060. * @classdesc
  66061. * Layer source to cluster vector data. Works out of the box with point
  66062. * geometries. For other geometry types, or if not all geometries should be
  66063. * considered for clustering, a custom `geometryFunction` can be defined.
  66064. *
  66065. * @constructor
  66066. * @param {olx.source.ClusterOptions} options Constructor options.
  66067. * @extends {ol.source.Vector}
  66068. * @api
  66069. */
  66070. ol.source.Cluster = function(options) {
  66071. ol.source.Vector.call(this, {
  66072. attributions: options.attributions,
  66073. extent: options.extent,
  66074. logo: options.logo,
  66075. projection: options.projection,
  66076. wrapX: options.wrapX
  66077. });
  66078. /**
  66079. * @type {number|undefined}
  66080. * @protected
  66081. */
  66082. this.resolution = undefined;
  66083. /**
  66084. * @type {number}
  66085. * @protected
  66086. */
  66087. this.distance = options.distance !== undefined ? options.distance : 20;
  66088. /**
  66089. * @type {Array.<ol.Feature>}
  66090. * @protected
  66091. */
  66092. this.features = [];
  66093. /**
  66094. * @param {ol.Feature} feature Feature.
  66095. * @return {ol.geom.Point} Cluster calculation point.
  66096. * @protected
  66097. */
  66098. this.geometryFunction = options.geometryFunction || function(feature) {
  66099. var geometry = /** @type {ol.geom.Point} */ (feature.getGeometry());
  66100. ol.asserts.assert(geometry instanceof ol.geom.Point,
  66101. 10); // The default `geometryFunction` can only handle `ol.geom.Point` geometries
  66102. return geometry;
  66103. };
  66104. /**
  66105. * @type {ol.source.Vector}
  66106. * @protected
  66107. */
  66108. this.source = options.source;
  66109. this.source.on(ol.events.EventType.CHANGE,
  66110. ol.source.Cluster.prototype.refresh, this);
  66111. };
  66112. ol.inherits(ol.source.Cluster, ol.source.Vector);
  66113. /**
  66114. * Get the distance in pixels between clusters.
  66115. * @return {number} Distance.
  66116. * @api
  66117. */
  66118. ol.source.Cluster.prototype.getDistance = function() {
  66119. return this.distance;
  66120. };
  66121. /**
  66122. * Get a reference to the wrapped source.
  66123. * @return {ol.source.Vector} Source.
  66124. * @api
  66125. */
  66126. ol.source.Cluster.prototype.getSource = function() {
  66127. return this.source;
  66128. };
  66129. /**
  66130. * @inheritDoc
  66131. */
  66132. ol.source.Cluster.prototype.loadFeatures = function(extent, resolution,
  66133. projection) {
  66134. this.source.loadFeatures(extent, resolution, projection);
  66135. if (resolution !== this.resolution) {
  66136. this.clear();
  66137. this.resolution = resolution;
  66138. this.cluster();
  66139. this.addFeatures(this.features);
  66140. }
  66141. };
  66142. /**
  66143. * Set the distance in pixels between clusters.
  66144. * @param {number} distance The distance in pixels.
  66145. * @api
  66146. */
  66147. ol.source.Cluster.prototype.setDistance = function(distance) {
  66148. this.distance = distance;
  66149. this.refresh();
  66150. };
  66151. /**
  66152. * handle the source changing
  66153. * @override
  66154. */
  66155. ol.source.Cluster.prototype.refresh = function() {
  66156. this.clear();
  66157. this.cluster();
  66158. this.addFeatures(this.features);
  66159. ol.source.Vector.prototype.refresh.call(this);
  66160. };
  66161. /**
  66162. * @protected
  66163. */
  66164. ol.source.Cluster.prototype.cluster = function() {
  66165. if (this.resolution === undefined) {
  66166. return;
  66167. }
  66168. this.features.length = 0;
  66169. var extent = ol.extent.createEmpty();
  66170. var mapDistance = this.distance * this.resolution;
  66171. var features = this.source.getFeatures();
  66172. /**
  66173. * @type {!Object.<string, boolean>}
  66174. */
  66175. var clustered = {};
  66176. for (var i = 0, ii = features.length; i < ii; i++) {
  66177. var feature = features[i];
  66178. if (!(ol.getUid(feature).toString() in clustered)) {
  66179. var geometry = this.geometryFunction(feature);
  66180. if (geometry) {
  66181. var coordinates = geometry.getCoordinates();
  66182. ol.extent.createOrUpdateFromCoordinate(coordinates, extent);
  66183. ol.extent.buffer(extent, mapDistance, extent);
  66184. var neighbors = this.source.getFeaturesInExtent(extent);
  66185. neighbors = neighbors.filter(function(neighbor) {
  66186. var uid = ol.getUid(neighbor).toString();
  66187. if (!(uid in clustered)) {
  66188. clustered[uid] = true;
  66189. return true;
  66190. } else {
  66191. return false;
  66192. }
  66193. });
  66194. this.features.push(this.createCluster(neighbors));
  66195. }
  66196. }
  66197. }
  66198. };
  66199. /**
  66200. * @param {Array.<ol.Feature>} features Features
  66201. * @return {ol.Feature} The cluster feature.
  66202. * @protected
  66203. */
  66204. ol.source.Cluster.prototype.createCluster = function(features) {
  66205. var centroid = [0, 0];
  66206. for (var i = features.length - 1; i >= 0; --i) {
  66207. var geometry = this.geometryFunction(features[i]);
  66208. if (geometry) {
  66209. ol.coordinate.add(centroid, geometry.getCoordinates());
  66210. } else {
  66211. features.splice(i, 1);
  66212. }
  66213. }
  66214. ol.coordinate.scale(centroid, 1 / features.length);
  66215. var cluster = new ol.Feature(new ol.geom.Point(centroid));
  66216. cluster.set('features', features);
  66217. return cluster;
  66218. };
  66219. goog.provide('ol.source.Image');
  66220. goog.require('ol');
  66221. goog.require('ol.ImageState');
  66222. goog.require('ol.array');
  66223. goog.require('ol.events.Event');
  66224. goog.require('ol.extent');
  66225. goog.require('ol.proj');
  66226. goog.require('ol.reproj.Image');
  66227. goog.require('ol.source.Source');
  66228. /**
  66229. * @classdesc
  66230. * Abstract base class; normally only used for creating subclasses and not
  66231. * instantiated in apps.
  66232. * Base class for sources providing a single image.
  66233. *
  66234. * @constructor
  66235. * @abstract
  66236. * @extends {ol.source.Source}
  66237. * @param {ol.SourceImageOptions} options Single image source options.
  66238. * @api
  66239. */
  66240. ol.source.Image = function(options) {
  66241. ol.source.Source.call(this, {
  66242. attributions: options.attributions,
  66243. extent: options.extent,
  66244. logo: options.logo,
  66245. projection: options.projection,
  66246. state: options.state
  66247. });
  66248. /**
  66249. * @private
  66250. * @type {Array.<number>}
  66251. */
  66252. this.resolutions_ = options.resolutions !== undefined ?
  66253. options.resolutions : null;
  66254. /**
  66255. * @private
  66256. * @type {ol.reproj.Image}
  66257. */
  66258. this.reprojectedImage_ = null;
  66259. /**
  66260. * @private
  66261. * @type {number}
  66262. */
  66263. this.reprojectedRevision_ = 0;
  66264. };
  66265. ol.inherits(ol.source.Image, ol.source.Source);
  66266. /**
  66267. * @return {Array.<number>} Resolutions.
  66268. * @override
  66269. */
  66270. ol.source.Image.prototype.getResolutions = function() {
  66271. return this.resolutions_;
  66272. };
  66273. /**
  66274. * @protected
  66275. * @param {number} resolution Resolution.
  66276. * @return {number} Resolution.
  66277. */
  66278. ol.source.Image.prototype.findNearestResolution = function(resolution) {
  66279. if (this.resolutions_) {
  66280. var idx = ol.array.linearFindNearest(this.resolutions_, resolution, 0);
  66281. resolution = this.resolutions_[idx];
  66282. }
  66283. return resolution;
  66284. };
  66285. /**
  66286. * @param {ol.Extent} extent Extent.
  66287. * @param {number} resolution Resolution.
  66288. * @param {number} pixelRatio Pixel ratio.
  66289. * @param {ol.proj.Projection} projection Projection.
  66290. * @return {ol.ImageBase} Single image.
  66291. */
  66292. ol.source.Image.prototype.getImage = function(extent, resolution, pixelRatio, projection) {
  66293. var sourceProjection = this.getProjection();
  66294. if (!ol.ENABLE_RASTER_REPROJECTION ||
  66295. !sourceProjection ||
  66296. !projection ||
  66297. ol.proj.equivalent(sourceProjection, projection)) {
  66298. if (sourceProjection) {
  66299. projection = sourceProjection;
  66300. }
  66301. return this.getImageInternal(extent, resolution, pixelRatio, projection);
  66302. } else {
  66303. if (this.reprojectedImage_) {
  66304. if (this.reprojectedRevision_ == this.getRevision() &&
  66305. ol.proj.equivalent(
  66306. this.reprojectedImage_.getProjection(), projection) &&
  66307. this.reprojectedImage_.getResolution() == resolution &&
  66308. ol.extent.equals(this.reprojectedImage_.getExtent(), extent)) {
  66309. return this.reprojectedImage_;
  66310. }
  66311. this.reprojectedImage_.dispose();
  66312. this.reprojectedImage_ = null;
  66313. }
  66314. this.reprojectedImage_ = new ol.reproj.Image(
  66315. sourceProjection, projection, extent, resolution, pixelRatio,
  66316. function(extent, resolution, pixelRatio) {
  66317. return this.getImageInternal(extent, resolution,
  66318. pixelRatio, sourceProjection);
  66319. }.bind(this));
  66320. this.reprojectedRevision_ = this.getRevision();
  66321. return this.reprojectedImage_;
  66322. }
  66323. };
  66324. /**
  66325. * @abstract
  66326. * @param {ol.Extent} extent Extent.
  66327. * @param {number} resolution Resolution.
  66328. * @param {number} pixelRatio Pixel ratio.
  66329. * @param {ol.proj.Projection} projection Projection.
  66330. * @return {ol.ImageBase} Single image.
  66331. * @protected
  66332. */
  66333. ol.source.Image.prototype.getImageInternal = function(extent, resolution, pixelRatio, projection) {};
  66334. /**
  66335. * Handle image change events.
  66336. * @param {ol.events.Event} event Event.
  66337. * @protected
  66338. */
  66339. ol.source.Image.prototype.handleImageChange = function(event) {
  66340. var image = /** @type {ol.Image} */ (event.target);
  66341. switch (image.getState()) {
  66342. case ol.ImageState.LOADING:
  66343. this.dispatchEvent(
  66344. new ol.source.Image.Event(ol.source.Image.EventType_.IMAGELOADSTART,
  66345. image));
  66346. break;
  66347. case ol.ImageState.LOADED:
  66348. this.dispatchEvent(
  66349. new ol.source.Image.Event(ol.source.Image.EventType_.IMAGELOADEND,
  66350. image));
  66351. break;
  66352. case ol.ImageState.ERROR:
  66353. this.dispatchEvent(
  66354. new ol.source.Image.Event(ol.source.Image.EventType_.IMAGELOADERROR,
  66355. image));
  66356. break;
  66357. default:
  66358. // pass
  66359. }
  66360. };
  66361. /**
  66362. * Default image load function for image sources that use ol.Image image
  66363. * instances.
  66364. * @param {ol.Image} image Image.
  66365. * @param {string} src Source.
  66366. */
  66367. ol.source.Image.defaultImageLoadFunction = function(image, src) {
  66368. image.getImage().src = src;
  66369. };
  66370. /**
  66371. * @classdesc
  66372. * Events emitted by {@link ol.source.Image} instances are instances of this
  66373. * type.
  66374. *
  66375. * @constructor
  66376. * @extends {ol.events.Event}
  66377. * @implements {oli.source.ImageEvent}
  66378. * @param {string} type Type.
  66379. * @param {ol.Image} image The image.
  66380. */
  66381. ol.source.Image.Event = function(type, image) {
  66382. ol.events.Event.call(this, type);
  66383. /**
  66384. * The image related to the event.
  66385. * @type {ol.Image}
  66386. * @api
  66387. */
  66388. this.image = image;
  66389. };
  66390. ol.inherits(ol.source.Image.Event, ol.events.Event);
  66391. /**
  66392. * @enum {string}
  66393. * @private
  66394. */
  66395. ol.source.Image.EventType_ = {
  66396. /**
  66397. * Triggered when an image starts loading.
  66398. * @event ol.source.Image.Event#imageloadstart
  66399. * @api
  66400. */
  66401. IMAGELOADSTART: 'imageloadstart',
  66402. /**
  66403. * Triggered when an image finishes loading.
  66404. * @event ol.source.Image.Event#imageloadend
  66405. * @api
  66406. */
  66407. IMAGELOADEND: 'imageloadend',
  66408. /**
  66409. * Triggered if image loading results in an error.
  66410. * @event ol.source.Image.Event#imageloaderror
  66411. * @api
  66412. */
  66413. IMAGELOADERROR: 'imageloaderror'
  66414. };
  66415. goog.provide('ol.uri');
  66416. /**
  66417. * Appends query parameters to a URI.
  66418. *
  66419. * @param {string} uri The original URI, which may already have query data.
  66420. * @param {!Object} params An object where keys are URI-encoded parameter keys,
  66421. * and the values are arbitrary types or arrays.
  66422. * @return {string} The new URI.
  66423. */
  66424. ol.uri.appendParams = function(uri, params) {
  66425. var keyParams = [];
  66426. // Skip any null or undefined parameter values
  66427. Object.keys(params).forEach(function(k) {
  66428. if (params[k] !== null && params[k] !== undefined) {
  66429. keyParams.push(k + '=' + encodeURIComponent(params[k]));
  66430. }
  66431. });
  66432. var qs = keyParams.join('&');
  66433. // remove any trailing ? or &
  66434. uri = uri.replace(/[?&]$/, '');
  66435. // append ? or & depending on whether uri has existing parameters
  66436. uri = uri.indexOf('?') === -1 ? uri + '?' : uri + '&';
  66437. return uri + qs;
  66438. };
  66439. goog.provide('ol.source.ImageArcGISRest');
  66440. goog.require('ol');
  66441. goog.require('ol.Image');
  66442. goog.require('ol.asserts');
  66443. goog.require('ol.events');
  66444. goog.require('ol.events.EventType');
  66445. goog.require('ol.extent');
  66446. goog.require('ol.obj');
  66447. goog.require('ol.source.Image');
  66448. goog.require('ol.uri');
  66449. /**
  66450. * @classdesc
  66451. * Source for data from ArcGIS Rest services providing single, untiled images.
  66452. * Useful when underlying map service has labels.
  66453. *
  66454. * If underlying map service is not using labels,
  66455. * take advantage of ol image caching and use
  66456. * {@link ol.source.TileArcGISRest} data source.
  66457. *
  66458. * @constructor
  66459. * @fires ol.source.Image.Event
  66460. * @extends {ol.source.Image}
  66461. * @param {olx.source.ImageArcGISRestOptions=} opt_options Image ArcGIS Rest Options.
  66462. * @api
  66463. */
  66464. ol.source.ImageArcGISRest = function(opt_options) {
  66465. var options = opt_options || {};
  66466. ol.source.Image.call(this, {
  66467. attributions: options.attributions,
  66468. logo: options.logo,
  66469. projection: options.projection,
  66470. resolutions: options.resolutions
  66471. });
  66472. /**
  66473. * @private
  66474. * @type {?string}
  66475. */
  66476. this.crossOrigin_ =
  66477. options.crossOrigin !== undefined ? options.crossOrigin : null;
  66478. /**
  66479. * @private
  66480. * @type {boolean}
  66481. */
  66482. this.hidpi_ = options.hidpi !== undefined ? options.hidpi : true;
  66483. /**
  66484. * @private
  66485. * @type {string|undefined}
  66486. */
  66487. this.url_ = options.url;
  66488. /**
  66489. * @private
  66490. * @type {ol.ImageLoadFunctionType}
  66491. */
  66492. this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
  66493. options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
  66494. /**
  66495. * @private
  66496. * @type {!Object}
  66497. */
  66498. this.params_ = options.params || {};
  66499. /**
  66500. * @private
  66501. * @type {ol.Image}
  66502. */
  66503. this.image_ = null;
  66504. /**
  66505. * @private
  66506. * @type {ol.Size}
  66507. */
  66508. this.imageSize_ = [0, 0];
  66509. /**
  66510. * @private
  66511. * @type {number}
  66512. */
  66513. this.renderedRevision_ = 0;
  66514. /**
  66515. * @private
  66516. * @type {number}
  66517. */
  66518. this.ratio_ = options.ratio !== undefined ? options.ratio : 1.5;
  66519. };
  66520. ol.inherits(ol.source.ImageArcGISRest, ol.source.Image);
  66521. /**
  66522. * Get the user-provided params, i.e. those passed to the constructor through
  66523. * the "params" option, and possibly updated using the updateParams method.
  66524. * @return {Object} Params.
  66525. * @api
  66526. */
  66527. ol.source.ImageArcGISRest.prototype.getParams = function() {
  66528. return this.params_;
  66529. };
  66530. /**
  66531. * @inheritDoc
  66532. */
  66533. ol.source.ImageArcGISRest.prototype.getImageInternal = function(extent, resolution, pixelRatio, projection) {
  66534. if (this.url_ === undefined) {
  66535. return null;
  66536. }
  66537. resolution = this.findNearestResolution(resolution);
  66538. pixelRatio = this.hidpi_ ? pixelRatio : 1;
  66539. var image = this.image_;
  66540. if (image &&
  66541. this.renderedRevision_ == this.getRevision() &&
  66542. image.getResolution() == resolution &&
  66543. image.getPixelRatio() == pixelRatio &&
  66544. ol.extent.containsExtent(image.getExtent(), extent)) {
  66545. return image;
  66546. }
  66547. var params = {
  66548. 'F': 'image',
  66549. 'FORMAT': 'PNG32',
  66550. 'TRANSPARENT': true
  66551. };
  66552. ol.obj.assign(params, this.params_);
  66553. extent = extent.slice();
  66554. var centerX = (extent[0] + extent[2]) / 2;
  66555. var centerY = (extent[1] + extent[3]) / 2;
  66556. if (this.ratio_ != 1) {
  66557. var halfWidth = this.ratio_ * ol.extent.getWidth(extent) / 2;
  66558. var halfHeight = this.ratio_ * ol.extent.getHeight(extent) / 2;
  66559. extent[0] = centerX - halfWidth;
  66560. extent[1] = centerY - halfHeight;
  66561. extent[2] = centerX + halfWidth;
  66562. extent[3] = centerY + halfHeight;
  66563. }
  66564. var imageResolution = resolution / pixelRatio;
  66565. // Compute an integer width and height.
  66566. var width = Math.ceil(ol.extent.getWidth(extent) / imageResolution);
  66567. var height = Math.ceil(ol.extent.getHeight(extent) / imageResolution);
  66568. // Modify the extent to match the integer width and height.
  66569. extent[0] = centerX - imageResolution * width / 2;
  66570. extent[2] = centerX + imageResolution * width / 2;
  66571. extent[1] = centerY - imageResolution * height / 2;
  66572. extent[3] = centerY + imageResolution * height / 2;
  66573. this.imageSize_[0] = width;
  66574. this.imageSize_[1] = height;
  66575. var url = this.getRequestUrl_(extent, this.imageSize_, pixelRatio,
  66576. projection, params);
  66577. this.image_ = new ol.Image(extent, resolution, pixelRatio,
  66578. url, this.crossOrigin_, this.imageLoadFunction_);
  66579. this.renderedRevision_ = this.getRevision();
  66580. ol.events.listen(this.image_, ol.events.EventType.CHANGE,
  66581. this.handleImageChange, this);
  66582. return this.image_;
  66583. };
  66584. /**
  66585. * Return the image load function of the source.
  66586. * @return {ol.ImageLoadFunctionType} The image load function.
  66587. * @api
  66588. */
  66589. ol.source.ImageArcGISRest.prototype.getImageLoadFunction = function() {
  66590. return this.imageLoadFunction_;
  66591. };
  66592. /**
  66593. * @param {ol.Extent} extent Extent.
  66594. * @param {ol.Size} size Size.
  66595. * @param {number} pixelRatio Pixel ratio.
  66596. * @param {ol.proj.Projection} projection Projection.
  66597. * @param {Object} params Params.
  66598. * @return {string} Request URL.
  66599. * @private
  66600. */
  66601. ol.source.ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projection, params) {
  66602. // ArcGIS Server only wants the numeric portion of the projection ID.
  66603. var srid = projection.getCode().split(':').pop();
  66604. params['SIZE'] = size[0] + ',' + size[1];
  66605. params['BBOX'] = extent.join(',');
  66606. params['BBOXSR'] = srid;
  66607. params['IMAGESR'] = srid;
  66608. params['DPI'] = Math.round(90 * pixelRatio);
  66609. var url = this.url_;
  66610. var modifiedUrl = url
  66611. .replace(/MapServer\/?$/, 'MapServer/export')
  66612. .replace(/ImageServer\/?$/, 'ImageServer/exportImage');
  66613. if (modifiedUrl == url) {
  66614. ol.asserts.assert(false, 50); // `options.featureTypes` should be an Array
  66615. }
  66616. return ol.uri.appendParams(modifiedUrl, params);
  66617. };
  66618. /**
  66619. * Return the URL used for this ArcGIS source.
  66620. * @return {string|undefined} URL.
  66621. * @api
  66622. */
  66623. ol.source.ImageArcGISRest.prototype.getUrl = function() {
  66624. return this.url_;
  66625. };
  66626. /**
  66627. * Set the image load function of the source.
  66628. * @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
  66629. * @api
  66630. */
  66631. ol.source.ImageArcGISRest.prototype.setImageLoadFunction = function(imageLoadFunction) {
  66632. this.image_ = null;
  66633. this.imageLoadFunction_ = imageLoadFunction;
  66634. this.changed();
  66635. };
  66636. /**
  66637. * Set the URL to use for requests.
  66638. * @param {string|undefined} url URL.
  66639. * @api
  66640. */
  66641. ol.source.ImageArcGISRest.prototype.setUrl = function(url) {
  66642. if (url != this.url_) {
  66643. this.url_ = url;
  66644. this.image_ = null;
  66645. this.changed();
  66646. }
  66647. };
  66648. /**
  66649. * Update the user-provided params.
  66650. * @param {Object} params Params.
  66651. * @api
  66652. */
  66653. ol.source.ImageArcGISRest.prototype.updateParams = function(params) {
  66654. ol.obj.assign(this.params_, params);
  66655. this.image_ = null;
  66656. this.changed();
  66657. };
  66658. goog.provide('ol.source.ImageCanvas');
  66659. goog.require('ol');
  66660. goog.require('ol.ImageCanvas');
  66661. goog.require('ol.extent');
  66662. goog.require('ol.source.Image');
  66663. /**
  66664. * @classdesc
  66665. * Base class for image sources where a canvas element is the image.
  66666. *
  66667. * @constructor
  66668. * @extends {ol.source.Image}
  66669. * @param {olx.source.ImageCanvasOptions} options Constructor options.
  66670. * @api
  66671. */
  66672. ol.source.ImageCanvas = function(options) {
  66673. ol.source.Image.call(this, {
  66674. attributions: options.attributions,
  66675. logo: options.logo,
  66676. projection: options.projection,
  66677. resolutions: options.resolutions,
  66678. state: options.state
  66679. });
  66680. /**
  66681. * @private
  66682. * @type {ol.CanvasFunctionType}
  66683. */
  66684. this.canvasFunction_ = options.canvasFunction;
  66685. /**
  66686. * @private
  66687. * @type {ol.ImageCanvas}
  66688. */
  66689. this.canvas_ = null;
  66690. /**
  66691. * @private
  66692. * @type {number}
  66693. */
  66694. this.renderedRevision_ = 0;
  66695. /**
  66696. * @private
  66697. * @type {number}
  66698. */
  66699. this.ratio_ = options.ratio !== undefined ?
  66700. options.ratio : 1.5;
  66701. };
  66702. ol.inherits(ol.source.ImageCanvas, ol.source.Image);
  66703. /**
  66704. * @inheritDoc
  66705. */
  66706. ol.source.ImageCanvas.prototype.getImageInternal = function(extent, resolution, pixelRatio, projection) {
  66707. resolution = this.findNearestResolution(resolution);
  66708. var canvas = this.canvas_;
  66709. if (canvas &&
  66710. this.renderedRevision_ == this.getRevision() &&
  66711. canvas.getResolution() == resolution &&
  66712. canvas.getPixelRatio() == pixelRatio &&
  66713. ol.extent.containsExtent(canvas.getExtent(), extent)) {
  66714. return canvas;
  66715. }
  66716. extent = extent.slice();
  66717. ol.extent.scaleFromCenter(extent, this.ratio_);
  66718. var width = ol.extent.getWidth(extent) / resolution;
  66719. var height = ol.extent.getHeight(extent) / resolution;
  66720. var size = [width * pixelRatio, height * pixelRatio];
  66721. var canvasElement = this.canvasFunction_(
  66722. extent, resolution, pixelRatio, size, projection);
  66723. if (canvasElement) {
  66724. canvas = new ol.ImageCanvas(extent, resolution, pixelRatio, canvasElement);
  66725. }
  66726. this.canvas_ = canvas;
  66727. this.renderedRevision_ = this.getRevision();
  66728. return canvas;
  66729. };
  66730. goog.provide('ol.source.ImageMapGuide');
  66731. goog.require('ol');
  66732. goog.require('ol.Image');
  66733. goog.require('ol.events');
  66734. goog.require('ol.events.EventType');
  66735. goog.require('ol.extent');
  66736. goog.require('ol.obj');
  66737. goog.require('ol.source.Image');
  66738. goog.require('ol.uri');
  66739. /**
  66740. * @classdesc
  66741. * Source for images from Mapguide servers
  66742. *
  66743. * @constructor
  66744. * @fires ol.source.Image.Event
  66745. * @extends {ol.source.Image}
  66746. * @param {olx.source.ImageMapGuideOptions} options Options.
  66747. * @api
  66748. */
  66749. ol.source.ImageMapGuide = function(options) {
  66750. ol.source.Image.call(this, {
  66751. projection: options.projection,
  66752. resolutions: options.resolutions
  66753. });
  66754. /**
  66755. * @private
  66756. * @type {?string}
  66757. */
  66758. this.crossOrigin_ =
  66759. options.crossOrigin !== undefined ? options.crossOrigin : null;
  66760. /**
  66761. * @private
  66762. * @type {number}
  66763. */
  66764. this.displayDpi_ = options.displayDpi !== undefined ?
  66765. options.displayDpi : 96;
  66766. /**
  66767. * @private
  66768. * @type {!Object}
  66769. */
  66770. this.params_ = options.params || {};
  66771. /**
  66772. * @private
  66773. * @type {string|undefined}
  66774. */
  66775. this.url_ = options.url;
  66776. /**
  66777. * @private
  66778. * @type {ol.ImageLoadFunctionType}
  66779. */
  66780. this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
  66781. options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
  66782. /**
  66783. * @private
  66784. * @type {boolean}
  66785. */
  66786. this.hidpi_ = options.hidpi !== undefined ? options.hidpi : true;
  66787. /**
  66788. * @private
  66789. * @type {number}
  66790. */
  66791. this.metersPerUnit_ = options.metersPerUnit !== undefined ?
  66792. options.metersPerUnit : 1;
  66793. /**
  66794. * @private
  66795. * @type {number}
  66796. */
  66797. this.ratio_ = options.ratio !== undefined ? options.ratio : 1;
  66798. /**
  66799. * @private
  66800. * @type {boolean}
  66801. */
  66802. this.useOverlay_ = options.useOverlay !== undefined ?
  66803. options.useOverlay : false;
  66804. /**
  66805. * @private
  66806. * @type {ol.Image}
  66807. */
  66808. this.image_ = null;
  66809. /**
  66810. * @private
  66811. * @type {number}
  66812. */
  66813. this.renderedRevision_ = 0;
  66814. };
  66815. ol.inherits(ol.source.ImageMapGuide, ol.source.Image);
  66816. /**
  66817. * Get the user-provided params, i.e. those passed to the constructor through
  66818. * the "params" option, and possibly updated using the updateParams method.
  66819. * @return {Object} Params.
  66820. * @api
  66821. */
  66822. ol.source.ImageMapGuide.prototype.getParams = function() {
  66823. return this.params_;
  66824. };
  66825. /**
  66826. * @inheritDoc
  66827. */
  66828. ol.source.ImageMapGuide.prototype.getImageInternal = function(extent, resolution, pixelRatio, projection) {
  66829. resolution = this.findNearestResolution(resolution);
  66830. pixelRatio = this.hidpi_ ? pixelRatio : 1;
  66831. var image = this.image_;
  66832. if (image &&
  66833. this.renderedRevision_ == this.getRevision() &&
  66834. image.getResolution() == resolution &&
  66835. image.getPixelRatio() == pixelRatio &&
  66836. ol.extent.containsExtent(image.getExtent(), extent)) {
  66837. return image;
  66838. }
  66839. if (this.ratio_ != 1) {
  66840. extent = extent.slice();
  66841. ol.extent.scaleFromCenter(extent, this.ratio_);
  66842. }
  66843. var width = ol.extent.getWidth(extent) / resolution;
  66844. var height = ol.extent.getHeight(extent) / resolution;
  66845. var size = [width * pixelRatio, height * pixelRatio];
  66846. if (this.url_ !== undefined) {
  66847. var imageUrl = this.getUrl(this.url_, this.params_, extent, size,
  66848. projection);
  66849. image = new ol.Image(extent, resolution, pixelRatio,
  66850. imageUrl, this.crossOrigin_,
  66851. this.imageLoadFunction_);
  66852. ol.events.listen(image, ol.events.EventType.CHANGE,
  66853. this.handleImageChange, this);
  66854. } else {
  66855. image = null;
  66856. }
  66857. this.image_ = image;
  66858. this.renderedRevision_ = this.getRevision();
  66859. return image;
  66860. };
  66861. /**
  66862. * Return the image load function of the source.
  66863. * @return {ol.ImageLoadFunctionType} The image load function.
  66864. * @api
  66865. */
  66866. ol.source.ImageMapGuide.prototype.getImageLoadFunction = function() {
  66867. return this.imageLoadFunction_;
  66868. };
  66869. /**
  66870. * @param {ol.Extent} extent The map extents.
  66871. * @param {ol.Size} size The viewport size.
  66872. * @param {number} metersPerUnit The meters-per-unit value.
  66873. * @param {number} dpi The display resolution.
  66874. * @return {number} The computed map scale.
  66875. */
  66876. ol.source.ImageMapGuide.getScale = function(extent, size, metersPerUnit, dpi) {
  66877. var mcsW = ol.extent.getWidth(extent);
  66878. var mcsH = ol.extent.getHeight(extent);
  66879. var devW = size[0];
  66880. var devH = size[1];
  66881. var mpp = 0.0254 / dpi;
  66882. if (devH * mcsW > devW * mcsH) {
  66883. return mcsW * metersPerUnit / (devW * mpp); // width limited
  66884. } else {
  66885. return mcsH * metersPerUnit / (devH * mpp); // height limited
  66886. }
  66887. };
  66888. /**
  66889. * Update the user-provided params.
  66890. * @param {Object} params Params.
  66891. * @api
  66892. */
  66893. ol.source.ImageMapGuide.prototype.updateParams = function(params) {
  66894. ol.obj.assign(this.params_, params);
  66895. this.changed();
  66896. };
  66897. /**
  66898. * @param {string} baseUrl The mapagent url.
  66899. * @param {Object.<string, string|number>} params Request parameters.
  66900. * @param {ol.Extent} extent Extent.
  66901. * @param {ol.Size} size Size.
  66902. * @param {ol.proj.Projection} projection Projection.
  66903. * @return {string} The mapagent map image request URL.
  66904. */
  66905. ol.source.ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, size, projection) {
  66906. var scale = ol.source.ImageMapGuide.getScale(extent, size,
  66907. this.metersPerUnit_, this.displayDpi_);
  66908. var center = ol.extent.getCenter(extent);
  66909. var baseParams = {
  66910. 'OPERATION': this.useOverlay_ ? 'GETDYNAMICMAPOVERLAYIMAGE' : 'GETMAPIMAGE',
  66911. 'VERSION': '2.0.0',
  66912. 'LOCALE': 'en',
  66913. 'CLIENTAGENT': 'ol.source.ImageMapGuide source',
  66914. 'CLIP': '1',
  66915. 'SETDISPLAYDPI': this.displayDpi_,
  66916. 'SETDISPLAYWIDTH': Math.round(size[0]),
  66917. 'SETDISPLAYHEIGHT': Math.round(size[1]),
  66918. 'SETVIEWSCALE': scale,
  66919. 'SETVIEWCENTERX': center[0],
  66920. 'SETVIEWCENTERY': center[1]
  66921. };
  66922. ol.obj.assign(baseParams, params);
  66923. return ol.uri.appendParams(baseUrl, baseParams);
  66924. };
  66925. /**
  66926. * Set the image load function of the MapGuide source.
  66927. * @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
  66928. * @api
  66929. */
  66930. ol.source.ImageMapGuide.prototype.setImageLoadFunction = function(
  66931. imageLoadFunction) {
  66932. this.image_ = null;
  66933. this.imageLoadFunction_ = imageLoadFunction;
  66934. this.changed();
  66935. };
  66936. goog.provide('ol.source.ImageStatic');
  66937. goog.require('ol');
  66938. goog.require('ol.Image');
  66939. goog.require('ol.ImageState');
  66940. goog.require('ol.dom');
  66941. goog.require('ol.events');
  66942. goog.require('ol.events.EventType');
  66943. goog.require('ol.extent');
  66944. goog.require('ol.proj');
  66945. goog.require('ol.source.Image');
  66946. /**
  66947. * @classdesc
  66948. * A layer source for displaying a single, static image.
  66949. *
  66950. * @constructor
  66951. * @extends {ol.source.Image}
  66952. * @param {olx.source.ImageStaticOptions} options Options.
  66953. * @api
  66954. */
  66955. ol.source.ImageStatic = function(options) {
  66956. var imageExtent = options.imageExtent;
  66957. var crossOrigin = options.crossOrigin !== undefined ?
  66958. options.crossOrigin : null;
  66959. var /** @type {ol.ImageLoadFunctionType} */ imageLoadFunction =
  66960. options.imageLoadFunction !== undefined ?
  66961. options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
  66962. ol.source.Image.call(this, {
  66963. attributions: options.attributions,
  66964. logo: options.logo,
  66965. projection: ol.proj.get(options.projection)
  66966. });
  66967. /**
  66968. * @private
  66969. * @type {ol.Image}
  66970. */
  66971. this.image_ = new ol.Image(imageExtent, undefined, 1, options.url, crossOrigin, imageLoadFunction);
  66972. /**
  66973. * @private
  66974. * @type {ol.Size}
  66975. */
  66976. this.imageSize_ = options.imageSize ? options.imageSize : null;
  66977. ol.events.listen(this.image_, ol.events.EventType.CHANGE,
  66978. this.handleImageChange, this);
  66979. };
  66980. ol.inherits(ol.source.ImageStatic, ol.source.Image);
  66981. /**
  66982. * @inheritDoc
  66983. */
  66984. ol.source.ImageStatic.prototype.getImageInternal = function(extent, resolution, pixelRatio, projection) {
  66985. if (ol.extent.intersects(extent, this.image_.getExtent())) {
  66986. return this.image_;
  66987. }
  66988. return null;
  66989. };
  66990. /**
  66991. * @inheritDoc
  66992. */
  66993. ol.source.ImageStatic.prototype.handleImageChange = function(evt) {
  66994. if (this.image_.getState() == ol.ImageState.LOADED) {
  66995. var imageExtent = this.image_.getExtent();
  66996. var image = this.image_.getImage();
  66997. var imageWidth, imageHeight;
  66998. if (this.imageSize_) {
  66999. imageWidth = this.imageSize_[0];
  67000. imageHeight = this.imageSize_[1];
  67001. } else {
  67002. imageWidth = image.width;
  67003. imageHeight = image.height;
  67004. }
  67005. var resolution = ol.extent.getHeight(imageExtent) / imageHeight;
  67006. var targetWidth = Math.ceil(ol.extent.getWidth(imageExtent) / resolution);
  67007. if (targetWidth != imageWidth) {
  67008. var context = ol.dom.createCanvasContext2D(targetWidth, imageHeight);
  67009. var canvas = context.canvas;
  67010. context.drawImage(image, 0, 0, imageWidth, imageHeight,
  67011. 0, 0, canvas.width, canvas.height);
  67012. this.image_.setImage(canvas);
  67013. }
  67014. }
  67015. ol.source.Image.prototype.handleImageChange.call(this, evt);
  67016. };
  67017. goog.provide('ol.source.ImageVector');
  67018. goog.require('ol');
  67019. goog.require('ol.dom');
  67020. goog.require('ol.events');
  67021. goog.require('ol.events.EventType');
  67022. goog.require('ol.ext.rbush');
  67023. goog.require('ol.extent');
  67024. goog.require('ol.render.canvas.ReplayGroup');
  67025. goog.require('ol.renderer.vector');
  67026. goog.require('ol.source.ImageCanvas');
  67027. goog.require('ol.style.Style');
  67028. goog.require('ol.transform');
  67029. /**
  67030. * @deprecated
  67031. * @classdesc
  67032. * **Deprecated**. Use an `ol.layer.Vector` with `renderMode: 'image'` and an
  67033. * `ol.source.Vector` instead.
  67034. *
  67035. * An image source whose images are canvas elements into which vector features
  67036. * read from a vector source (`ol.source.Vector`) are drawn. An
  67037. * `ol.source.ImageVector` object is to be used as the `source` of an image
  67038. * layer (`ol.layer.Image`). Image layers are rotated, scaled, and translated,
  67039. * as opposed to being re-rendered, during animations and interactions. So, like
  67040. * any other image layer, an image layer configured with an
  67041. * `ol.source.ImageVector` will exhibit this behaviour. This is in contrast to a
  67042. * vector layer, where vector features are re-drawn during animations and
  67043. * interactions.
  67044. *
  67045. * @constructor
  67046. * @extends {ol.source.ImageCanvas}
  67047. * @param {olx.source.ImageVectorOptions} options Options.
  67048. * @api
  67049. */
  67050. ol.source.ImageVector = function(options) {
  67051. /**
  67052. * @private
  67053. * @type {ol.source.Vector}
  67054. */
  67055. this.source_ = options.source;
  67056. /**
  67057. * @private
  67058. * @type {ol.Transform}
  67059. */
  67060. this.transform_ = ol.transform.create();
  67061. /**
  67062. * @private
  67063. * @type {CanvasRenderingContext2D}
  67064. */
  67065. this.canvasContext_ = ol.dom.createCanvasContext2D();
  67066. /**
  67067. * @private
  67068. * @type {ol.Size}
  67069. */
  67070. this.canvasSize_ = [0, 0];
  67071. /**
  67072. * Declutter tree.
  67073. * @private
  67074. */
  67075. this.declutterTree_ = ol.ext.rbush(9);
  67076. /**
  67077. * @private
  67078. * @type {number}
  67079. */
  67080. this.renderBuffer_ = options.renderBuffer == undefined ? 100 : options.renderBuffer;
  67081. /**
  67082. * @private
  67083. * @type {ol.render.canvas.ReplayGroup}
  67084. */
  67085. this.replayGroup_ = null;
  67086. ol.source.ImageCanvas.call(this, {
  67087. attributions: options.attributions,
  67088. canvasFunction: this.canvasFunctionInternal_.bind(this),
  67089. logo: options.logo,
  67090. projection: options.projection,
  67091. ratio: options.ratio,
  67092. resolutions: options.resolutions,
  67093. state: this.source_.getState()
  67094. });
  67095. /**
  67096. * User provided style.
  67097. * @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
  67098. * @private
  67099. */
  67100. this.style_ = null;
  67101. /**
  67102. * Style function for use within the library.
  67103. * @type {ol.StyleFunction|undefined}
  67104. * @private
  67105. */
  67106. this.styleFunction_ = undefined;
  67107. this.setStyle(options.style);
  67108. ol.events.listen(this.source_, ol.events.EventType.CHANGE,
  67109. this.handleSourceChange_, this);
  67110. };
  67111. ol.inherits(ol.source.ImageVector, ol.source.ImageCanvas);
  67112. /**
  67113. * @param {ol.Extent} extent Extent.
  67114. * @param {number} resolution Resolution.
  67115. * @param {number} pixelRatio Pixel ratio.
  67116. * @param {ol.Size} size Size.
  67117. * @param {ol.proj.Projection} projection Projection;
  67118. * @return {HTMLCanvasElement} Canvas element.
  67119. * @private
  67120. */
  67121. ol.source.ImageVector.prototype.canvasFunctionInternal_ = function(extent, resolution, pixelRatio, size, projection) {
  67122. var replayGroup = new ol.render.canvas.ReplayGroup(
  67123. ol.renderer.vector.getTolerance(resolution, pixelRatio), extent,
  67124. resolution, pixelRatio, this.source_.getOverlaps(), this.declutterTree_, this.renderBuffer_);
  67125. this.source_.loadFeatures(extent, resolution, projection);
  67126. var loading = false;
  67127. this.source_.forEachFeatureInExtent(extent,
  67128. /**
  67129. * @param {ol.Feature} feature Feature.
  67130. */
  67131. function(feature) {
  67132. loading = loading ||
  67133. this.renderFeature_(feature, resolution, pixelRatio, replayGroup);
  67134. }, this);
  67135. replayGroup.finish();
  67136. if (loading) {
  67137. return null;
  67138. }
  67139. if (this.canvasSize_[0] != size[0] || this.canvasSize_[1] != size[1]) {
  67140. this.canvasContext_.canvas.width = size[0];
  67141. this.canvasContext_.canvas.height = size[1];
  67142. this.canvasSize_[0] = size[0];
  67143. this.canvasSize_[1] = size[1];
  67144. } else {
  67145. this.canvasContext_.clearRect(0, 0, size[0], size[1]);
  67146. }
  67147. this.declutterTree_.clear();
  67148. var transform = this.getTransform_(ol.extent.getCenter(extent),
  67149. resolution, pixelRatio, size);
  67150. replayGroup.replay(this.canvasContext_, transform, 0, {});
  67151. this.replayGroup_ = replayGroup;
  67152. return this.canvasContext_.canvas;
  67153. };
  67154. /**
  67155. * @inheritDoc
  67156. */
  67157. ol.source.ImageVector.prototype.forEachFeatureAtCoordinate = function(
  67158. coordinate, resolution, rotation, hitTolerance, skippedFeatureUids, callback) {
  67159. if (!this.replayGroup_) {
  67160. return undefined;
  67161. } else {
  67162. /** @type {Object.<string, boolean>} */
  67163. var features = {};
  67164. var result = this.replayGroup_.forEachFeatureAtCoordinate(
  67165. coordinate, resolution, 0, hitTolerance, skippedFeatureUids,
  67166. /**
  67167. * @param {ol.Feature|ol.render.Feature} feature Feature.
  67168. * @return {?} Callback result.
  67169. */
  67170. function(feature) {
  67171. var key = ol.getUid(feature).toString();
  67172. if (!(key in features)) {
  67173. features[key] = true;
  67174. return callback(feature);
  67175. }
  67176. }, null);
  67177. return result;
  67178. }
  67179. };
  67180. /**
  67181. * Get a reference to the wrapped source.
  67182. * @return {ol.source.Vector} Source.
  67183. * @api
  67184. */
  67185. ol.source.ImageVector.prototype.getSource = function() {
  67186. return this.source_;
  67187. };
  67188. /**
  67189. * Get the style for features. This returns whatever was passed to the `style`
  67190. * option at construction or to the `setStyle` method.
  67191. * @return {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
  67192. * Layer style.
  67193. * @api
  67194. */
  67195. ol.source.ImageVector.prototype.getStyle = function() {
  67196. return this.style_;
  67197. };
  67198. /**
  67199. * Get the style function.
  67200. * @return {ol.StyleFunction|undefined} Layer style function.
  67201. * @api
  67202. */
  67203. ol.source.ImageVector.prototype.getStyleFunction = function() {
  67204. return this.styleFunction_;
  67205. };
  67206. /**
  67207. * @param {ol.Coordinate} center Center.
  67208. * @param {number} resolution Resolution.
  67209. * @param {number} pixelRatio Pixel ratio.
  67210. * @param {ol.Size} size Size.
  67211. * @return {!ol.Transform} Transform.
  67212. * @private
  67213. */
  67214. ol.source.ImageVector.prototype.getTransform_ = function(center, resolution, pixelRatio, size) {
  67215. var dx1 = size[0] / 2;
  67216. var dy1 = size[1] / 2;
  67217. var sx = pixelRatio / resolution;
  67218. var sy = -sx;
  67219. var dx2 = -center[0];
  67220. var dy2 = -center[1];
  67221. return ol.transform.compose(this.transform_, dx1, dy1, sx, sy, 0, dx2, dy2);
  67222. };
  67223. /**
  67224. * Handle changes in image style state.
  67225. * @param {ol.events.Event} event Image style change event.
  67226. * @private
  67227. */
  67228. ol.source.ImageVector.prototype.handleImageChange_ = function(event) {
  67229. this.changed();
  67230. };
  67231. /**
  67232. * @private
  67233. */
  67234. ol.source.ImageVector.prototype.handleSourceChange_ = function() {
  67235. // setState will trigger a CHANGE event, so we always rely
  67236. // change events by calling setState.
  67237. this.setState(this.source_.getState());
  67238. };
  67239. /**
  67240. * @param {ol.Feature} feature Feature.
  67241. * @param {number} resolution Resolution.
  67242. * @param {number} pixelRatio Pixel ratio.
  67243. * @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
  67244. * @return {boolean} `true` if an image is loading.
  67245. * @private
  67246. */
  67247. ol.source.ImageVector.prototype.renderFeature_ = function(feature, resolution, pixelRatio, replayGroup) {
  67248. var styles;
  67249. var styleFunction = feature.getStyleFunction();
  67250. if (styleFunction) {
  67251. styles = styleFunction.call(feature, resolution);
  67252. } else if (this.styleFunction_) {
  67253. styles = this.styleFunction_(feature, resolution);
  67254. }
  67255. if (!styles) {
  67256. return false;
  67257. }
  67258. var i, ii, loading = false;
  67259. if (!Array.isArray(styles)) {
  67260. styles = [styles];
  67261. }
  67262. for (i = 0, ii = styles.length; i < ii; ++i) {
  67263. loading = ol.renderer.vector.renderFeature(
  67264. replayGroup, feature, styles[i],
  67265. ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
  67266. this.handleImageChange_, this) || loading;
  67267. }
  67268. return loading;
  67269. };
  67270. /**
  67271. * Set the style for features. This can be a single style object, an array
  67272. * of styles, or a function that takes a feature and resolution and returns
  67273. * an array of styles. If it is `undefined` the default style is used. If
  67274. * it is `null` the layer has no style (a `null` style), so only features
  67275. * that have their own styles will be rendered in the layer. See
  67276. * {@link ol.style} for information on the default style.
  67277. * @param {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined}
  67278. * style Layer style.
  67279. * @api
  67280. */
  67281. ol.source.ImageVector.prototype.setStyle = function(style) {
  67282. this.style_ = style !== undefined ? style : ol.style.Style.defaultFunction;
  67283. this.styleFunction_ = !style ?
  67284. undefined : ol.style.Style.createFunction(this.style_);
  67285. this.changed();
  67286. };
  67287. goog.provide('ol.source.WMSServerType');
  67288. /**
  67289. * Available server types: `'carmentaserver'`, `'geoserver'`, `'mapserver'`,
  67290. * `'qgis'`. These are servers that have vendor parameters beyond the WMS
  67291. * specification that OpenLayers can make use of.
  67292. * @enum {string}
  67293. */
  67294. ol.source.WMSServerType = {
  67295. CARMENTA_SERVER: 'carmentaserver',
  67296. GEOSERVER: 'geoserver',
  67297. MAPSERVER: 'mapserver',
  67298. QGIS: 'qgis'
  67299. };
  67300. // FIXME cannot be shared between maps with different projections
  67301. goog.provide('ol.source.ImageWMS');
  67302. goog.require('ol');
  67303. goog.require('ol.Image');
  67304. goog.require('ol.asserts');
  67305. goog.require('ol.events');
  67306. goog.require('ol.events.EventType');
  67307. goog.require('ol.extent');
  67308. goog.require('ol.obj');
  67309. goog.require('ol.proj');
  67310. goog.require('ol.reproj');
  67311. goog.require('ol.source.Image');
  67312. goog.require('ol.source.WMSServerType');
  67313. goog.require('ol.string');
  67314. goog.require('ol.uri');
  67315. /**
  67316. * @classdesc
  67317. * Source for WMS servers providing single, untiled images.
  67318. *
  67319. * @constructor
  67320. * @fires ol.source.Image.Event
  67321. * @extends {ol.source.Image}
  67322. * @param {olx.source.ImageWMSOptions=} opt_options Options.
  67323. * @api
  67324. */
  67325. ol.source.ImageWMS = function(opt_options) {
  67326. var options = opt_options || {};
  67327. ol.source.Image.call(this, {
  67328. attributions: options.attributions,
  67329. logo: options.logo,
  67330. projection: options.projection,
  67331. resolutions: options.resolutions
  67332. });
  67333. /**
  67334. * @private
  67335. * @type {?string}
  67336. */
  67337. this.crossOrigin_ =
  67338. options.crossOrigin !== undefined ? options.crossOrigin : null;
  67339. /**
  67340. * @private
  67341. * @type {string|undefined}
  67342. */
  67343. this.url_ = options.url;
  67344. /**
  67345. * @private
  67346. * @type {ol.ImageLoadFunctionType}
  67347. */
  67348. this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
  67349. options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
  67350. /**
  67351. * @private
  67352. * @type {!Object}
  67353. */
  67354. this.params_ = options.params || {};
  67355. /**
  67356. * @private
  67357. * @type {boolean}
  67358. */
  67359. this.v13_ = true;
  67360. this.updateV13_();
  67361. /**
  67362. * @private
  67363. * @type {ol.source.WMSServerType|undefined}
  67364. */
  67365. this.serverType_ = /** @type {ol.source.WMSServerType|undefined} */ (options.serverType);
  67366. /**
  67367. * @private
  67368. * @type {boolean}
  67369. */
  67370. this.hidpi_ = options.hidpi !== undefined ? options.hidpi : true;
  67371. /**
  67372. * @private
  67373. * @type {ol.Image}
  67374. */
  67375. this.image_ = null;
  67376. /**
  67377. * @private
  67378. * @type {ol.Size}
  67379. */
  67380. this.imageSize_ = [0, 0];
  67381. /**
  67382. * @private
  67383. * @type {number}
  67384. */
  67385. this.renderedRevision_ = 0;
  67386. /**
  67387. * @private
  67388. * @type {number}
  67389. */
  67390. this.ratio_ = options.ratio !== undefined ? options.ratio : 1.5;
  67391. };
  67392. ol.inherits(ol.source.ImageWMS, ol.source.Image);
  67393. /**
  67394. * @const
  67395. * @type {ol.Size}
  67396. * @private
  67397. */
  67398. ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_ = [101, 101];
  67399. /**
  67400. * Return the GetFeatureInfo URL for the passed coordinate, resolution, and
  67401. * projection. Return `undefined` if the GetFeatureInfo URL cannot be
  67402. * constructed.
  67403. * @param {ol.Coordinate} coordinate Coordinate.
  67404. * @param {number} resolution Resolution.
  67405. * @param {ol.ProjectionLike} projection Projection.
  67406. * @param {!Object} params GetFeatureInfo params. `INFO_FORMAT` at least should
  67407. * be provided. If `QUERY_LAYERS` is not provided then the layers specified
  67408. * in the `LAYERS` parameter will be used. `VERSION` should not be
  67409. * specified here.
  67410. * @return {string|undefined} GetFeatureInfo URL.
  67411. * @api
  67412. */
  67413. ol.source.ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projection, params) {
  67414. if (this.url_ === undefined) {
  67415. return undefined;
  67416. }
  67417. var projectionObj = ol.proj.get(projection);
  67418. var sourceProjectionObj = this.getProjection();
  67419. if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
  67420. resolution = ol.reproj.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, resolution);
  67421. coordinate = ol.proj.transform(coordinate, projectionObj, sourceProjectionObj);
  67422. }
  67423. var extent = ol.extent.getForViewAndSize(
  67424. coordinate, resolution, 0,
  67425. ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_);
  67426. var baseParams = {
  67427. 'SERVICE': 'WMS',
  67428. 'VERSION': ol.DEFAULT_WMS_VERSION,
  67429. 'REQUEST': 'GetFeatureInfo',
  67430. 'FORMAT': 'image/png',
  67431. 'TRANSPARENT': true,
  67432. 'QUERY_LAYERS': this.params_['LAYERS']
  67433. };
  67434. ol.obj.assign(baseParams, this.params_, params);
  67435. var x = Math.floor((coordinate[0] - extent[0]) / resolution);
  67436. var y = Math.floor((extent[3] - coordinate[1]) / resolution);
  67437. baseParams[this.v13_ ? 'I' : 'X'] = x;
  67438. baseParams[this.v13_ ? 'J' : 'Y'] = y;
  67439. return this.getRequestUrl_(
  67440. extent, ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_,
  67441. 1, sourceProjectionObj || projectionObj, baseParams);
  67442. };
  67443. /**
  67444. * Get the user-provided params, i.e. those passed to the constructor through
  67445. * the "params" option, and possibly updated using the updateParams method.
  67446. * @return {Object} Params.
  67447. * @api
  67448. */
  67449. ol.source.ImageWMS.prototype.getParams = function() {
  67450. return this.params_;
  67451. };
  67452. /**
  67453. * @inheritDoc
  67454. */
  67455. ol.source.ImageWMS.prototype.getImageInternal = function(extent, resolution, pixelRatio, projection) {
  67456. if (this.url_ === undefined) {
  67457. return null;
  67458. }
  67459. resolution = this.findNearestResolution(resolution);
  67460. if (pixelRatio != 1 && (!this.hidpi_ || this.serverType_ === undefined)) {
  67461. pixelRatio = 1;
  67462. }
  67463. var imageResolution = resolution / pixelRatio;
  67464. var center = ol.extent.getCenter(extent);
  67465. var viewWidth = Math.ceil(ol.extent.getWidth(extent) / imageResolution);
  67466. var viewHeight = Math.ceil(ol.extent.getHeight(extent) / imageResolution);
  67467. var viewExtent = ol.extent.getForViewAndSize(center, imageResolution, 0,
  67468. [viewWidth, viewHeight]);
  67469. var requestWidth = Math.ceil(this.ratio_ * ol.extent.getWidth(extent) / imageResolution);
  67470. var requestHeight = Math.ceil(this.ratio_ * ol.extent.getHeight(extent) / imageResolution);
  67471. var requestExtent = ol.extent.getForViewAndSize(center, imageResolution, 0,
  67472. [requestWidth, requestHeight]);
  67473. var image = this.image_;
  67474. if (image &&
  67475. this.renderedRevision_ == this.getRevision() &&
  67476. image.getResolution() == resolution &&
  67477. image.getPixelRatio() == pixelRatio &&
  67478. ol.extent.containsExtent(image.getExtent(), viewExtent)) {
  67479. return image;
  67480. }
  67481. var params = {
  67482. 'SERVICE': 'WMS',
  67483. 'VERSION': ol.DEFAULT_WMS_VERSION,
  67484. 'REQUEST': 'GetMap',
  67485. 'FORMAT': 'image/png',
  67486. 'TRANSPARENT': true
  67487. };
  67488. ol.obj.assign(params, this.params_);
  67489. this.imageSize_[0] = Math.round(ol.extent.getWidth(requestExtent) / imageResolution);
  67490. this.imageSize_[1] = Math.round(ol.extent.getHeight(requestExtent) / imageResolution);
  67491. var url = this.getRequestUrl_(requestExtent, this.imageSize_, pixelRatio,
  67492. projection, params);
  67493. this.image_ = new ol.Image(requestExtent, resolution, pixelRatio,
  67494. url, this.crossOrigin_, this.imageLoadFunction_);
  67495. this.renderedRevision_ = this.getRevision();
  67496. ol.events.listen(this.image_, ol.events.EventType.CHANGE,
  67497. this.handleImageChange, this);
  67498. return this.image_;
  67499. };
  67500. /**
  67501. * Return the image load function of the source.
  67502. * @return {ol.ImageLoadFunctionType} The image load function.
  67503. * @api
  67504. */
  67505. ol.source.ImageWMS.prototype.getImageLoadFunction = function() {
  67506. return this.imageLoadFunction_;
  67507. };
  67508. /**
  67509. * @param {ol.Extent} extent Extent.
  67510. * @param {ol.Size} size Size.
  67511. * @param {number} pixelRatio Pixel ratio.
  67512. * @param {ol.proj.Projection} projection Projection.
  67513. * @param {Object} params Params.
  67514. * @return {string} Request URL.
  67515. * @private
  67516. */
  67517. ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projection, params) {
  67518. ol.asserts.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()`
  67519. params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
  67520. if (!('STYLES' in this.params_)) {
  67521. params['STYLES'] = '';
  67522. }
  67523. if (pixelRatio != 1) {
  67524. switch (this.serverType_) {
  67525. case ol.source.WMSServerType.GEOSERVER:
  67526. var dpi = (90 * pixelRatio + 0.5) | 0;
  67527. if ('FORMAT_OPTIONS' in params) {
  67528. params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
  67529. } else {
  67530. params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
  67531. }
  67532. break;
  67533. case ol.source.WMSServerType.MAPSERVER:
  67534. params['MAP_RESOLUTION'] = 90 * pixelRatio;
  67535. break;
  67536. case ol.source.WMSServerType.CARMENTA_SERVER:
  67537. case ol.source.WMSServerType.QGIS:
  67538. params['DPI'] = 90 * pixelRatio;
  67539. break;
  67540. default:
  67541. ol.asserts.assert(false, 8); // Unknown `serverType` configured
  67542. break;
  67543. }
  67544. }
  67545. params['WIDTH'] = size[0];
  67546. params['HEIGHT'] = size[1];
  67547. var axisOrientation = projection.getAxisOrientation();
  67548. var bbox;
  67549. if (this.v13_ && axisOrientation.substr(0, 2) == 'ne') {
  67550. bbox = [extent[1], extent[0], extent[3], extent[2]];
  67551. } else {
  67552. bbox = extent;
  67553. }
  67554. params['BBOX'] = bbox.join(',');
  67555. return ol.uri.appendParams(/** @type {string} */ (this.url_), params);
  67556. };
  67557. /**
  67558. * Return the URL used for this WMS source.
  67559. * @return {string|undefined} URL.
  67560. * @api
  67561. */
  67562. ol.source.ImageWMS.prototype.getUrl = function() {
  67563. return this.url_;
  67564. };
  67565. /**
  67566. * Set the image load function of the source.
  67567. * @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
  67568. * @api
  67569. */
  67570. ol.source.ImageWMS.prototype.setImageLoadFunction = function(
  67571. imageLoadFunction) {
  67572. this.image_ = null;
  67573. this.imageLoadFunction_ = imageLoadFunction;
  67574. this.changed();
  67575. };
  67576. /**
  67577. * Set the URL to use for requests.
  67578. * @param {string|undefined} url URL.
  67579. * @api
  67580. */
  67581. ol.source.ImageWMS.prototype.setUrl = function(url) {
  67582. if (url != this.url_) {
  67583. this.url_ = url;
  67584. this.image_ = null;
  67585. this.changed();
  67586. }
  67587. };
  67588. /**
  67589. * Update the user-provided params.
  67590. * @param {Object} params Params.
  67591. * @api
  67592. */
  67593. ol.source.ImageWMS.prototype.updateParams = function(params) {
  67594. ol.obj.assign(this.params_, params);
  67595. this.updateV13_();
  67596. this.image_ = null;
  67597. this.changed();
  67598. };
  67599. /**
  67600. * @private
  67601. */
  67602. ol.source.ImageWMS.prototype.updateV13_ = function() {
  67603. var version = this.params_['VERSION'] || ol.DEFAULT_WMS_VERSION;
  67604. this.v13_ = ol.string.compareVersions(version, '1.3') >= 0;
  67605. };
  67606. goog.provide('ol.source.OSM');
  67607. goog.require('ol');
  67608. goog.require('ol.source.XYZ');
  67609. /**
  67610. * @classdesc
  67611. * Layer source for the OpenStreetMap tile server.
  67612. *
  67613. * @constructor
  67614. * @extends {ol.source.XYZ}
  67615. * @param {olx.source.OSMOptions=} opt_options Open Street Map options.
  67616. * @api
  67617. */
  67618. ol.source.OSM = function(opt_options) {
  67619. var options = opt_options || {};
  67620. var attributions;
  67621. if (options.attributions !== undefined) {
  67622. attributions = options.attributions;
  67623. } else {
  67624. attributions = [ol.source.OSM.ATTRIBUTION];
  67625. }
  67626. var crossOrigin = options.crossOrigin !== undefined ?
  67627. options.crossOrigin : 'anonymous';
  67628. var url = options.url !== undefined ?
  67629. options.url : 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png';
  67630. ol.source.XYZ.call(this, {
  67631. attributions: attributions,
  67632. cacheSize: options.cacheSize,
  67633. crossOrigin: crossOrigin,
  67634. opaque: options.opaque !== undefined ? options.opaque : true,
  67635. maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
  67636. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  67637. tileLoadFunction: options.tileLoadFunction,
  67638. url: url,
  67639. wrapX: options.wrapX
  67640. });
  67641. };
  67642. ol.inherits(ol.source.OSM, ol.source.XYZ);
  67643. /**
  67644. * The attribution containing a link to the OpenStreetMap Copyright and License
  67645. * page.
  67646. * @const
  67647. * @type {string}
  67648. * @api
  67649. */
  67650. ol.source.OSM.ATTRIBUTION = '&copy; ' +
  67651. '<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> ' +
  67652. 'contributors.';
  67653. /**
  67654. * @fileoverview
  67655. * @suppress {accessControls, ambiguousFunctionDecl, checkDebuggerStatement, checkRegExp, checkTypes, checkVars, const, constantProperty, deprecated, duplicate, es5Strict, fileoverviewTags, missingProperties, nonStandardJsDocs, strictModuleDepCheck, suspiciousCode, undefinedNames, undefinedVars, unknownDefines, unusedLocalVariables, uselessCode, visibility}
  67656. */
  67657. goog.provide('ol.ext.pixelworks.Processor');
  67658. /** @typedef {function(*)} */
  67659. ol.ext.pixelworks.Processor = function() {};
  67660. (function() {(function (exports) {
  67661. 'use strict';
  67662. var hasImageData = true;
  67663. try {
  67664. new ImageData(10, 10);
  67665. } catch (_) {
  67666. hasImageData = false;
  67667. }
  67668. var context = document.createElement('canvas').getContext('2d');
  67669. function newImageData$1(data, width, height) {
  67670. if (hasImageData) {
  67671. return new ImageData(data, width, height);
  67672. } else {
  67673. var imageData = context.createImageData(width, height);
  67674. imageData.data.set(data);
  67675. return imageData;
  67676. }
  67677. }
  67678. var newImageData_1 = newImageData$1;
  67679. var util = {
  67680. newImageData: newImageData_1
  67681. };
  67682. var newImageData = util.newImageData;
  67683. function createMinion(operation) {
  67684. var workerHasImageData = true;
  67685. try {
  67686. new ImageData(10, 10);
  67687. } catch (_) {
  67688. workerHasImageData = false;
  67689. }
  67690. function newWorkerImageData(data, width, height) {
  67691. if (workerHasImageData) {
  67692. return new ImageData(data, width, height);
  67693. } else {
  67694. return {data: data, width: width, height: height};
  67695. }
  67696. }
  67697. return function(data) {
  67698. var buffers = data['buffers'];
  67699. var meta = data['meta'];
  67700. var imageOps = data['imageOps'];
  67701. var width = data['width'];
  67702. var height = data['height'];
  67703. var numBuffers = buffers.length;
  67704. var numBytes = buffers[0].byteLength;
  67705. var output, b;
  67706. if (imageOps) {
  67707. var images = new Array(numBuffers);
  67708. for (b = 0; b < numBuffers; ++b) {
  67709. images[b] = newWorkerImageData(
  67710. new Uint8ClampedArray(buffers[b]), width, height);
  67711. }
  67712. output = operation(images, meta).data;
  67713. } else {
  67714. output = new Uint8ClampedArray(numBytes);
  67715. var arrays = new Array(numBuffers);
  67716. var pixels = new Array(numBuffers);
  67717. for (b = 0; b < numBuffers; ++b) {
  67718. arrays[b] = new Uint8ClampedArray(buffers[b]);
  67719. pixels[b] = [0, 0, 0, 0];
  67720. }
  67721. for (var i = 0; i < numBytes; i += 4) {
  67722. for (var j = 0; j < numBuffers; ++j) {
  67723. var array = arrays[j];
  67724. pixels[j][0] = array[i];
  67725. pixels[j][1] = array[i + 1];
  67726. pixels[j][2] = array[i + 2];
  67727. pixels[j][3] = array[i + 3];
  67728. }
  67729. var pixel = operation(pixels, meta);
  67730. output[i] = pixel[0];
  67731. output[i + 1] = pixel[1];
  67732. output[i + 2] = pixel[2];
  67733. output[i + 3] = pixel[3];
  67734. }
  67735. }
  67736. return output.buffer;
  67737. };
  67738. }
  67739. function createWorker(config, onMessage) {
  67740. var lib = Object.keys(config.lib || {}).map(function(name) {
  67741. return 'var ' + name + ' = ' + config.lib[name].toString() + ';';
  67742. });
  67743. var lines = lib.concat([
  67744. 'var __minion__ = (' + createMinion.toString() + ')(', config.operation.toString(), ');',
  67745. 'self.addEventListener("message", function(event) {',
  67746. ' var buffer = __minion__(event.data);',
  67747. ' self.postMessage({buffer: buffer, meta: event.data.meta}, [buffer]);',
  67748. '});'
  67749. ]);
  67750. var blob = new Blob(lines, {type: 'text/javascript'});
  67751. var source = URL.createObjectURL(blob);
  67752. var worker = new Worker(source);
  67753. worker.addEventListener('message', onMessage);
  67754. return worker;
  67755. }
  67756. function createFauxWorker(config, onMessage) {
  67757. var minion = createMinion(config.operation);
  67758. return {
  67759. postMessage: function(data) {
  67760. setTimeout(function() {
  67761. onMessage({'data': {'buffer': minion(data), 'meta': data['meta']}});
  67762. }, 0);
  67763. }
  67764. };
  67765. }
  67766. function Processor(config) {
  67767. this._imageOps = !!config.imageOps;
  67768. var threads;
  67769. if (config.threads === 0) {
  67770. threads = 0;
  67771. } else if (this._imageOps) {
  67772. threads = 1;
  67773. } else {
  67774. threads = config.threads || 1;
  67775. }
  67776. var workers = [];
  67777. if (threads) {
  67778. for (var i = 0; i < threads; ++i) {
  67779. workers[i] = createWorker(config, this._onWorkerMessage.bind(this, i));
  67780. }
  67781. } else {
  67782. workers[0] = createFauxWorker(config, this._onWorkerMessage.bind(this, 0));
  67783. }
  67784. this._workers = workers;
  67785. this._queue = [];
  67786. this._maxQueueLength = config.queue || Infinity;
  67787. this._running = 0;
  67788. this._dataLookup = {};
  67789. this._job = null;
  67790. }
  67791. Processor.prototype.process = function(inputs, meta, callback) {
  67792. this._enqueue({
  67793. inputs: inputs,
  67794. meta: meta,
  67795. callback: callback
  67796. });
  67797. this._dispatch();
  67798. };
  67799. Processor.prototype.destroy = function() {
  67800. for (var key in this) {
  67801. this[key] = null;
  67802. }
  67803. this._destroyed = true;
  67804. };
  67805. Processor.prototype._enqueue = function(job) {
  67806. this._queue.push(job);
  67807. while (this._queue.length > this._maxQueueLength) {
  67808. this._queue.shift().callback(null, null);
  67809. }
  67810. };
  67811. Processor.prototype._dispatch = function() {
  67812. if (this._running === 0 && this._queue.length > 0) {
  67813. var job = this._job = this._queue.shift();
  67814. var width = job.inputs[0].width;
  67815. var height = job.inputs[0].height;
  67816. var buffers = job.inputs.map(function(input) {
  67817. return input.data.buffer;
  67818. });
  67819. var threads = this._workers.length;
  67820. this._running = threads;
  67821. if (threads === 1) {
  67822. this._workers[0].postMessage({
  67823. 'buffers': buffers,
  67824. 'meta': job.meta,
  67825. 'imageOps': this._imageOps,
  67826. 'width': width,
  67827. 'height': height
  67828. }, buffers);
  67829. } else {
  67830. var length = job.inputs[0].data.length;
  67831. var segmentLength = 4 * Math.ceil(length / 4 / threads);
  67832. for (var i = 0; i < threads; ++i) {
  67833. var offset = i * segmentLength;
  67834. var slices = [];
  67835. for (var j = 0, jj = buffers.length; j < jj; ++j) {
  67836. slices.push(buffers[i].slice(offset, offset + segmentLength));
  67837. }
  67838. this._workers[i].postMessage({
  67839. 'buffers': slices,
  67840. 'meta': job.meta,
  67841. 'imageOps': this._imageOps,
  67842. 'width': width,
  67843. 'height': height
  67844. }, slices);
  67845. }
  67846. }
  67847. }
  67848. };
  67849. Processor.prototype._onWorkerMessage = function(index, event) {
  67850. if (this._destroyed) {
  67851. return;
  67852. }
  67853. this._dataLookup[index] = event.data;
  67854. --this._running;
  67855. if (this._running === 0) {
  67856. this._resolveJob();
  67857. }
  67858. };
  67859. Processor.prototype._resolveJob = function() {
  67860. var job = this._job;
  67861. var threads = this._workers.length;
  67862. var data, meta;
  67863. if (threads === 1) {
  67864. data = new Uint8ClampedArray(this._dataLookup[0]['buffer']);
  67865. meta = this._dataLookup[0]['meta'];
  67866. } else {
  67867. var length = job.inputs[0].data.length;
  67868. data = new Uint8ClampedArray(length);
  67869. meta = new Array(length);
  67870. var segmentLength = 4 * Math.ceil(length / 4 / threads);
  67871. for (var i = 0; i < threads; ++i) {
  67872. var buffer = this._dataLookup[i]['buffer'];
  67873. var offset = i * segmentLength;
  67874. data.set(new Uint8ClampedArray(buffer), offset);
  67875. meta[i] = this._dataLookup[i]['meta'];
  67876. }
  67877. }
  67878. this._job = null;
  67879. this._dataLookup = {};
  67880. job.callback(null,
  67881. newImageData(data, job.inputs[0].width, job.inputs[0].height), meta);
  67882. this._dispatch();
  67883. };
  67884. var processor = Processor;
  67885. var Processor_1 = processor;
  67886. var lib = {
  67887. Processor: Processor_1
  67888. };
  67889. exports['default'] = lib;
  67890. exports.Processor = Processor_1;
  67891. }((this.pixelworks = this.pixelworks || {})));}).call(ol.ext);
  67892. goog.provide('ol.source.RasterOperationType');
  67893. /**
  67894. * Raster operation type. Supported values are `'pixel'` and `'image'`.
  67895. * @enum {string}
  67896. */
  67897. ol.source.RasterOperationType = {
  67898. PIXEL: 'pixel',
  67899. IMAGE: 'image'
  67900. };
  67901. goog.provide('ol.source.Raster');
  67902. goog.require('ol');
  67903. goog.require('ol.ImageCanvas');
  67904. goog.require('ol.TileQueue');
  67905. goog.require('ol.dom');
  67906. goog.require('ol.events');
  67907. goog.require('ol.events.Event');
  67908. goog.require('ol.events.EventType');
  67909. goog.require('ol.ext.pixelworks.Processor');
  67910. goog.require('ol.extent');
  67911. goog.require('ol.layer.Image');
  67912. goog.require('ol.layer.Tile');
  67913. goog.require('ol.obj');
  67914. goog.require('ol.renderer.canvas.ImageLayer');
  67915. goog.require('ol.renderer.canvas.TileLayer');
  67916. goog.require('ol.source.Image');
  67917. goog.require('ol.source.RasterOperationType');
  67918. goog.require('ol.source.State');
  67919. goog.require('ol.source.Tile');
  67920. goog.require('ol.transform');
  67921. /**
  67922. * @classdesc
  67923. * A source that transforms data from any number of input sources using an
  67924. * {@link ol.RasterOperation} function to transform input pixel values into
  67925. * output pixel values.
  67926. *
  67927. * @constructor
  67928. * @extends {ol.source.Image}
  67929. * @fires ol.source.Raster.Event
  67930. * @param {olx.source.RasterOptions} options Options.
  67931. * @api
  67932. */
  67933. ol.source.Raster = function(options) {
  67934. /**
  67935. * @private
  67936. * @type {*}
  67937. */
  67938. this.worker_ = null;
  67939. /**
  67940. * @private
  67941. * @type {ol.source.RasterOperationType}
  67942. */
  67943. this.operationType_ = options.operationType !== undefined ?
  67944. options.operationType : ol.source.RasterOperationType.PIXEL;
  67945. /**
  67946. * @private
  67947. * @type {number}
  67948. */
  67949. this.threads_ = options.threads !== undefined ? options.threads : 1;
  67950. /**
  67951. * @private
  67952. * @type {Array.<ol.renderer.canvas.Layer>}
  67953. */
  67954. this.renderers_ = ol.source.Raster.createRenderers_(options.sources);
  67955. for (var r = 0, rr = this.renderers_.length; r < rr; ++r) {
  67956. ol.events.listen(this.renderers_[r], ol.events.EventType.CHANGE,
  67957. this.changed, this);
  67958. }
  67959. /**
  67960. * @private
  67961. * @type {ol.TileQueue}
  67962. */
  67963. this.tileQueue_ = new ol.TileQueue(
  67964. function() {
  67965. return 1;
  67966. },
  67967. this.changed.bind(this));
  67968. var layerStatesArray = ol.source.Raster.getLayerStatesArray_(this.renderers_);
  67969. var layerStates = {};
  67970. for (var i = 0, ii = layerStatesArray.length; i < ii; ++i) {
  67971. layerStates[ol.getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
  67972. }
  67973. /**
  67974. * The most recently requested frame state.
  67975. * @type {olx.FrameState}
  67976. * @private
  67977. */
  67978. this.requestedFrameState_;
  67979. /**
  67980. * The most recently rendered image canvas.
  67981. * @type {ol.ImageCanvas}
  67982. * @private
  67983. */
  67984. this.renderedImageCanvas_ = null;
  67985. /**
  67986. * The most recently rendered revision.
  67987. * @type {number}
  67988. */
  67989. this.renderedRevision_;
  67990. /**
  67991. * @private
  67992. * @type {olx.FrameState}
  67993. */
  67994. this.frameState_ = {
  67995. animate: false,
  67996. coordinateToPixelTransform: ol.transform.create(),
  67997. extent: null,
  67998. focus: null,
  67999. index: 0,
  68000. layerStates: layerStates,
  68001. layerStatesArray: layerStatesArray,
  68002. logos: {},
  68003. pixelRatio: 1,
  68004. pixelToCoordinateTransform: ol.transform.create(),
  68005. postRenderFunctions: [],
  68006. size: [0, 0],
  68007. skippedFeatureUids: {},
  68008. tileQueue: this.tileQueue_,
  68009. time: Date.now(),
  68010. usedTiles: {},
  68011. viewState: /** @type {olx.ViewState} */ ({
  68012. rotation: 0
  68013. }),
  68014. viewHints: [],
  68015. wantedTiles: {}
  68016. };
  68017. ol.source.Image.call(this, {});
  68018. if (options.operation !== undefined) {
  68019. this.setOperation(options.operation, options.lib);
  68020. }
  68021. };
  68022. ol.inherits(ol.source.Raster, ol.source.Image);
  68023. /**
  68024. * Set the operation.
  68025. * @param {ol.RasterOperation} operation New operation.
  68026. * @param {Object=} opt_lib Functions that will be available to operations run
  68027. * in a worker.
  68028. * @api
  68029. */
  68030. ol.source.Raster.prototype.setOperation = function(operation, opt_lib) {
  68031. this.worker_ = new ol.ext.pixelworks.Processor({
  68032. operation: operation,
  68033. imageOps: this.operationType_ === ol.source.RasterOperationType.IMAGE,
  68034. queue: 1,
  68035. lib: opt_lib,
  68036. threads: this.threads_
  68037. });
  68038. this.changed();
  68039. };
  68040. /**
  68041. * Update the stored frame state.
  68042. * @param {ol.Extent} extent The view extent (in map units).
  68043. * @param {number} resolution The view resolution.
  68044. * @param {ol.proj.Projection} projection The view projection.
  68045. * @return {olx.FrameState} The updated frame state.
  68046. * @private
  68047. */
  68048. ol.source.Raster.prototype.updateFrameState_ = function(extent, resolution, projection) {
  68049. var frameState = /** @type {olx.FrameState} */ (
  68050. ol.obj.assign({}, this.frameState_));
  68051. frameState.viewState = /** @type {olx.ViewState} */ (
  68052. ol.obj.assign({}, frameState.viewState));
  68053. var center = ol.extent.getCenter(extent);
  68054. frameState.extent = extent.slice();
  68055. frameState.focus = center;
  68056. frameState.size[0] = Math.round(ol.extent.getWidth(extent) / resolution);
  68057. frameState.size[1] = Math.round(ol.extent.getHeight(extent) / resolution);
  68058. frameState.time = Date.now();
  68059. frameState.animate = false;
  68060. var viewState = frameState.viewState;
  68061. viewState.center = center;
  68062. viewState.projection = projection;
  68063. viewState.resolution = resolution;
  68064. return frameState;
  68065. };
  68066. /**
  68067. * Determine if all sources are ready.
  68068. * @return {boolean} All sources are ready.
  68069. * @private
  68070. */
  68071. ol.source.Raster.prototype.allSourcesReady_ = function() {
  68072. var ready = true;
  68073. var source;
  68074. for (var i = 0, ii = this.renderers_.length; i < ii; ++i) {
  68075. source = this.renderers_[i].getLayer().getSource();
  68076. if (source.getState() !== ol.source.State.READY) {
  68077. ready = false;
  68078. break;
  68079. }
  68080. }
  68081. return ready;
  68082. };
  68083. /**
  68084. * @inheritDoc
  68085. */
  68086. ol.source.Raster.prototype.getImage = function(extent, resolution, pixelRatio, projection) {
  68087. if (!this.allSourcesReady_()) {
  68088. return null;
  68089. }
  68090. var frameState = this.updateFrameState_(extent, resolution, projection);
  68091. this.requestedFrameState_ = frameState;
  68092. // check if we can't reuse the existing ol.ImageCanvas
  68093. if (this.renderedImageCanvas_) {
  68094. var renderedResolution = this.renderedImageCanvas_.getResolution();
  68095. var renderedExtent = this.renderedImageCanvas_.getExtent();
  68096. if (resolution !== renderedResolution || !ol.extent.equals(extent, renderedExtent)) {
  68097. this.renderedImageCanvas_ = null;
  68098. }
  68099. }
  68100. if (!this.renderedImageCanvas_ || this.getRevision() !== this.renderedRevision_) {
  68101. this.processSources_();
  68102. }
  68103. frameState.tileQueue.loadMoreTiles(16, 16);
  68104. if (frameState.animate) {
  68105. requestAnimationFrame(this.changed.bind(this));
  68106. }
  68107. return this.renderedImageCanvas_;
  68108. };
  68109. /**
  68110. * Start processing source data.
  68111. * @private
  68112. */
  68113. ol.source.Raster.prototype.processSources_ = function() {
  68114. var frameState = this.requestedFrameState_;
  68115. var len = this.renderers_.length;
  68116. var imageDatas = new Array(len);
  68117. for (var i = 0; i < len; ++i) {
  68118. var imageData = ol.source.Raster.getImageData_(
  68119. this.renderers_[i], frameState, frameState.layerStatesArray[i]);
  68120. if (imageData) {
  68121. imageDatas[i] = imageData;
  68122. } else {
  68123. return;
  68124. }
  68125. }
  68126. var data = {};
  68127. this.dispatchEvent(new ol.source.Raster.Event(
  68128. ol.source.Raster.EventType_.BEFOREOPERATIONS, frameState, data));
  68129. this.worker_.process(imageDatas, data,
  68130. this.onWorkerComplete_.bind(this, frameState));
  68131. };
  68132. /**
  68133. * Called when pixel processing is complete.
  68134. * @param {olx.FrameState} frameState The frame state.
  68135. * @param {Error} err Any error during processing.
  68136. * @param {ImageData} output The output image data.
  68137. * @param {Object} data The user data.
  68138. * @private
  68139. */
  68140. ol.source.Raster.prototype.onWorkerComplete_ = function(frameState, err, output, data) {
  68141. if (err || !output) {
  68142. return;
  68143. }
  68144. // do nothing if extent or resolution changed
  68145. var extent = frameState.extent;
  68146. var resolution = frameState.viewState.resolution;
  68147. if (resolution !== this.requestedFrameState_.viewState.resolution ||
  68148. !ol.extent.equals(extent, this.requestedFrameState_.extent)) {
  68149. return;
  68150. }
  68151. var context;
  68152. if (this.renderedImageCanvas_) {
  68153. context = this.renderedImageCanvas_.getImage().getContext('2d');
  68154. } else {
  68155. var width = Math.round(ol.extent.getWidth(extent) / resolution);
  68156. var height = Math.round(ol.extent.getHeight(extent) / resolution);
  68157. context = ol.dom.createCanvasContext2D(width, height);
  68158. this.renderedImageCanvas_ = new ol.ImageCanvas(extent, resolution, 1, context.canvas);
  68159. }
  68160. context.putImageData(output, 0, 0);
  68161. this.changed();
  68162. this.renderedRevision_ = this.getRevision();
  68163. this.dispatchEvent(new ol.source.Raster.Event(
  68164. ol.source.Raster.EventType_.AFTEROPERATIONS, frameState, data));
  68165. };
  68166. /**
  68167. * Get image data from a renderer.
  68168. * @param {ol.renderer.canvas.Layer} renderer Layer renderer.
  68169. * @param {olx.FrameState} frameState The frame state.
  68170. * @param {ol.LayerState} layerState The layer state.
  68171. * @return {ImageData} The image data.
  68172. * @private
  68173. */
  68174. ol.source.Raster.getImageData_ = function(renderer, frameState, layerState) {
  68175. if (!renderer.prepareFrame(frameState, layerState)) {
  68176. return null;
  68177. }
  68178. var width = frameState.size[0];
  68179. var height = frameState.size[1];
  68180. if (!ol.source.Raster.context_) {
  68181. ol.source.Raster.context_ = ol.dom.createCanvasContext2D(width, height);
  68182. } else {
  68183. var canvas = ol.source.Raster.context_.canvas;
  68184. if (canvas.width !== width || canvas.height !== height) {
  68185. ol.source.Raster.context_ = ol.dom.createCanvasContext2D(width, height);
  68186. } else {
  68187. ol.source.Raster.context_.clearRect(0, 0, width, height);
  68188. }
  68189. }
  68190. renderer.composeFrame(frameState, layerState, ol.source.Raster.context_);
  68191. return ol.source.Raster.context_.getImageData(0, 0, width, height);
  68192. };
  68193. /**
  68194. * A reusable canvas context.
  68195. * @type {CanvasRenderingContext2D}
  68196. * @private
  68197. */
  68198. ol.source.Raster.context_ = null;
  68199. /**
  68200. * Get a list of layer states from a list of renderers.
  68201. * @param {Array.<ol.renderer.canvas.Layer>} renderers Layer renderers.
  68202. * @return {Array.<ol.LayerState>} The layer states.
  68203. * @private
  68204. */
  68205. ol.source.Raster.getLayerStatesArray_ = function(renderers) {
  68206. return renderers.map(function(renderer) {
  68207. return renderer.getLayer().getLayerState();
  68208. });
  68209. };
  68210. /**
  68211. * Create renderers for all sources.
  68212. * @param {Array.<ol.source.Source>} sources The sources.
  68213. * @return {Array.<ol.renderer.canvas.Layer>} Array of layer renderers.
  68214. * @private
  68215. */
  68216. ol.source.Raster.createRenderers_ = function(sources) {
  68217. var len = sources.length;
  68218. var renderers = new Array(len);
  68219. for (var i = 0; i < len; ++i) {
  68220. renderers[i] = ol.source.Raster.createRenderer_(sources[i]);
  68221. }
  68222. return renderers;
  68223. };
  68224. /**
  68225. * Create a renderer for the provided source.
  68226. * @param {ol.source.Source} source The source.
  68227. * @return {ol.renderer.canvas.Layer} The renderer.
  68228. * @private
  68229. */
  68230. ol.source.Raster.createRenderer_ = function(source) {
  68231. var renderer = null;
  68232. if (source instanceof ol.source.Tile) {
  68233. renderer = ol.source.Raster.createTileRenderer_(source);
  68234. } else if (source instanceof ol.source.Image) {
  68235. renderer = ol.source.Raster.createImageRenderer_(source);
  68236. }
  68237. return renderer;
  68238. };
  68239. /**
  68240. * Create an image renderer for the provided source.
  68241. * @param {ol.source.Image} source The source.
  68242. * @return {ol.renderer.canvas.Layer} The renderer.
  68243. * @private
  68244. */
  68245. ol.source.Raster.createImageRenderer_ = function(source) {
  68246. var layer = new ol.layer.Image({source: source});
  68247. return new ol.renderer.canvas.ImageLayer(layer);
  68248. };
  68249. /**
  68250. * Create a tile renderer for the provided source.
  68251. * @param {ol.source.Tile} source The source.
  68252. * @return {ol.renderer.canvas.Layer} The renderer.
  68253. * @private
  68254. */
  68255. ol.source.Raster.createTileRenderer_ = function(source) {
  68256. var layer = new ol.layer.Tile({source: source});
  68257. return new ol.renderer.canvas.TileLayer(layer);
  68258. };
  68259. /**
  68260. * @classdesc
  68261. * Events emitted by {@link ol.source.Raster} instances are instances of this
  68262. * type.
  68263. *
  68264. * @constructor
  68265. * @extends {ol.events.Event}
  68266. * @implements {oli.source.RasterEvent}
  68267. * @param {string} type Type.
  68268. * @param {olx.FrameState} frameState The frame state.
  68269. * @param {Object} data An object made available to operations.
  68270. */
  68271. ol.source.Raster.Event = function(type, frameState, data) {
  68272. ol.events.Event.call(this, type);
  68273. /**
  68274. * The raster extent.
  68275. * @type {ol.Extent}
  68276. * @api
  68277. */
  68278. this.extent = frameState.extent;
  68279. /**
  68280. * The pixel resolution (map units per pixel).
  68281. * @type {number}
  68282. * @api
  68283. */
  68284. this.resolution = frameState.viewState.resolution / frameState.pixelRatio;
  68285. /**
  68286. * An object made available to all operations. This can be used by operations
  68287. * as a storage object (e.g. for calculating statistics).
  68288. * @type {Object}
  68289. * @api
  68290. */
  68291. this.data = data;
  68292. };
  68293. ol.inherits(ol.source.Raster.Event, ol.events.Event);
  68294. /**
  68295. * @override
  68296. */
  68297. ol.source.Raster.prototype.getImageInternal = function() {
  68298. return null; // not implemented
  68299. };
  68300. /**
  68301. * @enum {string}
  68302. * @private
  68303. */
  68304. ol.source.Raster.EventType_ = {
  68305. /**
  68306. * Triggered before operations are run.
  68307. * @event ol.source.Raster.Event#beforeoperations
  68308. * @api
  68309. */
  68310. BEFOREOPERATIONS: 'beforeoperations',
  68311. /**
  68312. * Triggered after operations are run.
  68313. * @event ol.source.Raster.Event#afteroperations
  68314. * @api
  68315. */
  68316. AFTEROPERATIONS: 'afteroperations'
  68317. };
  68318. goog.provide('ol.source.Stamen');
  68319. goog.require('ol');
  68320. goog.require('ol.source.OSM');
  68321. goog.require('ol.source.XYZ');
  68322. /**
  68323. * @classdesc
  68324. * Layer source for the Stamen tile server.
  68325. *
  68326. * @constructor
  68327. * @extends {ol.source.XYZ}
  68328. * @param {olx.source.StamenOptions} options Stamen options.
  68329. * @api
  68330. */
  68331. ol.source.Stamen = function(options) {
  68332. var i = options.layer.indexOf('-');
  68333. var provider = i == -1 ? options.layer : options.layer.slice(0, i);
  68334. var providerConfig = ol.source.Stamen.ProviderConfig[provider];
  68335. var layerConfig = ol.source.Stamen.LayerConfig[options.layer];
  68336. var url = options.url !== undefined ? options.url :
  68337. 'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer +
  68338. '/{z}/{x}/{y}.' + layerConfig.extension;
  68339. ol.source.XYZ.call(this, {
  68340. attributions: ol.source.Stamen.ATTRIBUTIONS,
  68341. cacheSize: options.cacheSize,
  68342. crossOrigin: 'anonymous',
  68343. maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom,
  68344. minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom,
  68345. opaque: layerConfig.opaque,
  68346. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  68347. tileLoadFunction: options.tileLoadFunction,
  68348. url: url,
  68349. wrapX: options.wrapX
  68350. });
  68351. };
  68352. ol.inherits(ol.source.Stamen, ol.source.XYZ);
  68353. /**
  68354. * @const
  68355. * @type {Array.<string>}
  68356. */
  68357. ol.source.Stamen.ATTRIBUTIONS = [
  68358. 'Map tiles by <a href="https://stamen.com/">Stamen Design</a>, ' +
  68359. 'under <a href="https://creativecommons.org/licenses/by/3.0/">CC BY' +
  68360. ' 3.0</a>.',
  68361. ol.source.OSM.ATTRIBUTION
  68362. ];
  68363. /**
  68364. * @type {Object.<string, {extension: string, opaque: boolean}>}
  68365. */
  68366. ol.source.Stamen.LayerConfig = {
  68367. 'terrain': {
  68368. extension: 'jpg',
  68369. opaque: true
  68370. },
  68371. 'terrain-background': {
  68372. extension: 'jpg',
  68373. opaque: true
  68374. },
  68375. 'terrain-labels': {
  68376. extension: 'png',
  68377. opaque: false
  68378. },
  68379. 'terrain-lines': {
  68380. extension: 'png',
  68381. opaque: false
  68382. },
  68383. 'toner-background': {
  68384. extension: 'png',
  68385. opaque: true
  68386. },
  68387. 'toner': {
  68388. extension: 'png',
  68389. opaque: true
  68390. },
  68391. 'toner-hybrid': {
  68392. extension: 'png',
  68393. opaque: false
  68394. },
  68395. 'toner-labels': {
  68396. extension: 'png',
  68397. opaque: false
  68398. },
  68399. 'toner-lines': {
  68400. extension: 'png',
  68401. opaque: false
  68402. },
  68403. 'toner-lite': {
  68404. extension: 'png',
  68405. opaque: true
  68406. },
  68407. 'watercolor': {
  68408. extension: 'jpg',
  68409. opaque: true
  68410. }
  68411. };
  68412. /**
  68413. * @type {Object.<string, {minZoom: number, maxZoom: number}>}
  68414. */
  68415. ol.source.Stamen.ProviderConfig = {
  68416. 'terrain': {
  68417. minZoom: 4,
  68418. maxZoom: 18
  68419. },
  68420. 'toner': {
  68421. minZoom: 0,
  68422. maxZoom: 20
  68423. },
  68424. 'watercolor': {
  68425. minZoom: 1,
  68426. maxZoom: 16
  68427. }
  68428. };
  68429. goog.provide('ol.source.TileArcGISRest');
  68430. goog.require('ol');
  68431. goog.require('ol.extent');
  68432. goog.require('ol.math');
  68433. goog.require('ol.obj');
  68434. goog.require('ol.size');
  68435. goog.require('ol.source.TileImage');
  68436. goog.require('ol.tilecoord');
  68437. goog.require('ol.uri');
  68438. /**
  68439. * @classdesc
  68440. * Layer source for tile data from ArcGIS Rest services. Map and Image
  68441. * Services are supported.
  68442. *
  68443. * For cached ArcGIS services, better performance is available using the
  68444. * {@link ol.source.XYZ} data source.
  68445. *
  68446. * @constructor
  68447. * @extends {ol.source.TileImage}
  68448. * @param {olx.source.TileArcGISRestOptions=} opt_options Tile ArcGIS Rest
  68449. * options.
  68450. * @api
  68451. */
  68452. ol.source.TileArcGISRest = function(opt_options) {
  68453. var options = opt_options || {};
  68454. ol.source.TileImage.call(this, {
  68455. attributions: options.attributions,
  68456. cacheSize: options.cacheSize,
  68457. crossOrigin: options.crossOrigin,
  68458. logo: options.logo,
  68459. projection: options.projection,
  68460. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  68461. tileGrid: options.tileGrid,
  68462. tileLoadFunction: options.tileLoadFunction,
  68463. url: options.url,
  68464. urls: options.urls,
  68465. wrapX: options.wrapX !== undefined ? options.wrapX : true,
  68466. transition: options.transition
  68467. });
  68468. /**
  68469. * @private
  68470. * @type {!Object}
  68471. */
  68472. this.params_ = options.params || {};
  68473. /**
  68474. * @private
  68475. * @type {ol.Extent}
  68476. */
  68477. this.tmpExtent_ = ol.extent.createEmpty();
  68478. this.setKey(this.getKeyForParams_());
  68479. };
  68480. ol.inherits(ol.source.TileArcGISRest, ol.source.TileImage);
  68481. /**
  68482. * @private
  68483. * @return {string} The key for the current params.
  68484. */
  68485. ol.source.TileArcGISRest.prototype.getKeyForParams_ = function() {
  68486. var i = 0;
  68487. var res = [];
  68488. for (var key in this.params_) {
  68489. res[i++] = key + '-' + this.params_[key];
  68490. }
  68491. return res.join('/');
  68492. };
  68493. /**
  68494. * Get the user-provided params, i.e. those passed to the constructor through
  68495. * the "params" option, and possibly updated using the updateParams method.
  68496. * @return {Object} Params.
  68497. * @api
  68498. */
  68499. ol.source.TileArcGISRest.prototype.getParams = function() {
  68500. return this.params_;
  68501. };
  68502. /**
  68503. * @param {ol.TileCoord} tileCoord Tile coordinate.
  68504. * @param {ol.Size} tileSize Tile size.
  68505. * @param {ol.Extent} tileExtent Tile extent.
  68506. * @param {number} pixelRatio Pixel ratio.
  68507. * @param {ol.proj.Projection} projection Projection.
  68508. * @param {Object} params Params.
  68509. * @return {string|undefined} Request URL.
  68510. * @private
  68511. */
  68512. ol.source.TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExtent,
  68513. pixelRatio, projection, params) {
  68514. var urls = this.urls;
  68515. if (!urls) {
  68516. return undefined;
  68517. }
  68518. // ArcGIS Server only wants the numeric portion of the projection ID.
  68519. var srid = projection.getCode().split(':').pop();
  68520. params['SIZE'] = tileSize[0] + ',' + tileSize[1];
  68521. params['BBOX'] = tileExtent.join(',');
  68522. params['BBOXSR'] = srid;
  68523. params['IMAGESR'] = srid;
  68524. params['DPI'] = Math.round(
  68525. params['DPI'] ? params['DPI'] * pixelRatio : 90 * pixelRatio
  68526. );
  68527. var url;
  68528. if (urls.length == 1) {
  68529. url = urls[0];
  68530. } else {
  68531. var index = ol.math.modulo(ol.tilecoord.hash(tileCoord), urls.length);
  68532. url = urls[index];
  68533. }
  68534. var modifiedUrl = url
  68535. .replace(/MapServer\/?$/, 'MapServer/export')
  68536. .replace(/ImageServer\/?$/, 'ImageServer/exportImage');
  68537. return ol.uri.appendParams(modifiedUrl, params);
  68538. };
  68539. /**
  68540. * @inheritDoc
  68541. */
  68542. ol.source.TileArcGISRest.prototype.getTilePixelRatio = function(pixelRatio) {
  68543. return /** @type {number} */ (pixelRatio);
  68544. };
  68545. /**
  68546. * @inheritDoc
  68547. */
  68548. ol.source.TileArcGISRest.prototype.fixedTileUrlFunction = function(tileCoord, pixelRatio, projection) {
  68549. var tileGrid = this.getTileGrid();
  68550. if (!tileGrid) {
  68551. tileGrid = this.getTileGridForProjection(projection);
  68552. }
  68553. if (tileGrid.getResolutions().length <= tileCoord[0]) {
  68554. return undefined;
  68555. }
  68556. var tileExtent = tileGrid.getTileCoordExtent(
  68557. tileCoord, this.tmpExtent_);
  68558. var tileSize = ol.size.toSize(
  68559. tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
  68560. if (pixelRatio != 1) {
  68561. tileSize = ol.size.scale(tileSize, pixelRatio, this.tmpSize);
  68562. }
  68563. // Apply default params and override with user specified values.
  68564. var baseParams = {
  68565. 'F': 'image',
  68566. 'FORMAT': 'PNG32',
  68567. 'TRANSPARENT': true
  68568. };
  68569. ol.obj.assign(baseParams, this.params_);
  68570. return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
  68571. pixelRatio, projection, baseParams);
  68572. };
  68573. /**
  68574. * Update the user-provided params.
  68575. * @param {Object} params Params.
  68576. * @api
  68577. */
  68578. ol.source.TileArcGISRest.prototype.updateParams = function(params) {
  68579. ol.obj.assign(this.params_, params);
  68580. this.setKey(this.getKeyForParams_());
  68581. };
  68582. goog.provide('ol.source.TileDebug');
  68583. goog.require('ol');
  68584. goog.require('ol.Tile');
  68585. goog.require('ol.TileState');
  68586. goog.require('ol.dom');
  68587. goog.require('ol.size');
  68588. goog.require('ol.source.Tile');
  68589. goog.require('ol.tilecoord');
  68590. /**
  68591. * @classdesc
  68592. * A pseudo tile source, which does not fetch tiles from a server, but renders
  68593. * a grid outline for the tile grid/projection along with the coordinates for
  68594. * each tile. See examples/canvas-tiles for an example.
  68595. *
  68596. * Uses Canvas context2d, so requires Canvas support.
  68597. *
  68598. * @constructor
  68599. * @extends {ol.source.Tile}
  68600. * @param {olx.source.TileDebugOptions} options Debug tile options.
  68601. * @api
  68602. */
  68603. ol.source.TileDebug = function(options) {
  68604. ol.source.Tile.call(this, {
  68605. opaque: false,
  68606. projection: options.projection,
  68607. tileGrid: options.tileGrid,
  68608. wrapX: options.wrapX !== undefined ? options.wrapX : true
  68609. });
  68610. };
  68611. ol.inherits(ol.source.TileDebug, ol.source.Tile);
  68612. /**
  68613. * @inheritDoc
  68614. */
  68615. ol.source.TileDebug.prototype.getTile = function(z, x, y) {
  68616. var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  68617. if (this.tileCache.containsKey(tileCoordKey)) {
  68618. return /** @type {!ol.source.TileDebug.Tile_} */ (this.tileCache.get(tileCoordKey));
  68619. } else {
  68620. var tileSize = ol.size.toSize(this.tileGrid.getTileSize(z));
  68621. var tileCoord = [z, x, y];
  68622. var textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord);
  68623. var text = !textTileCoord ? '' :
  68624. this.getTileCoordForTileUrlFunction(textTileCoord).toString();
  68625. var tile = new ol.source.TileDebug.Tile_(tileCoord, tileSize, text);
  68626. this.tileCache.set(tileCoordKey, tile);
  68627. return tile;
  68628. }
  68629. };
  68630. /**
  68631. * @constructor
  68632. * @extends {ol.Tile}
  68633. * @param {ol.TileCoord} tileCoord Tile coordinate.
  68634. * @param {ol.Size} tileSize Tile size.
  68635. * @param {string} text Text.
  68636. * @private
  68637. */
  68638. ol.source.TileDebug.Tile_ = function(tileCoord, tileSize, text) {
  68639. ol.Tile.call(this, tileCoord, ol.TileState.LOADED);
  68640. /**
  68641. * @private
  68642. * @type {ol.Size}
  68643. */
  68644. this.tileSize_ = tileSize;
  68645. /**
  68646. * @private
  68647. * @type {string}
  68648. */
  68649. this.text_ = text;
  68650. /**
  68651. * @private
  68652. * @type {HTMLCanvasElement}
  68653. */
  68654. this.canvas_ = null;
  68655. };
  68656. ol.inherits(ol.source.TileDebug.Tile_, ol.Tile);
  68657. /**
  68658. * Get the image element for this tile.
  68659. * @return {HTMLCanvasElement} Image.
  68660. */
  68661. ol.source.TileDebug.Tile_.prototype.getImage = function() {
  68662. if (this.canvas_) {
  68663. return this.canvas_;
  68664. } else {
  68665. var tileSize = this.tileSize_;
  68666. var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
  68667. context.strokeStyle = 'black';
  68668. context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
  68669. context.fillStyle = 'black';
  68670. context.textAlign = 'center';
  68671. context.textBaseline = 'middle';
  68672. context.font = '24px sans-serif';
  68673. context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
  68674. this.canvas_ = context.canvas;
  68675. return context.canvas;
  68676. }
  68677. };
  68678. /**
  68679. * @override
  68680. */
  68681. ol.source.TileDebug.Tile_.prototype.load = function() {};
  68682. // FIXME check order of async callbacks
  68683. /**
  68684. * @see http://mapbox.com/developers/api/
  68685. */
  68686. goog.provide('ol.source.TileJSON');
  68687. goog.require('ol');
  68688. goog.require('ol.TileUrlFunction');
  68689. goog.require('ol.asserts');
  68690. goog.require('ol.extent');
  68691. goog.require('ol.net');
  68692. goog.require('ol.proj');
  68693. goog.require('ol.source.State');
  68694. goog.require('ol.source.TileImage');
  68695. goog.require('ol.tilegrid');
  68696. /**
  68697. * @classdesc
  68698. * Layer source for tile data in TileJSON format.
  68699. *
  68700. * @constructor
  68701. * @extends {ol.source.TileImage}
  68702. * @param {olx.source.TileJSONOptions} options TileJSON options.
  68703. * @api
  68704. */
  68705. ol.source.TileJSON = function(options) {
  68706. /**
  68707. * @type {TileJSON}
  68708. * @private
  68709. */
  68710. this.tileJSON_ = null;
  68711. ol.source.TileImage.call(this, {
  68712. attributions: options.attributions,
  68713. cacheSize: options.cacheSize,
  68714. crossOrigin: options.crossOrigin,
  68715. projection: ol.proj.get('EPSG:3857'),
  68716. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  68717. state: ol.source.State.LOADING,
  68718. tileLoadFunction: options.tileLoadFunction,
  68719. wrapX: options.wrapX !== undefined ? options.wrapX : true,
  68720. transition: options.transition
  68721. });
  68722. if (options.url) {
  68723. if (options.jsonp) {
  68724. ol.net.jsonp(options.url, this.handleTileJSONResponse.bind(this),
  68725. this.handleTileJSONError.bind(this));
  68726. } else {
  68727. var client = new XMLHttpRequest();
  68728. client.addEventListener('load', this.onXHRLoad_.bind(this));
  68729. client.addEventListener('error', this.onXHRError_.bind(this));
  68730. client.open('GET', options.url);
  68731. client.send();
  68732. }
  68733. } else if (options.tileJSON) {
  68734. this.handleTileJSONResponse(options.tileJSON);
  68735. } else {
  68736. ol.asserts.assert(false, 51); // Either `url` or `tileJSON` options must be provided
  68737. }
  68738. };
  68739. ol.inherits(ol.source.TileJSON, ol.source.TileImage);
  68740. /**
  68741. * @private
  68742. * @param {Event} event The load event.
  68743. */
  68744. ol.source.TileJSON.prototype.onXHRLoad_ = function(event) {
  68745. var client = /** @type {XMLHttpRequest} */ (event.target);
  68746. // status will be 0 for file:// urls
  68747. if (!client.status || client.status >= 200 && client.status < 300) {
  68748. var response;
  68749. try {
  68750. response = /** @type {TileJSON} */(JSON.parse(client.responseText));
  68751. } catch (err) {
  68752. this.handleTileJSONError();
  68753. return;
  68754. }
  68755. this.handleTileJSONResponse(response);
  68756. } else {
  68757. this.handleTileJSONError();
  68758. }
  68759. };
  68760. /**
  68761. * @private
  68762. * @param {Event} event The error event.
  68763. */
  68764. ol.source.TileJSON.prototype.onXHRError_ = function(event) {
  68765. this.handleTileJSONError();
  68766. };
  68767. /**
  68768. * @return {TileJSON} The tilejson object.
  68769. * @api
  68770. */
  68771. ol.source.TileJSON.prototype.getTileJSON = function() {
  68772. return this.tileJSON_;
  68773. };
  68774. /**
  68775. * @protected
  68776. * @param {TileJSON} tileJSON Tile JSON.
  68777. */
  68778. ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
  68779. var epsg4326Projection = ol.proj.get('EPSG:4326');
  68780. var sourceProjection = this.getProjection();
  68781. var extent;
  68782. if (tileJSON.bounds !== undefined) {
  68783. var transform = ol.proj.getTransformFromProjections(
  68784. epsg4326Projection, sourceProjection);
  68785. extent = ol.extent.applyTransform(tileJSON.bounds, transform);
  68786. }
  68787. var minZoom = tileJSON.minzoom || 0;
  68788. var maxZoom = tileJSON.maxzoom || 22;
  68789. var tileGrid = ol.tilegrid.createXYZ({
  68790. extent: ol.tilegrid.extentFromProjection(sourceProjection),
  68791. maxZoom: maxZoom,
  68792. minZoom: minZoom
  68793. });
  68794. this.tileGrid = tileGrid;
  68795. this.tileUrlFunction =
  68796. ol.TileUrlFunction.createFromTemplates(tileJSON.tiles, tileGrid);
  68797. if (tileJSON.attribution !== undefined && !this.getAttributions2()) {
  68798. var attributionExtent = extent !== undefined ?
  68799. extent : epsg4326Projection.getExtent();
  68800. this.setAttributions(function(frameState) {
  68801. if (ol.extent.intersects(attributionExtent, frameState.extent)) {
  68802. return [tileJSON.attribution];
  68803. }
  68804. return null;
  68805. });
  68806. }
  68807. this.tileJSON_ = tileJSON;
  68808. this.setState(ol.source.State.READY);
  68809. };
  68810. /**
  68811. * @protected
  68812. */
  68813. ol.source.TileJSON.prototype.handleTileJSONError = function() {
  68814. this.setState(ol.source.State.ERROR);
  68815. };
  68816. goog.provide('ol.source.TileUTFGrid');
  68817. goog.require('ol');
  68818. goog.require('ol.Tile');
  68819. goog.require('ol.TileState');
  68820. goog.require('ol.TileUrlFunction');
  68821. goog.require('ol.asserts');
  68822. goog.require('ol.events');
  68823. goog.require('ol.events.EventType');
  68824. goog.require('ol.extent');
  68825. goog.require('ol.net');
  68826. goog.require('ol.proj');
  68827. goog.require('ol.source.State');
  68828. goog.require('ol.source.Tile');
  68829. goog.require('ol.tilecoord');
  68830. goog.require('ol.tilegrid');
  68831. /**
  68832. * @classdesc
  68833. * Layer source for UTFGrid interaction data loaded from TileJSON format.
  68834. *
  68835. * @constructor
  68836. * @extends {ol.source.Tile}
  68837. * @param {olx.source.TileUTFGridOptions} options Source options.
  68838. * @api
  68839. */
  68840. ol.source.TileUTFGrid = function(options) {
  68841. ol.source.Tile.call(this, {
  68842. projection: ol.proj.get('EPSG:3857'),
  68843. state: ol.source.State.LOADING
  68844. });
  68845. /**
  68846. * @private
  68847. * @type {boolean}
  68848. */
  68849. this.preemptive_ = options.preemptive !== undefined ?
  68850. options.preemptive : true;
  68851. /**
  68852. * @private
  68853. * @type {!ol.TileUrlFunctionType}
  68854. */
  68855. this.tileUrlFunction_ = ol.TileUrlFunction.nullTileUrlFunction;
  68856. /**
  68857. * @private
  68858. * @type {string|undefined}
  68859. */
  68860. this.template_ = undefined;
  68861. /**
  68862. * @private
  68863. * @type {boolean}
  68864. */
  68865. this.jsonp_ = options.jsonp || false;
  68866. if (options.url) {
  68867. if (this.jsonp_) {
  68868. ol.net.jsonp(options.url, this.handleTileJSONResponse.bind(this),
  68869. this.handleTileJSONError.bind(this));
  68870. } else {
  68871. var client = new XMLHttpRequest();
  68872. client.addEventListener('load', this.onXHRLoad_.bind(this));
  68873. client.addEventListener('error', this.onXHRError_.bind(this));
  68874. client.open('GET', options.url);
  68875. client.send();
  68876. }
  68877. } else if (options.tileJSON) {
  68878. this.handleTileJSONResponse(options.tileJSON);
  68879. } else {
  68880. ol.asserts.assert(false, 51); // Either `url` or `tileJSON` options must be provided
  68881. }
  68882. };
  68883. ol.inherits(ol.source.TileUTFGrid, ol.source.Tile);
  68884. /**
  68885. * @private
  68886. * @param {Event} event The load event.
  68887. */
  68888. ol.source.TileUTFGrid.prototype.onXHRLoad_ = function(event) {
  68889. var client = /** @type {XMLHttpRequest} */ (event.target);
  68890. // status will be 0 for file:// urls
  68891. if (!client.status || client.status >= 200 && client.status < 300) {
  68892. var response;
  68893. try {
  68894. response = /** @type {TileJSON} */(JSON.parse(client.responseText));
  68895. } catch (err) {
  68896. this.handleTileJSONError();
  68897. return;
  68898. }
  68899. this.handleTileJSONResponse(response);
  68900. } else {
  68901. this.handleTileJSONError();
  68902. }
  68903. };
  68904. /**
  68905. * @private
  68906. * @param {Event} event The error event.
  68907. */
  68908. ol.source.TileUTFGrid.prototype.onXHRError_ = function(event) {
  68909. this.handleTileJSONError();
  68910. };
  68911. /**
  68912. * Return the template from TileJSON.
  68913. * @return {string|undefined} The template from TileJSON.
  68914. * @api
  68915. */
  68916. ol.source.TileUTFGrid.prototype.getTemplate = function() {
  68917. return this.template_;
  68918. };
  68919. /**
  68920. * Calls the callback (synchronously by default) with the available data
  68921. * for given coordinate and resolution (or `null` if not yet loaded or
  68922. * in case of an error).
  68923. * @param {ol.Coordinate} coordinate Coordinate.
  68924. * @param {number} resolution Resolution.
  68925. * @param {function(this: T, *)} callback Callback.
  68926. * @param {T=} opt_this The object to use as `this` in the callback.
  68927. * @param {boolean=} opt_request If `true` the callback is always async.
  68928. * The tile data is requested if not yet loaded.
  68929. * @template T
  68930. * @api
  68931. */
  68932. ol.source.TileUTFGrid.prototype.forDataAtCoordinateAndResolution = function(
  68933. coordinate, resolution, callback, opt_this, opt_request) {
  68934. if (this.tileGrid) {
  68935. var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
  68936. coordinate, resolution);
  68937. var tile = /** @type {!ol.source.TileUTFGrid.Tile_} */(this.getTile(
  68938. tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
  68939. tile.forDataAtCoordinate(coordinate, callback, opt_this, opt_request);
  68940. } else {
  68941. if (opt_request === true) {
  68942. setTimeout(function() {
  68943. callback.call(opt_this, null);
  68944. }, 0);
  68945. } else {
  68946. callback.call(opt_this, null);
  68947. }
  68948. }
  68949. };
  68950. /**
  68951. * @protected
  68952. */
  68953. ol.source.TileUTFGrid.prototype.handleTileJSONError = function() {
  68954. this.setState(ol.source.State.ERROR);
  68955. };
  68956. /**
  68957. * TODO: very similar to ol.source.TileJSON#handleTileJSONResponse
  68958. * @protected
  68959. * @param {TileJSON} tileJSON Tile JSON.
  68960. */
  68961. ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
  68962. var epsg4326Projection = ol.proj.get('EPSG:4326');
  68963. var sourceProjection = this.getProjection();
  68964. var extent;
  68965. if (tileJSON.bounds !== undefined) {
  68966. var transform = ol.proj.getTransformFromProjections(
  68967. epsg4326Projection, sourceProjection);
  68968. extent = ol.extent.applyTransform(tileJSON.bounds, transform);
  68969. }
  68970. var minZoom = tileJSON.minzoom || 0;
  68971. var maxZoom = tileJSON.maxzoom || 22;
  68972. var tileGrid = ol.tilegrid.createXYZ({
  68973. extent: ol.tilegrid.extentFromProjection(sourceProjection),
  68974. maxZoom: maxZoom,
  68975. minZoom: minZoom
  68976. });
  68977. this.tileGrid = tileGrid;
  68978. this.template_ = tileJSON.template;
  68979. var grids = tileJSON.grids;
  68980. if (!grids) {
  68981. this.setState(ol.source.State.ERROR);
  68982. return;
  68983. }
  68984. this.tileUrlFunction_ =
  68985. ol.TileUrlFunction.createFromTemplates(grids, tileGrid);
  68986. if (tileJSON.attribution !== undefined) {
  68987. var attributionExtent = extent !== undefined ?
  68988. extent : epsg4326Projection.getExtent();
  68989. this.setAttributions(function(frameState) {
  68990. if (ol.extent.intersects(attributionExtent, frameState.extent)) {
  68991. return [tileJSON.attribution];
  68992. }
  68993. return null;
  68994. });
  68995. }
  68996. this.setState(ol.source.State.READY);
  68997. };
  68998. /**
  68999. * @inheritDoc
  69000. */
  69001. ol.source.TileUTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) {
  69002. var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  69003. if (this.tileCache.containsKey(tileCoordKey)) {
  69004. return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
  69005. } else {
  69006. var tileCoord = [z, x, y];
  69007. var urlTileCoord =
  69008. this.getTileCoordForTileUrlFunction(tileCoord, projection);
  69009. var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
  69010. var tile = new ol.source.TileUTFGrid.Tile_(
  69011. tileCoord,
  69012. tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY,
  69013. tileUrl !== undefined ? tileUrl : '',
  69014. this.tileGrid.getTileCoordExtent(tileCoord),
  69015. this.preemptive_,
  69016. this.jsonp_);
  69017. this.tileCache.set(tileCoordKey, tile);
  69018. return tile;
  69019. }
  69020. };
  69021. /**
  69022. * @inheritDoc
  69023. */
  69024. ol.source.TileUTFGrid.prototype.useTile = function(z, x, y) {
  69025. var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  69026. if (this.tileCache.containsKey(tileCoordKey)) {
  69027. this.tileCache.get(tileCoordKey);
  69028. }
  69029. };
  69030. /**
  69031. * @constructor
  69032. * @extends {ol.Tile}
  69033. * @param {ol.TileCoord} tileCoord Tile coordinate.
  69034. * @param {ol.TileState} state State.
  69035. * @param {string} src Image source URI.
  69036. * @param {ol.Extent} extent Extent of the tile.
  69037. * @param {boolean} preemptive Load the tile when visible (before it's needed).
  69038. * @param {boolean} jsonp Load the tile as a script.
  69039. * @private
  69040. */
  69041. ol.source.TileUTFGrid.Tile_ = function(tileCoord, state, src, extent, preemptive, jsonp) {
  69042. ol.Tile.call(this, tileCoord, state);
  69043. /**
  69044. * @private
  69045. * @type {string}
  69046. */
  69047. this.src_ = src;
  69048. /**
  69049. * @private
  69050. * @type {ol.Extent}
  69051. */
  69052. this.extent_ = extent;
  69053. /**
  69054. * @private
  69055. * @type {boolean}
  69056. */
  69057. this.preemptive_ = preemptive;
  69058. /**
  69059. * @private
  69060. * @type {Array.<string>}
  69061. */
  69062. this.grid_ = null;
  69063. /**
  69064. * @private
  69065. * @type {Array.<string>}
  69066. */
  69067. this.keys_ = null;
  69068. /**
  69069. * @private
  69070. * @type {Object.<string, Object>|undefined}
  69071. */
  69072. this.data_ = null;
  69073. /**
  69074. * @private
  69075. * @type {boolean}
  69076. */
  69077. this.jsonp_ = jsonp;
  69078. };
  69079. ol.inherits(ol.source.TileUTFGrid.Tile_, ol.Tile);
  69080. /**
  69081. * Get the image element for this tile.
  69082. * @return {Image} Image.
  69083. */
  69084. ol.source.TileUTFGrid.Tile_.prototype.getImage = function() {
  69085. return null;
  69086. };
  69087. /**
  69088. * Synchronously returns data at given coordinate (if available).
  69089. * @param {ol.Coordinate} coordinate Coordinate.
  69090. * @return {*} The data.
  69091. */
  69092. ol.source.TileUTFGrid.Tile_.prototype.getData = function(coordinate) {
  69093. if (!this.grid_ || !this.keys_) {
  69094. return null;
  69095. }
  69096. var xRelative = (coordinate[0] - this.extent_[0]) /
  69097. (this.extent_[2] - this.extent_[0]);
  69098. var yRelative = (coordinate[1] - this.extent_[1]) /
  69099. (this.extent_[3] - this.extent_[1]);
  69100. var row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)];
  69101. if (typeof row !== 'string') {
  69102. return null;
  69103. }
  69104. var code = row.charCodeAt(Math.floor(xRelative * row.length));
  69105. if (code >= 93) {
  69106. code--;
  69107. }
  69108. if (code >= 35) {
  69109. code--;
  69110. }
  69111. code -= 32;
  69112. var data = null;
  69113. if (code in this.keys_) {
  69114. var id = this.keys_[code];
  69115. if (this.data_ && id in this.data_) {
  69116. data = this.data_[id];
  69117. } else {
  69118. data = id;
  69119. }
  69120. }
  69121. return data;
  69122. };
  69123. /**
  69124. * Calls the callback (synchronously by default) with the available data
  69125. * for given coordinate (or `null` if not yet loaded).
  69126. * @param {ol.Coordinate} coordinate Coordinate.
  69127. * @param {function(this: T, *)} callback Callback.
  69128. * @param {T=} opt_this The object to use as `this` in the callback.
  69129. * @param {boolean=} opt_request If `true` the callback is always async.
  69130. * The tile data is requested if not yet loaded.
  69131. * @template T
  69132. */
  69133. ol.source.TileUTFGrid.Tile_.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) {
  69134. if (this.state == ol.TileState.IDLE && opt_request === true) {
  69135. ol.events.listenOnce(this, ol.events.EventType.CHANGE, function(e) {
  69136. callback.call(opt_this, this.getData(coordinate));
  69137. }, this);
  69138. this.loadInternal_();
  69139. } else {
  69140. if (opt_request === true) {
  69141. setTimeout(function() {
  69142. callback.call(opt_this, this.getData(coordinate));
  69143. }.bind(this), 0);
  69144. } else {
  69145. callback.call(opt_this, this.getData(coordinate));
  69146. }
  69147. }
  69148. };
  69149. /**
  69150. * @inheritDoc
  69151. */
  69152. ol.source.TileUTFGrid.Tile_.prototype.getKey = function() {
  69153. return this.src_;
  69154. };
  69155. /**
  69156. * @private
  69157. */
  69158. ol.source.TileUTFGrid.Tile_.prototype.handleError_ = function() {
  69159. this.state = ol.TileState.ERROR;
  69160. this.changed();
  69161. };
  69162. /**
  69163. * @param {!UTFGridJSON} json UTFGrid data.
  69164. * @private
  69165. */
  69166. ol.source.TileUTFGrid.Tile_.prototype.handleLoad_ = function(json) {
  69167. this.grid_ = json.grid;
  69168. this.keys_ = json.keys;
  69169. this.data_ = json.data;
  69170. this.state = ol.TileState.EMPTY;
  69171. this.changed();
  69172. };
  69173. /**
  69174. * @private
  69175. */
  69176. ol.source.TileUTFGrid.Tile_.prototype.loadInternal_ = function() {
  69177. if (this.state == ol.TileState.IDLE) {
  69178. this.state = ol.TileState.LOADING;
  69179. if (this.jsonp_) {
  69180. ol.net.jsonp(this.src_, this.handleLoad_.bind(this),
  69181. this.handleError_.bind(this));
  69182. } else {
  69183. var client = new XMLHttpRequest();
  69184. client.addEventListener('load', this.onXHRLoad_.bind(this));
  69185. client.addEventListener('error', this.onXHRError_.bind(this));
  69186. client.open('GET', this.src_);
  69187. client.send();
  69188. }
  69189. }
  69190. };
  69191. /**
  69192. * @private
  69193. * @param {Event} event The load event.
  69194. */
  69195. ol.source.TileUTFGrid.Tile_.prototype.onXHRLoad_ = function(event) {
  69196. var client = /** @type {XMLHttpRequest} */ (event.target);
  69197. // status will be 0 for file:// urls
  69198. if (!client.status || client.status >= 200 && client.status < 300) {
  69199. var response;
  69200. try {
  69201. response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText));
  69202. } catch (err) {
  69203. this.handleError_();
  69204. return;
  69205. }
  69206. this.handleLoad_(response);
  69207. } else {
  69208. this.handleError_();
  69209. }
  69210. };
  69211. /**
  69212. * @private
  69213. * @param {Event} event The error event.
  69214. */
  69215. ol.source.TileUTFGrid.Tile_.prototype.onXHRError_ = function(event) {
  69216. this.handleError_();
  69217. };
  69218. /**
  69219. * @override
  69220. */
  69221. ol.source.TileUTFGrid.Tile_.prototype.load = function() {
  69222. if (this.preemptive_) {
  69223. this.loadInternal_();
  69224. }
  69225. };
  69226. // FIXME add minZoom support
  69227. // FIXME add date line wrap (tile coord transform)
  69228. // FIXME cannot be shared between maps with different projections
  69229. goog.provide('ol.source.TileWMS');
  69230. goog.require('ol');
  69231. goog.require('ol.asserts');
  69232. goog.require('ol.extent');
  69233. goog.require('ol.obj');
  69234. goog.require('ol.math');
  69235. goog.require('ol.proj');
  69236. goog.require('ol.reproj');
  69237. goog.require('ol.size');
  69238. goog.require('ol.source.TileImage');
  69239. goog.require('ol.source.WMSServerType');
  69240. goog.require('ol.tilecoord');
  69241. goog.require('ol.string');
  69242. goog.require('ol.uri');
  69243. /**
  69244. * @classdesc
  69245. * Layer source for tile data from WMS servers.
  69246. *
  69247. * @constructor
  69248. * @extends {ol.source.TileImage}
  69249. * @param {olx.source.TileWMSOptions=} opt_options Tile WMS options.
  69250. * @api
  69251. */
  69252. ol.source.TileWMS = function(opt_options) {
  69253. var options = opt_options || {};
  69254. var params = options.params || {};
  69255. var transparent = 'TRANSPARENT' in params ? params['TRANSPARENT'] : true;
  69256. ol.source.TileImage.call(this, {
  69257. attributions: options.attributions,
  69258. cacheSize: options.cacheSize,
  69259. crossOrigin: options.crossOrigin,
  69260. logo: options.logo,
  69261. opaque: !transparent,
  69262. projection: options.projection,
  69263. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  69264. tileClass: options.tileClass,
  69265. tileGrid: options.tileGrid,
  69266. tileLoadFunction: options.tileLoadFunction,
  69267. url: options.url,
  69268. urls: options.urls,
  69269. wrapX: options.wrapX !== undefined ? options.wrapX : true,
  69270. transition: options.transition
  69271. });
  69272. /**
  69273. * @private
  69274. * @type {number}
  69275. */
  69276. this.gutter_ = options.gutter !== undefined ? options.gutter : 0;
  69277. /**
  69278. * @private
  69279. * @type {!Object}
  69280. */
  69281. this.params_ = params;
  69282. /**
  69283. * @private
  69284. * @type {boolean}
  69285. */
  69286. this.v13_ = true;
  69287. /**
  69288. * @private
  69289. * @type {ol.source.WMSServerType|undefined}
  69290. */
  69291. this.serverType_ = /** @type {ol.source.WMSServerType|undefined} */ (options.serverType);
  69292. /**
  69293. * @private
  69294. * @type {boolean}
  69295. */
  69296. this.hidpi_ = options.hidpi !== undefined ? options.hidpi : true;
  69297. /**
  69298. * @private
  69299. * @type {ol.Extent}
  69300. */
  69301. this.tmpExtent_ = ol.extent.createEmpty();
  69302. this.updateV13_();
  69303. this.setKey(this.getKeyForParams_());
  69304. };
  69305. ol.inherits(ol.source.TileWMS, ol.source.TileImage);
  69306. /**
  69307. * Return the GetFeatureInfo URL for the passed coordinate, resolution, and
  69308. * projection. Return `undefined` if the GetFeatureInfo URL cannot be
  69309. * constructed.
  69310. * @param {ol.Coordinate} coordinate Coordinate.
  69311. * @param {number} resolution Resolution.
  69312. * @param {ol.ProjectionLike} projection Projection.
  69313. * @param {!Object} params GetFeatureInfo params. `INFO_FORMAT` at least should
  69314. * be provided. If `QUERY_LAYERS` is not provided then the layers specified
  69315. * in the `LAYERS` parameter will be used. `VERSION` should not be
  69316. * specified here.
  69317. * @return {string|undefined} GetFeatureInfo URL.
  69318. * @api
  69319. */
  69320. ol.source.TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projection, params) {
  69321. var projectionObj = ol.proj.get(projection);
  69322. var sourceProjectionObj = this.getProjection();
  69323. var tileGrid = this.getTileGrid();
  69324. if (!tileGrid) {
  69325. tileGrid = this.getTileGridForProjection(projectionObj);
  69326. }
  69327. var tileCoord = tileGrid.getTileCoordForCoordAndResolution(coordinate, resolution);
  69328. if (tileGrid.getResolutions().length <= tileCoord[0]) {
  69329. return undefined;
  69330. }
  69331. var tileResolution = tileGrid.getResolution(tileCoord[0]);
  69332. var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
  69333. var tileSize = ol.size.toSize(tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
  69334. var gutter = this.gutter_;
  69335. if (gutter !== 0) {
  69336. tileSize = ol.size.buffer(tileSize, gutter, this.tmpSize);
  69337. tileExtent = ol.extent.buffer(tileExtent, tileResolution * gutter, tileExtent);
  69338. }
  69339. if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
  69340. tileResolution = ol.reproj.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, tileResolution);
  69341. tileExtent = ol.proj.transformExtent(tileExtent, projectionObj, sourceProjectionObj);
  69342. coordinate = ol.proj.transform(coordinate, projectionObj, sourceProjectionObj);
  69343. }
  69344. var baseParams = {
  69345. 'SERVICE': 'WMS',
  69346. 'VERSION': ol.DEFAULT_WMS_VERSION,
  69347. 'REQUEST': 'GetFeatureInfo',
  69348. 'FORMAT': 'image/png',
  69349. 'TRANSPARENT': true,
  69350. 'QUERY_LAYERS': this.params_['LAYERS']
  69351. };
  69352. ol.obj.assign(baseParams, this.params_, params);
  69353. var x = Math.floor((coordinate[0] - tileExtent[0]) / tileResolution);
  69354. var y = Math.floor((tileExtent[3] - coordinate[1]) / tileResolution);
  69355. baseParams[this.v13_ ? 'I' : 'X'] = x;
  69356. baseParams[this.v13_ ? 'J' : 'Y'] = y;
  69357. return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
  69358. 1, sourceProjectionObj || projectionObj, baseParams);
  69359. };
  69360. /**
  69361. * @inheritDoc
  69362. */
  69363. ol.source.TileWMS.prototype.getGutterInternal = function() {
  69364. return this.gutter_;
  69365. };
  69366. /**
  69367. * Get the user-provided params, i.e. those passed to the constructor through
  69368. * the "params" option, and possibly updated using the updateParams method.
  69369. * @return {Object} Params.
  69370. * @api
  69371. */
  69372. ol.source.TileWMS.prototype.getParams = function() {
  69373. return this.params_;
  69374. };
  69375. /**
  69376. * @param {ol.TileCoord} tileCoord Tile coordinate.
  69377. * @param {ol.Size} tileSize Tile size.
  69378. * @param {ol.Extent} tileExtent Tile extent.
  69379. * @param {number} pixelRatio Pixel ratio.
  69380. * @param {ol.proj.Projection} projection Projection.
  69381. * @param {Object} params Params.
  69382. * @return {string|undefined} Request URL.
  69383. * @private
  69384. */
  69385. ol.source.TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExtent,
  69386. pixelRatio, projection, params) {
  69387. var urls = this.urls;
  69388. if (!urls) {
  69389. return undefined;
  69390. }
  69391. params['WIDTH'] = tileSize[0];
  69392. params['HEIGHT'] = tileSize[1];
  69393. params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
  69394. if (!('STYLES' in this.params_)) {
  69395. params['STYLES'] = '';
  69396. }
  69397. if (pixelRatio != 1) {
  69398. switch (this.serverType_) {
  69399. case ol.source.WMSServerType.GEOSERVER:
  69400. var dpi = (90 * pixelRatio + 0.5) | 0;
  69401. if ('FORMAT_OPTIONS' in params) {
  69402. params['FORMAT_OPTIONS'] += ';dpi:' + dpi;
  69403. } else {
  69404. params['FORMAT_OPTIONS'] = 'dpi:' + dpi;
  69405. }
  69406. break;
  69407. case ol.source.WMSServerType.MAPSERVER:
  69408. params['MAP_RESOLUTION'] = 90 * pixelRatio;
  69409. break;
  69410. case ol.source.WMSServerType.CARMENTA_SERVER:
  69411. case ol.source.WMSServerType.QGIS:
  69412. params['DPI'] = 90 * pixelRatio;
  69413. break;
  69414. default:
  69415. ol.asserts.assert(false, 52); // Unknown `serverType` configured
  69416. break;
  69417. }
  69418. }
  69419. var axisOrientation = projection.getAxisOrientation();
  69420. var bbox = tileExtent;
  69421. if (this.v13_ && axisOrientation.substr(0, 2) == 'ne') {
  69422. var tmp;
  69423. tmp = tileExtent[0];
  69424. bbox[0] = tileExtent[1];
  69425. bbox[1] = tmp;
  69426. tmp = tileExtent[2];
  69427. bbox[2] = tileExtent[3];
  69428. bbox[3] = tmp;
  69429. }
  69430. params['BBOX'] = bbox.join(',');
  69431. var url;
  69432. if (urls.length == 1) {
  69433. url = urls[0];
  69434. } else {
  69435. var index = ol.math.modulo(ol.tilecoord.hash(tileCoord), urls.length);
  69436. url = urls[index];
  69437. }
  69438. return ol.uri.appendParams(url, params);
  69439. };
  69440. /**
  69441. * @inheritDoc
  69442. */
  69443. ol.source.TileWMS.prototype.getTilePixelRatio = function(pixelRatio) {
  69444. return (!this.hidpi_ || this.serverType_ === undefined) ? 1 :
  69445. /** @type {number} */ (pixelRatio);
  69446. };
  69447. /**
  69448. * @private
  69449. * @return {string} The key for the current params.
  69450. */
  69451. ol.source.TileWMS.prototype.getKeyForParams_ = function() {
  69452. var i = 0;
  69453. var res = [];
  69454. for (var key in this.params_) {
  69455. res[i++] = key + '-' + this.params_[key];
  69456. }
  69457. return res.join('/');
  69458. };
  69459. /**
  69460. * @inheritDoc
  69461. */
  69462. ol.source.TileWMS.prototype.fixedTileUrlFunction = function(tileCoord, pixelRatio, projection) {
  69463. var tileGrid = this.getTileGrid();
  69464. if (!tileGrid) {
  69465. tileGrid = this.getTileGridForProjection(projection);
  69466. }
  69467. if (tileGrid.getResolutions().length <= tileCoord[0]) {
  69468. return undefined;
  69469. }
  69470. if (pixelRatio != 1 && (!this.hidpi_ || this.serverType_ === undefined)) {
  69471. pixelRatio = 1;
  69472. }
  69473. var tileResolution = tileGrid.getResolution(tileCoord[0]);
  69474. var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
  69475. var tileSize = ol.size.toSize(
  69476. tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
  69477. var gutter = this.gutter_;
  69478. if (gutter !== 0) {
  69479. tileSize = ol.size.buffer(tileSize, gutter, this.tmpSize);
  69480. tileExtent = ol.extent.buffer(tileExtent,
  69481. tileResolution * gutter, tileExtent);
  69482. }
  69483. if (pixelRatio != 1) {
  69484. tileSize = ol.size.scale(tileSize, pixelRatio, this.tmpSize);
  69485. }
  69486. var baseParams = {
  69487. 'SERVICE': 'WMS',
  69488. 'VERSION': ol.DEFAULT_WMS_VERSION,
  69489. 'REQUEST': 'GetMap',
  69490. 'FORMAT': 'image/png',
  69491. 'TRANSPARENT': true
  69492. };
  69493. ol.obj.assign(baseParams, this.params_);
  69494. return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
  69495. pixelRatio, projection, baseParams);
  69496. };
  69497. /**
  69498. * Update the user-provided params.
  69499. * @param {Object} params Params.
  69500. * @api
  69501. */
  69502. ol.source.TileWMS.prototype.updateParams = function(params) {
  69503. ol.obj.assign(this.params_, params);
  69504. this.updateV13_();
  69505. this.setKey(this.getKeyForParams_());
  69506. };
  69507. /**
  69508. * @private
  69509. */
  69510. ol.source.TileWMS.prototype.updateV13_ = function() {
  69511. var version = this.params_['VERSION'] || ol.DEFAULT_WMS_VERSION;
  69512. this.v13_ = ol.string.compareVersions(version, '1.3') >= 0;
  69513. };
  69514. goog.provide('ol.VectorImageTile');
  69515. goog.require('ol');
  69516. goog.require('ol.Tile');
  69517. goog.require('ol.TileState');
  69518. goog.require('ol.dom');
  69519. goog.require('ol.events');
  69520. goog.require('ol.extent');
  69521. goog.require('ol.events.EventType');
  69522. goog.require('ol.featureloader');
  69523. /**
  69524. * @constructor
  69525. * @extends {ol.Tile}
  69526. * @param {ol.TileCoord} tileCoord Tile coordinate.
  69527. * @param {ol.TileState} state State.
  69528. * @param {number} sourceRevision Source revision.
  69529. * @param {ol.format.Feature} format Feature format.
  69530. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
  69531. * @param {ol.TileCoord} urlTileCoord Wrapped tile coordinate for source urls.
  69532. * @param {ol.TileUrlFunctionType} tileUrlFunction Tile url function.
  69533. * @param {ol.tilegrid.TileGrid} sourceTileGrid Tile grid of the source.
  69534. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid of the renderer.
  69535. * @param {Object.<string,ol.VectorTile>} sourceTiles Source tiles.
  69536. * @param {number} pixelRatio Pixel ratio.
  69537. * @param {ol.proj.Projection} projection Projection.
  69538. * @param {function(new: ol.VectorTile, ol.TileCoord, ol.TileState, string,
  69539. * ol.format.Feature, ol.TileLoadFunctionType)} tileClass Class to
  69540. * instantiate for source tiles.
  69541. * @param {function(this: ol.source.VectorTile, ol.events.Event)} handleTileChange
  69542. * Function to call when a source tile's state changes.
  69543. * @param {olx.TileOptions=} opt_options Tile options.
  69544. */
  69545. ol.VectorImageTile = function(tileCoord, state, sourceRevision, format,
  69546. tileLoadFunction, urlTileCoord, tileUrlFunction, sourceTileGrid, tileGrid,
  69547. sourceTiles, pixelRatio, projection, tileClass, handleTileChange, opt_options) {
  69548. ol.Tile.call(this, tileCoord, state, opt_options);
  69549. /**
  69550. * @private
  69551. * @type {Object.<string, CanvasRenderingContext2D>}
  69552. */
  69553. this.context_ = {};
  69554. /**
  69555. * @private
  69556. * @type {ol.FeatureLoader}
  69557. */
  69558. this.loader_;
  69559. /**
  69560. * @private
  69561. * @type {Object.<string, ol.TileReplayState>}
  69562. */
  69563. this.replayState_ = {};
  69564. /**
  69565. * @private
  69566. * @type {Object.<string,ol.VectorTile>}
  69567. */
  69568. this.sourceTiles_ = sourceTiles;
  69569. /**
  69570. * Keys of source tiles used by this tile. Use with {@link #getTile}.
  69571. * @type {Array.<string>}
  69572. */
  69573. this.tileKeys = [];
  69574. /**
  69575. * @type {number}
  69576. */
  69577. this.sourceRevision_ = sourceRevision;
  69578. /**
  69579. * @type {ol.TileCoord}
  69580. */
  69581. this.wrappedTileCoord = urlTileCoord;
  69582. /**
  69583. * @type {Array.<ol.EventsKey>}
  69584. */
  69585. this.loadListenerKeys_ = [];
  69586. /**
  69587. * @type {Array.<ol.EventsKey>}
  69588. */
  69589. this.sourceTileListenerKeys_ = [];
  69590. if (urlTileCoord) {
  69591. var extent = tileGrid.getTileCoordExtent(urlTileCoord);
  69592. var resolution = tileGrid.getResolution(tileCoord[0]);
  69593. var sourceZ = sourceTileGrid.getZForResolution(resolution);
  69594. sourceTileGrid.forEachTileCoord(extent, sourceZ, function(sourceTileCoord) {
  69595. var sharedExtent = ol.extent.getIntersection(extent,
  69596. sourceTileGrid.getTileCoordExtent(sourceTileCoord));
  69597. var sourceExtent = sourceTileGrid.getExtent();
  69598. if (sourceExtent) {
  69599. sharedExtent = ol.extent.getIntersection(sharedExtent, sourceExtent);
  69600. }
  69601. if (ol.extent.getWidth(sharedExtent) / resolution >= 0.5 &&
  69602. ol.extent.getHeight(sharedExtent) / resolution >= 0.5) {
  69603. // only include source tile if overlap is at least 1 pixel
  69604. var sourceTileKey = sourceTileCoord.toString();
  69605. var sourceTile = sourceTiles[sourceTileKey];
  69606. if (!sourceTile) {
  69607. var tileUrl = tileUrlFunction(sourceTileCoord, pixelRatio, projection);
  69608. sourceTile = sourceTiles[sourceTileKey] = new tileClass(sourceTileCoord,
  69609. tileUrl == undefined ? ol.TileState.EMPTY : ol.TileState.IDLE,
  69610. tileUrl == undefined ? '' : tileUrl,
  69611. format, tileLoadFunction);
  69612. this.sourceTileListenerKeys_.push(
  69613. ol.events.listen(sourceTile, ol.events.EventType.CHANGE, handleTileChange));
  69614. }
  69615. sourceTile.consumers++;
  69616. this.tileKeys.push(sourceTileKey);
  69617. }
  69618. }.bind(this));
  69619. }
  69620. };
  69621. ol.inherits(ol.VectorImageTile, ol.Tile);
  69622. /**
  69623. * @inheritDoc
  69624. */
  69625. ol.VectorImageTile.prototype.disposeInternal = function() {
  69626. for (var i = 0, ii = this.tileKeys.length; i < ii; ++i) {
  69627. var sourceTileKey = this.tileKeys[i];
  69628. var sourceTile = this.getTile(sourceTileKey);
  69629. sourceTile.consumers--;
  69630. if (sourceTile.consumers == 0) {
  69631. delete this.sourceTiles_[sourceTileKey];
  69632. sourceTile.dispose();
  69633. }
  69634. }
  69635. this.tileKeys.length = 0;
  69636. this.sourceTiles_ = null;
  69637. this.loadListenerKeys_.forEach(ol.events.unlistenByKey);
  69638. this.loadListenerKeys_.length = 0;
  69639. if (this.interimTile) {
  69640. this.interimTile.dispose();
  69641. }
  69642. this.state = ol.TileState.ABORT;
  69643. this.changed();
  69644. this.sourceTileListenerKeys_.forEach(ol.events.unlistenByKey);
  69645. this.sourceTileListenerKeys_.length = 0;
  69646. ol.Tile.prototype.disposeInternal.call(this);
  69647. };
  69648. /**
  69649. * @param {ol.layer.Layer} layer Layer.
  69650. * @return {CanvasRenderingContext2D} The rendering context.
  69651. */
  69652. ol.VectorImageTile.prototype.getContext = function(layer) {
  69653. var key = ol.getUid(layer).toString();
  69654. if (!(key in this.context_)) {
  69655. this.context_[key] = ol.dom.createCanvasContext2D();
  69656. }
  69657. return this.context_[key];
  69658. };
  69659. /**
  69660. * Get the Canvas for this tile.
  69661. * @param {ol.layer.Layer} layer Layer.
  69662. * @return {HTMLCanvasElement} Canvas.
  69663. */
  69664. ol.VectorImageTile.prototype.getImage = function(layer) {
  69665. return this.getReplayState(layer).renderedTileRevision == -1 ?
  69666. null : this.getContext(layer).canvas;
  69667. };
  69668. /**
  69669. * @param {ol.layer.Layer} layer Layer.
  69670. * @return {ol.TileReplayState} The replay state.
  69671. */
  69672. ol.VectorImageTile.prototype.getReplayState = function(layer) {
  69673. var key = ol.getUid(layer).toString();
  69674. if (!(key in this.replayState_)) {
  69675. this.replayState_[key] = {
  69676. dirty: false,
  69677. renderedRenderOrder: null,
  69678. renderedRevision: -1,
  69679. renderedTileRevision: -1
  69680. };
  69681. }
  69682. return this.replayState_[key];
  69683. };
  69684. /**
  69685. * @inheritDoc
  69686. */
  69687. ol.VectorImageTile.prototype.getKey = function() {
  69688. return this.tileKeys.join('/') + '-' + this.sourceRevision_;
  69689. };
  69690. /**
  69691. * @param {string} tileKey Key (tileCoord) of the source tile.
  69692. * @return {ol.VectorTile} Source tile.
  69693. */
  69694. ol.VectorImageTile.prototype.getTile = function(tileKey) {
  69695. return this.sourceTiles_[tileKey];
  69696. };
  69697. /**
  69698. * @inheritDoc
  69699. */
  69700. ol.VectorImageTile.prototype.load = function() {
  69701. // Source tiles with LOADED state - we just count them because once they are
  69702. // loaded, we're no longer listening to state changes.
  69703. var leftToLoad = 0;
  69704. // Source tiles with ERROR state - we track them because they can still have
  69705. // an ERROR state after another load attempt.
  69706. var errorSourceTiles = {};
  69707. if (this.state == ol.TileState.IDLE) {
  69708. this.setState(ol.TileState.LOADING);
  69709. }
  69710. if (this.state == ol.TileState.LOADING) {
  69711. this.tileKeys.forEach(function(sourceTileKey) {
  69712. var sourceTile = this.getTile(sourceTileKey);
  69713. if (sourceTile.state == ol.TileState.IDLE) {
  69714. sourceTile.setLoader(this.loader_);
  69715. sourceTile.load();
  69716. }
  69717. if (sourceTile.state == ol.TileState.LOADING) {
  69718. var key = ol.events.listen(sourceTile, ol.events.EventType.CHANGE, function(e) {
  69719. var state = sourceTile.getState();
  69720. if (state == ol.TileState.LOADED ||
  69721. state == ol.TileState.ERROR) {
  69722. var uid = ol.getUid(sourceTile);
  69723. if (state == ol.TileState.ERROR) {
  69724. errorSourceTiles[uid] = true;
  69725. } else {
  69726. --leftToLoad;
  69727. delete errorSourceTiles[uid];
  69728. }
  69729. if (leftToLoad - Object.keys(errorSourceTiles).length == 0) {
  69730. this.finishLoading_();
  69731. }
  69732. }
  69733. }.bind(this));
  69734. this.loadListenerKeys_.push(key);
  69735. ++leftToLoad;
  69736. }
  69737. }.bind(this));
  69738. }
  69739. if (leftToLoad - Object.keys(errorSourceTiles).length == 0) {
  69740. setTimeout(this.finishLoading_.bind(this), 0);
  69741. }
  69742. };
  69743. /**
  69744. * @private
  69745. */
  69746. ol.VectorImageTile.prototype.finishLoading_ = function() {
  69747. var loaded = this.tileKeys.length;
  69748. var empty = 0;
  69749. for (var i = loaded - 1; i >= 0; --i) {
  69750. var state = this.getTile(this.tileKeys[i]).getState();
  69751. if (state != ol.TileState.LOADED) {
  69752. --loaded;
  69753. }
  69754. if (state == ol.TileState.EMPTY) {
  69755. ++empty;
  69756. }
  69757. }
  69758. if (loaded == this.tileKeys.length) {
  69759. this.loadListenerKeys_.forEach(ol.events.unlistenByKey);
  69760. this.loadListenerKeys_.length = 0;
  69761. this.setState(ol.TileState.LOADED);
  69762. } else {
  69763. this.setState(empty == this.tileKeys.length ? ol.TileState.EMPTY : ol.TileState.ERROR);
  69764. }
  69765. };
  69766. /**
  69767. * Sets the loader for a tile.
  69768. * @param {ol.VectorTile} tile Vector tile.
  69769. * @param {string} url URL.
  69770. */
  69771. ol.VectorImageTile.defaultLoadFunction = function(tile, url) {
  69772. var loader = ol.featureloader.loadFeaturesXhr(
  69773. url, tile.getFormat(), tile.onLoad.bind(tile), tile.onError.bind(tile));
  69774. tile.setLoader(loader);
  69775. };
  69776. goog.provide('ol.VectorTile');
  69777. goog.require('ol');
  69778. goog.require('ol.Tile');
  69779. goog.require('ol.TileState');
  69780. /**
  69781. * @constructor
  69782. * @extends {ol.Tile}
  69783. * @param {ol.TileCoord} tileCoord Tile coordinate.
  69784. * @param {ol.TileState} state State.
  69785. * @param {string} src Data source url.
  69786. * @param {ol.format.Feature} format Feature format.
  69787. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
  69788. * @param {olx.TileOptions=} opt_options Tile options.
  69789. */
  69790. ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction, opt_options) {
  69791. ol.Tile.call(this, tileCoord, state, opt_options);
  69792. /**
  69793. * @type {number}
  69794. */
  69795. this.consumers = 0;
  69796. /**
  69797. * @private
  69798. * @type {ol.Extent}
  69799. */
  69800. this.extent_ = null;
  69801. /**
  69802. * @private
  69803. * @type {ol.format.Feature}
  69804. */
  69805. this.format_ = format;
  69806. /**
  69807. * @private
  69808. * @type {Array.<ol.Feature>}
  69809. */
  69810. this.features_ = null;
  69811. /**
  69812. * @private
  69813. * @type {ol.FeatureLoader}
  69814. */
  69815. this.loader_;
  69816. /**
  69817. * Data projection
  69818. * @private
  69819. * @type {ol.proj.Projection}
  69820. */
  69821. this.projection_;
  69822. /**
  69823. * @private
  69824. * @type {Object.<string, ol.render.ReplayGroup>}
  69825. */
  69826. this.replayGroups_ = {};
  69827. /**
  69828. * @private
  69829. * @type {ol.TileLoadFunctionType}
  69830. */
  69831. this.tileLoadFunction_ = tileLoadFunction;
  69832. /**
  69833. * @private
  69834. * @type {string}
  69835. */
  69836. this.url_ = src;
  69837. };
  69838. ol.inherits(ol.VectorTile, ol.Tile);
  69839. /**
  69840. * @inheritDoc
  69841. */
  69842. ol.VectorTile.prototype.disposeInternal = function() {
  69843. this.features_ = null;
  69844. this.replayGroups_ = {};
  69845. this.state = ol.TileState.ABORT;
  69846. this.changed();
  69847. ol.Tile.prototype.disposeInternal.call(this);
  69848. };
  69849. /**
  69850. * Gets the extent of the vector tile.
  69851. * @return {ol.Extent} The extent.
  69852. * @api
  69853. */
  69854. ol.VectorTile.prototype.getExtent = function() {
  69855. return this.extent_ || ol.VectorTile.DEFAULT_EXTENT;
  69856. };
  69857. /**
  69858. * Get the feature format assigned for reading this tile's features.
  69859. * @return {ol.format.Feature} Feature format.
  69860. * @api
  69861. */
  69862. ol.VectorTile.prototype.getFormat = function() {
  69863. return this.format_;
  69864. };
  69865. /**
  69866. * Get the features for this tile. Geometries will be in the projection returned
  69867. * by {@link ol.VectorTile#getProjection}.
  69868. * @return {Array.<ol.Feature|ol.render.Feature>} Features.
  69869. * @api
  69870. */
  69871. ol.VectorTile.prototype.getFeatures = function() {
  69872. return this.features_;
  69873. };
  69874. /**
  69875. * @inheritDoc
  69876. */
  69877. ol.VectorTile.prototype.getKey = function() {
  69878. return this.url_;
  69879. };
  69880. /**
  69881. * Get the feature projection of features returned by
  69882. * {@link ol.VectorTile#getFeatures}.
  69883. * @return {ol.proj.Projection} Feature projection.
  69884. * @api
  69885. */
  69886. ol.VectorTile.prototype.getProjection = function() {
  69887. return this.projection_;
  69888. };
  69889. /**
  69890. * @param {ol.layer.Layer} layer Layer.
  69891. * @param {string} key Key.
  69892. * @return {ol.render.ReplayGroup} Replay group.
  69893. */
  69894. ol.VectorTile.prototype.getReplayGroup = function(layer, key) {
  69895. return this.replayGroups_[ol.getUid(layer) + ',' + key];
  69896. };
  69897. /**
  69898. * @inheritDoc
  69899. */
  69900. ol.VectorTile.prototype.load = function() {
  69901. if (this.state == ol.TileState.IDLE) {
  69902. this.setState(ol.TileState.LOADING);
  69903. this.tileLoadFunction_(this, this.url_);
  69904. this.loader_(null, NaN, null);
  69905. }
  69906. };
  69907. /**
  69908. * Handler for successful tile load.
  69909. * @param {Array.<ol.Feature>} features The loaded features.
  69910. * @param {ol.proj.Projection} dataProjection Data projection.
  69911. * @param {ol.Extent} extent Extent.
  69912. */
  69913. ol.VectorTile.prototype.onLoad = function(features, dataProjection, extent) {
  69914. this.setProjection(dataProjection);
  69915. this.setFeatures(features);
  69916. this.setExtent(extent);
  69917. };
  69918. /**
  69919. * Handler for tile load errors.
  69920. */
  69921. ol.VectorTile.prototype.onError = function() {
  69922. this.setState(ol.TileState.ERROR);
  69923. };
  69924. /**
  69925. * Function for use in an {@link ol.source.VectorTile}'s `tileLoadFunction`.
  69926. * Sets the extent of the vector tile. This is only required for tiles in
  69927. * projections with `tile-pixels` as units. The extent should be set to
  69928. * `[0, 0, tilePixelSize, tilePixelSize]`, where `tilePixelSize` is calculated
  69929. * by multiplying the tile size with the tile pixel ratio. For sources using
  69930. * {@link ol.format.MVT} as feature format, the
  69931. * {@link ol.format.MVT#getLastExtent} method will return the correct extent.
  69932. * The default is `[0, 0, 4096, 4096]`.
  69933. * @param {ol.Extent} extent The extent.
  69934. * @api
  69935. */
  69936. ol.VectorTile.prototype.setExtent = function(extent) {
  69937. this.extent_ = extent;
  69938. };
  69939. /**
  69940. * Function for use in an {@link ol.source.VectorTile}'s `tileLoadFunction`.
  69941. * Sets the features for the tile.
  69942. * @param {Array.<ol.Feature>} features Features.
  69943. * @api
  69944. */
  69945. ol.VectorTile.prototype.setFeatures = function(features) {
  69946. this.features_ = features;
  69947. this.setState(ol.TileState.LOADED);
  69948. };
  69949. /**
  69950. * Function for use in an {@link ol.source.VectorTile}'s `tileLoadFunction`.
  69951. * Sets the projection of the features that were added with
  69952. * {@link ol.VectorTile#setFeatures}.
  69953. * @param {ol.proj.Projection} projection Feature projection.
  69954. * @api
  69955. */
  69956. ol.VectorTile.prototype.setProjection = function(projection) {
  69957. this.projection_ = projection;
  69958. };
  69959. /**
  69960. * @param {ol.layer.Layer} layer Layer.
  69961. * @param {string} key Key.
  69962. * @param {ol.render.ReplayGroup} replayGroup Replay group.
  69963. */
  69964. ol.VectorTile.prototype.setReplayGroup = function(layer, key, replayGroup) {
  69965. this.replayGroups_[ol.getUid(layer) + ',' + key] = replayGroup;
  69966. };
  69967. /**
  69968. * Set the feature loader for reading this tile's features.
  69969. * @param {ol.FeatureLoader} loader Feature loader.
  69970. * @api
  69971. */
  69972. ol.VectorTile.prototype.setLoader = function(loader) {
  69973. this.loader_ = loader;
  69974. };
  69975. /**
  69976. * @const
  69977. * @type {ol.Extent}
  69978. */
  69979. ol.VectorTile.DEFAULT_EXTENT = [0, 0, 4096, 4096];
  69980. goog.provide('ol.source.VectorTile');
  69981. goog.require('ol');
  69982. goog.require('ol.TileState');
  69983. goog.require('ol.VectorImageTile');
  69984. goog.require('ol.VectorTile');
  69985. goog.require('ol.size');
  69986. goog.require('ol.source.UrlTile');
  69987. goog.require('ol.tilecoord');
  69988. goog.require('ol.tilegrid');
  69989. /**
  69990. * @classdesc
  69991. * Class for layer sources providing vector data divided into a tile grid, to be
  69992. * used with {@link ol.layer.VectorTile}. Although this source receives tiles
  69993. * with vector features from the server, it is not meant for feature editing.
  69994. * Features are optimized for rendering, their geometries are clipped at or near
  69995. * tile boundaries and simplified for a view resolution. See
  69996. * {@link ol.source.Vector} for vector sources that are suitable for feature
  69997. * editing.
  69998. *
  69999. * @constructor
  70000. * @fires ol.source.Tile.Event
  70001. * @extends {ol.source.UrlTile}
  70002. * @param {olx.source.VectorTileOptions} options Vector tile options.
  70003. * @api
  70004. */
  70005. ol.source.VectorTile = function(options) {
  70006. var projection = options.projection || 'EPSG:3857';
  70007. var extent = options.extent || ol.tilegrid.extentFromProjection(projection);
  70008. var tileGrid = options.tileGrid || ol.tilegrid.createXYZ({
  70009. extent: extent,
  70010. maxZoom: options.maxZoom || 22,
  70011. minZoom: options.minZoom,
  70012. tileSize: options.tileSize || 512
  70013. });
  70014. ol.source.UrlTile.call(this, {
  70015. attributions: options.attributions,
  70016. cacheSize: options.cacheSize !== undefined ? options.cacheSize : 128,
  70017. extent: extent,
  70018. logo: options.logo,
  70019. opaque: false,
  70020. projection: projection,
  70021. state: options.state,
  70022. tileGrid: tileGrid,
  70023. tileLoadFunction: options.tileLoadFunction ?
  70024. options.tileLoadFunction : ol.VectorImageTile.defaultLoadFunction,
  70025. tileUrlFunction: options.tileUrlFunction,
  70026. url: options.url,
  70027. urls: options.urls,
  70028. wrapX: options.wrapX === undefined ? true : options.wrapX,
  70029. transition: options.transition
  70030. });
  70031. /**
  70032. * @private
  70033. * @type {ol.format.Feature}
  70034. */
  70035. this.format_ = options.format ? options.format : null;
  70036. /**
  70037. * @private
  70038. * @type {Object.<string,ol.VectorTile>}
  70039. */
  70040. this.sourceTiles_ = {};
  70041. /**
  70042. * @private
  70043. * @type {boolean}
  70044. */
  70045. this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
  70046. /**
  70047. * @protected
  70048. * @type {function(new: ol.VectorTile, ol.TileCoord, ol.TileState, string,
  70049. * ol.format.Feature, ol.TileLoadFunctionType)}
  70050. */
  70051. this.tileClass = options.tileClass ? options.tileClass : ol.VectorTile;
  70052. /**
  70053. * @private
  70054. * @type {Object.<string,ol.tilegrid.TileGrid>}
  70055. */
  70056. this.tileGrids_ = {};
  70057. };
  70058. ol.inherits(ol.source.VectorTile, ol.source.UrlTile);
  70059. /**
  70060. * @return {boolean} The source can have overlapping geometries.
  70061. */
  70062. ol.source.VectorTile.prototype.getOverlaps = function() {
  70063. return this.overlaps_;
  70064. };
  70065. /**
  70066. * clear {@link ol.TileCache} and delete all source tiles
  70067. * @api
  70068. */
  70069. ol.source.VectorTile.prototype.clear = function() {
  70070. this.tileCache.clear();
  70071. this.sourceTiles_ = {};
  70072. };
  70073. /**
  70074. * @inheritDoc
  70075. */
  70076. ol.source.VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projection) {
  70077. var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
  70078. if (this.tileCache.containsKey(tileCoordKey)) {
  70079. return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
  70080. } else {
  70081. var tileCoord = [z, x, y];
  70082. var urlTileCoord = this.getTileCoordForTileUrlFunction(
  70083. tileCoord, projection);
  70084. var tile = new ol.VectorImageTile(
  70085. tileCoord,
  70086. urlTileCoord !== null ? ol.TileState.IDLE : ol.TileState.EMPTY,
  70087. this.getRevision(),
  70088. this.format_, this.tileLoadFunction, urlTileCoord, this.tileUrlFunction,
  70089. this.tileGrid, this.getTileGridForProjection(projection),
  70090. this.sourceTiles_, pixelRatio, projection, this.tileClass,
  70091. this.handleTileChange.bind(this),
  70092. this.tileOptions);
  70093. this.tileCache.set(tileCoordKey, tile);
  70094. return tile;
  70095. }
  70096. };
  70097. /**
  70098. * @inheritDoc
  70099. */
  70100. ol.source.VectorTile.prototype.getTileGridForProjection = function(projection) {
  70101. var code = projection.getCode();
  70102. var tileGrid = this.tileGrids_[code];
  70103. if (!tileGrid) {
  70104. // A tile grid that matches the tile size of the source tile grid is more
  70105. // likely to have 1:1 relationships between source tiles and rendered tiles.
  70106. var sourceTileGrid = this.tileGrid;
  70107. tileGrid = this.tileGrids_[code] = ol.tilegrid.createForProjection(projection, undefined,
  70108. sourceTileGrid ? sourceTileGrid.getTileSize(sourceTileGrid.getMinZoom()) : undefined);
  70109. }
  70110. return tileGrid;
  70111. };
  70112. /**
  70113. * @inheritDoc
  70114. */
  70115. ol.source.VectorTile.prototype.getTilePixelRatio = function(pixelRatio) {
  70116. return pixelRatio;
  70117. };
  70118. /**
  70119. * @inheritDoc
  70120. */
  70121. ol.source.VectorTile.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
  70122. var tileSize = ol.size.toSize(this.getTileGridForProjection(projection).getTileSize(z));
  70123. return [Math.round(tileSize[0] * pixelRatio), Math.round(tileSize[1] * pixelRatio)];
  70124. };
  70125. goog.provide('ol.source.WMTSRequestEncoding');
  70126. /**
  70127. * Request encoding. One of 'KVP', 'REST'.
  70128. * @enum {string}
  70129. */
  70130. ol.source.WMTSRequestEncoding = {
  70131. KVP: 'KVP', // see spec §8
  70132. REST: 'REST' // see spec §10
  70133. };
  70134. goog.provide('ol.tilegrid.WMTS');
  70135. goog.require('ol');
  70136. goog.require('ol.array');
  70137. goog.require('ol.proj');
  70138. goog.require('ol.tilegrid.TileGrid');
  70139. /**
  70140. * @classdesc
  70141. * Set the grid pattern for sources accessing WMTS tiled-image servers.
  70142. *
  70143. * @constructor
  70144. * @extends {ol.tilegrid.TileGrid}
  70145. * @param {olx.tilegrid.WMTSOptions} options WMTS options.
  70146. * @struct
  70147. * @api
  70148. */
  70149. ol.tilegrid.WMTS = function(options) {
  70150. /**
  70151. * @private
  70152. * @type {!Array.<string>}
  70153. */
  70154. this.matrixIds_ = options.matrixIds;
  70155. // FIXME: should the matrixIds become optional?
  70156. ol.tilegrid.TileGrid.call(this, {
  70157. extent: options.extent,
  70158. origin: options.origin,
  70159. origins: options.origins,
  70160. resolutions: options.resolutions,
  70161. tileSize: options.tileSize,
  70162. tileSizes: options.tileSizes,
  70163. sizes: options.sizes
  70164. });
  70165. };
  70166. ol.inherits(ol.tilegrid.WMTS, ol.tilegrid.TileGrid);
  70167. /**
  70168. * @param {number} z Z.
  70169. * @return {string} MatrixId..
  70170. */
  70171. ol.tilegrid.WMTS.prototype.getMatrixId = function(z) {
  70172. return this.matrixIds_[z];
  70173. };
  70174. /**
  70175. * Get the list of matrix identifiers.
  70176. * @return {Array.<string>} MatrixIds.
  70177. * @api
  70178. */
  70179. ol.tilegrid.WMTS.prototype.getMatrixIds = function() {
  70180. return this.matrixIds_;
  70181. };
  70182. /**
  70183. * Create a tile grid from a WMTS capabilities matrix set and an
  70184. * optional TileMatrixSetLimits.
  70185. * @param {Object} matrixSet An object representing a matrixSet in the
  70186. * capabilities document.
  70187. * @param {ol.Extent=} opt_extent An optional extent to restrict the tile
  70188. * ranges the server provides.
  70189. * @param {Array.<Object>=} opt_matrixLimits An optional object representing
  70190. * the available matrices for tileGrid.
  70191. * @return {ol.tilegrid.WMTS} WMTS tileGrid instance.
  70192. * @api
  70193. */
  70194. ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_extent,
  70195. opt_matrixLimits) {
  70196. /** @type {!Array.<number>} */
  70197. var resolutions = [];
  70198. /** @type {!Array.<string>} */
  70199. var matrixIds = [];
  70200. /** @type {!Array.<ol.Coordinate>} */
  70201. var origins = [];
  70202. /** @type {!Array.<ol.Size>} */
  70203. var tileSizes = [];
  70204. /** @type {!Array.<ol.Size>} */
  70205. var sizes = [];
  70206. var matrixLimits = opt_matrixLimits !== undefined ? opt_matrixLimits : [];
  70207. var supportedCRSPropName = 'SupportedCRS';
  70208. var matrixIdsPropName = 'TileMatrix';
  70209. var identifierPropName = 'Identifier';
  70210. var scaleDenominatorPropName = 'ScaleDenominator';
  70211. var topLeftCornerPropName = 'TopLeftCorner';
  70212. var tileWidthPropName = 'TileWidth';
  70213. var tileHeightPropName = 'TileHeight';
  70214. var code = matrixSet[supportedCRSPropName];
  70215. var projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
  70216. ol.proj.get(code);
  70217. var metersPerUnit = projection.getMetersPerUnit();
  70218. // swap origin x and y coordinates if axis orientation is lat/long
  70219. var switchOriginXY = projection.getAxisOrientation().substr(0, 2) == 'ne';
  70220. matrixSet[matrixIdsPropName].sort(function(a, b) {
  70221. return b[scaleDenominatorPropName] - a[scaleDenominatorPropName];
  70222. });
  70223. matrixSet[matrixIdsPropName].forEach(function(elt, index, array) {
  70224. var matrixAvailable;
  70225. // use of matrixLimits to filter TileMatrices from GetCapabilities
  70226. // TileMatrixSet from unavailable matrix levels.
  70227. if (matrixLimits.length > 0) {
  70228. matrixAvailable = ol.array.find(matrixLimits,
  70229. function(elt_ml, index_ml, array_ml) {
  70230. return elt[identifierPropName] == elt_ml[matrixIdsPropName];
  70231. });
  70232. } else {
  70233. matrixAvailable = true;
  70234. }
  70235. if (matrixAvailable) {
  70236. matrixIds.push(elt[identifierPropName]);
  70237. var resolution = elt[scaleDenominatorPropName] * 0.28E-3 / metersPerUnit;
  70238. var tileWidth = elt[tileWidthPropName];
  70239. var tileHeight = elt[tileHeightPropName];
  70240. if (switchOriginXY) {
  70241. origins.push([elt[topLeftCornerPropName][1],
  70242. elt[topLeftCornerPropName][0]]);
  70243. } else {
  70244. origins.push(elt[topLeftCornerPropName]);
  70245. }
  70246. resolutions.push(resolution);
  70247. tileSizes.push(tileWidth == tileHeight ?
  70248. tileWidth : [tileWidth, tileHeight]);
  70249. // top-left origin, so height is negative
  70250. sizes.push([elt['MatrixWidth'], -elt['MatrixHeight']]);
  70251. }
  70252. });
  70253. return new ol.tilegrid.WMTS({
  70254. extent: opt_extent,
  70255. origins: origins,
  70256. resolutions: resolutions,
  70257. matrixIds: matrixIds,
  70258. tileSizes: tileSizes,
  70259. sizes: sizes
  70260. });
  70261. };
  70262. goog.provide('ol.source.WMTS');
  70263. goog.require('ol');
  70264. goog.require('ol.TileUrlFunction');
  70265. goog.require('ol.array');
  70266. goog.require('ol.extent');
  70267. goog.require('ol.obj');
  70268. goog.require('ol.proj');
  70269. goog.require('ol.source.TileImage');
  70270. goog.require('ol.source.WMTSRequestEncoding');
  70271. goog.require('ol.tilegrid.WMTS');
  70272. goog.require('ol.uri');
  70273. /**
  70274. * @classdesc
  70275. * Layer source for tile data from WMTS servers.
  70276. *
  70277. * @constructor
  70278. * @extends {ol.source.TileImage}
  70279. * @param {olx.source.WMTSOptions} options WMTS options.
  70280. * @api
  70281. */
  70282. ol.source.WMTS = function(options) {
  70283. // TODO: add support for TileMatrixLimits
  70284. /**
  70285. * @private
  70286. * @type {string}
  70287. */
  70288. this.version_ = options.version !== undefined ? options.version : '1.0.0';
  70289. /**
  70290. * @private
  70291. * @type {string}
  70292. */
  70293. this.format_ = options.format !== undefined ? options.format : 'image/jpeg';
  70294. /**
  70295. * @private
  70296. * @type {!Object}
  70297. */
  70298. this.dimensions_ = options.dimensions !== undefined ? options.dimensions : {};
  70299. /**
  70300. * @private
  70301. * @type {string}
  70302. */
  70303. this.layer_ = options.layer;
  70304. /**
  70305. * @private
  70306. * @type {string}
  70307. */
  70308. this.matrixSet_ = options.matrixSet;
  70309. /**
  70310. * @private
  70311. * @type {string}
  70312. */
  70313. this.style_ = options.style;
  70314. var urls = options.urls;
  70315. if (urls === undefined && options.url !== undefined) {
  70316. urls = ol.TileUrlFunction.expandUrl(options.url);
  70317. }
  70318. // FIXME: should we guess this requestEncoding from options.url(s)
  70319. // structure? that would mean KVP only if a template is not provided.
  70320. /**
  70321. * @private
  70322. * @type {ol.source.WMTSRequestEncoding}
  70323. */
  70324. this.requestEncoding_ = options.requestEncoding !== undefined ?
  70325. /** @type {ol.source.WMTSRequestEncoding} */ (options.requestEncoding) :
  70326. ol.source.WMTSRequestEncoding.KVP;
  70327. var requestEncoding = this.requestEncoding_;
  70328. // FIXME: should we create a default tileGrid?
  70329. // we could issue a getCapabilities xhr to retrieve missing configuration
  70330. var tileGrid = options.tileGrid;
  70331. // context property names are lower case to allow for a case insensitive
  70332. // replacement as some services use different naming conventions
  70333. var context = {
  70334. 'layer': this.layer_,
  70335. 'style': this.style_,
  70336. 'tilematrixset': this.matrixSet_
  70337. };
  70338. if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
  70339. ol.obj.assign(context, {
  70340. 'Service': 'WMTS',
  70341. 'Request': 'GetTile',
  70342. 'Version': this.version_,
  70343. 'Format': this.format_
  70344. });
  70345. }
  70346. var dimensions = this.dimensions_;
  70347. /**
  70348. * @param {string} template Template.
  70349. * @return {ol.TileUrlFunctionType} Tile URL function.
  70350. * @private
  70351. */
  70352. this.createFromWMTSTemplate_ = function(template) {
  70353. // TODO: we may want to create our own appendParams function so that params
  70354. // order conforms to wmts spec guidance, and so that we can avoid to escape
  70355. // special template params
  70356. template = (requestEncoding == ol.source.WMTSRequestEncoding.KVP) ?
  70357. ol.uri.appendParams(template, context) :
  70358. template.replace(/\{(\w+?)\}/g, function(m, p) {
  70359. return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
  70360. });
  70361. return (
  70362. /**
  70363. * @param {ol.TileCoord} tileCoord Tile coordinate.
  70364. * @param {number} pixelRatio Pixel ratio.
  70365. * @param {ol.proj.Projection} projection Projection.
  70366. * @return {string|undefined} Tile URL.
  70367. */
  70368. function(tileCoord, pixelRatio, projection) {
  70369. if (!tileCoord) {
  70370. return undefined;
  70371. } else {
  70372. var localContext = {
  70373. 'TileMatrix': tileGrid.getMatrixId(tileCoord[0]),
  70374. 'TileCol': tileCoord[1],
  70375. 'TileRow': -tileCoord[2] - 1
  70376. };
  70377. ol.obj.assign(localContext, dimensions);
  70378. var url = template;
  70379. if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
  70380. url = ol.uri.appendParams(url, localContext);
  70381. } else {
  70382. url = url.replace(/\{(\w+?)\}/g, function(m, p) {
  70383. return localContext[p];
  70384. });
  70385. }
  70386. return url;
  70387. }
  70388. });
  70389. };
  70390. var tileUrlFunction = (urls && urls.length > 0) ?
  70391. ol.TileUrlFunction.createFromTileUrlFunctions(
  70392. urls.map(this.createFromWMTSTemplate_)) :
  70393. ol.TileUrlFunction.nullTileUrlFunction;
  70394. ol.source.TileImage.call(this, {
  70395. attributions: options.attributions,
  70396. cacheSize: options.cacheSize,
  70397. crossOrigin: options.crossOrigin,
  70398. logo: options.logo,
  70399. projection: options.projection,
  70400. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  70401. tileClass: options.tileClass,
  70402. tileGrid: tileGrid,
  70403. tileLoadFunction: options.tileLoadFunction,
  70404. tilePixelRatio: options.tilePixelRatio,
  70405. tileUrlFunction: tileUrlFunction,
  70406. urls: urls,
  70407. wrapX: options.wrapX !== undefined ? options.wrapX : false,
  70408. transition: options.transition
  70409. });
  70410. this.setKey(this.getKeyForDimensions_());
  70411. };
  70412. ol.inherits(ol.source.WMTS, ol.source.TileImage);
  70413. /**
  70414. * Set the URLs to use for requests.
  70415. * URLs may contain OCG conform URL Template Variables: {TileMatrix}, {TileRow}, {TileCol}.
  70416. * @override
  70417. */
  70418. ol.source.WMTS.prototype.setUrls = function(urls) {
  70419. this.urls = urls;
  70420. var key = urls.join('\n');
  70421. this.setTileUrlFunction(this.fixedTileUrlFunction ?
  70422. this.fixedTileUrlFunction.bind(this) :
  70423. ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(this.createFromWMTSTemplate_.bind(this))), key);
  70424. };
  70425. /**
  70426. * Get the dimensions, i.e. those passed to the constructor through the
  70427. * "dimensions" option, and possibly updated using the updateDimensions
  70428. * method.
  70429. * @return {!Object} Dimensions.
  70430. * @api
  70431. */
  70432. ol.source.WMTS.prototype.getDimensions = function() {
  70433. return this.dimensions_;
  70434. };
  70435. /**
  70436. * Return the image format of the WMTS source.
  70437. * @return {string} Format.
  70438. * @api
  70439. */
  70440. ol.source.WMTS.prototype.getFormat = function() {
  70441. return this.format_;
  70442. };
  70443. /**
  70444. * Return the layer of the WMTS source.
  70445. * @return {string} Layer.
  70446. * @api
  70447. */
  70448. ol.source.WMTS.prototype.getLayer = function() {
  70449. return this.layer_;
  70450. };
  70451. /**
  70452. * Return the matrix set of the WMTS source.
  70453. * @return {string} MatrixSet.
  70454. * @api
  70455. */
  70456. ol.source.WMTS.prototype.getMatrixSet = function() {
  70457. return this.matrixSet_;
  70458. };
  70459. /**
  70460. * Return the request encoding, either "KVP" or "REST".
  70461. * @return {ol.source.WMTSRequestEncoding} Request encoding.
  70462. * @api
  70463. */
  70464. ol.source.WMTS.prototype.getRequestEncoding = function() {
  70465. return this.requestEncoding_;
  70466. };
  70467. /**
  70468. * Return the style of the WMTS source.
  70469. * @return {string} Style.
  70470. * @api
  70471. */
  70472. ol.source.WMTS.prototype.getStyle = function() {
  70473. return this.style_;
  70474. };
  70475. /**
  70476. * Return the version of the WMTS source.
  70477. * @return {string} Version.
  70478. * @api
  70479. */
  70480. ol.source.WMTS.prototype.getVersion = function() {
  70481. return this.version_;
  70482. };
  70483. /**
  70484. * @private
  70485. * @return {string} The key for the current dimensions.
  70486. */
  70487. ol.source.WMTS.prototype.getKeyForDimensions_ = function() {
  70488. var i = 0;
  70489. var res = [];
  70490. for (var key in this.dimensions_) {
  70491. res[i++] = key + '-' + this.dimensions_[key];
  70492. }
  70493. return res.join('/');
  70494. };
  70495. /**
  70496. * Update the dimensions.
  70497. * @param {Object} dimensions Dimensions.
  70498. * @api
  70499. */
  70500. ol.source.WMTS.prototype.updateDimensions = function(dimensions) {
  70501. ol.obj.assign(this.dimensions_, dimensions);
  70502. this.setKey(this.getKeyForDimensions_());
  70503. };
  70504. /**
  70505. * Generate source options from a capabilities object.
  70506. * @param {Object} wmtsCap An object representing the capabilities document.
  70507. * @param {Object} config Configuration properties for the layer. Defaults for
  70508. * the layer will apply if not provided.
  70509. *
  70510. * Required config properties:
  70511. * - layer - {string} The layer identifier.
  70512. *
  70513. * Optional config properties:
  70514. * - matrixSet - {string} The matrix set identifier, required if there is
  70515. * more than one matrix set in the layer capabilities.
  70516. * - projection - {string} The desired CRS when no matrixSet is specified.
  70517. * eg: "EPSG:3857". If the desired projection is not available,
  70518. * an error is thrown.
  70519. * - requestEncoding - {string} url encoding format for the layer. Default is
  70520. * the first tile url format found in the GetCapabilities response.
  70521. * - style - {string} The name of the style
  70522. * - format - {string} Image format for the layer. Default is the first
  70523. * format returned in the GetCapabilities response.
  70524. * - crossOrigin - {string|null|undefined} Cross origin. Default is `undefined`.
  70525. * @return {?olx.source.WMTSOptions} WMTS source options object or `null` if the layer was not found.
  70526. * @api
  70527. */
  70528. ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
  70529. var layers = wmtsCap['Contents']['Layer'];
  70530. var l = ol.array.find(layers, function(elt, index, array) {
  70531. return elt['Identifier'] == config['layer'];
  70532. });
  70533. if (l === null) {
  70534. return null;
  70535. }
  70536. var tileMatrixSets = wmtsCap['Contents']['TileMatrixSet'];
  70537. var idx, matrixSet, matrixLimits;
  70538. if (l['TileMatrixSetLink'].length > 1) {
  70539. if ('projection' in config) {
  70540. idx = ol.array.findIndex(l['TileMatrixSetLink'],
  70541. function(elt, index, array) {
  70542. var tileMatrixSet = ol.array.find(tileMatrixSets, function(el) {
  70543. return el['Identifier'] == elt['TileMatrixSet'];
  70544. });
  70545. var supportedCRS = tileMatrixSet['SupportedCRS'];
  70546. var proj1 = ol.proj.get(supportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
  70547. ol.proj.get(supportedCRS);
  70548. var proj2 = ol.proj.get(config['projection']);
  70549. if (proj1 && proj2) {
  70550. return ol.proj.equivalent(proj1, proj2);
  70551. } else {
  70552. return supportedCRS == config['projection'];
  70553. }
  70554. });
  70555. } else {
  70556. idx = ol.array.findIndex(l['TileMatrixSetLink'],
  70557. function(elt, index, array) {
  70558. return elt['TileMatrixSet'] == config['matrixSet'];
  70559. });
  70560. }
  70561. } else {
  70562. idx = 0;
  70563. }
  70564. if (idx < 0) {
  70565. idx = 0;
  70566. }
  70567. matrixSet = /** @type {string} */
  70568. (l['TileMatrixSetLink'][idx]['TileMatrixSet']);
  70569. matrixLimits = /** @type {Array.<Object>} */
  70570. (l['TileMatrixSetLink'][idx]['TileMatrixSetLimits']);
  70571. var format = /** @type {string} */ (l['Format'][0]);
  70572. if ('format' in config) {
  70573. format = config['format'];
  70574. }
  70575. idx = ol.array.findIndex(l['Style'], function(elt, index, array) {
  70576. if ('style' in config) {
  70577. return elt['Title'] == config['style'];
  70578. } else {
  70579. return elt['isDefault'];
  70580. }
  70581. });
  70582. if (idx < 0) {
  70583. idx = 0;
  70584. }
  70585. var style = /** @type {string} */ (l['Style'][idx]['Identifier']);
  70586. var dimensions = {};
  70587. if ('Dimension' in l) {
  70588. l['Dimension'].forEach(function(elt, index, array) {
  70589. var key = elt['Identifier'];
  70590. var value = elt['Default'];
  70591. if (value === undefined) {
  70592. value = elt['Value'][0];
  70593. }
  70594. dimensions[key] = value;
  70595. });
  70596. }
  70597. var matrixSets = wmtsCap['Contents']['TileMatrixSet'];
  70598. var matrixSetObj = ol.array.find(matrixSets, function(elt, index, array) {
  70599. return elt['Identifier'] == matrixSet;
  70600. });
  70601. var projection;
  70602. var code = matrixSetObj['SupportedCRS'];
  70603. if (code) {
  70604. projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
  70605. ol.proj.get(code);
  70606. }
  70607. if ('projection' in config) {
  70608. var projConfig = ol.proj.get(config['projection']);
  70609. if (projConfig) {
  70610. if (!projection || ol.proj.equivalent(projConfig, projection)) {
  70611. projection = projConfig;
  70612. }
  70613. }
  70614. }
  70615. var wgs84BoundingBox = l['WGS84BoundingBox'];
  70616. var extent, wrapX;
  70617. if (wgs84BoundingBox !== undefined) {
  70618. var wgs84ProjectionExtent = ol.proj.get('EPSG:4326').getExtent();
  70619. wrapX = (wgs84BoundingBox[0] == wgs84ProjectionExtent[0] &&
  70620. wgs84BoundingBox[2] == wgs84ProjectionExtent[2]);
  70621. extent = ol.proj.transformExtent(
  70622. wgs84BoundingBox, 'EPSG:4326', projection);
  70623. var projectionExtent = projection.getExtent();
  70624. if (projectionExtent) {
  70625. // If possible, do a sanity check on the extent - it should never be
  70626. // bigger than the validity extent of the projection of a matrix set.
  70627. if (!ol.extent.containsExtent(projectionExtent, extent)) {
  70628. extent = undefined;
  70629. }
  70630. }
  70631. }
  70632. var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
  70633. matrixSetObj, extent, matrixLimits);
  70634. /** @type {!Array.<string>} */
  70635. var urls = [];
  70636. var requestEncoding = config['requestEncoding'];
  70637. requestEncoding = requestEncoding !== undefined ? requestEncoding : '';
  70638. if ('OperationsMetadata' in wmtsCap && 'GetTile' in wmtsCap['OperationsMetadata']) {
  70639. var gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'];
  70640. for (var i = 0, ii = gets.length; i < ii; ++i) {
  70641. if (gets[i]['Constraint']) {
  70642. var constraint = ol.array.find(gets[i]['Constraint'], function(element) {
  70643. return element['name'] == 'GetEncoding';
  70644. });
  70645. var encodings = constraint['AllowedValues']['Value'];
  70646. if (requestEncoding === '') {
  70647. // requestEncoding not provided, use the first encoding from the list
  70648. requestEncoding = encodings[0];
  70649. }
  70650. if (requestEncoding === ol.source.WMTSRequestEncoding.KVP) {
  70651. if (ol.array.includes(encodings, ol.source.WMTSRequestEncoding.KVP)) {
  70652. urls.push(/** @type {string} */ (gets[i]['href']));
  70653. }
  70654. } else {
  70655. break;
  70656. }
  70657. } else if (gets[i]['href']) {
  70658. requestEncoding = ol.source.WMTSRequestEncoding.KVP;
  70659. urls.push(/** @type {string} */ (gets[i]['href']));
  70660. }
  70661. }
  70662. }
  70663. if (urls.length === 0) {
  70664. requestEncoding = ol.source.WMTSRequestEncoding.REST;
  70665. l['ResourceURL'].forEach(function(element) {
  70666. if (element['resourceType'] === 'tile') {
  70667. format = element['format'];
  70668. urls.push(/** @type {string} */ (element['template']));
  70669. }
  70670. });
  70671. }
  70672. return {
  70673. urls: urls,
  70674. layer: config['layer'],
  70675. matrixSet: matrixSet,
  70676. format: format,
  70677. projection: projection,
  70678. requestEncoding: requestEncoding,
  70679. tileGrid: tileGrid,
  70680. style: style,
  70681. dimensions: dimensions,
  70682. wrapX: wrapX,
  70683. crossOrigin: config['crossOrigin']
  70684. };
  70685. };
  70686. goog.provide('ol.source.Zoomify');
  70687. goog.require('ol');
  70688. goog.require('ol.ImageTile');
  70689. goog.require('ol.TileState');
  70690. goog.require('ol.TileUrlFunction');
  70691. goog.require('ol.asserts');
  70692. goog.require('ol.dom');
  70693. goog.require('ol.extent');
  70694. goog.require('ol.size');
  70695. goog.require('ol.source.TileImage');
  70696. goog.require('ol.tilegrid.TileGrid');
  70697. /**
  70698. * @classdesc
  70699. * Layer source for tile data in Zoomify format (both Zoomify and Internet
  70700. * Imaging Protocol are supported).
  70701. *
  70702. * @constructor
  70703. * @extends {ol.source.TileImage}
  70704. * @param {olx.source.ZoomifyOptions=} opt_options Options.
  70705. * @api
  70706. */
  70707. ol.source.Zoomify = function(opt_options) {
  70708. var options = opt_options || {};
  70709. var size = options.size;
  70710. var tierSizeCalculation = options.tierSizeCalculation !== undefined ?
  70711. options.tierSizeCalculation :
  70712. ol.source.Zoomify.TierSizeCalculation_.DEFAULT;
  70713. var imageWidth = size[0];
  70714. var imageHeight = size[1];
  70715. var extent = options.extent || [0, -size[1], size[0], 0];
  70716. var tierSizeInTiles = [];
  70717. var tileSize = options.tileSize || ol.DEFAULT_TILE_SIZE;
  70718. var tileSizeForTierSizeCalculation = tileSize;
  70719. switch (tierSizeCalculation) {
  70720. case ol.source.Zoomify.TierSizeCalculation_.DEFAULT:
  70721. while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
  70722. tierSizeInTiles.push([
  70723. Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
  70724. Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
  70725. ]);
  70726. tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
  70727. }
  70728. break;
  70729. case ol.source.Zoomify.TierSizeCalculation_.TRUNCATED:
  70730. var width = imageWidth;
  70731. var height = imageHeight;
  70732. while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
  70733. tierSizeInTiles.push([
  70734. Math.ceil(width / tileSizeForTierSizeCalculation),
  70735. Math.ceil(height / tileSizeForTierSizeCalculation)
  70736. ]);
  70737. width >>= 1;
  70738. height >>= 1;
  70739. }
  70740. break;
  70741. default:
  70742. ol.asserts.assert(false, 53); // Unknown `tierSizeCalculation` configured
  70743. break;
  70744. }
  70745. tierSizeInTiles.push([1, 1]);
  70746. tierSizeInTiles.reverse();
  70747. var resolutions = [1];
  70748. var tileCountUpToTier = [0];
  70749. var i, ii;
  70750. for (i = 1, ii = tierSizeInTiles.length; i < ii; i++) {
  70751. resolutions.push(1 << i);
  70752. tileCountUpToTier.push(
  70753. tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] +
  70754. tileCountUpToTier[i - 1]
  70755. );
  70756. }
  70757. resolutions.reverse();
  70758. var tileGrid = new ol.tilegrid.TileGrid({
  70759. tileSize: tileSize,
  70760. extent: extent,
  70761. origin: ol.extent.getTopLeft(extent),
  70762. resolutions: resolutions
  70763. });
  70764. var url = options.url;
  70765. if (url && url.indexOf('{TileGroup}') == -1 && url.indexOf('{tileIndex}') == -1) {
  70766. url += '{TileGroup}/{z}-{x}-{y}.jpg';
  70767. }
  70768. var urls = ol.TileUrlFunction.expandUrl(url);
  70769. /**
  70770. * @param {string} template Template.
  70771. * @return {ol.TileUrlFunctionType} Tile URL function.
  70772. */
  70773. function createFromTemplate(template) {
  70774. return (
  70775. /**
  70776. * @param {ol.TileCoord} tileCoord Tile Coordinate.
  70777. * @param {number} pixelRatio Pixel ratio.
  70778. * @param {ol.proj.Projection} projection Projection.
  70779. * @return {string|undefined} Tile URL.
  70780. */
  70781. function(tileCoord, pixelRatio, projection) {
  70782. if (!tileCoord) {
  70783. return undefined;
  70784. } else {
  70785. var tileCoordZ = tileCoord[0];
  70786. var tileCoordX = tileCoord[1];
  70787. var tileCoordY = -tileCoord[2] - 1;
  70788. var tileIndex =
  70789. tileCoordX +
  70790. tileCoordY * tierSizeInTiles[tileCoordZ][0];
  70791. var tileSize = tileGrid.getTileSize(tileCoordZ);
  70792. var tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
  70793. var localContext = {
  70794. 'z': tileCoordZ,
  70795. 'x': tileCoordX,
  70796. 'y': tileCoordY,
  70797. 'tileIndex': tileIndex,
  70798. 'TileGroup': 'TileGroup' + tileGroup
  70799. };
  70800. return template.replace(/\{(\w+?)\}/g, function(m, p) {
  70801. return localContext[p];
  70802. });
  70803. }
  70804. });
  70805. }
  70806. var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
  70807. var ZoomifyTileClass = ol.source.Zoomify.Tile_.bind(null, tileGrid);
  70808. ol.source.TileImage.call(this, {
  70809. attributions: options.attributions,
  70810. cacheSize: options.cacheSize,
  70811. crossOrigin: options.crossOrigin,
  70812. logo: options.logo,
  70813. projection: options.projection,
  70814. reprojectionErrorThreshold: options.reprojectionErrorThreshold,
  70815. tileClass: ZoomifyTileClass,
  70816. tileGrid: tileGrid,
  70817. tileUrlFunction: tileUrlFunction,
  70818. transition: options.transition
  70819. });
  70820. };
  70821. ol.inherits(ol.source.Zoomify, ol.source.TileImage);
  70822. /**
  70823. * @constructor
  70824. * @extends {ol.ImageTile}
  70825. * @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to.
  70826. * @param {ol.TileCoord} tileCoord Tile coordinate.
  70827. * @param {ol.TileState} state State.
  70828. * @param {string} src Image source URI.
  70829. * @param {?string} crossOrigin Cross origin.
  70830. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
  70831. * @param {olx.TileOptions=} opt_options Tile options.
  70832. * @private
  70833. */
  70834. ol.source.Zoomify.Tile_ = function(
  70835. tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
  70836. ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
  70837. /**
  70838. * @private
  70839. * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
  70840. */
  70841. this.zoomifyImage_ = null;
  70842. /**
  70843. * @private
  70844. * @type {ol.Size}
  70845. */
  70846. this.tileSize_ = ol.size.toSize(tileGrid.getTileSize(tileCoord[0]));
  70847. };
  70848. ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile);
  70849. /**
  70850. * @inheritDoc
  70851. */
  70852. ol.source.Zoomify.Tile_.prototype.getImage = function() {
  70853. if (this.zoomifyImage_) {
  70854. return this.zoomifyImage_;
  70855. }
  70856. var image = ol.ImageTile.prototype.getImage.call(this);
  70857. if (this.state == ol.TileState.LOADED) {
  70858. var tileSize = this.tileSize_;
  70859. if (image.width == tileSize[0] && image.height == tileSize[1]) {
  70860. this.zoomifyImage_ = image;
  70861. return image;
  70862. } else {
  70863. var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]);
  70864. context.drawImage(image, 0, 0);
  70865. this.zoomifyImage_ = context.canvas;
  70866. return context.canvas;
  70867. }
  70868. } else {
  70869. return image;
  70870. }
  70871. };
  70872. /**
  70873. * @enum {string}
  70874. * @private
  70875. */
  70876. ol.source.Zoomify.TierSizeCalculation_ = {
  70877. DEFAULT: 'default',
  70878. TRUNCATED: 'truncated'
  70879. };
  70880. // Copyright 2009 The Closure Library Authors.
  70881. // All Rights Reserved.
  70882. //
  70883. // Licensed under the Apache License, Version 2.0 (the "License");
  70884. // you may not use this file except in compliance with the License.
  70885. // You may obtain a copy of the License at
  70886. //
  70887. // http://www.apache.org/licenses/LICENSE-2.0
  70888. //
  70889. // Unless required by applicable law or agreed to in writing, software
  70890. // distributed under the License is distributed on an "AS-IS" BASIS,
  70891. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  70892. // See the License for the specific language governing permissions and
  70893. // limitations under the License.
  70894. //
  70895. // This file has been auto-generated by GenJsDeps, please do not edit.
  70896. goog.addDependency(
  70897. 'demos/editor/equationeditor.js', ['goog.demos.editor.EquationEditor'],
  70898. ['goog.ui.equation.EquationEditorDialog']);
  70899. goog.addDependency(
  70900. 'demos/editor/helloworld.js', ['goog.demos.editor.HelloWorld'],
  70901. ['goog.dom', 'goog.dom.TagName', 'goog.editor.Plugin']);
  70902. goog.addDependency(
  70903. 'demos/editor/helloworlddialog.js',
  70904. [
  70905. 'goog.demos.editor.HelloWorldDialog',
  70906. 'goog.demos.editor.HelloWorldDialog.OkEvent'
  70907. ],
  70908. [
  70909. 'goog.dom.TagName', 'goog.events.Event', 'goog.string',
  70910. 'goog.ui.editor.AbstractDialog', 'goog.ui.editor.AbstractDialog.Builder',
  70911. 'goog.ui.editor.AbstractDialog.EventType'
  70912. ]);
  70913. goog.addDependency(
  70914. 'demos/editor/helloworlddialogplugin.js',
  70915. [
  70916. 'goog.demos.editor.HelloWorldDialogPlugin',
  70917. 'goog.demos.editor.HelloWorldDialogPlugin.Command'
  70918. ],
  70919. [
  70920. 'goog.demos.editor.HelloWorldDialog', 'goog.dom.TagName',
  70921. 'goog.editor.plugins.AbstractDialogPlugin', 'goog.editor.range',
  70922. 'goog.functions', 'goog.ui.editor.AbstractDialog.EventType'
  70923. ]);
  70924. /**
  70925. * @fileoverview Custom exports file.
  70926. * @suppress {checkVars,extraRequire}
  70927. */
  70928. goog.require('ol');
  70929. goog.require('ol.AssertionError');
  70930. goog.require('ol.Attribution');
  70931. goog.require('ol.CanvasMap');
  70932. goog.require('ol.Collection');
  70933. goog.require('ol.DeviceOrientation');
  70934. goog.require('ol.Feature');
  70935. goog.require('ol.Geolocation');
  70936. goog.require('ol.Graticule');
  70937. goog.require('ol.Image');
  70938. goog.require('ol.ImageTile');
  70939. goog.require('ol.Kinetic');
  70940. goog.require('ol.Map');
  70941. goog.require('ol.MapBrowserEvent');
  70942. goog.require('ol.MapEvent');
  70943. goog.require('ol.Object');
  70944. goog.require('ol.Observable');
  70945. goog.require('ol.Overlay');
  70946. goog.require('ol.PluggableMap');
  70947. goog.require('ol.Sphere');
  70948. goog.require('ol.Tile');
  70949. goog.require('ol.VectorTile');
  70950. goog.require('ol.View');
  70951. goog.require('ol.color');
  70952. goog.require('ol.colorlike');
  70953. goog.require('ol.control');
  70954. goog.require('ol.control.Attribution');
  70955. goog.require('ol.control.Control');
  70956. goog.require('ol.control.FullScreen');
  70957. goog.require('ol.control.MousePosition');
  70958. goog.require('ol.control.OverviewMap');
  70959. goog.require('ol.control.Rotate');
  70960. goog.require('ol.control.ScaleLine');
  70961. goog.require('ol.control.Zoom');
  70962. goog.require('ol.control.ZoomSlider');
  70963. goog.require('ol.control.ZoomToExtent');
  70964. goog.require('ol.coordinate');
  70965. goog.require('ol.easing');
  70966. goog.require('ol.events.Event');
  70967. goog.require('ol.events.condition');
  70968. goog.require('ol.extent');
  70969. goog.require('ol.featureloader');
  70970. goog.require('ol.format.EsriJSON');
  70971. goog.require('ol.format.Feature');
  70972. goog.require('ol.format.GML');
  70973. goog.require('ol.format.GML2');
  70974. goog.require('ol.format.GML3');
  70975. goog.require('ol.format.GMLBase');
  70976. goog.require('ol.format.GPX');
  70977. goog.require('ol.format.GeoJSON');
  70978. goog.require('ol.format.IGC');
  70979. goog.require('ol.format.KML');
  70980. goog.require('ol.format.MVT');
  70981. goog.require('ol.format.OSMXML');
  70982. goog.require('ol.format.Polyline');
  70983. goog.require('ol.format.TopoJSON');
  70984. goog.require('ol.format.WFS');
  70985. goog.require('ol.format.WKT');
  70986. goog.require('ol.format.WMSCapabilities');
  70987. goog.require('ol.format.WMSGetFeatureInfo');
  70988. goog.require('ol.format.WMTSCapabilities');
  70989. goog.require('ol.format.filter');
  70990. goog.require('ol.format.filter.And');
  70991. goog.require('ol.format.filter.Bbox');
  70992. goog.require('ol.format.filter.Comparison');
  70993. goog.require('ol.format.filter.ComparisonBinary');
  70994. goog.require('ol.format.filter.Contains');
  70995. goog.require('ol.format.filter.During');
  70996. goog.require('ol.format.filter.EqualTo');
  70997. goog.require('ol.format.filter.Filter');
  70998. goog.require('ol.format.filter.GreaterThan');
  70999. goog.require('ol.format.filter.GreaterThanOrEqualTo');
  71000. goog.require('ol.format.filter.Intersects');
  71001. goog.require('ol.format.filter.IsBetween');
  71002. goog.require('ol.format.filter.IsLike');
  71003. goog.require('ol.format.filter.IsNull');
  71004. goog.require('ol.format.filter.LessThan');
  71005. goog.require('ol.format.filter.LessThanOrEqualTo');
  71006. goog.require('ol.format.filter.Not');
  71007. goog.require('ol.format.filter.NotEqualTo');
  71008. goog.require('ol.format.filter.Or');
  71009. goog.require('ol.format.filter.Spatial');
  71010. goog.require('ol.format.filter.Within');
  71011. goog.require('ol.geom.Circle');
  71012. goog.require('ol.geom.Geometry');
  71013. goog.require('ol.geom.GeometryCollection');
  71014. goog.require('ol.geom.LineString');
  71015. goog.require('ol.geom.LinearRing');
  71016. goog.require('ol.geom.MultiLineString');
  71017. goog.require('ol.geom.MultiPoint');
  71018. goog.require('ol.geom.MultiPolygon');
  71019. goog.require('ol.geom.Point');
  71020. goog.require('ol.geom.Polygon');
  71021. goog.require('ol.geom.SimpleGeometry');
  71022. goog.require('ol.has');
  71023. goog.require('ol.interaction');
  71024. goog.require('ol.interaction.DoubleClickZoom');
  71025. goog.require('ol.interaction.DragAndDrop');
  71026. goog.require('ol.interaction.DragBox');
  71027. goog.require('ol.interaction.DragPan');
  71028. goog.require('ol.interaction.DragRotate');
  71029. goog.require('ol.interaction.DragRotateAndZoom');
  71030. goog.require('ol.interaction.DragZoom');
  71031. goog.require('ol.interaction.Draw');
  71032. goog.require('ol.interaction.Extent');
  71033. goog.require('ol.interaction.Interaction');
  71034. goog.require('ol.interaction.KeyboardPan');
  71035. goog.require('ol.interaction.KeyboardZoom');
  71036. goog.require('ol.interaction.Modify');
  71037. goog.require('ol.interaction.MouseWheelZoom');
  71038. goog.require('ol.interaction.PinchRotate');
  71039. goog.require('ol.interaction.PinchZoom');
  71040. goog.require('ol.interaction.Pointer');
  71041. goog.require('ol.interaction.Select');
  71042. goog.require('ol.interaction.Snap');
  71043. goog.require('ol.interaction.Translate');
  71044. goog.require('ol.layer.Base');
  71045. goog.require('ol.layer.Group');
  71046. goog.require('ol.layer.Heatmap');
  71047. goog.require('ol.layer.Image');
  71048. goog.require('ol.layer.Layer');
  71049. goog.require('ol.layer.Tile');
  71050. goog.require('ol.layer.Vector');
  71051. goog.require('ol.layer.VectorTile');
  71052. goog.require('ol.loadingstrategy');
  71053. goog.require('ol.proj');
  71054. goog.require('ol.proj.Projection');
  71055. goog.require('ol.proj.Units');
  71056. goog.require('ol.proj.common');
  71057. goog.require('ol.render');
  71058. goog.require('ol.render.Event');
  71059. goog.require('ol.render.Feature');
  71060. goog.require('ol.render.VectorContext');
  71061. goog.require('ol.render.canvas.Immediate');
  71062. goog.require('ol.render.webgl.Immediate');
  71063. goog.require('ol.renderer.canvas.ImageLayer');
  71064. goog.require('ol.renderer.canvas.Map');
  71065. goog.require('ol.renderer.canvas.TileLayer');
  71066. goog.require('ol.renderer.canvas.VectorLayer');
  71067. goog.require('ol.renderer.canvas.VectorTileLayer');
  71068. goog.require('ol.renderer.webgl.ImageLayer');
  71069. goog.require('ol.renderer.webgl.Map');
  71070. goog.require('ol.renderer.webgl.TileLayer');
  71071. goog.require('ol.renderer.webgl.VectorLayer');
  71072. goog.require('ol.size');
  71073. goog.require('ol.source.BingMaps');
  71074. goog.require('ol.source.CartoDB');
  71075. goog.require('ol.source.Cluster');
  71076. goog.require('ol.source.Image');
  71077. goog.require('ol.source.ImageArcGISRest');
  71078. goog.require('ol.source.ImageCanvas');
  71079. goog.require('ol.source.ImageMapGuide');
  71080. goog.require('ol.source.ImageStatic');
  71081. goog.require('ol.source.ImageVector');
  71082. goog.require('ol.source.ImageWMS');
  71083. goog.require('ol.source.OSM');
  71084. goog.require('ol.source.Raster');
  71085. goog.require('ol.source.Source');
  71086. goog.require('ol.source.Stamen');
  71087. goog.require('ol.source.Tile');
  71088. goog.require('ol.source.TileArcGISRest');
  71089. goog.require('ol.source.TileDebug');
  71090. goog.require('ol.source.TileImage');
  71091. goog.require('ol.source.TileJSON');
  71092. goog.require('ol.source.TileUTFGrid');
  71093. goog.require('ol.source.TileWMS');
  71094. goog.require('ol.source.UrlTile');
  71095. goog.require('ol.source.Vector');
  71096. goog.require('ol.source.VectorTile');
  71097. goog.require('ol.source.WMTS');
  71098. goog.require('ol.source.XYZ');
  71099. goog.require('ol.source.Zoomify');
  71100. goog.require('ol.style');
  71101. goog.require('ol.style.AtlasManager');
  71102. goog.require('ol.style.Circle');
  71103. goog.require('ol.style.Fill');
  71104. goog.require('ol.style.Icon');
  71105. goog.require('ol.style.IconImageCache');
  71106. goog.require('ol.style.Image');
  71107. goog.require('ol.style.RegularShape');
  71108. goog.require('ol.style.Stroke');
  71109. goog.require('ol.style.Style');
  71110. goog.require('ol.style.Text');
  71111. goog.require('ol.tilegrid');
  71112. goog.require('ol.tilegrid.TileGrid');
  71113. goog.require('ol.tilegrid.WMTS');
  71114. goog.require('ol.webgl.Context');
  71115. goog.require('ol.xml');
  71116. goog.exportProperty(
  71117. ol.AssertionError.prototype,
  71118. 'code',
  71119. ol.AssertionError.prototype.code);
  71120. goog.exportSymbol(
  71121. 'ol.Attribution',
  71122. ol.Attribution,
  71123. OPENLAYERS);
  71124. goog.exportProperty(
  71125. ol.Attribution.prototype,
  71126. 'getHTML',
  71127. ol.Attribution.prototype.getHTML);
  71128. goog.exportSymbol(
  71129. 'ol.CanvasMap',
  71130. ol.CanvasMap,
  71131. OPENLAYERS);
  71132. goog.exportSymbol(
  71133. 'ol.Collection',
  71134. ol.Collection,
  71135. OPENLAYERS);
  71136. goog.exportProperty(
  71137. ol.Collection.prototype,
  71138. 'clear',
  71139. ol.Collection.prototype.clear);
  71140. goog.exportProperty(
  71141. ol.Collection.prototype,
  71142. 'extend',
  71143. ol.Collection.prototype.extend);
  71144. goog.exportProperty(
  71145. ol.Collection.prototype,
  71146. 'forEach',
  71147. ol.Collection.prototype.forEach);
  71148. goog.exportProperty(
  71149. ol.Collection.prototype,
  71150. 'getArray',
  71151. ol.Collection.prototype.getArray);
  71152. goog.exportProperty(
  71153. ol.Collection.prototype,
  71154. 'item',
  71155. ol.Collection.prototype.item);
  71156. goog.exportProperty(
  71157. ol.Collection.prototype,
  71158. 'getLength',
  71159. ol.Collection.prototype.getLength);
  71160. goog.exportProperty(
  71161. ol.Collection.prototype,
  71162. 'insertAt',
  71163. ol.Collection.prototype.insertAt);
  71164. goog.exportProperty(
  71165. ol.Collection.prototype,
  71166. 'pop',
  71167. ol.Collection.prototype.pop);
  71168. goog.exportProperty(
  71169. ol.Collection.prototype,
  71170. 'push',
  71171. ol.Collection.prototype.push);
  71172. goog.exportProperty(
  71173. ol.Collection.prototype,
  71174. 'remove',
  71175. ol.Collection.prototype.remove);
  71176. goog.exportProperty(
  71177. ol.Collection.prototype,
  71178. 'removeAt',
  71179. ol.Collection.prototype.removeAt);
  71180. goog.exportProperty(
  71181. ol.Collection.prototype,
  71182. 'setAt',
  71183. ol.Collection.prototype.setAt);
  71184. goog.exportProperty(
  71185. ol.Collection.Event.prototype,
  71186. 'element',
  71187. ol.Collection.Event.prototype.element);
  71188. goog.exportSymbol(
  71189. 'ol.color.asArray',
  71190. ol.color.asArray,
  71191. OPENLAYERS);
  71192. goog.exportSymbol(
  71193. 'ol.color.asString',
  71194. ol.color.asString,
  71195. OPENLAYERS);
  71196. goog.exportSymbol(
  71197. 'ol.colorlike.asColorLike',
  71198. ol.colorlike.asColorLike,
  71199. OPENLAYERS);
  71200. goog.exportSymbol(
  71201. 'ol.control.defaults',
  71202. ol.control.defaults,
  71203. OPENLAYERS);
  71204. goog.exportSymbol(
  71205. 'ol.coordinate.add',
  71206. ol.coordinate.add,
  71207. OPENLAYERS);
  71208. goog.exportSymbol(
  71209. 'ol.coordinate.createStringXY',
  71210. ol.coordinate.createStringXY,
  71211. OPENLAYERS);
  71212. goog.exportSymbol(
  71213. 'ol.coordinate.format',
  71214. ol.coordinate.format,
  71215. OPENLAYERS);
  71216. goog.exportSymbol(
  71217. 'ol.coordinate.rotate',
  71218. ol.coordinate.rotate,
  71219. OPENLAYERS);
  71220. goog.exportSymbol(
  71221. 'ol.coordinate.toStringHDMS',
  71222. ol.coordinate.toStringHDMS,
  71223. OPENLAYERS);
  71224. goog.exportSymbol(
  71225. 'ol.coordinate.toStringXY',
  71226. ol.coordinate.toStringXY,
  71227. OPENLAYERS);
  71228. goog.exportSymbol(
  71229. 'ol.DeviceOrientation',
  71230. ol.DeviceOrientation,
  71231. OPENLAYERS);
  71232. goog.exportProperty(
  71233. ol.DeviceOrientation.prototype,
  71234. 'getAlpha',
  71235. ol.DeviceOrientation.prototype.getAlpha);
  71236. goog.exportProperty(
  71237. ol.DeviceOrientation.prototype,
  71238. 'getBeta',
  71239. ol.DeviceOrientation.prototype.getBeta);
  71240. goog.exportProperty(
  71241. ol.DeviceOrientation.prototype,
  71242. 'getGamma',
  71243. ol.DeviceOrientation.prototype.getGamma);
  71244. goog.exportProperty(
  71245. ol.DeviceOrientation.prototype,
  71246. 'getHeading',
  71247. ol.DeviceOrientation.prototype.getHeading);
  71248. goog.exportProperty(
  71249. ol.DeviceOrientation.prototype,
  71250. 'getTracking',
  71251. ol.DeviceOrientation.prototype.getTracking);
  71252. goog.exportProperty(
  71253. ol.DeviceOrientation.prototype,
  71254. 'setTracking',
  71255. ol.DeviceOrientation.prototype.setTracking);
  71256. goog.exportSymbol(
  71257. 'ol.easing.easeIn',
  71258. ol.easing.easeIn,
  71259. OPENLAYERS);
  71260. goog.exportSymbol(
  71261. 'ol.easing.easeOut',
  71262. ol.easing.easeOut,
  71263. OPENLAYERS);
  71264. goog.exportSymbol(
  71265. 'ol.easing.inAndOut',
  71266. ol.easing.inAndOut,
  71267. OPENLAYERS);
  71268. goog.exportSymbol(
  71269. 'ol.easing.linear',
  71270. ol.easing.linear,
  71271. OPENLAYERS);
  71272. goog.exportSymbol(
  71273. 'ol.easing.upAndDown',
  71274. ol.easing.upAndDown,
  71275. OPENLAYERS);
  71276. goog.exportSymbol(
  71277. 'ol.extent.boundingExtent',
  71278. ol.extent.boundingExtent,
  71279. OPENLAYERS);
  71280. goog.exportSymbol(
  71281. 'ol.extent.buffer',
  71282. ol.extent.buffer,
  71283. OPENLAYERS);
  71284. goog.exportSymbol(
  71285. 'ol.extent.containsCoordinate',
  71286. ol.extent.containsCoordinate,
  71287. OPENLAYERS);
  71288. goog.exportSymbol(
  71289. 'ol.extent.containsExtent',
  71290. ol.extent.containsExtent,
  71291. OPENLAYERS);
  71292. goog.exportSymbol(
  71293. 'ol.extent.containsXY',
  71294. ol.extent.containsXY,
  71295. OPENLAYERS);
  71296. goog.exportSymbol(
  71297. 'ol.extent.createEmpty',
  71298. ol.extent.createEmpty,
  71299. OPENLAYERS);
  71300. goog.exportSymbol(
  71301. 'ol.extent.equals',
  71302. ol.extent.equals,
  71303. OPENLAYERS);
  71304. goog.exportSymbol(
  71305. 'ol.extent.extend',
  71306. ol.extent.extend,
  71307. OPENLAYERS);
  71308. goog.exportSymbol(
  71309. 'ol.extent.getArea',
  71310. ol.extent.getArea,
  71311. OPENLAYERS);
  71312. goog.exportSymbol(
  71313. 'ol.extent.getBottomLeft',
  71314. ol.extent.getBottomLeft,
  71315. OPENLAYERS);
  71316. goog.exportSymbol(
  71317. 'ol.extent.getBottomRight',
  71318. ol.extent.getBottomRight,
  71319. OPENLAYERS);
  71320. goog.exportSymbol(
  71321. 'ol.extent.getCenter',
  71322. ol.extent.getCenter,
  71323. OPENLAYERS);
  71324. goog.exportSymbol(
  71325. 'ol.extent.getHeight',
  71326. ol.extent.getHeight,
  71327. OPENLAYERS);
  71328. goog.exportSymbol(
  71329. 'ol.extent.getIntersection',
  71330. ol.extent.getIntersection,
  71331. OPENLAYERS);
  71332. goog.exportSymbol(
  71333. 'ol.extent.getSize',
  71334. ol.extent.getSize,
  71335. OPENLAYERS);
  71336. goog.exportSymbol(
  71337. 'ol.extent.getTopLeft',
  71338. ol.extent.getTopLeft,
  71339. OPENLAYERS);
  71340. goog.exportSymbol(
  71341. 'ol.extent.getTopRight',
  71342. ol.extent.getTopRight,
  71343. OPENLAYERS);
  71344. goog.exportSymbol(
  71345. 'ol.extent.getWidth',
  71346. ol.extent.getWidth,
  71347. OPENLAYERS);
  71348. goog.exportSymbol(
  71349. 'ol.extent.intersects',
  71350. ol.extent.intersects,
  71351. OPENLAYERS);
  71352. goog.exportSymbol(
  71353. 'ol.extent.isEmpty',
  71354. ol.extent.isEmpty,
  71355. OPENLAYERS);
  71356. goog.exportSymbol(
  71357. 'ol.extent.applyTransform',
  71358. ol.extent.applyTransform,
  71359. OPENLAYERS);
  71360. goog.exportSymbol(
  71361. 'ol.Feature',
  71362. ol.Feature,
  71363. OPENLAYERS);
  71364. goog.exportProperty(
  71365. ol.Feature.prototype,
  71366. 'clone',
  71367. ol.Feature.prototype.clone);
  71368. goog.exportProperty(
  71369. ol.Feature.prototype,
  71370. 'getGeometry',
  71371. ol.Feature.prototype.getGeometry);
  71372. goog.exportProperty(
  71373. ol.Feature.prototype,
  71374. 'getId',
  71375. ol.Feature.prototype.getId);
  71376. goog.exportProperty(
  71377. ol.Feature.prototype,
  71378. 'getGeometryName',
  71379. ol.Feature.prototype.getGeometryName);
  71380. goog.exportProperty(
  71381. ol.Feature.prototype,
  71382. 'getStyle',
  71383. ol.Feature.prototype.getStyle);
  71384. goog.exportProperty(
  71385. ol.Feature.prototype,
  71386. 'getStyleFunction',
  71387. ol.Feature.prototype.getStyleFunction);
  71388. goog.exportProperty(
  71389. ol.Feature.prototype,
  71390. 'setGeometry',
  71391. ol.Feature.prototype.setGeometry);
  71392. goog.exportProperty(
  71393. ol.Feature.prototype,
  71394. 'setStyle',
  71395. ol.Feature.prototype.setStyle);
  71396. goog.exportProperty(
  71397. ol.Feature.prototype,
  71398. 'setId',
  71399. ol.Feature.prototype.setId);
  71400. goog.exportProperty(
  71401. ol.Feature.prototype,
  71402. 'setGeometryName',
  71403. ol.Feature.prototype.setGeometryName);
  71404. goog.exportSymbol(
  71405. 'ol.featureloader.xhr',
  71406. ol.featureloader.xhr,
  71407. OPENLAYERS);
  71408. goog.exportSymbol(
  71409. 'ol.Geolocation',
  71410. ol.Geolocation,
  71411. OPENLAYERS);
  71412. goog.exportProperty(
  71413. ol.Geolocation.prototype,
  71414. 'getAccuracy',
  71415. ol.Geolocation.prototype.getAccuracy);
  71416. goog.exportProperty(
  71417. ol.Geolocation.prototype,
  71418. 'getAccuracyGeometry',
  71419. ol.Geolocation.prototype.getAccuracyGeometry);
  71420. goog.exportProperty(
  71421. ol.Geolocation.prototype,
  71422. 'getAltitude',
  71423. ol.Geolocation.prototype.getAltitude);
  71424. goog.exportProperty(
  71425. ol.Geolocation.prototype,
  71426. 'getAltitudeAccuracy',
  71427. ol.Geolocation.prototype.getAltitudeAccuracy);
  71428. goog.exportProperty(
  71429. ol.Geolocation.prototype,
  71430. 'getHeading',
  71431. ol.Geolocation.prototype.getHeading);
  71432. goog.exportProperty(
  71433. ol.Geolocation.prototype,
  71434. 'getPosition',
  71435. ol.Geolocation.prototype.getPosition);
  71436. goog.exportProperty(
  71437. ol.Geolocation.prototype,
  71438. 'getProjection',
  71439. ol.Geolocation.prototype.getProjection);
  71440. goog.exportProperty(
  71441. ol.Geolocation.prototype,
  71442. 'getSpeed',
  71443. ol.Geolocation.prototype.getSpeed);
  71444. goog.exportProperty(
  71445. ol.Geolocation.prototype,
  71446. 'getTracking',
  71447. ol.Geolocation.prototype.getTracking);
  71448. goog.exportProperty(
  71449. ol.Geolocation.prototype,
  71450. 'getTrackingOptions',
  71451. ol.Geolocation.prototype.getTrackingOptions);
  71452. goog.exportProperty(
  71453. ol.Geolocation.prototype,
  71454. 'setProjection',
  71455. ol.Geolocation.prototype.setProjection);
  71456. goog.exportProperty(
  71457. ol.Geolocation.prototype,
  71458. 'setTracking',
  71459. ol.Geolocation.prototype.setTracking);
  71460. goog.exportProperty(
  71461. ol.Geolocation.prototype,
  71462. 'setTrackingOptions',
  71463. ol.Geolocation.prototype.setTrackingOptions);
  71464. goog.exportSymbol(
  71465. 'ol.Graticule',
  71466. ol.Graticule,
  71467. OPENLAYERS);
  71468. goog.exportProperty(
  71469. ol.Graticule.prototype,
  71470. 'getMap',
  71471. ol.Graticule.prototype.getMap);
  71472. goog.exportProperty(
  71473. ol.Graticule.prototype,
  71474. 'getMeridians',
  71475. ol.Graticule.prototype.getMeridians);
  71476. goog.exportProperty(
  71477. ol.Graticule.prototype,
  71478. 'getParallels',
  71479. ol.Graticule.prototype.getParallels);
  71480. goog.exportProperty(
  71481. ol.Graticule.prototype,
  71482. 'setMap',
  71483. ol.Graticule.prototype.setMap);
  71484. goog.exportSymbol(
  71485. 'ol.has.DEVICE_PIXEL_RATIO',
  71486. ol.has.DEVICE_PIXEL_RATIO,
  71487. OPENLAYERS);
  71488. goog.exportSymbol(
  71489. 'ol.has.CANVAS',
  71490. ol.has.CANVAS,
  71491. OPENLAYERS);
  71492. goog.exportSymbol(
  71493. 'ol.has.DEVICE_ORIENTATION',
  71494. ol.has.DEVICE_ORIENTATION,
  71495. OPENLAYERS);
  71496. goog.exportSymbol(
  71497. 'ol.has.GEOLOCATION',
  71498. ol.has.GEOLOCATION,
  71499. OPENLAYERS);
  71500. goog.exportSymbol(
  71501. 'ol.has.TOUCH',
  71502. ol.has.TOUCH,
  71503. OPENLAYERS);
  71504. goog.exportSymbol(
  71505. 'ol.has.WEBGL',
  71506. ol.has.WEBGL,
  71507. OPENLAYERS);
  71508. goog.exportProperty(
  71509. ol.Image.prototype,
  71510. 'getImage',
  71511. ol.Image.prototype.getImage);
  71512. goog.exportProperty(
  71513. ol.Image.prototype,
  71514. 'load',
  71515. ol.Image.prototype.load);
  71516. goog.exportProperty(
  71517. ol.ImageTile.prototype,
  71518. 'getImage',
  71519. ol.ImageTile.prototype.getImage);
  71520. goog.exportSymbol(
  71521. 'ol.inherits',
  71522. ol.inherits,
  71523. OPENLAYERS);
  71524. goog.exportSymbol(
  71525. 'ol.interaction.defaults',
  71526. ol.interaction.defaults,
  71527. OPENLAYERS);
  71528. goog.exportSymbol(
  71529. 'ol.Kinetic',
  71530. ol.Kinetic,
  71531. OPENLAYERS);
  71532. goog.exportSymbol(
  71533. 'ol.loadingstrategy.all',
  71534. ol.loadingstrategy.all,
  71535. OPENLAYERS);
  71536. goog.exportSymbol(
  71537. 'ol.loadingstrategy.bbox',
  71538. ol.loadingstrategy.bbox,
  71539. OPENLAYERS);
  71540. goog.exportSymbol(
  71541. 'ol.loadingstrategy.tile',
  71542. ol.loadingstrategy.tile,
  71543. OPENLAYERS);
  71544. goog.exportSymbol(
  71545. 'ol.Map',
  71546. ol.Map,
  71547. OPENLAYERS);
  71548. goog.exportProperty(
  71549. ol.MapBrowserEvent.prototype,
  71550. 'originalEvent',
  71551. ol.MapBrowserEvent.prototype.originalEvent);
  71552. goog.exportProperty(
  71553. ol.MapBrowserEvent.prototype,
  71554. 'pixel',
  71555. ol.MapBrowserEvent.prototype.pixel);
  71556. goog.exportProperty(
  71557. ol.MapBrowserEvent.prototype,
  71558. 'coordinate',
  71559. ol.MapBrowserEvent.prototype.coordinate);
  71560. goog.exportProperty(
  71561. ol.MapBrowserEvent.prototype,
  71562. 'dragging',
  71563. ol.MapBrowserEvent.prototype.dragging);
  71564. goog.exportProperty(
  71565. ol.MapEvent.prototype,
  71566. 'map',
  71567. ol.MapEvent.prototype.map);
  71568. goog.exportProperty(
  71569. ol.MapEvent.prototype,
  71570. 'frameState',
  71571. ol.MapEvent.prototype.frameState);
  71572. goog.exportSymbol(
  71573. 'ol.Object',
  71574. ol.Object,
  71575. OPENLAYERS);
  71576. goog.exportProperty(
  71577. ol.Object.prototype,
  71578. 'get',
  71579. ol.Object.prototype.get);
  71580. goog.exportProperty(
  71581. ol.Object.prototype,
  71582. 'getKeys',
  71583. ol.Object.prototype.getKeys);
  71584. goog.exportProperty(
  71585. ol.Object.prototype,
  71586. 'getProperties',
  71587. ol.Object.prototype.getProperties);
  71588. goog.exportProperty(
  71589. ol.Object.prototype,
  71590. 'set',
  71591. ol.Object.prototype.set);
  71592. goog.exportProperty(
  71593. ol.Object.prototype,
  71594. 'setProperties',
  71595. ol.Object.prototype.setProperties);
  71596. goog.exportProperty(
  71597. ol.Object.prototype,
  71598. 'unset',
  71599. ol.Object.prototype.unset);
  71600. goog.exportProperty(
  71601. ol.Object.Event.prototype,
  71602. 'key',
  71603. ol.Object.Event.prototype.key);
  71604. goog.exportProperty(
  71605. ol.Object.Event.prototype,
  71606. 'oldValue',
  71607. ol.Object.Event.prototype.oldValue);
  71608. goog.exportSymbol(
  71609. 'ol.Observable',
  71610. ol.Observable,
  71611. OPENLAYERS);
  71612. goog.exportSymbol(
  71613. 'ol.Observable.unByKey',
  71614. ol.Observable.unByKey,
  71615. OPENLAYERS);
  71616. goog.exportProperty(
  71617. ol.Observable.prototype,
  71618. 'changed',
  71619. ol.Observable.prototype.changed);
  71620. goog.exportProperty(
  71621. ol.Observable.prototype,
  71622. 'dispatchEvent',
  71623. ol.Observable.prototype.dispatchEvent);
  71624. goog.exportProperty(
  71625. ol.Observable.prototype,
  71626. 'getRevision',
  71627. ol.Observable.prototype.getRevision);
  71628. goog.exportProperty(
  71629. ol.Observable.prototype,
  71630. 'on',
  71631. ol.Observable.prototype.on);
  71632. goog.exportProperty(
  71633. ol.Observable.prototype,
  71634. 'once',
  71635. ol.Observable.prototype.once);
  71636. goog.exportProperty(
  71637. ol.Observable.prototype,
  71638. 'un',
  71639. ol.Observable.prototype.un);
  71640. goog.exportSymbol(
  71641. 'ol.Overlay',
  71642. ol.Overlay,
  71643. OPENLAYERS);
  71644. goog.exportProperty(
  71645. ol.Overlay.prototype,
  71646. 'getElement',
  71647. ol.Overlay.prototype.getElement);
  71648. goog.exportProperty(
  71649. ol.Overlay.prototype,
  71650. 'getId',
  71651. ol.Overlay.prototype.getId);
  71652. goog.exportProperty(
  71653. ol.Overlay.prototype,
  71654. 'getMap',
  71655. ol.Overlay.prototype.getMap);
  71656. goog.exportProperty(
  71657. ol.Overlay.prototype,
  71658. 'getOffset',
  71659. ol.Overlay.prototype.getOffset);
  71660. goog.exportProperty(
  71661. ol.Overlay.prototype,
  71662. 'getPosition',
  71663. ol.Overlay.prototype.getPosition);
  71664. goog.exportProperty(
  71665. ol.Overlay.prototype,
  71666. 'getPositioning',
  71667. ol.Overlay.prototype.getPositioning);
  71668. goog.exportProperty(
  71669. ol.Overlay.prototype,
  71670. 'setElement',
  71671. ol.Overlay.prototype.setElement);
  71672. goog.exportProperty(
  71673. ol.Overlay.prototype,
  71674. 'setMap',
  71675. ol.Overlay.prototype.setMap);
  71676. goog.exportProperty(
  71677. ol.Overlay.prototype,
  71678. 'setOffset',
  71679. ol.Overlay.prototype.setOffset);
  71680. goog.exportProperty(
  71681. ol.Overlay.prototype,
  71682. 'setPosition',
  71683. ol.Overlay.prototype.setPosition);
  71684. goog.exportProperty(
  71685. ol.Overlay.prototype,
  71686. 'setPositioning',
  71687. ol.Overlay.prototype.setPositioning);
  71688. goog.exportSymbol(
  71689. 'ol.PluggableMap',
  71690. ol.PluggableMap,
  71691. OPENLAYERS);
  71692. goog.exportProperty(
  71693. ol.PluggableMap.prototype,
  71694. 'addControl',
  71695. ol.PluggableMap.prototype.addControl);
  71696. goog.exportProperty(
  71697. ol.PluggableMap.prototype,
  71698. 'addInteraction',
  71699. ol.PluggableMap.prototype.addInteraction);
  71700. goog.exportProperty(
  71701. ol.PluggableMap.prototype,
  71702. 'addLayer',
  71703. ol.PluggableMap.prototype.addLayer);
  71704. goog.exportProperty(
  71705. ol.PluggableMap.prototype,
  71706. 'addOverlay',
  71707. ol.PluggableMap.prototype.addOverlay);
  71708. goog.exportProperty(
  71709. ol.PluggableMap.prototype,
  71710. 'forEachFeatureAtPixel',
  71711. ol.PluggableMap.prototype.forEachFeatureAtPixel);
  71712. goog.exportProperty(
  71713. ol.PluggableMap.prototype,
  71714. 'getFeaturesAtPixel',
  71715. ol.PluggableMap.prototype.getFeaturesAtPixel);
  71716. goog.exportProperty(
  71717. ol.PluggableMap.prototype,
  71718. 'forEachLayerAtPixel',
  71719. ol.PluggableMap.prototype.forEachLayerAtPixel);
  71720. goog.exportProperty(
  71721. ol.PluggableMap.prototype,
  71722. 'hasFeatureAtPixel',
  71723. ol.PluggableMap.prototype.hasFeatureAtPixel);
  71724. goog.exportProperty(
  71725. ol.PluggableMap.prototype,
  71726. 'getEventCoordinate',
  71727. ol.PluggableMap.prototype.getEventCoordinate);
  71728. goog.exportProperty(
  71729. ol.PluggableMap.prototype,
  71730. 'getEventPixel',
  71731. ol.PluggableMap.prototype.getEventPixel);
  71732. goog.exportProperty(
  71733. ol.PluggableMap.prototype,
  71734. 'getTarget',
  71735. ol.PluggableMap.prototype.getTarget);
  71736. goog.exportProperty(
  71737. ol.PluggableMap.prototype,
  71738. 'getTargetElement',
  71739. ol.PluggableMap.prototype.getTargetElement);
  71740. goog.exportProperty(
  71741. ol.PluggableMap.prototype,
  71742. 'getCoordinateFromPixel',
  71743. ol.PluggableMap.prototype.getCoordinateFromPixel);
  71744. goog.exportProperty(
  71745. ol.PluggableMap.prototype,
  71746. 'getControls',
  71747. ol.PluggableMap.prototype.getControls);
  71748. goog.exportProperty(
  71749. ol.PluggableMap.prototype,
  71750. 'getOverlays',
  71751. ol.PluggableMap.prototype.getOverlays);
  71752. goog.exportProperty(
  71753. ol.PluggableMap.prototype,
  71754. 'getOverlayById',
  71755. ol.PluggableMap.prototype.getOverlayById);
  71756. goog.exportProperty(
  71757. ol.PluggableMap.prototype,
  71758. 'getInteractions',
  71759. ol.PluggableMap.prototype.getInteractions);
  71760. goog.exportProperty(
  71761. ol.PluggableMap.prototype,
  71762. 'getLayerGroup',
  71763. ol.PluggableMap.prototype.getLayerGroup);
  71764. goog.exportProperty(
  71765. ol.PluggableMap.prototype,
  71766. 'getLayers',
  71767. ol.PluggableMap.prototype.getLayers);
  71768. goog.exportProperty(
  71769. ol.PluggableMap.prototype,
  71770. 'getPixelFromCoordinate',
  71771. ol.PluggableMap.prototype.getPixelFromCoordinate);
  71772. goog.exportProperty(
  71773. ol.PluggableMap.prototype,
  71774. 'getSize',
  71775. ol.PluggableMap.prototype.getSize);
  71776. goog.exportProperty(
  71777. ol.PluggableMap.prototype,
  71778. 'getView',
  71779. ol.PluggableMap.prototype.getView);
  71780. goog.exportProperty(
  71781. ol.PluggableMap.prototype,
  71782. 'getViewport',
  71783. ol.PluggableMap.prototype.getViewport);
  71784. goog.exportProperty(
  71785. ol.PluggableMap.prototype,
  71786. 'renderSync',
  71787. ol.PluggableMap.prototype.renderSync);
  71788. goog.exportProperty(
  71789. ol.PluggableMap.prototype,
  71790. 'render',
  71791. ol.PluggableMap.prototype.render);
  71792. goog.exportProperty(
  71793. ol.PluggableMap.prototype,
  71794. 'removeControl',
  71795. ol.PluggableMap.prototype.removeControl);
  71796. goog.exportProperty(
  71797. ol.PluggableMap.prototype,
  71798. 'removeInteraction',
  71799. ol.PluggableMap.prototype.removeInteraction);
  71800. goog.exportProperty(
  71801. ol.PluggableMap.prototype,
  71802. 'removeLayer',
  71803. ol.PluggableMap.prototype.removeLayer);
  71804. goog.exportProperty(
  71805. ol.PluggableMap.prototype,
  71806. 'removeOverlay',
  71807. ol.PluggableMap.prototype.removeOverlay);
  71808. goog.exportProperty(
  71809. ol.PluggableMap.prototype,
  71810. 'setLayerGroup',
  71811. ol.PluggableMap.prototype.setLayerGroup);
  71812. goog.exportProperty(
  71813. ol.PluggableMap.prototype,
  71814. 'setSize',
  71815. ol.PluggableMap.prototype.setSize);
  71816. goog.exportProperty(
  71817. ol.PluggableMap.prototype,
  71818. 'setTarget',
  71819. ol.PluggableMap.prototype.setTarget);
  71820. goog.exportProperty(
  71821. ol.PluggableMap.prototype,
  71822. 'setView',
  71823. ol.PluggableMap.prototype.setView);
  71824. goog.exportProperty(
  71825. ol.PluggableMap.prototype,
  71826. 'updateSize',
  71827. ol.PluggableMap.prototype.updateSize);
  71828. goog.exportSymbol(
  71829. 'ol.proj.METERS_PER_UNIT',
  71830. ol.proj.METERS_PER_UNIT,
  71831. OPENLAYERS);
  71832. goog.exportSymbol(
  71833. 'ol.proj.setProj4',
  71834. ol.proj.setProj4,
  71835. OPENLAYERS);
  71836. goog.exportSymbol(
  71837. 'ol.proj.getPointResolution',
  71838. ol.proj.getPointResolution,
  71839. OPENLAYERS);
  71840. goog.exportSymbol(
  71841. 'ol.proj.addEquivalentProjections',
  71842. ol.proj.addEquivalentProjections,
  71843. OPENLAYERS);
  71844. goog.exportSymbol(
  71845. 'ol.proj.addProjection',
  71846. ol.proj.addProjection,
  71847. OPENLAYERS);
  71848. goog.exportSymbol(
  71849. 'ol.proj.addCoordinateTransforms',
  71850. ol.proj.addCoordinateTransforms,
  71851. OPENLAYERS);
  71852. goog.exportSymbol(
  71853. 'ol.proj.fromLonLat',
  71854. ol.proj.fromLonLat,
  71855. OPENLAYERS);
  71856. goog.exportSymbol(
  71857. 'ol.proj.toLonLat',
  71858. ol.proj.toLonLat,
  71859. OPENLAYERS);
  71860. goog.exportSymbol(
  71861. 'ol.proj.get',
  71862. ol.proj.get,
  71863. OPENLAYERS);
  71864. goog.exportSymbol(
  71865. 'ol.proj.equivalent',
  71866. ol.proj.equivalent,
  71867. OPENLAYERS);
  71868. goog.exportSymbol(
  71869. 'ol.proj.getTransform',
  71870. ol.proj.getTransform,
  71871. OPENLAYERS);
  71872. goog.exportSymbol(
  71873. 'ol.proj.transform',
  71874. ol.proj.transform,
  71875. OPENLAYERS);
  71876. goog.exportSymbol(
  71877. 'ol.proj.transformExtent',
  71878. ol.proj.transformExtent,
  71879. OPENLAYERS);
  71880. goog.exportSymbol(
  71881. 'ol.render.toContext',
  71882. ol.render.toContext,
  71883. OPENLAYERS);
  71884. goog.exportSymbol(
  71885. 'ol.size.toSize',
  71886. ol.size.toSize,
  71887. OPENLAYERS);
  71888. goog.exportSymbol(
  71889. 'ol.Sphere',
  71890. ol.Sphere,
  71891. OPENLAYERS);
  71892. goog.exportProperty(
  71893. ol.Sphere.prototype,
  71894. 'geodesicArea',
  71895. ol.Sphere.prototype.geodesicArea);
  71896. goog.exportProperty(
  71897. ol.Sphere.prototype,
  71898. 'haversineDistance',
  71899. ol.Sphere.prototype.haversineDistance);
  71900. goog.exportSymbol(
  71901. 'ol.Sphere.getLength',
  71902. ol.Sphere.getLength,
  71903. OPENLAYERS);
  71904. goog.exportSymbol(
  71905. 'ol.Sphere.getArea',
  71906. ol.Sphere.getArea,
  71907. OPENLAYERS);
  71908. goog.exportSymbol(
  71909. 'ol.style.iconImageCache',
  71910. ol.style.iconImageCache,
  71911. OPENLAYERS);
  71912. goog.exportProperty(
  71913. ol.Tile.prototype,
  71914. 'getTileCoord',
  71915. ol.Tile.prototype.getTileCoord);
  71916. goog.exportProperty(
  71917. ol.Tile.prototype,
  71918. 'load',
  71919. ol.Tile.prototype.load);
  71920. goog.exportSymbol(
  71921. 'ol.tilegrid.createXYZ',
  71922. ol.tilegrid.createXYZ,
  71923. OPENLAYERS);
  71924. goog.exportProperty(
  71925. ol.VectorTile.prototype,
  71926. 'getExtent',
  71927. ol.VectorTile.prototype.getExtent);
  71928. goog.exportProperty(
  71929. ol.VectorTile.prototype,
  71930. 'getFormat',
  71931. ol.VectorTile.prototype.getFormat);
  71932. goog.exportProperty(
  71933. ol.VectorTile.prototype,
  71934. 'getFeatures',
  71935. ol.VectorTile.prototype.getFeatures);
  71936. goog.exportProperty(
  71937. ol.VectorTile.prototype,
  71938. 'getProjection',
  71939. ol.VectorTile.prototype.getProjection);
  71940. goog.exportProperty(
  71941. ol.VectorTile.prototype,
  71942. 'setExtent',
  71943. ol.VectorTile.prototype.setExtent);
  71944. goog.exportProperty(
  71945. ol.VectorTile.prototype,
  71946. 'setFeatures',
  71947. ol.VectorTile.prototype.setFeatures);
  71948. goog.exportProperty(
  71949. ol.VectorTile.prototype,
  71950. 'setProjection',
  71951. ol.VectorTile.prototype.setProjection);
  71952. goog.exportProperty(
  71953. ol.VectorTile.prototype,
  71954. 'setLoader',
  71955. ol.VectorTile.prototype.setLoader);
  71956. goog.exportSymbol(
  71957. 'ol.View',
  71958. ol.View,
  71959. OPENLAYERS);
  71960. goog.exportProperty(
  71961. ol.View.prototype,
  71962. 'animate',
  71963. ol.View.prototype.animate);
  71964. goog.exportProperty(
  71965. ol.View.prototype,
  71966. 'getAnimating',
  71967. ol.View.prototype.getAnimating);
  71968. goog.exportProperty(
  71969. ol.View.prototype,
  71970. 'getInteracting',
  71971. ol.View.prototype.getInteracting);
  71972. goog.exportProperty(
  71973. ol.View.prototype,
  71974. 'cancelAnimations',
  71975. ol.View.prototype.cancelAnimations);
  71976. goog.exportProperty(
  71977. ol.View.prototype,
  71978. 'constrainCenter',
  71979. ol.View.prototype.constrainCenter);
  71980. goog.exportProperty(
  71981. ol.View.prototype,
  71982. 'constrainResolution',
  71983. ol.View.prototype.constrainResolution);
  71984. goog.exportProperty(
  71985. ol.View.prototype,
  71986. 'constrainRotation',
  71987. ol.View.prototype.constrainRotation);
  71988. goog.exportProperty(
  71989. ol.View.prototype,
  71990. 'getCenter',
  71991. ol.View.prototype.getCenter);
  71992. goog.exportProperty(
  71993. ol.View.prototype,
  71994. 'calculateExtent',
  71995. ol.View.prototype.calculateExtent);
  71996. goog.exportProperty(
  71997. ol.View.prototype,
  71998. 'getMaxResolution',
  71999. ol.View.prototype.getMaxResolution);
  72000. goog.exportProperty(
  72001. ol.View.prototype,
  72002. 'getMinResolution',
  72003. ol.View.prototype.getMinResolution);
  72004. goog.exportProperty(
  72005. ol.View.prototype,
  72006. 'getMaxZoom',
  72007. ol.View.prototype.getMaxZoom);
  72008. goog.exportProperty(
  72009. ol.View.prototype,
  72010. 'setMaxZoom',
  72011. ol.View.prototype.setMaxZoom);
  72012. goog.exportProperty(
  72013. ol.View.prototype,
  72014. 'getMinZoom',
  72015. ol.View.prototype.getMinZoom);
  72016. goog.exportProperty(
  72017. ol.View.prototype,
  72018. 'setMinZoom',
  72019. ol.View.prototype.setMinZoom);
  72020. goog.exportProperty(
  72021. ol.View.prototype,
  72022. 'getProjection',
  72023. ol.View.prototype.getProjection);
  72024. goog.exportProperty(
  72025. ol.View.prototype,
  72026. 'getResolution',
  72027. ol.View.prototype.getResolution);
  72028. goog.exportProperty(
  72029. ol.View.prototype,
  72030. 'getResolutions',
  72031. ol.View.prototype.getResolutions);
  72032. goog.exportProperty(
  72033. ol.View.prototype,
  72034. 'getResolutionForExtent',
  72035. ol.View.prototype.getResolutionForExtent);
  72036. goog.exportProperty(
  72037. ol.View.prototype,
  72038. 'getRotation',
  72039. ol.View.prototype.getRotation);
  72040. goog.exportProperty(
  72041. ol.View.prototype,
  72042. 'getZoom',
  72043. ol.View.prototype.getZoom);
  72044. goog.exportProperty(
  72045. ol.View.prototype,
  72046. 'getZoomForResolution',
  72047. ol.View.prototype.getZoomForResolution);
  72048. goog.exportProperty(
  72049. ol.View.prototype,
  72050. 'getResolutionForZoom',
  72051. ol.View.prototype.getResolutionForZoom);
  72052. goog.exportProperty(
  72053. ol.View.prototype,
  72054. 'fit',
  72055. ol.View.prototype.fit);
  72056. goog.exportProperty(
  72057. ol.View.prototype,
  72058. 'centerOn',
  72059. ol.View.prototype.centerOn);
  72060. goog.exportProperty(
  72061. ol.View.prototype,
  72062. 'rotate',
  72063. ol.View.prototype.rotate);
  72064. goog.exportProperty(
  72065. ol.View.prototype,
  72066. 'setCenter',
  72067. ol.View.prototype.setCenter);
  72068. goog.exportProperty(
  72069. ol.View.prototype,
  72070. 'setResolution',
  72071. ol.View.prototype.setResolution);
  72072. goog.exportProperty(
  72073. ol.View.prototype,
  72074. 'setRotation',
  72075. ol.View.prototype.setRotation);
  72076. goog.exportProperty(
  72077. ol.View.prototype,
  72078. 'setZoom',
  72079. ol.View.prototype.setZoom);
  72080. goog.exportSymbol(
  72081. 'ol.xml.getAllTextContent',
  72082. ol.xml.getAllTextContent,
  72083. OPENLAYERS);
  72084. goog.exportSymbol(
  72085. 'ol.xml.parse',
  72086. ol.xml.parse,
  72087. OPENLAYERS);
  72088. goog.exportProperty(
  72089. ol.webgl.Context.prototype,
  72090. 'getGL',
  72091. ol.webgl.Context.prototype.getGL);
  72092. goog.exportProperty(
  72093. ol.webgl.Context.prototype,
  72094. 'useProgram',
  72095. ol.webgl.Context.prototype.useProgram);
  72096. goog.exportSymbol(
  72097. 'ol.tilegrid.TileGrid',
  72098. ol.tilegrid.TileGrid,
  72099. OPENLAYERS);
  72100. goog.exportProperty(
  72101. ol.tilegrid.TileGrid.prototype,
  72102. 'forEachTileCoord',
  72103. ol.tilegrid.TileGrid.prototype.forEachTileCoord);
  72104. goog.exportProperty(
  72105. ol.tilegrid.TileGrid.prototype,
  72106. 'getMaxZoom',
  72107. ol.tilegrid.TileGrid.prototype.getMaxZoom);
  72108. goog.exportProperty(
  72109. ol.tilegrid.TileGrid.prototype,
  72110. 'getMinZoom',
  72111. ol.tilegrid.TileGrid.prototype.getMinZoom);
  72112. goog.exportProperty(
  72113. ol.tilegrid.TileGrid.prototype,
  72114. 'getOrigin',
  72115. ol.tilegrid.TileGrid.prototype.getOrigin);
  72116. goog.exportProperty(
  72117. ol.tilegrid.TileGrid.prototype,
  72118. 'getResolution',
  72119. ol.tilegrid.TileGrid.prototype.getResolution);
  72120. goog.exportProperty(
  72121. ol.tilegrid.TileGrid.prototype,
  72122. 'getResolutions',
  72123. ol.tilegrid.TileGrid.prototype.getResolutions);
  72124. goog.exportProperty(
  72125. ol.tilegrid.TileGrid.prototype,
  72126. 'getTileCoordExtent',
  72127. ol.tilegrid.TileGrid.prototype.getTileCoordExtent);
  72128. goog.exportProperty(
  72129. ol.tilegrid.TileGrid.prototype,
  72130. 'getTileCoordForCoordAndResolution',
  72131. ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution);
  72132. goog.exportProperty(
  72133. ol.tilegrid.TileGrid.prototype,
  72134. 'getTileCoordForCoordAndZ',
  72135. ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ);
  72136. goog.exportProperty(
  72137. ol.tilegrid.TileGrid.prototype,
  72138. 'getTileSize',
  72139. ol.tilegrid.TileGrid.prototype.getTileSize);
  72140. goog.exportProperty(
  72141. ol.tilegrid.TileGrid.prototype,
  72142. 'getZForResolution',
  72143. ol.tilegrid.TileGrid.prototype.getZForResolution);
  72144. goog.exportSymbol(
  72145. 'ol.tilegrid.WMTS',
  72146. ol.tilegrid.WMTS,
  72147. OPENLAYERS);
  72148. goog.exportProperty(
  72149. ol.tilegrid.WMTS.prototype,
  72150. 'getMatrixIds',
  72151. ol.tilegrid.WMTS.prototype.getMatrixIds);
  72152. goog.exportSymbol(
  72153. 'ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet',
  72154. ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet,
  72155. OPENLAYERS);
  72156. goog.exportSymbol(
  72157. 'ol.style.AtlasManager',
  72158. ol.style.AtlasManager,
  72159. OPENLAYERS);
  72160. goog.exportSymbol(
  72161. 'ol.style.Circle',
  72162. ol.style.Circle,
  72163. OPENLAYERS);
  72164. goog.exportProperty(
  72165. ol.style.Circle.prototype,
  72166. 'setRadius',
  72167. ol.style.Circle.prototype.setRadius);
  72168. goog.exportSymbol(
  72169. 'ol.style.Fill',
  72170. ol.style.Fill,
  72171. OPENLAYERS);
  72172. goog.exportProperty(
  72173. ol.style.Fill.prototype,
  72174. 'clone',
  72175. ol.style.Fill.prototype.clone);
  72176. goog.exportProperty(
  72177. ol.style.Fill.prototype,
  72178. 'getColor',
  72179. ol.style.Fill.prototype.getColor);
  72180. goog.exportProperty(
  72181. ol.style.Fill.prototype,
  72182. 'setColor',
  72183. ol.style.Fill.prototype.setColor);
  72184. goog.exportSymbol(
  72185. 'ol.style.Icon',
  72186. ol.style.Icon,
  72187. OPENLAYERS);
  72188. goog.exportProperty(
  72189. ol.style.Icon.prototype,
  72190. 'clone',
  72191. ol.style.Icon.prototype.clone);
  72192. goog.exportProperty(
  72193. ol.style.Icon.prototype,
  72194. 'getAnchor',
  72195. ol.style.Icon.prototype.getAnchor);
  72196. goog.exportProperty(
  72197. ol.style.Icon.prototype,
  72198. 'getColor',
  72199. ol.style.Icon.prototype.getColor);
  72200. goog.exportProperty(
  72201. ol.style.Icon.prototype,
  72202. 'getImage',
  72203. ol.style.Icon.prototype.getImage);
  72204. goog.exportProperty(
  72205. ol.style.Icon.prototype,
  72206. 'getOrigin',
  72207. ol.style.Icon.prototype.getOrigin);
  72208. goog.exportProperty(
  72209. ol.style.Icon.prototype,
  72210. 'getSrc',
  72211. ol.style.Icon.prototype.getSrc);
  72212. goog.exportProperty(
  72213. ol.style.Icon.prototype,
  72214. 'getSize',
  72215. ol.style.Icon.prototype.getSize);
  72216. goog.exportProperty(
  72217. ol.style.Icon.prototype,
  72218. 'load',
  72219. ol.style.Icon.prototype.load);
  72220. goog.exportProperty(
  72221. ol.style.IconImageCache.prototype,
  72222. 'setSize',
  72223. ol.style.IconImageCache.prototype.setSize);
  72224. goog.exportSymbol(
  72225. 'ol.style.Image',
  72226. ol.style.Image,
  72227. OPENLAYERS);
  72228. goog.exportProperty(
  72229. ol.style.Image.prototype,
  72230. 'getOpacity',
  72231. ol.style.Image.prototype.getOpacity);
  72232. goog.exportProperty(
  72233. ol.style.Image.prototype,
  72234. 'getRotateWithView',
  72235. ol.style.Image.prototype.getRotateWithView);
  72236. goog.exportProperty(
  72237. ol.style.Image.prototype,
  72238. 'getRotation',
  72239. ol.style.Image.prototype.getRotation);
  72240. goog.exportProperty(
  72241. ol.style.Image.prototype,
  72242. 'getScale',
  72243. ol.style.Image.prototype.getScale);
  72244. goog.exportProperty(
  72245. ol.style.Image.prototype,
  72246. 'getSnapToPixel',
  72247. ol.style.Image.prototype.getSnapToPixel);
  72248. goog.exportProperty(
  72249. ol.style.Image.prototype,
  72250. 'setOpacity',
  72251. ol.style.Image.prototype.setOpacity);
  72252. goog.exportProperty(
  72253. ol.style.Image.prototype,
  72254. 'setRotation',
  72255. ol.style.Image.prototype.setRotation);
  72256. goog.exportProperty(
  72257. ol.style.Image.prototype,
  72258. 'setScale',
  72259. ol.style.Image.prototype.setScale);
  72260. goog.exportSymbol(
  72261. 'ol.style.RegularShape',
  72262. ol.style.RegularShape,
  72263. OPENLAYERS);
  72264. goog.exportProperty(
  72265. ol.style.RegularShape.prototype,
  72266. 'clone',
  72267. ol.style.RegularShape.prototype.clone);
  72268. goog.exportProperty(
  72269. ol.style.RegularShape.prototype,
  72270. 'getAnchor',
  72271. ol.style.RegularShape.prototype.getAnchor);
  72272. goog.exportProperty(
  72273. ol.style.RegularShape.prototype,
  72274. 'getAngle',
  72275. ol.style.RegularShape.prototype.getAngle);
  72276. goog.exportProperty(
  72277. ol.style.RegularShape.prototype,
  72278. 'getFill',
  72279. ol.style.RegularShape.prototype.getFill);
  72280. goog.exportProperty(
  72281. ol.style.RegularShape.prototype,
  72282. 'getImage',
  72283. ol.style.RegularShape.prototype.getImage);
  72284. goog.exportProperty(
  72285. ol.style.RegularShape.prototype,
  72286. 'getOrigin',
  72287. ol.style.RegularShape.prototype.getOrigin);
  72288. goog.exportProperty(
  72289. ol.style.RegularShape.prototype,
  72290. 'getPoints',
  72291. ol.style.RegularShape.prototype.getPoints);
  72292. goog.exportProperty(
  72293. ol.style.RegularShape.prototype,
  72294. 'getRadius',
  72295. ol.style.RegularShape.prototype.getRadius);
  72296. goog.exportProperty(
  72297. ol.style.RegularShape.prototype,
  72298. 'getRadius2',
  72299. ol.style.RegularShape.prototype.getRadius2);
  72300. goog.exportProperty(
  72301. ol.style.RegularShape.prototype,
  72302. 'getSize',
  72303. ol.style.RegularShape.prototype.getSize);
  72304. goog.exportProperty(
  72305. ol.style.RegularShape.prototype,
  72306. 'getStroke',
  72307. ol.style.RegularShape.prototype.getStroke);
  72308. goog.exportSymbol(
  72309. 'ol.style.Stroke',
  72310. ol.style.Stroke,
  72311. OPENLAYERS);
  72312. goog.exportProperty(
  72313. ol.style.Stroke.prototype,
  72314. 'clone',
  72315. ol.style.Stroke.prototype.clone);
  72316. goog.exportProperty(
  72317. ol.style.Stroke.prototype,
  72318. 'getColor',
  72319. ol.style.Stroke.prototype.getColor);
  72320. goog.exportProperty(
  72321. ol.style.Stroke.prototype,
  72322. 'getLineCap',
  72323. ol.style.Stroke.prototype.getLineCap);
  72324. goog.exportProperty(
  72325. ol.style.Stroke.prototype,
  72326. 'getLineDash',
  72327. ol.style.Stroke.prototype.getLineDash);
  72328. goog.exportProperty(
  72329. ol.style.Stroke.prototype,
  72330. 'getLineDashOffset',
  72331. ol.style.Stroke.prototype.getLineDashOffset);
  72332. goog.exportProperty(
  72333. ol.style.Stroke.prototype,
  72334. 'getLineJoin',
  72335. ol.style.Stroke.prototype.getLineJoin);
  72336. goog.exportProperty(
  72337. ol.style.Stroke.prototype,
  72338. 'getMiterLimit',
  72339. ol.style.Stroke.prototype.getMiterLimit);
  72340. goog.exportProperty(
  72341. ol.style.Stroke.prototype,
  72342. 'getWidth',
  72343. ol.style.Stroke.prototype.getWidth);
  72344. goog.exportProperty(
  72345. ol.style.Stroke.prototype,
  72346. 'setColor',
  72347. ol.style.Stroke.prototype.setColor);
  72348. goog.exportProperty(
  72349. ol.style.Stroke.prototype,
  72350. 'setLineCap',
  72351. ol.style.Stroke.prototype.setLineCap);
  72352. goog.exportProperty(
  72353. ol.style.Stroke.prototype,
  72354. 'setLineDash',
  72355. ol.style.Stroke.prototype.setLineDash);
  72356. goog.exportProperty(
  72357. ol.style.Stroke.prototype,
  72358. 'setLineDashOffset',
  72359. ol.style.Stroke.prototype.setLineDashOffset);
  72360. goog.exportProperty(
  72361. ol.style.Stroke.prototype,
  72362. 'setLineJoin',
  72363. ol.style.Stroke.prototype.setLineJoin);
  72364. goog.exportProperty(
  72365. ol.style.Stroke.prototype,
  72366. 'setMiterLimit',
  72367. ol.style.Stroke.prototype.setMiterLimit);
  72368. goog.exportProperty(
  72369. ol.style.Stroke.prototype,
  72370. 'setWidth',
  72371. ol.style.Stroke.prototype.setWidth);
  72372. goog.exportSymbol(
  72373. 'ol.style.Style',
  72374. ol.style.Style,
  72375. OPENLAYERS);
  72376. goog.exportProperty(
  72377. ol.style.Style.prototype,
  72378. 'clone',
  72379. ol.style.Style.prototype.clone);
  72380. goog.exportProperty(
  72381. ol.style.Style.prototype,
  72382. 'getRenderer',
  72383. ol.style.Style.prototype.getRenderer);
  72384. goog.exportProperty(
  72385. ol.style.Style.prototype,
  72386. 'setRenderer',
  72387. ol.style.Style.prototype.setRenderer);
  72388. goog.exportProperty(
  72389. ol.style.Style.prototype,
  72390. 'getGeometry',
  72391. ol.style.Style.prototype.getGeometry);
  72392. goog.exportProperty(
  72393. ol.style.Style.prototype,
  72394. 'getGeometryFunction',
  72395. ol.style.Style.prototype.getGeometryFunction);
  72396. goog.exportProperty(
  72397. ol.style.Style.prototype,
  72398. 'getFill',
  72399. ol.style.Style.prototype.getFill);
  72400. goog.exportProperty(
  72401. ol.style.Style.prototype,
  72402. 'setFill',
  72403. ol.style.Style.prototype.setFill);
  72404. goog.exportProperty(
  72405. ol.style.Style.prototype,
  72406. 'getImage',
  72407. ol.style.Style.prototype.getImage);
  72408. goog.exportProperty(
  72409. ol.style.Style.prototype,
  72410. 'setImage',
  72411. ol.style.Style.prototype.setImage);
  72412. goog.exportProperty(
  72413. ol.style.Style.prototype,
  72414. 'getStroke',
  72415. ol.style.Style.prototype.getStroke);
  72416. goog.exportProperty(
  72417. ol.style.Style.prototype,
  72418. 'setStroke',
  72419. ol.style.Style.prototype.setStroke);
  72420. goog.exportProperty(
  72421. ol.style.Style.prototype,
  72422. 'getText',
  72423. ol.style.Style.prototype.getText);
  72424. goog.exportProperty(
  72425. ol.style.Style.prototype,
  72426. 'setText',
  72427. ol.style.Style.prototype.setText);
  72428. goog.exportProperty(
  72429. ol.style.Style.prototype,
  72430. 'getZIndex',
  72431. ol.style.Style.prototype.getZIndex);
  72432. goog.exportProperty(
  72433. ol.style.Style.prototype,
  72434. 'setGeometry',
  72435. ol.style.Style.prototype.setGeometry);
  72436. goog.exportProperty(
  72437. ol.style.Style.prototype,
  72438. 'setZIndex',
  72439. ol.style.Style.prototype.setZIndex);
  72440. goog.exportSymbol(
  72441. 'ol.style.Text',
  72442. ol.style.Text,
  72443. OPENLAYERS);
  72444. goog.exportProperty(
  72445. ol.style.Text.prototype,
  72446. 'clone',
  72447. ol.style.Text.prototype.clone);
  72448. goog.exportProperty(
  72449. ol.style.Text.prototype,
  72450. 'getOverflow',
  72451. ol.style.Text.prototype.getOverflow);
  72452. goog.exportProperty(
  72453. ol.style.Text.prototype,
  72454. 'getFont',
  72455. ol.style.Text.prototype.getFont);
  72456. goog.exportProperty(
  72457. ol.style.Text.prototype,
  72458. 'getMaxAngle',
  72459. ol.style.Text.prototype.getMaxAngle);
  72460. goog.exportProperty(
  72461. ol.style.Text.prototype,
  72462. 'getPlacement',
  72463. ol.style.Text.prototype.getPlacement);
  72464. goog.exportProperty(
  72465. ol.style.Text.prototype,
  72466. 'getOffsetX',
  72467. ol.style.Text.prototype.getOffsetX);
  72468. goog.exportProperty(
  72469. ol.style.Text.prototype,
  72470. 'getOffsetY',
  72471. ol.style.Text.prototype.getOffsetY);
  72472. goog.exportProperty(
  72473. ol.style.Text.prototype,
  72474. 'getFill',
  72475. ol.style.Text.prototype.getFill);
  72476. goog.exportProperty(
  72477. ol.style.Text.prototype,
  72478. 'getRotateWithView',
  72479. ol.style.Text.prototype.getRotateWithView);
  72480. goog.exportProperty(
  72481. ol.style.Text.prototype,
  72482. 'getRotation',
  72483. ol.style.Text.prototype.getRotation);
  72484. goog.exportProperty(
  72485. ol.style.Text.prototype,
  72486. 'getScale',
  72487. ol.style.Text.prototype.getScale);
  72488. goog.exportProperty(
  72489. ol.style.Text.prototype,
  72490. 'getStroke',
  72491. ol.style.Text.prototype.getStroke);
  72492. goog.exportProperty(
  72493. ol.style.Text.prototype,
  72494. 'getText',
  72495. ol.style.Text.prototype.getText);
  72496. goog.exportProperty(
  72497. ol.style.Text.prototype,
  72498. 'getTextAlign',
  72499. ol.style.Text.prototype.getTextAlign);
  72500. goog.exportProperty(
  72501. ol.style.Text.prototype,
  72502. 'getTextBaseline',
  72503. ol.style.Text.prototype.getTextBaseline);
  72504. goog.exportProperty(
  72505. ol.style.Text.prototype,
  72506. 'getBackgroundFill',
  72507. ol.style.Text.prototype.getBackgroundFill);
  72508. goog.exportProperty(
  72509. ol.style.Text.prototype,
  72510. 'getBackgroundStroke',
  72511. ol.style.Text.prototype.getBackgroundStroke);
  72512. goog.exportProperty(
  72513. ol.style.Text.prototype,
  72514. 'getPadding',
  72515. ol.style.Text.prototype.getPadding);
  72516. goog.exportProperty(
  72517. ol.style.Text.prototype,
  72518. 'setOverflow',
  72519. ol.style.Text.prototype.setOverflow);
  72520. goog.exportProperty(
  72521. ol.style.Text.prototype,
  72522. 'setFont',
  72523. ol.style.Text.prototype.setFont);
  72524. goog.exportProperty(
  72525. ol.style.Text.prototype,
  72526. 'setMaxAngle',
  72527. ol.style.Text.prototype.setMaxAngle);
  72528. goog.exportProperty(
  72529. ol.style.Text.prototype,
  72530. 'setOffsetX',
  72531. ol.style.Text.prototype.setOffsetX);
  72532. goog.exportProperty(
  72533. ol.style.Text.prototype,
  72534. 'setOffsetY',
  72535. ol.style.Text.prototype.setOffsetY);
  72536. goog.exportProperty(
  72537. ol.style.Text.prototype,
  72538. 'setPlacement',
  72539. ol.style.Text.prototype.setPlacement);
  72540. goog.exportProperty(
  72541. ol.style.Text.prototype,
  72542. 'setFill',
  72543. ol.style.Text.prototype.setFill);
  72544. goog.exportProperty(
  72545. ol.style.Text.prototype,
  72546. 'setRotation',
  72547. ol.style.Text.prototype.setRotation);
  72548. goog.exportProperty(
  72549. ol.style.Text.prototype,
  72550. 'setScale',
  72551. ol.style.Text.prototype.setScale);
  72552. goog.exportProperty(
  72553. ol.style.Text.prototype,
  72554. 'setStroke',
  72555. ol.style.Text.prototype.setStroke);
  72556. goog.exportProperty(
  72557. ol.style.Text.prototype,
  72558. 'setText',
  72559. ol.style.Text.prototype.setText);
  72560. goog.exportProperty(
  72561. ol.style.Text.prototype,
  72562. 'setTextAlign',
  72563. ol.style.Text.prototype.setTextAlign);
  72564. goog.exportProperty(
  72565. ol.style.Text.prototype,
  72566. 'setTextBaseline',
  72567. ol.style.Text.prototype.setTextBaseline);
  72568. goog.exportProperty(
  72569. ol.style.Text.prototype,
  72570. 'setBackgroundFill',
  72571. ol.style.Text.prototype.setBackgroundFill);
  72572. goog.exportProperty(
  72573. ol.style.Text.prototype,
  72574. 'setBackgroundStroke',
  72575. ol.style.Text.prototype.setBackgroundStroke);
  72576. goog.exportProperty(
  72577. ol.style.Text.prototype,
  72578. 'setPadding',
  72579. ol.style.Text.prototype.setPadding);
  72580. goog.exportSymbol(
  72581. 'ol.source.BingMaps',
  72582. ol.source.BingMaps,
  72583. OPENLAYERS);
  72584. goog.exportSymbol(
  72585. 'ol.source.BingMaps.TOS_ATTRIBUTION',
  72586. ol.source.BingMaps.TOS_ATTRIBUTION,
  72587. OPENLAYERS);
  72588. goog.exportProperty(
  72589. ol.source.BingMaps.prototype,
  72590. 'getApiKey',
  72591. ol.source.BingMaps.prototype.getApiKey);
  72592. goog.exportProperty(
  72593. ol.source.BingMaps.prototype,
  72594. 'getImagerySet',
  72595. ol.source.BingMaps.prototype.getImagerySet);
  72596. goog.exportSymbol(
  72597. 'ol.source.CartoDB',
  72598. ol.source.CartoDB,
  72599. OPENLAYERS);
  72600. goog.exportProperty(
  72601. ol.source.CartoDB.prototype,
  72602. 'getConfig',
  72603. ol.source.CartoDB.prototype.getConfig);
  72604. goog.exportProperty(
  72605. ol.source.CartoDB.prototype,
  72606. 'updateConfig',
  72607. ol.source.CartoDB.prototype.updateConfig);
  72608. goog.exportProperty(
  72609. ol.source.CartoDB.prototype,
  72610. 'setConfig',
  72611. ol.source.CartoDB.prototype.setConfig);
  72612. goog.exportSymbol(
  72613. 'ol.source.Cluster',
  72614. ol.source.Cluster,
  72615. OPENLAYERS);
  72616. goog.exportProperty(
  72617. ol.source.Cluster.prototype,
  72618. 'getDistance',
  72619. ol.source.Cluster.prototype.getDistance);
  72620. goog.exportProperty(
  72621. ol.source.Cluster.prototype,
  72622. 'getSource',
  72623. ol.source.Cluster.prototype.getSource);
  72624. goog.exportProperty(
  72625. ol.source.Cluster.prototype,
  72626. 'setDistance',
  72627. ol.source.Cluster.prototype.setDistance);
  72628. goog.exportSymbol(
  72629. 'ol.source.Image',
  72630. ol.source.Image,
  72631. OPENLAYERS);
  72632. goog.exportProperty(
  72633. ol.source.Image.Event.prototype,
  72634. 'image',
  72635. ol.source.Image.Event.prototype.image);
  72636. goog.exportSymbol(
  72637. 'ol.source.ImageArcGISRest',
  72638. ol.source.ImageArcGISRest,
  72639. OPENLAYERS);
  72640. goog.exportProperty(
  72641. ol.source.ImageArcGISRest.prototype,
  72642. 'getParams',
  72643. ol.source.ImageArcGISRest.prototype.getParams);
  72644. goog.exportProperty(
  72645. ol.source.ImageArcGISRest.prototype,
  72646. 'getImageLoadFunction',
  72647. ol.source.ImageArcGISRest.prototype.getImageLoadFunction);
  72648. goog.exportProperty(
  72649. ol.source.ImageArcGISRest.prototype,
  72650. 'getUrl',
  72651. ol.source.ImageArcGISRest.prototype.getUrl);
  72652. goog.exportProperty(
  72653. ol.source.ImageArcGISRest.prototype,
  72654. 'setImageLoadFunction',
  72655. ol.source.ImageArcGISRest.prototype.setImageLoadFunction);
  72656. goog.exportProperty(
  72657. ol.source.ImageArcGISRest.prototype,
  72658. 'setUrl',
  72659. ol.source.ImageArcGISRest.prototype.setUrl);
  72660. goog.exportProperty(
  72661. ol.source.ImageArcGISRest.prototype,
  72662. 'updateParams',
  72663. ol.source.ImageArcGISRest.prototype.updateParams);
  72664. goog.exportSymbol(
  72665. 'ol.source.ImageCanvas',
  72666. ol.source.ImageCanvas,
  72667. OPENLAYERS);
  72668. goog.exportSymbol(
  72669. 'ol.source.ImageMapGuide',
  72670. ol.source.ImageMapGuide,
  72671. OPENLAYERS);
  72672. goog.exportProperty(
  72673. ol.source.ImageMapGuide.prototype,
  72674. 'getParams',
  72675. ol.source.ImageMapGuide.prototype.getParams);
  72676. goog.exportProperty(
  72677. ol.source.ImageMapGuide.prototype,
  72678. 'getImageLoadFunction',
  72679. ol.source.ImageMapGuide.prototype.getImageLoadFunction);
  72680. goog.exportProperty(
  72681. ol.source.ImageMapGuide.prototype,
  72682. 'updateParams',
  72683. ol.source.ImageMapGuide.prototype.updateParams);
  72684. goog.exportProperty(
  72685. ol.source.ImageMapGuide.prototype,
  72686. 'setImageLoadFunction',
  72687. ol.source.ImageMapGuide.prototype.setImageLoadFunction);
  72688. goog.exportSymbol(
  72689. 'ol.source.ImageStatic',
  72690. ol.source.ImageStatic,
  72691. OPENLAYERS);
  72692. goog.exportSymbol(
  72693. 'ol.source.ImageVector',
  72694. ol.source.ImageVector,
  72695. OPENLAYERS);
  72696. goog.exportProperty(
  72697. ol.source.ImageVector.prototype,
  72698. 'getSource',
  72699. ol.source.ImageVector.prototype.getSource);
  72700. goog.exportProperty(
  72701. ol.source.ImageVector.prototype,
  72702. 'getStyle',
  72703. ol.source.ImageVector.prototype.getStyle);
  72704. goog.exportProperty(
  72705. ol.source.ImageVector.prototype,
  72706. 'getStyleFunction',
  72707. ol.source.ImageVector.prototype.getStyleFunction);
  72708. goog.exportProperty(
  72709. ol.source.ImageVector.prototype,
  72710. 'setStyle',
  72711. ol.source.ImageVector.prototype.setStyle);
  72712. goog.exportSymbol(
  72713. 'ol.source.ImageWMS',
  72714. ol.source.ImageWMS,
  72715. OPENLAYERS);
  72716. goog.exportProperty(
  72717. ol.source.ImageWMS.prototype,
  72718. 'getGetFeatureInfoUrl',
  72719. ol.source.ImageWMS.prototype.getGetFeatureInfoUrl);
  72720. goog.exportProperty(
  72721. ol.source.ImageWMS.prototype,
  72722. 'getParams',
  72723. ol.source.ImageWMS.prototype.getParams);
  72724. goog.exportProperty(
  72725. ol.source.ImageWMS.prototype,
  72726. 'getImageLoadFunction',
  72727. ol.source.ImageWMS.prototype.getImageLoadFunction);
  72728. goog.exportProperty(
  72729. ol.source.ImageWMS.prototype,
  72730. 'getUrl',
  72731. ol.source.ImageWMS.prototype.getUrl);
  72732. goog.exportProperty(
  72733. ol.source.ImageWMS.prototype,
  72734. 'setImageLoadFunction',
  72735. ol.source.ImageWMS.prototype.setImageLoadFunction);
  72736. goog.exportProperty(
  72737. ol.source.ImageWMS.prototype,
  72738. 'setUrl',
  72739. ol.source.ImageWMS.prototype.setUrl);
  72740. goog.exportProperty(
  72741. ol.source.ImageWMS.prototype,
  72742. 'updateParams',
  72743. ol.source.ImageWMS.prototype.updateParams);
  72744. goog.exportSymbol(
  72745. 'ol.source.OSM',
  72746. ol.source.OSM,
  72747. OPENLAYERS);
  72748. goog.exportSymbol(
  72749. 'ol.source.OSM.ATTRIBUTION',
  72750. ol.source.OSM.ATTRIBUTION,
  72751. OPENLAYERS);
  72752. goog.exportSymbol(
  72753. 'ol.source.Raster',
  72754. ol.source.Raster,
  72755. OPENLAYERS);
  72756. goog.exportProperty(
  72757. ol.source.Raster.prototype,
  72758. 'setOperation',
  72759. ol.source.Raster.prototype.setOperation);
  72760. goog.exportProperty(
  72761. ol.source.Raster.Event.prototype,
  72762. 'extent',
  72763. ol.source.Raster.Event.prototype.extent);
  72764. goog.exportProperty(
  72765. ol.source.Raster.Event.prototype,
  72766. 'resolution',
  72767. ol.source.Raster.Event.prototype.resolution);
  72768. goog.exportProperty(
  72769. ol.source.Raster.Event.prototype,
  72770. 'data',
  72771. ol.source.Raster.Event.prototype.data);
  72772. goog.exportSymbol(
  72773. 'ol.source.Source',
  72774. ol.source.Source,
  72775. OPENLAYERS);
  72776. goog.exportProperty(
  72777. ol.source.Source.prototype,
  72778. 'getAttributions',
  72779. ol.source.Source.prototype.getAttributions);
  72780. goog.exportProperty(
  72781. ol.source.Source.prototype,
  72782. 'getLogo',
  72783. ol.source.Source.prototype.getLogo);
  72784. goog.exportProperty(
  72785. ol.source.Source.prototype,
  72786. 'getProjection',
  72787. ol.source.Source.prototype.getProjection);
  72788. goog.exportProperty(
  72789. ol.source.Source.prototype,
  72790. 'getState',
  72791. ol.source.Source.prototype.getState);
  72792. goog.exportProperty(
  72793. ol.source.Source.prototype,
  72794. 'refresh',
  72795. ol.source.Source.prototype.refresh);
  72796. goog.exportProperty(
  72797. ol.source.Source.prototype,
  72798. 'setAttributions',
  72799. ol.source.Source.prototype.setAttributions);
  72800. goog.exportSymbol(
  72801. 'ol.source.Stamen',
  72802. ol.source.Stamen,
  72803. OPENLAYERS);
  72804. goog.exportSymbol(
  72805. 'ol.source.Tile',
  72806. ol.source.Tile,
  72807. OPENLAYERS);
  72808. goog.exportProperty(
  72809. ol.source.Tile.prototype,
  72810. 'getTileGrid',
  72811. ol.source.Tile.prototype.getTileGrid);
  72812. goog.exportProperty(
  72813. ol.source.Tile.Event.prototype,
  72814. 'tile',
  72815. ol.source.Tile.Event.prototype.tile);
  72816. goog.exportSymbol(
  72817. 'ol.source.TileArcGISRest',
  72818. ol.source.TileArcGISRest,
  72819. OPENLAYERS);
  72820. goog.exportProperty(
  72821. ol.source.TileArcGISRest.prototype,
  72822. 'getParams',
  72823. ol.source.TileArcGISRest.prototype.getParams);
  72824. goog.exportProperty(
  72825. ol.source.TileArcGISRest.prototype,
  72826. 'updateParams',
  72827. ol.source.TileArcGISRest.prototype.updateParams);
  72828. goog.exportSymbol(
  72829. 'ol.source.TileDebug',
  72830. ol.source.TileDebug,
  72831. OPENLAYERS);
  72832. goog.exportSymbol(
  72833. 'ol.source.TileImage',
  72834. ol.source.TileImage,
  72835. OPENLAYERS);
  72836. goog.exportProperty(
  72837. ol.source.TileImage.prototype,
  72838. 'setRenderReprojectionEdges',
  72839. ol.source.TileImage.prototype.setRenderReprojectionEdges);
  72840. goog.exportProperty(
  72841. ol.source.TileImage.prototype,
  72842. 'setTileGridForProjection',
  72843. ol.source.TileImage.prototype.setTileGridForProjection);
  72844. goog.exportSymbol(
  72845. 'ol.source.TileJSON',
  72846. ol.source.TileJSON,
  72847. OPENLAYERS);
  72848. goog.exportProperty(
  72849. ol.source.TileJSON.prototype,
  72850. 'getTileJSON',
  72851. ol.source.TileJSON.prototype.getTileJSON);
  72852. goog.exportSymbol(
  72853. 'ol.source.TileUTFGrid',
  72854. ol.source.TileUTFGrid,
  72855. OPENLAYERS);
  72856. goog.exportProperty(
  72857. ol.source.TileUTFGrid.prototype,
  72858. 'getTemplate',
  72859. ol.source.TileUTFGrid.prototype.getTemplate);
  72860. goog.exportProperty(
  72861. ol.source.TileUTFGrid.prototype,
  72862. 'forDataAtCoordinateAndResolution',
  72863. ol.source.TileUTFGrid.prototype.forDataAtCoordinateAndResolution);
  72864. goog.exportSymbol(
  72865. 'ol.source.TileWMS',
  72866. ol.source.TileWMS,
  72867. OPENLAYERS);
  72868. goog.exportProperty(
  72869. ol.source.TileWMS.prototype,
  72870. 'getGetFeatureInfoUrl',
  72871. ol.source.TileWMS.prototype.getGetFeatureInfoUrl);
  72872. goog.exportProperty(
  72873. ol.source.TileWMS.prototype,
  72874. 'getParams',
  72875. ol.source.TileWMS.prototype.getParams);
  72876. goog.exportProperty(
  72877. ol.source.TileWMS.prototype,
  72878. 'updateParams',
  72879. ol.source.TileWMS.prototype.updateParams);
  72880. goog.exportProperty(
  72881. ol.source.UrlTile.prototype,
  72882. 'getTileLoadFunction',
  72883. ol.source.UrlTile.prototype.getTileLoadFunction);
  72884. goog.exportProperty(
  72885. ol.source.UrlTile.prototype,
  72886. 'getTileUrlFunction',
  72887. ol.source.UrlTile.prototype.getTileUrlFunction);
  72888. goog.exportProperty(
  72889. ol.source.UrlTile.prototype,
  72890. 'getUrls',
  72891. ol.source.UrlTile.prototype.getUrls);
  72892. goog.exportProperty(
  72893. ol.source.UrlTile.prototype,
  72894. 'setTileLoadFunction',
  72895. ol.source.UrlTile.prototype.setTileLoadFunction);
  72896. goog.exportProperty(
  72897. ol.source.UrlTile.prototype,
  72898. 'setTileUrlFunction',
  72899. ol.source.UrlTile.prototype.setTileUrlFunction);
  72900. goog.exportProperty(
  72901. ol.source.UrlTile.prototype,
  72902. 'setUrl',
  72903. ol.source.UrlTile.prototype.setUrl);
  72904. goog.exportProperty(
  72905. ol.source.UrlTile.prototype,
  72906. 'setUrls',
  72907. ol.source.UrlTile.prototype.setUrls);
  72908. goog.exportSymbol(
  72909. 'ol.source.Vector',
  72910. ol.source.Vector,
  72911. OPENLAYERS);
  72912. goog.exportProperty(
  72913. ol.source.Vector.prototype,
  72914. 'addFeature',
  72915. ol.source.Vector.prototype.addFeature);
  72916. goog.exportProperty(
  72917. ol.source.Vector.prototype,
  72918. 'addFeatures',
  72919. ol.source.Vector.prototype.addFeatures);
  72920. goog.exportProperty(
  72921. ol.source.Vector.prototype,
  72922. 'clear',
  72923. ol.source.Vector.prototype.clear);
  72924. goog.exportProperty(
  72925. ol.source.Vector.prototype,
  72926. 'forEachFeature',
  72927. ol.source.Vector.prototype.forEachFeature);
  72928. goog.exportProperty(
  72929. ol.source.Vector.prototype,
  72930. 'forEachFeatureInExtent',
  72931. ol.source.Vector.prototype.forEachFeatureInExtent);
  72932. goog.exportProperty(
  72933. ol.source.Vector.prototype,
  72934. 'forEachFeatureIntersectingExtent',
  72935. ol.source.Vector.prototype.forEachFeatureIntersectingExtent);
  72936. goog.exportProperty(
  72937. ol.source.Vector.prototype,
  72938. 'getFeaturesCollection',
  72939. ol.source.Vector.prototype.getFeaturesCollection);
  72940. goog.exportProperty(
  72941. ol.source.Vector.prototype,
  72942. 'getFeatures',
  72943. ol.source.Vector.prototype.getFeatures);
  72944. goog.exportProperty(
  72945. ol.source.Vector.prototype,
  72946. 'getFeaturesAtCoordinate',
  72947. ol.source.Vector.prototype.getFeaturesAtCoordinate);
  72948. goog.exportProperty(
  72949. ol.source.Vector.prototype,
  72950. 'getFeaturesInExtent',
  72951. ol.source.Vector.prototype.getFeaturesInExtent);
  72952. goog.exportProperty(
  72953. ol.source.Vector.prototype,
  72954. 'getClosestFeatureToCoordinate',
  72955. ol.source.Vector.prototype.getClosestFeatureToCoordinate);
  72956. goog.exportProperty(
  72957. ol.source.Vector.prototype,
  72958. 'getExtent',
  72959. ol.source.Vector.prototype.getExtent);
  72960. goog.exportProperty(
  72961. ol.source.Vector.prototype,
  72962. 'getFeatureById',
  72963. ol.source.Vector.prototype.getFeatureById);
  72964. goog.exportProperty(
  72965. ol.source.Vector.prototype,
  72966. 'getFormat',
  72967. ol.source.Vector.prototype.getFormat);
  72968. goog.exportProperty(
  72969. ol.source.Vector.prototype,
  72970. 'getUrl',
  72971. ol.source.Vector.prototype.getUrl);
  72972. goog.exportProperty(
  72973. ol.source.Vector.prototype,
  72974. 'removeLoadedExtent',
  72975. ol.source.Vector.prototype.removeLoadedExtent);
  72976. goog.exportProperty(
  72977. ol.source.Vector.prototype,
  72978. 'removeFeature',
  72979. ol.source.Vector.prototype.removeFeature);
  72980. goog.exportProperty(
  72981. ol.source.Vector.prototype,
  72982. 'setLoader',
  72983. ol.source.Vector.prototype.setLoader);
  72984. goog.exportProperty(
  72985. ol.source.Vector.Event.prototype,
  72986. 'feature',
  72987. ol.source.Vector.Event.prototype.feature);
  72988. goog.exportSymbol(
  72989. 'ol.source.VectorTile',
  72990. ol.source.VectorTile,
  72991. OPENLAYERS);
  72992. goog.exportProperty(
  72993. ol.source.VectorTile.prototype,
  72994. 'clear',
  72995. ol.source.VectorTile.prototype.clear);
  72996. goog.exportSymbol(
  72997. 'ol.source.WMTS',
  72998. ol.source.WMTS,
  72999. OPENLAYERS);
  73000. goog.exportProperty(
  73001. ol.source.WMTS.prototype,
  73002. 'getDimensions',
  73003. ol.source.WMTS.prototype.getDimensions);
  73004. goog.exportProperty(
  73005. ol.source.WMTS.prototype,
  73006. 'getFormat',
  73007. ol.source.WMTS.prototype.getFormat);
  73008. goog.exportProperty(
  73009. ol.source.WMTS.prototype,
  73010. 'getLayer',
  73011. ol.source.WMTS.prototype.getLayer);
  73012. goog.exportProperty(
  73013. ol.source.WMTS.prototype,
  73014. 'getMatrixSet',
  73015. ol.source.WMTS.prototype.getMatrixSet);
  73016. goog.exportProperty(
  73017. ol.source.WMTS.prototype,
  73018. 'getRequestEncoding',
  73019. ol.source.WMTS.prototype.getRequestEncoding);
  73020. goog.exportProperty(
  73021. ol.source.WMTS.prototype,
  73022. 'getStyle',
  73023. ol.source.WMTS.prototype.getStyle);
  73024. goog.exportProperty(
  73025. ol.source.WMTS.prototype,
  73026. 'getVersion',
  73027. ol.source.WMTS.prototype.getVersion);
  73028. goog.exportProperty(
  73029. ol.source.WMTS.prototype,
  73030. 'updateDimensions',
  73031. ol.source.WMTS.prototype.updateDimensions);
  73032. goog.exportSymbol(
  73033. 'ol.source.WMTS.optionsFromCapabilities',
  73034. ol.source.WMTS.optionsFromCapabilities,
  73035. OPENLAYERS);
  73036. goog.exportSymbol(
  73037. 'ol.source.XYZ',
  73038. ol.source.XYZ,
  73039. OPENLAYERS);
  73040. goog.exportSymbol(
  73041. 'ol.source.Zoomify',
  73042. ol.source.Zoomify,
  73043. OPENLAYERS);
  73044. goog.exportSymbol(
  73045. 'ol.renderer.webgl.ImageLayer',
  73046. ol.renderer.webgl.ImageLayer,
  73047. OPENLAYERS);
  73048. goog.exportSymbol(
  73049. 'ol.renderer.webgl.Map',
  73050. ol.renderer.webgl.Map,
  73051. OPENLAYERS);
  73052. goog.exportSymbol(
  73053. 'ol.renderer.webgl.TileLayer',
  73054. ol.renderer.webgl.TileLayer,
  73055. OPENLAYERS);
  73056. goog.exportSymbol(
  73057. 'ol.renderer.webgl.VectorLayer',
  73058. ol.renderer.webgl.VectorLayer,
  73059. OPENLAYERS);
  73060. goog.exportSymbol(
  73061. 'ol.renderer.canvas.ImageLayer',
  73062. ol.renderer.canvas.ImageLayer,
  73063. OPENLAYERS);
  73064. goog.exportSymbol(
  73065. 'ol.renderer.canvas.Map',
  73066. ol.renderer.canvas.Map,
  73067. OPENLAYERS);
  73068. goog.exportSymbol(
  73069. 'ol.renderer.canvas.TileLayer',
  73070. ol.renderer.canvas.TileLayer,
  73071. OPENLAYERS);
  73072. goog.exportSymbol(
  73073. 'ol.renderer.canvas.VectorLayer',
  73074. ol.renderer.canvas.VectorLayer,
  73075. OPENLAYERS);
  73076. goog.exportSymbol(
  73077. 'ol.renderer.canvas.VectorTileLayer',
  73078. ol.renderer.canvas.VectorTileLayer,
  73079. OPENLAYERS);
  73080. goog.exportProperty(
  73081. ol.render.Event.prototype,
  73082. 'vectorContext',
  73083. ol.render.Event.prototype.vectorContext);
  73084. goog.exportProperty(
  73085. ol.render.Event.prototype,
  73086. 'frameState',
  73087. ol.render.Event.prototype.frameState);
  73088. goog.exportProperty(
  73089. ol.render.Event.prototype,
  73090. 'context',
  73091. ol.render.Event.prototype.context);
  73092. goog.exportProperty(
  73093. ol.render.Event.prototype,
  73094. 'glContext',
  73095. ol.render.Event.prototype.glContext);
  73096. goog.exportProperty(
  73097. ol.render.Feature.prototype,
  73098. 'get',
  73099. ol.render.Feature.prototype.get);
  73100. goog.exportProperty(
  73101. ol.render.Feature.prototype,
  73102. 'getExtent',
  73103. ol.render.Feature.prototype.getExtent);
  73104. goog.exportProperty(
  73105. ol.render.Feature.prototype,
  73106. 'getId',
  73107. ol.render.Feature.prototype.getId);
  73108. goog.exportProperty(
  73109. ol.render.Feature.prototype,
  73110. 'getGeometry',
  73111. ol.render.Feature.prototype.getGeometry);
  73112. goog.exportProperty(
  73113. ol.render.Feature.prototype,
  73114. 'getProperties',
  73115. ol.render.Feature.prototype.getProperties);
  73116. goog.exportProperty(
  73117. ol.render.Feature.prototype,
  73118. 'getType',
  73119. ol.render.Feature.prototype.getType);
  73120. goog.exportSymbol(
  73121. 'ol.render.VectorContext',
  73122. ol.render.VectorContext,
  73123. OPENLAYERS);
  73124. goog.exportProperty(
  73125. ol.render.webgl.Immediate.prototype,
  73126. 'setStyle',
  73127. ol.render.webgl.Immediate.prototype.setStyle);
  73128. goog.exportProperty(
  73129. ol.render.webgl.Immediate.prototype,
  73130. 'drawGeometry',
  73131. ol.render.webgl.Immediate.prototype.drawGeometry);
  73132. goog.exportProperty(
  73133. ol.render.webgl.Immediate.prototype,
  73134. 'drawFeature',
  73135. ol.render.webgl.Immediate.prototype.drawFeature);
  73136. goog.exportProperty(
  73137. ol.render.canvas.Immediate.prototype,
  73138. 'drawCircle',
  73139. ol.render.canvas.Immediate.prototype.drawCircle);
  73140. goog.exportProperty(
  73141. ol.render.canvas.Immediate.prototype,
  73142. 'setStyle',
  73143. ol.render.canvas.Immediate.prototype.setStyle);
  73144. goog.exportProperty(
  73145. ol.render.canvas.Immediate.prototype,
  73146. 'drawGeometry',
  73147. ol.render.canvas.Immediate.prototype.drawGeometry);
  73148. goog.exportProperty(
  73149. ol.render.canvas.Immediate.prototype,
  73150. 'drawFeature',
  73151. ol.render.canvas.Immediate.prototype.drawFeature);
  73152. goog.exportSymbol(
  73153. 'ol.proj.common.add',
  73154. ol.proj.common.add,
  73155. OPENLAYERS);
  73156. goog.exportSymbol(
  73157. 'ol.proj.Projection',
  73158. ol.proj.Projection,
  73159. OPENLAYERS);
  73160. goog.exportProperty(
  73161. ol.proj.Projection.prototype,
  73162. 'getCode',
  73163. ol.proj.Projection.prototype.getCode);
  73164. goog.exportProperty(
  73165. ol.proj.Projection.prototype,
  73166. 'getExtent',
  73167. ol.proj.Projection.prototype.getExtent);
  73168. goog.exportProperty(
  73169. ol.proj.Projection.prototype,
  73170. 'getUnits',
  73171. ol.proj.Projection.prototype.getUnits);
  73172. goog.exportProperty(
  73173. ol.proj.Projection.prototype,
  73174. 'getMetersPerUnit',
  73175. ol.proj.Projection.prototype.getMetersPerUnit);
  73176. goog.exportProperty(
  73177. ol.proj.Projection.prototype,
  73178. 'getWorldExtent',
  73179. ol.proj.Projection.prototype.getWorldExtent);
  73180. goog.exportProperty(
  73181. ol.proj.Projection.prototype,
  73182. 'getAxisOrientation',
  73183. ol.proj.Projection.prototype.getAxisOrientation);
  73184. goog.exportProperty(
  73185. ol.proj.Projection.prototype,
  73186. 'isGlobal',
  73187. ol.proj.Projection.prototype.isGlobal);
  73188. goog.exportProperty(
  73189. ol.proj.Projection.prototype,
  73190. 'setGlobal',
  73191. ol.proj.Projection.prototype.setGlobal);
  73192. goog.exportProperty(
  73193. ol.proj.Projection.prototype,
  73194. 'setExtent',
  73195. ol.proj.Projection.prototype.setExtent);
  73196. goog.exportProperty(
  73197. ol.proj.Projection.prototype,
  73198. 'setWorldExtent',
  73199. ol.proj.Projection.prototype.setWorldExtent);
  73200. goog.exportProperty(
  73201. ol.proj.Projection.prototype,
  73202. 'setGetPointResolution',
  73203. ol.proj.Projection.prototype.setGetPointResolution);
  73204. goog.exportSymbol(
  73205. 'ol.proj.Units.METERS_PER_UNIT',
  73206. ol.proj.Units.METERS_PER_UNIT,
  73207. OPENLAYERS);
  73208. goog.exportSymbol(
  73209. 'ol.layer.Base',
  73210. ol.layer.Base,
  73211. OPENLAYERS);
  73212. goog.exportProperty(
  73213. ol.layer.Base.prototype,
  73214. 'getExtent',
  73215. ol.layer.Base.prototype.getExtent);
  73216. goog.exportProperty(
  73217. ol.layer.Base.prototype,
  73218. 'getMaxResolution',
  73219. ol.layer.Base.prototype.getMaxResolution);
  73220. goog.exportProperty(
  73221. ol.layer.Base.prototype,
  73222. 'getMinResolution',
  73223. ol.layer.Base.prototype.getMinResolution);
  73224. goog.exportProperty(
  73225. ol.layer.Base.prototype,
  73226. 'getOpacity',
  73227. ol.layer.Base.prototype.getOpacity);
  73228. goog.exportProperty(
  73229. ol.layer.Base.prototype,
  73230. 'getVisible',
  73231. ol.layer.Base.prototype.getVisible);
  73232. goog.exportProperty(
  73233. ol.layer.Base.prototype,
  73234. 'getZIndex',
  73235. ol.layer.Base.prototype.getZIndex);
  73236. goog.exportProperty(
  73237. ol.layer.Base.prototype,
  73238. 'setExtent',
  73239. ol.layer.Base.prototype.setExtent);
  73240. goog.exportProperty(
  73241. ol.layer.Base.prototype,
  73242. 'setMaxResolution',
  73243. ol.layer.Base.prototype.setMaxResolution);
  73244. goog.exportProperty(
  73245. ol.layer.Base.prototype,
  73246. 'setMinResolution',
  73247. ol.layer.Base.prototype.setMinResolution);
  73248. goog.exportProperty(
  73249. ol.layer.Base.prototype,
  73250. 'setOpacity',
  73251. ol.layer.Base.prototype.setOpacity);
  73252. goog.exportProperty(
  73253. ol.layer.Base.prototype,
  73254. 'setVisible',
  73255. ol.layer.Base.prototype.setVisible);
  73256. goog.exportProperty(
  73257. ol.layer.Base.prototype,
  73258. 'setZIndex',
  73259. ol.layer.Base.prototype.setZIndex);
  73260. goog.exportSymbol(
  73261. 'ol.layer.Group',
  73262. ol.layer.Group,
  73263. OPENLAYERS);
  73264. goog.exportProperty(
  73265. ol.layer.Group.prototype,
  73266. 'getLayers',
  73267. ol.layer.Group.prototype.getLayers);
  73268. goog.exportProperty(
  73269. ol.layer.Group.prototype,
  73270. 'setLayers',
  73271. ol.layer.Group.prototype.setLayers);
  73272. goog.exportSymbol(
  73273. 'ol.layer.Heatmap',
  73274. ol.layer.Heatmap,
  73275. OPENLAYERS);
  73276. goog.exportProperty(
  73277. ol.layer.Heatmap.prototype,
  73278. 'getBlur',
  73279. ol.layer.Heatmap.prototype.getBlur);
  73280. goog.exportProperty(
  73281. ol.layer.Heatmap.prototype,
  73282. 'getGradient',
  73283. ol.layer.Heatmap.prototype.getGradient);
  73284. goog.exportProperty(
  73285. ol.layer.Heatmap.prototype,
  73286. 'getRadius',
  73287. ol.layer.Heatmap.prototype.getRadius);
  73288. goog.exportProperty(
  73289. ol.layer.Heatmap.prototype,
  73290. 'setBlur',
  73291. ol.layer.Heatmap.prototype.setBlur);
  73292. goog.exportProperty(
  73293. ol.layer.Heatmap.prototype,
  73294. 'setGradient',
  73295. ol.layer.Heatmap.prototype.setGradient);
  73296. goog.exportProperty(
  73297. ol.layer.Heatmap.prototype,
  73298. 'setRadius',
  73299. ol.layer.Heatmap.prototype.setRadius);
  73300. goog.exportSymbol(
  73301. 'ol.layer.Image',
  73302. ol.layer.Image,
  73303. OPENLAYERS);
  73304. goog.exportProperty(
  73305. ol.layer.Image.prototype,
  73306. 'getSource',
  73307. ol.layer.Image.prototype.getSource);
  73308. goog.exportSymbol(
  73309. 'ol.layer.Layer',
  73310. ol.layer.Layer,
  73311. OPENLAYERS);
  73312. goog.exportProperty(
  73313. ol.layer.Layer.prototype,
  73314. 'getSource',
  73315. ol.layer.Layer.prototype.getSource);
  73316. goog.exportProperty(
  73317. ol.layer.Layer.prototype,
  73318. 'setMap',
  73319. ol.layer.Layer.prototype.setMap);
  73320. goog.exportProperty(
  73321. ol.layer.Layer.prototype,
  73322. 'setSource',
  73323. ol.layer.Layer.prototype.setSource);
  73324. goog.exportSymbol(
  73325. 'ol.layer.Tile',
  73326. ol.layer.Tile,
  73327. OPENLAYERS);
  73328. goog.exportProperty(
  73329. ol.layer.Tile.prototype,
  73330. 'getPreload',
  73331. ol.layer.Tile.prototype.getPreload);
  73332. goog.exportProperty(
  73333. ol.layer.Tile.prototype,
  73334. 'getSource',
  73335. ol.layer.Tile.prototype.getSource);
  73336. goog.exportProperty(
  73337. ol.layer.Tile.prototype,
  73338. 'setPreload',
  73339. ol.layer.Tile.prototype.setPreload);
  73340. goog.exportProperty(
  73341. ol.layer.Tile.prototype,
  73342. 'getUseInterimTilesOnError',
  73343. ol.layer.Tile.prototype.getUseInterimTilesOnError);
  73344. goog.exportProperty(
  73345. ol.layer.Tile.prototype,
  73346. 'setUseInterimTilesOnError',
  73347. ol.layer.Tile.prototype.setUseInterimTilesOnError);
  73348. goog.exportSymbol(
  73349. 'ol.layer.Vector',
  73350. ol.layer.Vector,
  73351. OPENLAYERS);
  73352. goog.exportProperty(
  73353. ol.layer.Vector.prototype,
  73354. 'getSource',
  73355. ol.layer.Vector.prototype.getSource);
  73356. goog.exportProperty(
  73357. ol.layer.Vector.prototype,
  73358. 'getStyle',
  73359. ol.layer.Vector.prototype.getStyle);
  73360. goog.exportProperty(
  73361. ol.layer.Vector.prototype,
  73362. 'getStyleFunction',
  73363. ol.layer.Vector.prototype.getStyleFunction);
  73364. goog.exportProperty(
  73365. ol.layer.Vector.prototype,
  73366. 'setStyle',
  73367. ol.layer.Vector.prototype.setStyle);
  73368. goog.exportSymbol(
  73369. 'ol.layer.VectorTile',
  73370. ol.layer.VectorTile,
  73371. OPENLAYERS);
  73372. goog.exportProperty(
  73373. ol.layer.VectorTile.prototype,
  73374. 'getPreload',
  73375. ol.layer.VectorTile.prototype.getPreload);
  73376. goog.exportProperty(
  73377. ol.layer.VectorTile.prototype,
  73378. 'getUseInterimTilesOnError',
  73379. ol.layer.VectorTile.prototype.getUseInterimTilesOnError);
  73380. goog.exportProperty(
  73381. ol.layer.VectorTile.prototype,
  73382. 'setPreload',
  73383. ol.layer.VectorTile.prototype.setPreload);
  73384. goog.exportProperty(
  73385. ol.layer.VectorTile.prototype,
  73386. 'setUseInterimTilesOnError',
  73387. ol.layer.VectorTile.prototype.setUseInterimTilesOnError);
  73388. goog.exportProperty(
  73389. ol.layer.VectorTile.prototype,
  73390. 'getSource',
  73391. ol.layer.VectorTile.prototype.getSource);
  73392. goog.exportSymbol(
  73393. 'ol.interaction.DoubleClickZoom',
  73394. ol.interaction.DoubleClickZoom,
  73395. OPENLAYERS);
  73396. goog.exportSymbol(
  73397. 'ol.interaction.DoubleClickZoom.handleEvent',
  73398. ol.interaction.DoubleClickZoom.handleEvent,
  73399. OPENLAYERS);
  73400. goog.exportSymbol(
  73401. 'ol.interaction.DragAndDrop',
  73402. ol.interaction.DragAndDrop,
  73403. OPENLAYERS);
  73404. goog.exportSymbol(
  73405. 'ol.interaction.DragAndDrop.handleEvent',
  73406. ol.interaction.DragAndDrop.handleEvent,
  73407. OPENLAYERS);
  73408. goog.exportProperty(
  73409. ol.interaction.DragAndDrop.Event.prototype,
  73410. 'features',
  73411. ol.interaction.DragAndDrop.Event.prototype.features);
  73412. goog.exportProperty(
  73413. ol.interaction.DragAndDrop.Event.prototype,
  73414. 'file',
  73415. ol.interaction.DragAndDrop.Event.prototype.file);
  73416. goog.exportProperty(
  73417. ol.interaction.DragAndDrop.Event.prototype,
  73418. 'projection',
  73419. ol.interaction.DragAndDrop.Event.prototype.projection);
  73420. goog.exportSymbol(
  73421. 'ol.interaction.DragBox',
  73422. ol.interaction.DragBox,
  73423. OPENLAYERS);
  73424. goog.exportProperty(
  73425. ol.interaction.DragBox.prototype,
  73426. 'getGeometry',
  73427. ol.interaction.DragBox.prototype.getGeometry);
  73428. goog.exportProperty(
  73429. ol.interaction.DragBox.Event.prototype,
  73430. 'coordinate',
  73431. ol.interaction.DragBox.Event.prototype.coordinate);
  73432. goog.exportProperty(
  73433. ol.interaction.DragBox.Event.prototype,
  73434. 'mapBrowserEvent',
  73435. ol.interaction.DragBox.Event.prototype.mapBrowserEvent);
  73436. goog.exportSymbol(
  73437. 'ol.interaction.DragPan',
  73438. ol.interaction.DragPan,
  73439. OPENLAYERS);
  73440. goog.exportSymbol(
  73441. 'ol.interaction.DragRotate',
  73442. ol.interaction.DragRotate,
  73443. OPENLAYERS);
  73444. goog.exportSymbol(
  73445. 'ol.interaction.DragRotateAndZoom',
  73446. ol.interaction.DragRotateAndZoom,
  73447. OPENLAYERS);
  73448. goog.exportSymbol(
  73449. 'ol.interaction.DragZoom',
  73450. ol.interaction.DragZoom,
  73451. OPENLAYERS);
  73452. goog.exportSymbol(
  73453. 'ol.interaction.Draw',
  73454. ol.interaction.Draw,
  73455. OPENLAYERS);
  73456. goog.exportSymbol(
  73457. 'ol.interaction.Draw.handleEvent',
  73458. ol.interaction.Draw.handleEvent,
  73459. OPENLAYERS);
  73460. goog.exportProperty(
  73461. ol.interaction.Draw.prototype,
  73462. 'removeLastPoint',
  73463. ol.interaction.Draw.prototype.removeLastPoint);
  73464. goog.exportProperty(
  73465. ol.interaction.Draw.prototype,
  73466. 'finishDrawing',
  73467. ol.interaction.Draw.prototype.finishDrawing);
  73468. goog.exportProperty(
  73469. ol.interaction.Draw.prototype,
  73470. 'extend',
  73471. ol.interaction.Draw.prototype.extend);
  73472. goog.exportSymbol(
  73473. 'ol.interaction.Draw.createRegularPolygon',
  73474. ol.interaction.Draw.createRegularPolygon,
  73475. OPENLAYERS);
  73476. goog.exportSymbol(
  73477. 'ol.interaction.Draw.createBox',
  73478. ol.interaction.Draw.createBox,
  73479. OPENLAYERS);
  73480. goog.exportProperty(
  73481. ol.interaction.Draw.Event.prototype,
  73482. 'feature',
  73483. ol.interaction.Draw.Event.prototype.feature);
  73484. goog.exportSymbol(
  73485. 'ol.interaction.Extent',
  73486. ol.interaction.Extent,
  73487. OPENLAYERS);
  73488. goog.exportProperty(
  73489. ol.interaction.Extent.prototype,
  73490. 'getExtent',
  73491. ol.interaction.Extent.prototype.getExtent);
  73492. goog.exportProperty(
  73493. ol.interaction.Extent.prototype,
  73494. 'setExtent',
  73495. ol.interaction.Extent.prototype.setExtent);
  73496. goog.exportProperty(
  73497. ol.interaction.Extent.Event.prototype,
  73498. 'extent',
  73499. ol.interaction.Extent.Event.prototype.extent);
  73500. goog.exportSymbol(
  73501. 'ol.interaction.Interaction',
  73502. ol.interaction.Interaction,
  73503. OPENLAYERS);
  73504. goog.exportProperty(
  73505. ol.interaction.Interaction.prototype,
  73506. 'getActive',
  73507. ol.interaction.Interaction.prototype.getActive);
  73508. goog.exportProperty(
  73509. ol.interaction.Interaction.prototype,
  73510. 'getMap',
  73511. ol.interaction.Interaction.prototype.getMap);
  73512. goog.exportProperty(
  73513. ol.interaction.Interaction.prototype,
  73514. 'setActive',
  73515. ol.interaction.Interaction.prototype.setActive);
  73516. goog.exportSymbol(
  73517. 'ol.interaction.KeyboardPan',
  73518. ol.interaction.KeyboardPan,
  73519. OPENLAYERS);
  73520. goog.exportSymbol(
  73521. 'ol.interaction.KeyboardPan.handleEvent',
  73522. ol.interaction.KeyboardPan.handleEvent,
  73523. OPENLAYERS);
  73524. goog.exportSymbol(
  73525. 'ol.interaction.KeyboardZoom',
  73526. ol.interaction.KeyboardZoom,
  73527. OPENLAYERS);
  73528. goog.exportSymbol(
  73529. 'ol.interaction.KeyboardZoom.handleEvent',
  73530. ol.interaction.KeyboardZoom.handleEvent,
  73531. OPENLAYERS);
  73532. goog.exportSymbol(
  73533. 'ol.interaction.Modify',
  73534. ol.interaction.Modify,
  73535. OPENLAYERS);
  73536. goog.exportSymbol(
  73537. 'ol.interaction.Modify.handleEvent',
  73538. ol.interaction.Modify.handleEvent,
  73539. OPENLAYERS);
  73540. goog.exportProperty(
  73541. ol.interaction.Modify.prototype,
  73542. 'removePoint',
  73543. ol.interaction.Modify.prototype.removePoint);
  73544. goog.exportProperty(
  73545. ol.interaction.Modify.Event.prototype,
  73546. 'features',
  73547. ol.interaction.Modify.Event.prototype.features);
  73548. goog.exportProperty(
  73549. ol.interaction.Modify.Event.prototype,
  73550. 'mapBrowserEvent',
  73551. ol.interaction.Modify.Event.prototype.mapBrowserEvent);
  73552. goog.exportSymbol(
  73553. 'ol.interaction.MouseWheelZoom',
  73554. ol.interaction.MouseWheelZoom,
  73555. OPENLAYERS);
  73556. goog.exportSymbol(
  73557. 'ol.interaction.MouseWheelZoom.handleEvent',
  73558. ol.interaction.MouseWheelZoom.handleEvent,
  73559. OPENLAYERS);
  73560. goog.exportProperty(
  73561. ol.interaction.MouseWheelZoom.prototype,
  73562. 'setMouseAnchor',
  73563. ol.interaction.MouseWheelZoom.prototype.setMouseAnchor);
  73564. goog.exportSymbol(
  73565. 'ol.interaction.PinchRotate',
  73566. ol.interaction.PinchRotate,
  73567. OPENLAYERS);
  73568. goog.exportSymbol(
  73569. 'ol.interaction.PinchZoom',
  73570. ol.interaction.PinchZoom,
  73571. OPENLAYERS);
  73572. goog.exportSymbol(
  73573. 'ol.interaction.Pointer',
  73574. ol.interaction.Pointer,
  73575. OPENLAYERS);
  73576. goog.exportSymbol(
  73577. 'ol.interaction.Pointer.handleEvent',
  73578. ol.interaction.Pointer.handleEvent,
  73579. OPENLAYERS);
  73580. goog.exportSymbol(
  73581. 'ol.interaction.Select',
  73582. ol.interaction.Select,
  73583. OPENLAYERS);
  73584. goog.exportProperty(
  73585. ol.interaction.Select.prototype,
  73586. 'getFeatures',
  73587. ol.interaction.Select.prototype.getFeatures);
  73588. goog.exportProperty(
  73589. ol.interaction.Select.prototype,
  73590. 'getHitTolerance',
  73591. ol.interaction.Select.prototype.getHitTolerance);
  73592. goog.exportProperty(
  73593. ol.interaction.Select.prototype,
  73594. 'getLayer',
  73595. ol.interaction.Select.prototype.getLayer);
  73596. goog.exportSymbol(
  73597. 'ol.interaction.Select.handleEvent',
  73598. ol.interaction.Select.handleEvent,
  73599. OPENLAYERS);
  73600. goog.exportProperty(
  73601. ol.interaction.Select.prototype,
  73602. 'setHitTolerance',
  73603. ol.interaction.Select.prototype.setHitTolerance);
  73604. goog.exportProperty(
  73605. ol.interaction.Select.prototype,
  73606. 'setMap',
  73607. ol.interaction.Select.prototype.setMap);
  73608. goog.exportProperty(
  73609. ol.interaction.Select.Event.prototype,
  73610. 'selected',
  73611. ol.interaction.Select.Event.prototype.selected);
  73612. goog.exportProperty(
  73613. ol.interaction.Select.Event.prototype,
  73614. 'deselected',
  73615. ol.interaction.Select.Event.prototype.deselected);
  73616. goog.exportProperty(
  73617. ol.interaction.Select.Event.prototype,
  73618. 'mapBrowserEvent',
  73619. ol.interaction.Select.Event.prototype.mapBrowserEvent);
  73620. goog.exportSymbol(
  73621. 'ol.interaction.Snap',
  73622. ol.interaction.Snap,
  73623. OPENLAYERS);
  73624. goog.exportProperty(
  73625. ol.interaction.Snap.prototype,
  73626. 'addFeature',
  73627. ol.interaction.Snap.prototype.addFeature);
  73628. goog.exportProperty(
  73629. ol.interaction.Snap.prototype,
  73630. 'removeFeature',
  73631. ol.interaction.Snap.prototype.removeFeature);
  73632. goog.exportSymbol(
  73633. 'ol.interaction.Translate',
  73634. ol.interaction.Translate,
  73635. OPENLAYERS);
  73636. goog.exportProperty(
  73637. ol.interaction.Translate.prototype,
  73638. 'getHitTolerance',
  73639. ol.interaction.Translate.prototype.getHitTolerance);
  73640. goog.exportProperty(
  73641. ol.interaction.Translate.prototype,
  73642. 'setHitTolerance',
  73643. ol.interaction.Translate.prototype.setHitTolerance);
  73644. goog.exportProperty(
  73645. ol.interaction.Translate.Event.prototype,
  73646. 'features',
  73647. ol.interaction.Translate.Event.prototype.features);
  73648. goog.exportProperty(
  73649. ol.interaction.Translate.Event.prototype,
  73650. 'coordinate',
  73651. ol.interaction.Translate.Event.prototype.coordinate);
  73652. goog.exportSymbol(
  73653. 'ol.geom.Circle',
  73654. ol.geom.Circle,
  73655. OPENLAYERS);
  73656. goog.exportProperty(
  73657. ol.geom.Circle.prototype,
  73658. 'clone',
  73659. ol.geom.Circle.prototype.clone);
  73660. goog.exportProperty(
  73661. ol.geom.Circle.prototype,
  73662. 'getCenter',
  73663. ol.geom.Circle.prototype.getCenter);
  73664. goog.exportProperty(
  73665. ol.geom.Circle.prototype,
  73666. 'getRadius',
  73667. ol.geom.Circle.prototype.getRadius);
  73668. goog.exportProperty(
  73669. ol.geom.Circle.prototype,
  73670. 'getType',
  73671. ol.geom.Circle.prototype.getType);
  73672. goog.exportProperty(
  73673. ol.geom.Circle.prototype,
  73674. 'intersectsExtent',
  73675. ol.geom.Circle.prototype.intersectsExtent);
  73676. goog.exportProperty(
  73677. ol.geom.Circle.prototype,
  73678. 'setCenter',
  73679. ol.geom.Circle.prototype.setCenter);
  73680. goog.exportProperty(
  73681. ol.geom.Circle.prototype,
  73682. 'setCenterAndRadius',
  73683. ol.geom.Circle.prototype.setCenterAndRadius);
  73684. goog.exportProperty(
  73685. ol.geom.Circle.prototype,
  73686. 'setRadius',
  73687. ol.geom.Circle.prototype.setRadius);
  73688. goog.exportProperty(
  73689. ol.geom.Circle.prototype,
  73690. 'transform',
  73691. ol.geom.Circle.prototype.transform);
  73692. goog.exportSymbol(
  73693. 'ol.geom.Geometry',
  73694. ol.geom.Geometry,
  73695. OPENLAYERS);
  73696. goog.exportProperty(
  73697. ol.geom.Geometry.prototype,
  73698. 'getClosestPoint',
  73699. ol.geom.Geometry.prototype.getClosestPoint);
  73700. goog.exportProperty(
  73701. ol.geom.Geometry.prototype,
  73702. 'intersectsCoordinate',
  73703. ol.geom.Geometry.prototype.intersectsCoordinate);
  73704. goog.exportProperty(
  73705. ol.geom.Geometry.prototype,
  73706. 'getExtent',
  73707. ol.geom.Geometry.prototype.getExtent);
  73708. goog.exportProperty(
  73709. ol.geom.Geometry.prototype,
  73710. 'rotate',
  73711. ol.geom.Geometry.prototype.rotate);
  73712. goog.exportProperty(
  73713. ol.geom.Geometry.prototype,
  73714. 'scale',
  73715. ol.geom.Geometry.prototype.scale);
  73716. goog.exportProperty(
  73717. ol.geom.Geometry.prototype,
  73718. 'simplify',
  73719. ol.geom.Geometry.prototype.simplify);
  73720. goog.exportProperty(
  73721. ol.geom.Geometry.prototype,
  73722. 'transform',
  73723. ol.geom.Geometry.prototype.transform);
  73724. goog.exportSymbol(
  73725. 'ol.geom.GeometryCollection',
  73726. ol.geom.GeometryCollection,
  73727. OPENLAYERS);
  73728. goog.exportProperty(
  73729. ol.geom.GeometryCollection.prototype,
  73730. 'clone',
  73731. ol.geom.GeometryCollection.prototype.clone);
  73732. goog.exportProperty(
  73733. ol.geom.GeometryCollection.prototype,
  73734. 'getGeometries',
  73735. ol.geom.GeometryCollection.prototype.getGeometries);
  73736. goog.exportProperty(
  73737. ol.geom.GeometryCollection.prototype,
  73738. 'getType',
  73739. ol.geom.GeometryCollection.prototype.getType);
  73740. goog.exportProperty(
  73741. ol.geom.GeometryCollection.prototype,
  73742. 'intersectsExtent',
  73743. ol.geom.GeometryCollection.prototype.intersectsExtent);
  73744. goog.exportProperty(
  73745. ol.geom.GeometryCollection.prototype,
  73746. 'setGeometries',
  73747. ol.geom.GeometryCollection.prototype.setGeometries);
  73748. goog.exportProperty(
  73749. ol.geom.GeometryCollection.prototype,
  73750. 'applyTransform',
  73751. ol.geom.GeometryCollection.prototype.applyTransform);
  73752. goog.exportProperty(
  73753. ol.geom.GeometryCollection.prototype,
  73754. 'translate',
  73755. ol.geom.GeometryCollection.prototype.translate);
  73756. goog.exportSymbol(
  73757. 'ol.geom.LinearRing',
  73758. ol.geom.LinearRing,
  73759. OPENLAYERS);
  73760. goog.exportProperty(
  73761. ol.geom.LinearRing.prototype,
  73762. 'clone',
  73763. ol.geom.LinearRing.prototype.clone);
  73764. goog.exportProperty(
  73765. ol.geom.LinearRing.prototype,
  73766. 'getArea',
  73767. ol.geom.LinearRing.prototype.getArea);
  73768. goog.exportProperty(
  73769. ol.geom.LinearRing.prototype,
  73770. 'getCoordinates',
  73771. ol.geom.LinearRing.prototype.getCoordinates);
  73772. goog.exportProperty(
  73773. ol.geom.LinearRing.prototype,
  73774. 'getType',
  73775. ol.geom.LinearRing.prototype.getType);
  73776. goog.exportProperty(
  73777. ol.geom.LinearRing.prototype,
  73778. 'setCoordinates',
  73779. ol.geom.LinearRing.prototype.setCoordinates);
  73780. goog.exportSymbol(
  73781. 'ol.geom.LineString',
  73782. ol.geom.LineString,
  73783. OPENLAYERS);
  73784. goog.exportProperty(
  73785. ol.geom.LineString.prototype,
  73786. 'appendCoordinate',
  73787. ol.geom.LineString.prototype.appendCoordinate);
  73788. goog.exportProperty(
  73789. ol.geom.LineString.prototype,
  73790. 'clone',
  73791. ol.geom.LineString.prototype.clone);
  73792. goog.exportProperty(
  73793. ol.geom.LineString.prototype,
  73794. 'forEachSegment',
  73795. ol.geom.LineString.prototype.forEachSegment);
  73796. goog.exportProperty(
  73797. ol.geom.LineString.prototype,
  73798. 'getCoordinateAtM',
  73799. ol.geom.LineString.prototype.getCoordinateAtM);
  73800. goog.exportProperty(
  73801. ol.geom.LineString.prototype,
  73802. 'getCoordinates',
  73803. ol.geom.LineString.prototype.getCoordinates);
  73804. goog.exportProperty(
  73805. ol.geom.LineString.prototype,
  73806. 'getCoordinateAt',
  73807. ol.geom.LineString.prototype.getCoordinateAt);
  73808. goog.exportProperty(
  73809. ol.geom.LineString.prototype,
  73810. 'getLength',
  73811. ol.geom.LineString.prototype.getLength);
  73812. goog.exportProperty(
  73813. ol.geom.LineString.prototype,
  73814. 'getType',
  73815. ol.geom.LineString.prototype.getType);
  73816. goog.exportProperty(
  73817. ol.geom.LineString.prototype,
  73818. 'intersectsExtent',
  73819. ol.geom.LineString.prototype.intersectsExtent);
  73820. goog.exportProperty(
  73821. ol.geom.LineString.prototype,
  73822. 'setCoordinates',
  73823. ol.geom.LineString.prototype.setCoordinates);
  73824. goog.exportSymbol(
  73825. 'ol.geom.MultiLineString',
  73826. ol.geom.MultiLineString,
  73827. OPENLAYERS);
  73828. goog.exportProperty(
  73829. ol.geom.MultiLineString.prototype,
  73830. 'appendLineString',
  73831. ol.geom.MultiLineString.prototype.appendLineString);
  73832. goog.exportProperty(
  73833. ol.geom.MultiLineString.prototype,
  73834. 'clone',
  73835. ol.geom.MultiLineString.prototype.clone);
  73836. goog.exportProperty(
  73837. ol.geom.MultiLineString.prototype,
  73838. 'getCoordinateAtM',
  73839. ol.geom.MultiLineString.prototype.getCoordinateAtM);
  73840. goog.exportProperty(
  73841. ol.geom.MultiLineString.prototype,
  73842. 'getCoordinates',
  73843. ol.geom.MultiLineString.prototype.getCoordinates);
  73844. goog.exportProperty(
  73845. ol.geom.MultiLineString.prototype,
  73846. 'getLineString',
  73847. ol.geom.MultiLineString.prototype.getLineString);
  73848. goog.exportProperty(
  73849. ol.geom.MultiLineString.prototype,
  73850. 'getLineStrings',
  73851. ol.geom.MultiLineString.prototype.getLineStrings);
  73852. goog.exportProperty(
  73853. ol.geom.MultiLineString.prototype,
  73854. 'getType',
  73855. ol.geom.MultiLineString.prototype.getType);
  73856. goog.exportProperty(
  73857. ol.geom.MultiLineString.prototype,
  73858. 'intersectsExtent',
  73859. ol.geom.MultiLineString.prototype.intersectsExtent);
  73860. goog.exportProperty(
  73861. ol.geom.MultiLineString.prototype,
  73862. 'setCoordinates',
  73863. ol.geom.MultiLineString.prototype.setCoordinates);
  73864. goog.exportSymbol(
  73865. 'ol.geom.MultiPoint',
  73866. ol.geom.MultiPoint,
  73867. OPENLAYERS);
  73868. goog.exportProperty(
  73869. ol.geom.MultiPoint.prototype,
  73870. 'appendPoint',
  73871. ol.geom.MultiPoint.prototype.appendPoint);
  73872. goog.exportProperty(
  73873. ol.geom.MultiPoint.prototype,
  73874. 'clone',
  73875. ol.geom.MultiPoint.prototype.clone);
  73876. goog.exportProperty(
  73877. ol.geom.MultiPoint.prototype,
  73878. 'getCoordinates',
  73879. ol.geom.MultiPoint.prototype.getCoordinates);
  73880. goog.exportProperty(
  73881. ol.geom.MultiPoint.prototype,
  73882. 'getPoint',
  73883. ol.geom.MultiPoint.prototype.getPoint);
  73884. goog.exportProperty(
  73885. ol.geom.MultiPoint.prototype,
  73886. 'getPoints',
  73887. ol.geom.MultiPoint.prototype.getPoints);
  73888. goog.exportProperty(
  73889. ol.geom.MultiPoint.prototype,
  73890. 'getType',
  73891. ol.geom.MultiPoint.prototype.getType);
  73892. goog.exportProperty(
  73893. ol.geom.MultiPoint.prototype,
  73894. 'intersectsExtent',
  73895. ol.geom.MultiPoint.prototype.intersectsExtent);
  73896. goog.exportProperty(
  73897. ol.geom.MultiPoint.prototype,
  73898. 'setCoordinates',
  73899. ol.geom.MultiPoint.prototype.setCoordinates);
  73900. goog.exportSymbol(
  73901. 'ol.geom.MultiPolygon',
  73902. ol.geom.MultiPolygon,
  73903. OPENLAYERS);
  73904. goog.exportProperty(
  73905. ol.geom.MultiPolygon.prototype,
  73906. 'appendPolygon',
  73907. ol.geom.MultiPolygon.prototype.appendPolygon);
  73908. goog.exportProperty(
  73909. ol.geom.MultiPolygon.prototype,
  73910. 'clone',
  73911. ol.geom.MultiPolygon.prototype.clone);
  73912. goog.exportProperty(
  73913. ol.geom.MultiPolygon.prototype,
  73914. 'getArea',
  73915. ol.geom.MultiPolygon.prototype.getArea);
  73916. goog.exportProperty(
  73917. ol.geom.MultiPolygon.prototype,
  73918. 'getCoordinates',
  73919. ol.geom.MultiPolygon.prototype.getCoordinates);
  73920. goog.exportProperty(
  73921. ol.geom.MultiPolygon.prototype,
  73922. 'getInteriorPoints',
  73923. ol.geom.MultiPolygon.prototype.getInteriorPoints);
  73924. goog.exportProperty(
  73925. ol.geom.MultiPolygon.prototype,
  73926. 'getPolygon',
  73927. ol.geom.MultiPolygon.prototype.getPolygon);
  73928. goog.exportProperty(
  73929. ol.geom.MultiPolygon.prototype,
  73930. 'getPolygons',
  73931. ol.geom.MultiPolygon.prototype.getPolygons);
  73932. goog.exportProperty(
  73933. ol.geom.MultiPolygon.prototype,
  73934. 'getType',
  73935. ol.geom.MultiPolygon.prototype.getType);
  73936. goog.exportProperty(
  73937. ol.geom.MultiPolygon.prototype,
  73938. 'intersectsExtent',
  73939. ol.geom.MultiPolygon.prototype.intersectsExtent);
  73940. goog.exportProperty(
  73941. ol.geom.MultiPolygon.prototype,
  73942. 'setCoordinates',
  73943. ol.geom.MultiPolygon.prototype.setCoordinates);
  73944. goog.exportSymbol(
  73945. 'ol.geom.Point',
  73946. ol.geom.Point,
  73947. OPENLAYERS);
  73948. goog.exportProperty(
  73949. ol.geom.Point.prototype,
  73950. 'clone',
  73951. ol.geom.Point.prototype.clone);
  73952. goog.exportProperty(
  73953. ol.geom.Point.prototype,
  73954. 'getCoordinates',
  73955. ol.geom.Point.prototype.getCoordinates);
  73956. goog.exportProperty(
  73957. ol.geom.Point.prototype,
  73958. 'getType',
  73959. ol.geom.Point.prototype.getType);
  73960. goog.exportProperty(
  73961. ol.geom.Point.prototype,
  73962. 'intersectsExtent',
  73963. ol.geom.Point.prototype.intersectsExtent);
  73964. goog.exportProperty(
  73965. ol.geom.Point.prototype,
  73966. 'setCoordinates',
  73967. ol.geom.Point.prototype.setCoordinates);
  73968. goog.exportSymbol(
  73969. 'ol.geom.Polygon',
  73970. ol.geom.Polygon,
  73971. OPENLAYERS);
  73972. goog.exportProperty(
  73973. ol.geom.Polygon.prototype,
  73974. 'appendLinearRing',
  73975. ol.geom.Polygon.prototype.appendLinearRing);
  73976. goog.exportProperty(
  73977. ol.geom.Polygon.prototype,
  73978. 'clone',
  73979. ol.geom.Polygon.prototype.clone);
  73980. goog.exportProperty(
  73981. ol.geom.Polygon.prototype,
  73982. 'getArea',
  73983. ol.geom.Polygon.prototype.getArea);
  73984. goog.exportProperty(
  73985. ol.geom.Polygon.prototype,
  73986. 'getCoordinates',
  73987. ol.geom.Polygon.prototype.getCoordinates);
  73988. goog.exportProperty(
  73989. ol.geom.Polygon.prototype,
  73990. 'getInteriorPoint',
  73991. ol.geom.Polygon.prototype.getInteriorPoint);
  73992. goog.exportProperty(
  73993. ol.geom.Polygon.prototype,
  73994. 'getLinearRingCount',
  73995. ol.geom.Polygon.prototype.getLinearRingCount);
  73996. goog.exportProperty(
  73997. ol.geom.Polygon.prototype,
  73998. 'getLinearRing',
  73999. ol.geom.Polygon.prototype.getLinearRing);
  74000. goog.exportProperty(
  74001. ol.geom.Polygon.prototype,
  74002. 'getLinearRings',
  74003. ol.geom.Polygon.prototype.getLinearRings);
  74004. goog.exportProperty(
  74005. ol.geom.Polygon.prototype,
  74006. 'getType',
  74007. ol.geom.Polygon.prototype.getType);
  74008. goog.exportProperty(
  74009. ol.geom.Polygon.prototype,
  74010. 'intersectsExtent',
  74011. ol.geom.Polygon.prototype.intersectsExtent);
  74012. goog.exportProperty(
  74013. ol.geom.Polygon.prototype,
  74014. 'setCoordinates',
  74015. ol.geom.Polygon.prototype.setCoordinates);
  74016. goog.exportSymbol(
  74017. 'ol.geom.Polygon.circular',
  74018. ol.geom.Polygon.circular,
  74019. OPENLAYERS);
  74020. goog.exportSymbol(
  74021. 'ol.geom.Polygon.fromExtent',
  74022. ol.geom.Polygon.fromExtent,
  74023. OPENLAYERS);
  74024. goog.exportSymbol(
  74025. 'ol.geom.Polygon.fromCircle',
  74026. ol.geom.Polygon.fromCircle,
  74027. OPENLAYERS);
  74028. goog.exportSymbol(
  74029. 'ol.geom.SimpleGeometry',
  74030. ol.geom.SimpleGeometry,
  74031. OPENLAYERS);
  74032. goog.exportProperty(
  74033. ol.geom.SimpleGeometry.prototype,
  74034. 'getFirstCoordinate',
  74035. ol.geom.SimpleGeometry.prototype.getFirstCoordinate);
  74036. goog.exportProperty(
  74037. ol.geom.SimpleGeometry.prototype,
  74038. 'getLastCoordinate',
  74039. ol.geom.SimpleGeometry.prototype.getLastCoordinate);
  74040. goog.exportProperty(
  74041. ol.geom.SimpleGeometry.prototype,
  74042. 'getLayout',
  74043. ol.geom.SimpleGeometry.prototype.getLayout);
  74044. goog.exportProperty(
  74045. ol.geom.SimpleGeometry.prototype,
  74046. 'applyTransform',
  74047. ol.geom.SimpleGeometry.prototype.applyTransform);
  74048. goog.exportProperty(
  74049. ol.geom.SimpleGeometry.prototype,
  74050. 'translate',
  74051. ol.geom.SimpleGeometry.prototype.translate);
  74052. goog.exportSymbol(
  74053. 'ol.format.EsriJSON',
  74054. ol.format.EsriJSON,
  74055. OPENLAYERS);
  74056. goog.exportProperty(
  74057. ol.format.EsriJSON.prototype,
  74058. 'readFeature',
  74059. ol.format.EsriJSON.prototype.readFeature);
  74060. goog.exportProperty(
  74061. ol.format.EsriJSON.prototype,
  74062. 'readFeatures',
  74063. ol.format.EsriJSON.prototype.readFeatures);
  74064. goog.exportProperty(
  74065. ol.format.EsriJSON.prototype,
  74066. 'readGeometry',
  74067. ol.format.EsriJSON.prototype.readGeometry);
  74068. goog.exportProperty(
  74069. ol.format.EsriJSON.prototype,
  74070. 'readProjection',
  74071. ol.format.EsriJSON.prototype.readProjection);
  74072. goog.exportProperty(
  74073. ol.format.EsriJSON.prototype,
  74074. 'writeGeometry',
  74075. ol.format.EsriJSON.prototype.writeGeometry);
  74076. goog.exportProperty(
  74077. ol.format.EsriJSON.prototype,
  74078. 'writeGeometryObject',
  74079. ol.format.EsriJSON.prototype.writeGeometryObject);
  74080. goog.exportProperty(
  74081. ol.format.EsriJSON.prototype,
  74082. 'writeFeature',
  74083. ol.format.EsriJSON.prototype.writeFeature);
  74084. goog.exportProperty(
  74085. ol.format.EsriJSON.prototype,
  74086. 'writeFeatureObject',
  74087. ol.format.EsriJSON.prototype.writeFeatureObject);
  74088. goog.exportProperty(
  74089. ol.format.EsriJSON.prototype,
  74090. 'writeFeatures',
  74091. ol.format.EsriJSON.prototype.writeFeatures);
  74092. goog.exportProperty(
  74093. ol.format.EsriJSON.prototype,
  74094. 'writeFeaturesObject',
  74095. ol.format.EsriJSON.prototype.writeFeaturesObject);
  74096. goog.exportSymbol(
  74097. 'ol.format.Feature',
  74098. ol.format.Feature,
  74099. OPENLAYERS);
  74100. goog.exportSymbol(
  74101. 'ol.format.filter.and',
  74102. ol.format.filter.and,
  74103. OPENLAYERS);
  74104. goog.exportSymbol(
  74105. 'ol.format.filter.or',
  74106. ol.format.filter.or,
  74107. OPENLAYERS);
  74108. goog.exportSymbol(
  74109. 'ol.format.filter.not',
  74110. ol.format.filter.not,
  74111. OPENLAYERS);
  74112. goog.exportSymbol(
  74113. 'ol.format.filter.bbox',
  74114. ol.format.filter.bbox,
  74115. OPENLAYERS);
  74116. goog.exportSymbol(
  74117. 'ol.format.filter.contains',
  74118. ol.format.filter.contains,
  74119. OPENLAYERS);
  74120. goog.exportSymbol(
  74121. 'ol.format.filter.intersects',
  74122. ol.format.filter.intersects,
  74123. OPENLAYERS);
  74124. goog.exportSymbol(
  74125. 'ol.format.filter.within',
  74126. ol.format.filter.within,
  74127. OPENLAYERS);
  74128. goog.exportSymbol(
  74129. 'ol.format.filter.equalTo',
  74130. ol.format.filter.equalTo,
  74131. OPENLAYERS);
  74132. goog.exportSymbol(
  74133. 'ol.format.filter.notEqualTo',
  74134. ol.format.filter.notEqualTo,
  74135. OPENLAYERS);
  74136. goog.exportSymbol(
  74137. 'ol.format.filter.lessThan',
  74138. ol.format.filter.lessThan,
  74139. OPENLAYERS);
  74140. goog.exportSymbol(
  74141. 'ol.format.filter.lessThanOrEqualTo',
  74142. ol.format.filter.lessThanOrEqualTo,
  74143. OPENLAYERS);
  74144. goog.exportSymbol(
  74145. 'ol.format.filter.greaterThan',
  74146. ol.format.filter.greaterThan,
  74147. OPENLAYERS);
  74148. goog.exportSymbol(
  74149. 'ol.format.filter.greaterThanOrEqualTo',
  74150. ol.format.filter.greaterThanOrEqualTo,
  74151. OPENLAYERS);
  74152. goog.exportSymbol(
  74153. 'ol.format.filter.isNull',
  74154. ol.format.filter.isNull,
  74155. OPENLAYERS);
  74156. goog.exportSymbol(
  74157. 'ol.format.filter.between',
  74158. ol.format.filter.between,
  74159. OPENLAYERS);
  74160. goog.exportSymbol(
  74161. 'ol.format.filter.like',
  74162. ol.format.filter.like,
  74163. OPENLAYERS);
  74164. goog.exportSymbol(
  74165. 'ol.format.filter.during',
  74166. ol.format.filter.during,
  74167. OPENLAYERS);
  74168. goog.exportSymbol(
  74169. 'ol.format.GeoJSON',
  74170. ol.format.GeoJSON,
  74171. OPENLAYERS);
  74172. goog.exportProperty(
  74173. ol.format.GeoJSON.prototype,
  74174. 'readFeature',
  74175. ol.format.GeoJSON.prototype.readFeature);
  74176. goog.exportProperty(
  74177. ol.format.GeoJSON.prototype,
  74178. 'readFeatures',
  74179. ol.format.GeoJSON.prototype.readFeatures);
  74180. goog.exportProperty(
  74181. ol.format.GeoJSON.prototype,
  74182. 'readGeometry',
  74183. ol.format.GeoJSON.prototype.readGeometry);
  74184. goog.exportProperty(
  74185. ol.format.GeoJSON.prototype,
  74186. 'readProjection',
  74187. ol.format.GeoJSON.prototype.readProjection);
  74188. goog.exportProperty(
  74189. ol.format.GeoJSON.prototype,
  74190. 'writeFeature',
  74191. ol.format.GeoJSON.prototype.writeFeature);
  74192. goog.exportProperty(
  74193. ol.format.GeoJSON.prototype,
  74194. 'writeFeatureObject',
  74195. ol.format.GeoJSON.prototype.writeFeatureObject);
  74196. goog.exportProperty(
  74197. ol.format.GeoJSON.prototype,
  74198. 'writeFeatures',
  74199. ol.format.GeoJSON.prototype.writeFeatures);
  74200. goog.exportProperty(
  74201. ol.format.GeoJSON.prototype,
  74202. 'writeFeaturesObject',
  74203. ol.format.GeoJSON.prototype.writeFeaturesObject);
  74204. goog.exportProperty(
  74205. ol.format.GeoJSON.prototype,
  74206. 'writeGeometry',
  74207. ol.format.GeoJSON.prototype.writeGeometry);
  74208. goog.exportProperty(
  74209. ol.format.GeoJSON.prototype,
  74210. 'writeGeometryObject',
  74211. ol.format.GeoJSON.prototype.writeGeometryObject);
  74212. goog.exportSymbol(
  74213. 'ol.format.GML',
  74214. ol.format.GML,
  74215. OPENLAYERS);
  74216. goog.exportProperty(
  74217. ol.format.GML.prototype,
  74218. 'writeFeatures',
  74219. ol.format.GML.prototype.writeFeatures);
  74220. goog.exportProperty(
  74221. ol.format.GML.prototype,
  74222. 'writeFeaturesNode',
  74223. ol.format.GML.prototype.writeFeaturesNode);
  74224. goog.exportSymbol(
  74225. 'ol.format.GML2',
  74226. ol.format.GML2,
  74227. OPENLAYERS);
  74228. goog.exportSymbol(
  74229. 'ol.format.GML3',
  74230. ol.format.GML3,
  74231. OPENLAYERS);
  74232. goog.exportProperty(
  74233. ol.format.GML3.prototype,
  74234. 'writeGeometryNode',
  74235. ol.format.GML3.prototype.writeGeometryNode);
  74236. goog.exportProperty(
  74237. ol.format.GML3.prototype,
  74238. 'writeFeatures',
  74239. ol.format.GML3.prototype.writeFeatures);
  74240. goog.exportProperty(
  74241. ol.format.GML3.prototype,
  74242. 'writeFeaturesNode',
  74243. ol.format.GML3.prototype.writeFeaturesNode);
  74244. goog.exportProperty(
  74245. ol.format.GMLBase.prototype,
  74246. 'readFeatures',
  74247. ol.format.GMLBase.prototype.readFeatures);
  74248. goog.exportSymbol(
  74249. 'ol.format.GPX',
  74250. ol.format.GPX,
  74251. OPENLAYERS);
  74252. goog.exportProperty(
  74253. ol.format.GPX.prototype,
  74254. 'readFeature',
  74255. ol.format.GPX.prototype.readFeature);
  74256. goog.exportProperty(
  74257. ol.format.GPX.prototype,
  74258. 'readFeatures',
  74259. ol.format.GPX.prototype.readFeatures);
  74260. goog.exportProperty(
  74261. ol.format.GPX.prototype,
  74262. 'readProjection',
  74263. ol.format.GPX.prototype.readProjection);
  74264. goog.exportProperty(
  74265. ol.format.GPX.prototype,
  74266. 'writeFeatures',
  74267. ol.format.GPX.prototype.writeFeatures);
  74268. goog.exportProperty(
  74269. ol.format.GPX.prototype,
  74270. 'writeFeaturesNode',
  74271. ol.format.GPX.prototype.writeFeaturesNode);
  74272. goog.exportSymbol(
  74273. 'ol.format.IGC',
  74274. ol.format.IGC,
  74275. OPENLAYERS);
  74276. goog.exportProperty(
  74277. ol.format.IGC.prototype,
  74278. 'readFeature',
  74279. ol.format.IGC.prototype.readFeature);
  74280. goog.exportProperty(
  74281. ol.format.IGC.prototype,
  74282. 'readFeatures',
  74283. ol.format.IGC.prototype.readFeatures);
  74284. goog.exportProperty(
  74285. ol.format.IGC.prototype,
  74286. 'readProjection',
  74287. ol.format.IGC.prototype.readProjection);
  74288. goog.exportSymbol(
  74289. 'ol.format.KML',
  74290. ol.format.KML,
  74291. OPENLAYERS);
  74292. goog.exportProperty(
  74293. ol.format.KML.prototype,
  74294. 'readFeature',
  74295. ol.format.KML.prototype.readFeature);
  74296. goog.exportProperty(
  74297. ol.format.KML.prototype,
  74298. 'readFeatures',
  74299. ol.format.KML.prototype.readFeatures);
  74300. goog.exportProperty(
  74301. ol.format.KML.prototype,
  74302. 'readName',
  74303. ol.format.KML.prototype.readName);
  74304. goog.exportProperty(
  74305. ol.format.KML.prototype,
  74306. 'readNetworkLinks',
  74307. ol.format.KML.prototype.readNetworkLinks);
  74308. goog.exportProperty(
  74309. ol.format.KML.prototype,
  74310. 'readRegion',
  74311. ol.format.KML.prototype.readRegion);
  74312. goog.exportProperty(
  74313. ol.format.KML.prototype,
  74314. 'readRegionFromNode',
  74315. ol.format.KML.prototype.readRegionFromNode);
  74316. goog.exportProperty(
  74317. ol.format.KML.prototype,
  74318. 'readProjection',
  74319. ol.format.KML.prototype.readProjection);
  74320. goog.exportProperty(
  74321. ol.format.KML.prototype,
  74322. 'writeFeatures',
  74323. ol.format.KML.prototype.writeFeatures);
  74324. goog.exportProperty(
  74325. ol.format.KML.prototype,
  74326. 'writeFeaturesNode',
  74327. ol.format.KML.prototype.writeFeaturesNode);
  74328. goog.exportSymbol(
  74329. 'ol.format.MVT',
  74330. ol.format.MVT,
  74331. OPENLAYERS);
  74332. goog.exportProperty(
  74333. ol.format.MVT.prototype,
  74334. 'getLastExtent',
  74335. ol.format.MVT.prototype.getLastExtent);
  74336. goog.exportProperty(
  74337. ol.format.MVT.prototype,
  74338. 'readFeatures',
  74339. ol.format.MVT.prototype.readFeatures);
  74340. goog.exportProperty(
  74341. ol.format.MVT.prototype,
  74342. 'readProjection',
  74343. ol.format.MVT.prototype.readProjection);
  74344. goog.exportProperty(
  74345. ol.format.MVT.prototype,
  74346. 'setLayers',
  74347. ol.format.MVT.prototype.setLayers);
  74348. goog.exportSymbol(
  74349. 'ol.format.OSMXML',
  74350. ol.format.OSMXML,
  74351. OPENLAYERS);
  74352. goog.exportProperty(
  74353. ol.format.OSMXML.prototype,
  74354. 'readFeatures',
  74355. ol.format.OSMXML.prototype.readFeatures);
  74356. goog.exportProperty(
  74357. ol.format.OSMXML.prototype,
  74358. 'readProjection',
  74359. ol.format.OSMXML.prototype.readProjection);
  74360. goog.exportSymbol(
  74361. 'ol.format.Polyline',
  74362. ol.format.Polyline,
  74363. OPENLAYERS);
  74364. goog.exportSymbol(
  74365. 'ol.format.Polyline.encodeDeltas',
  74366. ol.format.Polyline.encodeDeltas,
  74367. OPENLAYERS);
  74368. goog.exportSymbol(
  74369. 'ol.format.Polyline.decodeDeltas',
  74370. ol.format.Polyline.decodeDeltas,
  74371. OPENLAYERS);
  74372. goog.exportSymbol(
  74373. 'ol.format.Polyline.encodeFloats',
  74374. ol.format.Polyline.encodeFloats,
  74375. OPENLAYERS);
  74376. goog.exportSymbol(
  74377. 'ol.format.Polyline.decodeFloats',
  74378. ol.format.Polyline.decodeFloats,
  74379. OPENLAYERS);
  74380. goog.exportProperty(
  74381. ol.format.Polyline.prototype,
  74382. 'readFeature',
  74383. ol.format.Polyline.prototype.readFeature);
  74384. goog.exportProperty(
  74385. ol.format.Polyline.prototype,
  74386. 'readFeatures',
  74387. ol.format.Polyline.prototype.readFeatures);
  74388. goog.exportProperty(
  74389. ol.format.Polyline.prototype,
  74390. 'readGeometry',
  74391. ol.format.Polyline.prototype.readGeometry);
  74392. goog.exportProperty(
  74393. ol.format.Polyline.prototype,
  74394. 'readProjection',
  74395. ol.format.Polyline.prototype.readProjection);
  74396. goog.exportProperty(
  74397. ol.format.Polyline.prototype,
  74398. 'writeGeometry',
  74399. ol.format.Polyline.prototype.writeGeometry);
  74400. goog.exportSymbol(
  74401. 'ol.format.TopoJSON',
  74402. ol.format.TopoJSON,
  74403. OPENLAYERS);
  74404. goog.exportProperty(
  74405. ol.format.TopoJSON.prototype,
  74406. 'readFeatures',
  74407. ol.format.TopoJSON.prototype.readFeatures);
  74408. goog.exportProperty(
  74409. ol.format.TopoJSON.prototype,
  74410. 'readProjection',
  74411. ol.format.TopoJSON.prototype.readProjection);
  74412. goog.exportSymbol(
  74413. 'ol.format.WFS',
  74414. ol.format.WFS,
  74415. OPENLAYERS);
  74416. goog.exportProperty(
  74417. ol.format.WFS.prototype,
  74418. 'readFeatures',
  74419. ol.format.WFS.prototype.readFeatures);
  74420. goog.exportProperty(
  74421. ol.format.WFS.prototype,
  74422. 'readTransactionResponse',
  74423. ol.format.WFS.prototype.readTransactionResponse);
  74424. goog.exportProperty(
  74425. ol.format.WFS.prototype,
  74426. 'readFeatureCollectionMetadata',
  74427. ol.format.WFS.prototype.readFeatureCollectionMetadata);
  74428. goog.exportSymbol(
  74429. 'ol.format.WFS.writeFilter',
  74430. ol.format.WFS.writeFilter,
  74431. OPENLAYERS);
  74432. goog.exportProperty(
  74433. ol.format.WFS.prototype,
  74434. 'writeGetFeature',
  74435. ol.format.WFS.prototype.writeGetFeature);
  74436. goog.exportProperty(
  74437. ol.format.WFS.prototype,
  74438. 'writeTransaction',
  74439. ol.format.WFS.prototype.writeTransaction);
  74440. goog.exportProperty(
  74441. ol.format.WFS.prototype,
  74442. 'readProjection',
  74443. ol.format.WFS.prototype.readProjection);
  74444. goog.exportSymbol(
  74445. 'ol.format.WKT',
  74446. ol.format.WKT,
  74447. OPENLAYERS);
  74448. goog.exportProperty(
  74449. ol.format.WKT.prototype,
  74450. 'readFeature',
  74451. ol.format.WKT.prototype.readFeature);
  74452. goog.exportProperty(
  74453. ol.format.WKT.prototype,
  74454. 'readFeatures',
  74455. ol.format.WKT.prototype.readFeatures);
  74456. goog.exportProperty(
  74457. ol.format.WKT.prototype,
  74458. 'readGeometry',
  74459. ol.format.WKT.prototype.readGeometry);
  74460. goog.exportProperty(
  74461. ol.format.WKT.prototype,
  74462. 'writeFeature',
  74463. ol.format.WKT.prototype.writeFeature);
  74464. goog.exportProperty(
  74465. ol.format.WKT.prototype,
  74466. 'writeFeatures',
  74467. ol.format.WKT.prototype.writeFeatures);
  74468. goog.exportProperty(
  74469. ol.format.WKT.prototype,
  74470. 'writeGeometry',
  74471. ol.format.WKT.prototype.writeGeometry);
  74472. goog.exportSymbol(
  74473. 'ol.format.WMSCapabilities',
  74474. ol.format.WMSCapabilities,
  74475. OPENLAYERS);
  74476. goog.exportProperty(
  74477. ol.format.WMSCapabilities.prototype,
  74478. 'read',
  74479. ol.format.WMSCapabilities.prototype.read);
  74480. goog.exportSymbol(
  74481. 'ol.format.WMSGetFeatureInfo',
  74482. ol.format.WMSGetFeatureInfo,
  74483. OPENLAYERS);
  74484. goog.exportProperty(
  74485. ol.format.WMSGetFeatureInfo.prototype,
  74486. 'readFeatures',
  74487. ol.format.WMSGetFeatureInfo.prototype.readFeatures);
  74488. goog.exportSymbol(
  74489. 'ol.format.WMTSCapabilities',
  74490. ol.format.WMTSCapabilities,
  74491. OPENLAYERS);
  74492. goog.exportProperty(
  74493. ol.format.WMTSCapabilities.prototype,
  74494. 'read',
  74495. ol.format.WMTSCapabilities.prototype.read);
  74496. goog.exportSymbol(
  74497. 'ol.format.filter.And',
  74498. ol.format.filter.And,
  74499. OPENLAYERS);
  74500. goog.exportSymbol(
  74501. 'ol.format.filter.Bbox',
  74502. ol.format.filter.Bbox,
  74503. OPENLAYERS);
  74504. goog.exportSymbol(
  74505. 'ol.format.filter.Comparison',
  74506. ol.format.filter.Comparison,
  74507. OPENLAYERS);
  74508. goog.exportSymbol(
  74509. 'ol.format.filter.ComparisonBinary',
  74510. ol.format.filter.ComparisonBinary,
  74511. OPENLAYERS);
  74512. goog.exportSymbol(
  74513. 'ol.format.filter.Contains',
  74514. ol.format.filter.Contains,
  74515. OPENLAYERS);
  74516. goog.exportSymbol(
  74517. 'ol.format.filter.During',
  74518. ol.format.filter.During,
  74519. OPENLAYERS);
  74520. goog.exportSymbol(
  74521. 'ol.format.filter.EqualTo',
  74522. ol.format.filter.EqualTo,
  74523. OPENLAYERS);
  74524. goog.exportSymbol(
  74525. 'ol.format.filter.Filter',
  74526. ol.format.filter.Filter,
  74527. OPENLAYERS);
  74528. goog.exportSymbol(
  74529. 'ol.format.filter.GreaterThan',
  74530. ol.format.filter.GreaterThan,
  74531. OPENLAYERS);
  74532. goog.exportSymbol(
  74533. 'ol.format.filter.GreaterThanOrEqualTo',
  74534. ol.format.filter.GreaterThanOrEqualTo,
  74535. OPENLAYERS);
  74536. goog.exportSymbol(
  74537. 'ol.format.filter.Intersects',
  74538. ol.format.filter.Intersects,
  74539. OPENLAYERS);
  74540. goog.exportSymbol(
  74541. 'ol.format.filter.IsBetween',
  74542. ol.format.filter.IsBetween,
  74543. OPENLAYERS);
  74544. goog.exportSymbol(
  74545. 'ol.format.filter.IsLike',
  74546. ol.format.filter.IsLike,
  74547. OPENLAYERS);
  74548. goog.exportSymbol(
  74549. 'ol.format.filter.IsNull',
  74550. ol.format.filter.IsNull,
  74551. OPENLAYERS);
  74552. goog.exportSymbol(
  74553. 'ol.format.filter.LessThan',
  74554. ol.format.filter.LessThan,
  74555. OPENLAYERS);
  74556. goog.exportSymbol(
  74557. 'ol.format.filter.LessThanOrEqualTo',
  74558. ol.format.filter.LessThanOrEqualTo,
  74559. OPENLAYERS);
  74560. goog.exportSymbol(
  74561. 'ol.format.filter.Not',
  74562. ol.format.filter.Not,
  74563. OPENLAYERS);
  74564. goog.exportSymbol(
  74565. 'ol.format.filter.NotEqualTo',
  74566. ol.format.filter.NotEqualTo,
  74567. OPENLAYERS);
  74568. goog.exportSymbol(
  74569. 'ol.format.filter.Or',
  74570. ol.format.filter.Or,
  74571. OPENLAYERS);
  74572. goog.exportSymbol(
  74573. 'ol.format.filter.Spatial',
  74574. ol.format.filter.Spatial,
  74575. OPENLAYERS);
  74576. goog.exportSymbol(
  74577. 'ol.format.filter.Within',
  74578. ol.format.filter.Within,
  74579. OPENLAYERS);
  74580. goog.exportSymbol(
  74581. 'ol.events.condition.altKeyOnly',
  74582. ol.events.condition.altKeyOnly,
  74583. OPENLAYERS);
  74584. goog.exportSymbol(
  74585. 'ol.events.condition.altShiftKeysOnly',
  74586. ol.events.condition.altShiftKeysOnly,
  74587. OPENLAYERS);
  74588. goog.exportSymbol(
  74589. 'ol.events.condition.always',
  74590. ol.events.condition.always,
  74591. OPENLAYERS);
  74592. goog.exportSymbol(
  74593. 'ol.events.condition.click',
  74594. ol.events.condition.click,
  74595. OPENLAYERS);
  74596. goog.exportSymbol(
  74597. 'ol.events.condition.never',
  74598. ol.events.condition.never,
  74599. OPENLAYERS);
  74600. goog.exportSymbol(
  74601. 'ol.events.condition.pointerMove',
  74602. ol.events.condition.pointerMove,
  74603. OPENLAYERS);
  74604. goog.exportSymbol(
  74605. 'ol.events.condition.singleClick',
  74606. ol.events.condition.singleClick,
  74607. OPENLAYERS);
  74608. goog.exportSymbol(
  74609. 'ol.events.condition.doubleClick',
  74610. ol.events.condition.doubleClick,
  74611. OPENLAYERS);
  74612. goog.exportSymbol(
  74613. 'ol.events.condition.noModifierKeys',
  74614. ol.events.condition.noModifierKeys,
  74615. OPENLAYERS);
  74616. goog.exportSymbol(
  74617. 'ol.events.condition.platformModifierKeyOnly',
  74618. ol.events.condition.platformModifierKeyOnly,
  74619. OPENLAYERS);
  74620. goog.exportSymbol(
  74621. 'ol.events.condition.shiftKeyOnly',
  74622. ol.events.condition.shiftKeyOnly,
  74623. OPENLAYERS);
  74624. goog.exportSymbol(
  74625. 'ol.events.condition.targetNotEditable',
  74626. ol.events.condition.targetNotEditable,
  74627. OPENLAYERS);
  74628. goog.exportSymbol(
  74629. 'ol.events.condition.mouseOnly',
  74630. ol.events.condition.mouseOnly,
  74631. OPENLAYERS);
  74632. goog.exportSymbol(
  74633. 'ol.events.condition.primaryAction',
  74634. ol.events.condition.primaryAction,
  74635. OPENLAYERS);
  74636. goog.exportProperty(
  74637. ol.events.Event.prototype,
  74638. 'type',
  74639. ol.events.Event.prototype.type);
  74640. goog.exportProperty(
  74641. ol.events.Event.prototype,
  74642. 'target',
  74643. ol.events.Event.prototype.target);
  74644. goog.exportProperty(
  74645. ol.events.Event.prototype,
  74646. 'preventDefault',
  74647. ol.events.Event.prototype.preventDefault);
  74648. goog.exportProperty(
  74649. ol.events.Event.prototype,
  74650. 'stopPropagation',
  74651. ol.events.Event.prototype.stopPropagation);
  74652. goog.exportSymbol(
  74653. 'ol.control.Attribution',
  74654. ol.control.Attribution,
  74655. OPENLAYERS);
  74656. goog.exportSymbol(
  74657. 'ol.control.Attribution.render',
  74658. ol.control.Attribution.render,
  74659. OPENLAYERS);
  74660. goog.exportProperty(
  74661. ol.control.Attribution.prototype,
  74662. 'getCollapsible',
  74663. ol.control.Attribution.prototype.getCollapsible);
  74664. goog.exportProperty(
  74665. ol.control.Attribution.prototype,
  74666. 'setCollapsible',
  74667. ol.control.Attribution.prototype.setCollapsible);
  74668. goog.exportProperty(
  74669. ol.control.Attribution.prototype,
  74670. 'setCollapsed',
  74671. ol.control.Attribution.prototype.setCollapsed);
  74672. goog.exportProperty(
  74673. ol.control.Attribution.prototype,
  74674. 'getCollapsed',
  74675. ol.control.Attribution.prototype.getCollapsed);
  74676. goog.exportSymbol(
  74677. 'ol.control.Control',
  74678. ol.control.Control,
  74679. OPENLAYERS);
  74680. goog.exportProperty(
  74681. ol.control.Control.prototype,
  74682. 'getMap',
  74683. ol.control.Control.prototype.getMap);
  74684. goog.exportProperty(
  74685. ol.control.Control.prototype,
  74686. 'setMap',
  74687. ol.control.Control.prototype.setMap);
  74688. goog.exportProperty(
  74689. ol.control.Control.prototype,
  74690. 'setTarget',
  74691. ol.control.Control.prototype.setTarget);
  74692. goog.exportSymbol(
  74693. 'ol.control.FullScreen',
  74694. ol.control.FullScreen,
  74695. OPENLAYERS);
  74696. goog.exportSymbol(
  74697. 'ol.control.MousePosition',
  74698. ol.control.MousePosition,
  74699. OPENLAYERS);
  74700. goog.exportSymbol(
  74701. 'ol.control.MousePosition.render',
  74702. ol.control.MousePosition.render,
  74703. OPENLAYERS);
  74704. goog.exportProperty(
  74705. ol.control.MousePosition.prototype,
  74706. 'getCoordinateFormat',
  74707. ol.control.MousePosition.prototype.getCoordinateFormat);
  74708. goog.exportProperty(
  74709. ol.control.MousePosition.prototype,
  74710. 'getProjection',
  74711. ol.control.MousePosition.prototype.getProjection);
  74712. goog.exportProperty(
  74713. ol.control.MousePosition.prototype,
  74714. 'setCoordinateFormat',
  74715. ol.control.MousePosition.prototype.setCoordinateFormat);
  74716. goog.exportProperty(
  74717. ol.control.MousePosition.prototype,
  74718. 'setProjection',
  74719. ol.control.MousePosition.prototype.setProjection);
  74720. goog.exportSymbol(
  74721. 'ol.control.OverviewMap',
  74722. ol.control.OverviewMap,
  74723. OPENLAYERS);
  74724. goog.exportSymbol(
  74725. 'ol.control.OverviewMap.render',
  74726. ol.control.OverviewMap.render,
  74727. OPENLAYERS);
  74728. goog.exportProperty(
  74729. ol.control.OverviewMap.prototype,
  74730. 'getCollapsible',
  74731. ol.control.OverviewMap.prototype.getCollapsible);
  74732. goog.exportProperty(
  74733. ol.control.OverviewMap.prototype,
  74734. 'setCollapsible',
  74735. ol.control.OverviewMap.prototype.setCollapsible);
  74736. goog.exportProperty(
  74737. ol.control.OverviewMap.prototype,
  74738. 'setCollapsed',
  74739. ol.control.OverviewMap.prototype.setCollapsed);
  74740. goog.exportProperty(
  74741. ol.control.OverviewMap.prototype,
  74742. 'getCollapsed',
  74743. ol.control.OverviewMap.prototype.getCollapsed);
  74744. goog.exportProperty(
  74745. ol.control.OverviewMap.prototype,
  74746. 'getOverviewMap',
  74747. ol.control.OverviewMap.prototype.getOverviewMap);
  74748. goog.exportSymbol(
  74749. 'ol.control.Rotate',
  74750. ol.control.Rotate,
  74751. OPENLAYERS);
  74752. goog.exportSymbol(
  74753. 'ol.control.Rotate.render',
  74754. ol.control.Rotate.render,
  74755. OPENLAYERS);
  74756. goog.exportSymbol(
  74757. 'ol.control.ScaleLine',
  74758. ol.control.ScaleLine,
  74759. OPENLAYERS);
  74760. goog.exportProperty(
  74761. ol.control.ScaleLine.prototype,
  74762. 'getUnits',
  74763. ol.control.ScaleLine.prototype.getUnits);
  74764. goog.exportSymbol(
  74765. 'ol.control.ScaleLine.render',
  74766. ol.control.ScaleLine.render,
  74767. OPENLAYERS);
  74768. goog.exportProperty(
  74769. ol.control.ScaleLine.prototype,
  74770. 'setUnits',
  74771. ol.control.ScaleLine.prototype.setUnits);
  74772. goog.exportSymbol(
  74773. 'ol.control.Zoom',
  74774. ol.control.Zoom,
  74775. OPENLAYERS);
  74776. goog.exportSymbol(
  74777. 'ol.control.ZoomSlider',
  74778. ol.control.ZoomSlider,
  74779. OPENLAYERS);
  74780. goog.exportSymbol(
  74781. 'ol.control.ZoomSlider.render',
  74782. ol.control.ZoomSlider.render,
  74783. OPENLAYERS);
  74784. goog.exportSymbol(
  74785. 'ol.control.ZoomToExtent',
  74786. ol.control.ZoomToExtent,
  74787. OPENLAYERS);
  74788. goog.exportProperty(
  74789. ol.Object.prototype,
  74790. 'changed',
  74791. ol.Object.prototype.changed);
  74792. goog.exportProperty(
  74793. ol.Object.prototype,
  74794. 'dispatchEvent',
  74795. ol.Object.prototype.dispatchEvent);
  74796. goog.exportProperty(
  74797. ol.Object.prototype,
  74798. 'getRevision',
  74799. ol.Object.prototype.getRevision);
  74800. goog.exportProperty(
  74801. ol.Object.prototype,
  74802. 'on',
  74803. ol.Object.prototype.on);
  74804. goog.exportProperty(
  74805. ol.Object.prototype,
  74806. 'once',
  74807. ol.Object.prototype.once);
  74808. goog.exportProperty(
  74809. ol.Object.prototype,
  74810. 'un',
  74811. ol.Object.prototype.un);
  74812. goog.exportProperty(
  74813. ol.PluggableMap.prototype,
  74814. 'get',
  74815. ol.PluggableMap.prototype.get);
  74816. goog.exportProperty(
  74817. ol.PluggableMap.prototype,
  74818. 'getKeys',
  74819. ol.PluggableMap.prototype.getKeys);
  74820. goog.exportProperty(
  74821. ol.PluggableMap.prototype,
  74822. 'getProperties',
  74823. ol.PluggableMap.prototype.getProperties);
  74824. goog.exportProperty(
  74825. ol.PluggableMap.prototype,
  74826. 'set',
  74827. ol.PluggableMap.prototype.set);
  74828. goog.exportProperty(
  74829. ol.PluggableMap.prototype,
  74830. 'setProperties',
  74831. ol.PluggableMap.prototype.setProperties);
  74832. goog.exportProperty(
  74833. ol.PluggableMap.prototype,
  74834. 'unset',
  74835. ol.PluggableMap.prototype.unset);
  74836. goog.exportProperty(
  74837. ol.PluggableMap.prototype,
  74838. 'changed',
  74839. ol.PluggableMap.prototype.changed);
  74840. goog.exportProperty(
  74841. ol.PluggableMap.prototype,
  74842. 'dispatchEvent',
  74843. ol.PluggableMap.prototype.dispatchEvent);
  74844. goog.exportProperty(
  74845. ol.PluggableMap.prototype,
  74846. 'getRevision',
  74847. ol.PluggableMap.prototype.getRevision);
  74848. goog.exportProperty(
  74849. ol.PluggableMap.prototype,
  74850. 'on',
  74851. ol.PluggableMap.prototype.on);
  74852. goog.exportProperty(
  74853. ol.PluggableMap.prototype,
  74854. 'once',
  74855. ol.PluggableMap.prototype.once);
  74856. goog.exportProperty(
  74857. ol.PluggableMap.prototype,
  74858. 'un',
  74859. ol.PluggableMap.prototype.un);
  74860. goog.exportProperty(
  74861. ol.CanvasMap.prototype,
  74862. 'addControl',
  74863. ol.CanvasMap.prototype.addControl);
  74864. goog.exportProperty(
  74865. ol.CanvasMap.prototype,
  74866. 'addInteraction',
  74867. ol.CanvasMap.prototype.addInteraction);
  74868. goog.exportProperty(
  74869. ol.CanvasMap.prototype,
  74870. 'addLayer',
  74871. ol.CanvasMap.prototype.addLayer);
  74872. goog.exportProperty(
  74873. ol.CanvasMap.prototype,
  74874. 'addOverlay',
  74875. ol.CanvasMap.prototype.addOverlay);
  74876. goog.exportProperty(
  74877. ol.CanvasMap.prototype,
  74878. 'forEachFeatureAtPixel',
  74879. ol.CanvasMap.prototype.forEachFeatureAtPixel);
  74880. goog.exportProperty(
  74881. ol.CanvasMap.prototype,
  74882. 'getFeaturesAtPixel',
  74883. ol.CanvasMap.prototype.getFeaturesAtPixel);
  74884. goog.exportProperty(
  74885. ol.CanvasMap.prototype,
  74886. 'forEachLayerAtPixel',
  74887. ol.CanvasMap.prototype.forEachLayerAtPixel);
  74888. goog.exportProperty(
  74889. ol.CanvasMap.prototype,
  74890. 'hasFeatureAtPixel',
  74891. ol.CanvasMap.prototype.hasFeatureAtPixel);
  74892. goog.exportProperty(
  74893. ol.CanvasMap.prototype,
  74894. 'getEventCoordinate',
  74895. ol.CanvasMap.prototype.getEventCoordinate);
  74896. goog.exportProperty(
  74897. ol.CanvasMap.prototype,
  74898. 'getEventPixel',
  74899. ol.CanvasMap.prototype.getEventPixel);
  74900. goog.exportProperty(
  74901. ol.CanvasMap.prototype,
  74902. 'getTarget',
  74903. ol.CanvasMap.prototype.getTarget);
  74904. goog.exportProperty(
  74905. ol.CanvasMap.prototype,
  74906. 'getTargetElement',
  74907. ol.CanvasMap.prototype.getTargetElement);
  74908. goog.exportProperty(
  74909. ol.CanvasMap.prototype,
  74910. 'getCoordinateFromPixel',
  74911. ol.CanvasMap.prototype.getCoordinateFromPixel);
  74912. goog.exportProperty(
  74913. ol.CanvasMap.prototype,
  74914. 'getControls',
  74915. ol.CanvasMap.prototype.getControls);
  74916. goog.exportProperty(
  74917. ol.CanvasMap.prototype,
  74918. 'getOverlays',
  74919. ol.CanvasMap.prototype.getOverlays);
  74920. goog.exportProperty(
  74921. ol.CanvasMap.prototype,
  74922. 'getOverlayById',
  74923. ol.CanvasMap.prototype.getOverlayById);
  74924. goog.exportProperty(
  74925. ol.CanvasMap.prototype,
  74926. 'getInteractions',
  74927. ol.CanvasMap.prototype.getInteractions);
  74928. goog.exportProperty(
  74929. ol.CanvasMap.prototype,
  74930. 'getLayerGroup',
  74931. ol.CanvasMap.prototype.getLayerGroup);
  74932. goog.exportProperty(
  74933. ol.CanvasMap.prototype,
  74934. 'getLayers',
  74935. ol.CanvasMap.prototype.getLayers);
  74936. goog.exportProperty(
  74937. ol.CanvasMap.prototype,
  74938. 'getPixelFromCoordinate',
  74939. ol.CanvasMap.prototype.getPixelFromCoordinate);
  74940. goog.exportProperty(
  74941. ol.CanvasMap.prototype,
  74942. 'getSize',
  74943. ol.CanvasMap.prototype.getSize);
  74944. goog.exportProperty(
  74945. ol.CanvasMap.prototype,
  74946. 'getView',
  74947. ol.CanvasMap.prototype.getView);
  74948. goog.exportProperty(
  74949. ol.CanvasMap.prototype,
  74950. 'getViewport',
  74951. ol.CanvasMap.prototype.getViewport);
  74952. goog.exportProperty(
  74953. ol.CanvasMap.prototype,
  74954. 'renderSync',
  74955. ol.CanvasMap.prototype.renderSync);
  74956. goog.exportProperty(
  74957. ol.CanvasMap.prototype,
  74958. 'render',
  74959. ol.CanvasMap.prototype.render);
  74960. goog.exportProperty(
  74961. ol.CanvasMap.prototype,
  74962. 'removeControl',
  74963. ol.CanvasMap.prototype.removeControl);
  74964. goog.exportProperty(
  74965. ol.CanvasMap.prototype,
  74966. 'removeInteraction',
  74967. ol.CanvasMap.prototype.removeInteraction);
  74968. goog.exportProperty(
  74969. ol.CanvasMap.prototype,
  74970. 'removeLayer',
  74971. ol.CanvasMap.prototype.removeLayer);
  74972. goog.exportProperty(
  74973. ol.CanvasMap.prototype,
  74974. 'removeOverlay',
  74975. ol.CanvasMap.prototype.removeOverlay);
  74976. goog.exportProperty(
  74977. ol.CanvasMap.prototype,
  74978. 'setLayerGroup',
  74979. ol.CanvasMap.prototype.setLayerGroup);
  74980. goog.exportProperty(
  74981. ol.CanvasMap.prototype,
  74982. 'setSize',
  74983. ol.CanvasMap.prototype.setSize);
  74984. goog.exportProperty(
  74985. ol.CanvasMap.prototype,
  74986. 'setTarget',
  74987. ol.CanvasMap.prototype.setTarget);
  74988. goog.exportProperty(
  74989. ol.CanvasMap.prototype,
  74990. 'setView',
  74991. ol.CanvasMap.prototype.setView);
  74992. goog.exportProperty(
  74993. ol.CanvasMap.prototype,
  74994. 'updateSize',
  74995. ol.CanvasMap.prototype.updateSize);
  74996. goog.exportProperty(
  74997. ol.CanvasMap.prototype,
  74998. 'get',
  74999. ol.CanvasMap.prototype.get);
  75000. goog.exportProperty(
  75001. ol.CanvasMap.prototype,
  75002. 'getKeys',
  75003. ol.CanvasMap.prototype.getKeys);
  75004. goog.exportProperty(
  75005. ol.CanvasMap.prototype,
  75006. 'getProperties',
  75007. ol.CanvasMap.prototype.getProperties);
  75008. goog.exportProperty(
  75009. ol.CanvasMap.prototype,
  75010. 'set',
  75011. ol.CanvasMap.prototype.set);
  75012. goog.exportProperty(
  75013. ol.CanvasMap.prototype,
  75014. 'setProperties',
  75015. ol.CanvasMap.prototype.setProperties);
  75016. goog.exportProperty(
  75017. ol.CanvasMap.prototype,
  75018. 'unset',
  75019. ol.CanvasMap.prototype.unset);
  75020. goog.exportProperty(
  75021. ol.CanvasMap.prototype,
  75022. 'changed',
  75023. ol.CanvasMap.prototype.changed);
  75024. goog.exportProperty(
  75025. ol.CanvasMap.prototype,
  75026. 'dispatchEvent',
  75027. ol.CanvasMap.prototype.dispatchEvent);
  75028. goog.exportProperty(
  75029. ol.CanvasMap.prototype,
  75030. 'getRevision',
  75031. ol.CanvasMap.prototype.getRevision);
  75032. goog.exportProperty(
  75033. ol.CanvasMap.prototype,
  75034. 'on',
  75035. ol.CanvasMap.prototype.on);
  75036. goog.exportProperty(
  75037. ol.CanvasMap.prototype,
  75038. 'once',
  75039. ol.CanvasMap.prototype.once);
  75040. goog.exportProperty(
  75041. ol.CanvasMap.prototype,
  75042. 'un',
  75043. ol.CanvasMap.prototype.un);
  75044. goog.exportProperty(
  75045. ol.Collection.prototype,
  75046. 'get',
  75047. ol.Collection.prototype.get);
  75048. goog.exportProperty(
  75049. ol.Collection.prototype,
  75050. 'getKeys',
  75051. ol.Collection.prototype.getKeys);
  75052. goog.exportProperty(
  75053. ol.Collection.prototype,
  75054. 'getProperties',
  75055. ol.Collection.prototype.getProperties);
  75056. goog.exportProperty(
  75057. ol.Collection.prototype,
  75058. 'set',
  75059. ol.Collection.prototype.set);
  75060. goog.exportProperty(
  75061. ol.Collection.prototype,
  75062. 'setProperties',
  75063. ol.Collection.prototype.setProperties);
  75064. goog.exportProperty(
  75065. ol.Collection.prototype,
  75066. 'unset',
  75067. ol.Collection.prototype.unset);
  75068. goog.exportProperty(
  75069. ol.Collection.prototype,
  75070. 'changed',
  75071. ol.Collection.prototype.changed);
  75072. goog.exportProperty(
  75073. ol.Collection.prototype,
  75074. 'dispatchEvent',
  75075. ol.Collection.prototype.dispatchEvent);
  75076. goog.exportProperty(
  75077. ol.Collection.prototype,
  75078. 'getRevision',
  75079. ol.Collection.prototype.getRevision);
  75080. goog.exportProperty(
  75081. ol.Collection.prototype,
  75082. 'on',
  75083. ol.Collection.prototype.on);
  75084. goog.exportProperty(
  75085. ol.Collection.prototype,
  75086. 'once',
  75087. ol.Collection.prototype.once);
  75088. goog.exportProperty(
  75089. ol.Collection.prototype,
  75090. 'un',
  75091. ol.Collection.prototype.un);
  75092. goog.exportProperty(
  75093. ol.Collection.Event.prototype,
  75094. 'type',
  75095. ol.Collection.Event.prototype.type);
  75096. goog.exportProperty(
  75097. ol.Collection.Event.prototype,
  75098. 'target',
  75099. ol.Collection.Event.prototype.target);
  75100. goog.exportProperty(
  75101. ol.Collection.Event.prototype,
  75102. 'preventDefault',
  75103. ol.Collection.Event.prototype.preventDefault);
  75104. goog.exportProperty(
  75105. ol.Collection.Event.prototype,
  75106. 'stopPropagation',
  75107. ol.Collection.Event.prototype.stopPropagation);
  75108. goog.exportProperty(
  75109. ol.DeviceOrientation.prototype,
  75110. 'get',
  75111. ol.DeviceOrientation.prototype.get);
  75112. goog.exportProperty(
  75113. ol.DeviceOrientation.prototype,
  75114. 'getKeys',
  75115. ol.DeviceOrientation.prototype.getKeys);
  75116. goog.exportProperty(
  75117. ol.DeviceOrientation.prototype,
  75118. 'getProperties',
  75119. ol.DeviceOrientation.prototype.getProperties);
  75120. goog.exportProperty(
  75121. ol.DeviceOrientation.prototype,
  75122. 'set',
  75123. ol.DeviceOrientation.prototype.set);
  75124. goog.exportProperty(
  75125. ol.DeviceOrientation.prototype,
  75126. 'setProperties',
  75127. ol.DeviceOrientation.prototype.setProperties);
  75128. goog.exportProperty(
  75129. ol.DeviceOrientation.prototype,
  75130. 'unset',
  75131. ol.DeviceOrientation.prototype.unset);
  75132. goog.exportProperty(
  75133. ol.DeviceOrientation.prototype,
  75134. 'changed',
  75135. ol.DeviceOrientation.prototype.changed);
  75136. goog.exportProperty(
  75137. ol.DeviceOrientation.prototype,
  75138. 'dispatchEvent',
  75139. ol.DeviceOrientation.prototype.dispatchEvent);
  75140. goog.exportProperty(
  75141. ol.DeviceOrientation.prototype,
  75142. 'getRevision',
  75143. ol.DeviceOrientation.prototype.getRevision);
  75144. goog.exportProperty(
  75145. ol.DeviceOrientation.prototype,
  75146. 'on',
  75147. ol.DeviceOrientation.prototype.on);
  75148. goog.exportProperty(
  75149. ol.DeviceOrientation.prototype,
  75150. 'once',
  75151. ol.DeviceOrientation.prototype.once);
  75152. goog.exportProperty(
  75153. ol.DeviceOrientation.prototype,
  75154. 'un',
  75155. ol.DeviceOrientation.prototype.un);
  75156. goog.exportProperty(
  75157. ol.Feature.prototype,
  75158. 'get',
  75159. ol.Feature.prototype.get);
  75160. goog.exportProperty(
  75161. ol.Feature.prototype,
  75162. 'getKeys',
  75163. ol.Feature.prototype.getKeys);
  75164. goog.exportProperty(
  75165. ol.Feature.prototype,
  75166. 'getProperties',
  75167. ol.Feature.prototype.getProperties);
  75168. goog.exportProperty(
  75169. ol.Feature.prototype,
  75170. 'set',
  75171. ol.Feature.prototype.set);
  75172. goog.exportProperty(
  75173. ol.Feature.prototype,
  75174. 'setProperties',
  75175. ol.Feature.prototype.setProperties);
  75176. goog.exportProperty(
  75177. ol.Feature.prototype,
  75178. 'unset',
  75179. ol.Feature.prototype.unset);
  75180. goog.exportProperty(
  75181. ol.Feature.prototype,
  75182. 'changed',
  75183. ol.Feature.prototype.changed);
  75184. goog.exportProperty(
  75185. ol.Feature.prototype,
  75186. 'dispatchEvent',
  75187. ol.Feature.prototype.dispatchEvent);
  75188. goog.exportProperty(
  75189. ol.Feature.prototype,
  75190. 'getRevision',
  75191. ol.Feature.prototype.getRevision);
  75192. goog.exportProperty(
  75193. ol.Feature.prototype,
  75194. 'on',
  75195. ol.Feature.prototype.on);
  75196. goog.exportProperty(
  75197. ol.Feature.prototype,
  75198. 'once',
  75199. ol.Feature.prototype.once);
  75200. goog.exportProperty(
  75201. ol.Feature.prototype,
  75202. 'un',
  75203. ol.Feature.prototype.un);
  75204. goog.exportProperty(
  75205. ol.Geolocation.prototype,
  75206. 'get',
  75207. ol.Geolocation.prototype.get);
  75208. goog.exportProperty(
  75209. ol.Geolocation.prototype,
  75210. 'getKeys',
  75211. ol.Geolocation.prototype.getKeys);
  75212. goog.exportProperty(
  75213. ol.Geolocation.prototype,
  75214. 'getProperties',
  75215. ol.Geolocation.prototype.getProperties);
  75216. goog.exportProperty(
  75217. ol.Geolocation.prototype,
  75218. 'set',
  75219. ol.Geolocation.prototype.set);
  75220. goog.exportProperty(
  75221. ol.Geolocation.prototype,
  75222. 'setProperties',
  75223. ol.Geolocation.prototype.setProperties);
  75224. goog.exportProperty(
  75225. ol.Geolocation.prototype,
  75226. 'unset',
  75227. ol.Geolocation.prototype.unset);
  75228. goog.exportProperty(
  75229. ol.Geolocation.prototype,
  75230. 'changed',
  75231. ol.Geolocation.prototype.changed);
  75232. goog.exportProperty(
  75233. ol.Geolocation.prototype,
  75234. 'dispatchEvent',
  75235. ol.Geolocation.prototype.dispatchEvent);
  75236. goog.exportProperty(
  75237. ol.Geolocation.prototype,
  75238. 'getRevision',
  75239. ol.Geolocation.prototype.getRevision);
  75240. goog.exportProperty(
  75241. ol.Geolocation.prototype,
  75242. 'on',
  75243. ol.Geolocation.prototype.on);
  75244. goog.exportProperty(
  75245. ol.Geolocation.prototype,
  75246. 'once',
  75247. ol.Geolocation.prototype.once);
  75248. goog.exportProperty(
  75249. ol.Geolocation.prototype,
  75250. 'un',
  75251. ol.Geolocation.prototype.un);
  75252. goog.exportProperty(
  75253. ol.ImageTile.prototype,
  75254. 'getTileCoord',
  75255. ol.ImageTile.prototype.getTileCoord);
  75256. goog.exportProperty(
  75257. ol.ImageTile.prototype,
  75258. 'load',
  75259. ol.ImageTile.prototype.load);
  75260. goog.exportProperty(
  75261. ol.Map.prototype,
  75262. 'addControl',
  75263. ol.Map.prototype.addControl);
  75264. goog.exportProperty(
  75265. ol.Map.prototype,
  75266. 'addInteraction',
  75267. ol.Map.prototype.addInteraction);
  75268. goog.exportProperty(
  75269. ol.Map.prototype,
  75270. 'addLayer',
  75271. ol.Map.prototype.addLayer);
  75272. goog.exportProperty(
  75273. ol.Map.prototype,
  75274. 'addOverlay',
  75275. ol.Map.prototype.addOverlay);
  75276. goog.exportProperty(
  75277. ol.Map.prototype,
  75278. 'forEachFeatureAtPixel',
  75279. ol.Map.prototype.forEachFeatureAtPixel);
  75280. goog.exportProperty(
  75281. ol.Map.prototype,
  75282. 'getFeaturesAtPixel',
  75283. ol.Map.prototype.getFeaturesAtPixel);
  75284. goog.exportProperty(
  75285. ol.Map.prototype,
  75286. 'forEachLayerAtPixel',
  75287. ol.Map.prototype.forEachLayerAtPixel);
  75288. goog.exportProperty(
  75289. ol.Map.prototype,
  75290. 'hasFeatureAtPixel',
  75291. ol.Map.prototype.hasFeatureAtPixel);
  75292. goog.exportProperty(
  75293. ol.Map.prototype,
  75294. 'getEventCoordinate',
  75295. ol.Map.prototype.getEventCoordinate);
  75296. goog.exportProperty(
  75297. ol.Map.prototype,
  75298. 'getEventPixel',
  75299. ol.Map.prototype.getEventPixel);
  75300. goog.exportProperty(
  75301. ol.Map.prototype,
  75302. 'getTarget',
  75303. ol.Map.prototype.getTarget);
  75304. goog.exportProperty(
  75305. ol.Map.prototype,
  75306. 'getTargetElement',
  75307. ol.Map.prototype.getTargetElement);
  75308. goog.exportProperty(
  75309. ol.Map.prototype,
  75310. 'getCoordinateFromPixel',
  75311. ol.Map.prototype.getCoordinateFromPixel);
  75312. goog.exportProperty(
  75313. ol.Map.prototype,
  75314. 'getControls',
  75315. ol.Map.prototype.getControls);
  75316. goog.exportProperty(
  75317. ol.Map.prototype,
  75318. 'getOverlays',
  75319. ol.Map.prototype.getOverlays);
  75320. goog.exportProperty(
  75321. ol.Map.prototype,
  75322. 'getOverlayById',
  75323. ol.Map.prototype.getOverlayById);
  75324. goog.exportProperty(
  75325. ol.Map.prototype,
  75326. 'getInteractions',
  75327. ol.Map.prototype.getInteractions);
  75328. goog.exportProperty(
  75329. ol.Map.prototype,
  75330. 'getLayerGroup',
  75331. ol.Map.prototype.getLayerGroup);
  75332. goog.exportProperty(
  75333. ol.Map.prototype,
  75334. 'getLayers',
  75335. ol.Map.prototype.getLayers);
  75336. goog.exportProperty(
  75337. ol.Map.prototype,
  75338. 'getPixelFromCoordinate',
  75339. ol.Map.prototype.getPixelFromCoordinate);
  75340. goog.exportProperty(
  75341. ol.Map.prototype,
  75342. 'getSize',
  75343. ol.Map.prototype.getSize);
  75344. goog.exportProperty(
  75345. ol.Map.prototype,
  75346. 'getView',
  75347. ol.Map.prototype.getView);
  75348. goog.exportProperty(
  75349. ol.Map.prototype,
  75350. 'getViewport',
  75351. ol.Map.prototype.getViewport);
  75352. goog.exportProperty(
  75353. ol.Map.prototype,
  75354. 'renderSync',
  75355. ol.Map.prototype.renderSync);
  75356. goog.exportProperty(
  75357. ol.Map.prototype,
  75358. 'render',
  75359. ol.Map.prototype.render);
  75360. goog.exportProperty(
  75361. ol.Map.prototype,
  75362. 'removeControl',
  75363. ol.Map.prototype.removeControl);
  75364. goog.exportProperty(
  75365. ol.Map.prototype,
  75366. 'removeInteraction',
  75367. ol.Map.prototype.removeInteraction);
  75368. goog.exportProperty(
  75369. ol.Map.prototype,
  75370. 'removeLayer',
  75371. ol.Map.prototype.removeLayer);
  75372. goog.exportProperty(
  75373. ol.Map.prototype,
  75374. 'removeOverlay',
  75375. ol.Map.prototype.removeOverlay);
  75376. goog.exportProperty(
  75377. ol.Map.prototype,
  75378. 'setLayerGroup',
  75379. ol.Map.prototype.setLayerGroup);
  75380. goog.exportProperty(
  75381. ol.Map.prototype,
  75382. 'setSize',
  75383. ol.Map.prototype.setSize);
  75384. goog.exportProperty(
  75385. ol.Map.prototype,
  75386. 'setTarget',
  75387. ol.Map.prototype.setTarget);
  75388. goog.exportProperty(
  75389. ol.Map.prototype,
  75390. 'setView',
  75391. ol.Map.prototype.setView);
  75392. goog.exportProperty(
  75393. ol.Map.prototype,
  75394. 'updateSize',
  75395. ol.Map.prototype.updateSize);
  75396. goog.exportProperty(
  75397. ol.Map.prototype,
  75398. 'get',
  75399. ol.Map.prototype.get);
  75400. goog.exportProperty(
  75401. ol.Map.prototype,
  75402. 'getKeys',
  75403. ol.Map.prototype.getKeys);
  75404. goog.exportProperty(
  75405. ol.Map.prototype,
  75406. 'getProperties',
  75407. ol.Map.prototype.getProperties);
  75408. goog.exportProperty(
  75409. ol.Map.prototype,
  75410. 'set',
  75411. ol.Map.prototype.set);
  75412. goog.exportProperty(
  75413. ol.Map.prototype,
  75414. 'setProperties',
  75415. ol.Map.prototype.setProperties);
  75416. goog.exportProperty(
  75417. ol.Map.prototype,
  75418. 'unset',
  75419. ol.Map.prototype.unset);
  75420. goog.exportProperty(
  75421. ol.Map.prototype,
  75422. 'changed',
  75423. ol.Map.prototype.changed);
  75424. goog.exportProperty(
  75425. ol.Map.prototype,
  75426. 'dispatchEvent',
  75427. ol.Map.prototype.dispatchEvent);
  75428. goog.exportProperty(
  75429. ol.Map.prototype,
  75430. 'getRevision',
  75431. ol.Map.prototype.getRevision);
  75432. goog.exportProperty(
  75433. ol.Map.prototype,
  75434. 'on',
  75435. ol.Map.prototype.on);
  75436. goog.exportProperty(
  75437. ol.Map.prototype,
  75438. 'once',
  75439. ol.Map.prototype.once);
  75440. goog.exportProperty(
  75441. ol.Map.prototype,
  75442. 'un',
  75443. ol.Map.prototype.un);
  75444. goog.exportProperty(
  75445. ol.MapEvent.prototype,
  75446. 'type',
  75447. ol.MapEvent.prototype.type);
  75448. goog.exportProperty(
  75449. ol.MapEvent.prototype,
  75450. 'target',
  75451. ol.MapEvent.prototype.target);
  75452. goog.exportProperty(
  75453. ol.MapEvent.prototype,
  75454. 'preventDefault',
  75455. ol.MapEvent.prototype.preventDefault);
  75456. goog.exportProperty(
  75457. ol.MapEvent.prototype,
  75458. 'stopPropagation',
  75459. ol.MapEvent.prototype.stopPropagation);
  75460. goog.exportProperty(
  75461. ol.MapBrowserEvent.prototype,
  75462. 'map',
  75463. ol.MapBrowserEvent.prototype.map);
  75464. goog.exportProperty(
  75465. ol.MapBrowserEvent.prototype,
  75466. 'frameState',
  75467. ol.MapBrowserEvent.prototype.frameState);
  75468. goog.exportProperty(
  75469. ol.MapBrowserEvent.prototype,
  75470. 'type',
  75471. ol.MapBrowserEvent.prototype.type);
  75472. goog.exportProperty(
  75473. ol.MapBrowserEvent.prototype,
  75474. 'target',
  75475. ol.MapBrowserEvent.prototype.target);
  75476. goog.exportProperty(
  75477. ol.MapBrowserEvent.prototype,
  75478. 'preventDefault',
  75479. ol.MapBrowserEvent.prototype.preventDefault);
  75480. goog.exportProperty(
  75481. ol.MapBrowserEvent.prototype,
  75482. 'stopPropagation',
  75483. ol.MapBrowserEvent.prototype.stopPropagation);
  75484. goog.exportProperty(
  75485. ol.MapBrowserPointerEvent.prototype,
  75486. 'originalEvent',
  75487. ol.MapBrowserPointerEvent.prototype.originalEvent);
  75488. goog.exportProperty(
  75489. ol.MapBrowserPointerEvent.prototype,
  75490. 'pixel',
  75491. ol.MapBrowserPointerEvent.prototype.pixel);
  75492. goog.exportProperty(
  75493. ol.MapBrowserPointerEvent.prototype,
  75494. 'coordinate',
  75495. ol.MapBrowserPointerEvent.prototype.coordinate);
  75496. goog.exportProperty(
  75497. ol.MapBrowserPointerEvent.prototype,
  75498. 'dragging',
  75499. ol.MapBrowserPointerEvent.prototype.dragging);
  75500. goog.exportProperty(
  75501. ol.MapBrowserPointerEvent.prototype,
  75502. 'preventDefault',
  75503. ol.MapBrowserPointerEvent.prototype.preventDefault);
  75504. goog.exportProperty(
  75505. ol.MapBrowserPointerEvent.prototype,
  75506. 'stopPropagation',
  75507. ol.MapBrowserPointerEvent.prototype.stopPropagation);
  75508. goog.exportProperty(
  75509. ol.MapBrowserPointerEvent.prototype,
  75510. 'map',
  75511. ol.MapBrowserPointerEvent.prototype.map);
  75512. goog.exportProperty(
  75513. ol.MapBrowserPointerEvent.prototype,
  75514. 'frameState',
  75515. ol.MapBrowserPointerEvent.prototype.frameState);
  75516. goog.exportProperty(
  75517. ol.MapBrowserPointerEvent.prototype,
  75518. 'type',
  75519. ol.MapBrowserPointerEvent.prototype.type);
  75520. goog.exportProperty(
  75521. ol.MapBrowserPointerEvent.prototype,
  75522. 'target',
  75523. ol.MapBrowserPointerEvent.prototype.target);
  75524. goog.exportProperty(
  75525. ol.Object.Event.prototype,
  75526. 'type',
  75527. ol.Object.Event.prototype.type);
  75528. goog.exportProperty(
  75529. ol.Object.Event.prototype,
  75530. 'target',
  75531. ol.Object.Event.prototype.target);
  75532. goog.exportProperty(
  75533. ol.Object.Event.prototype,
  75534. 'preventDefault',
  75535. ol.Object.Event.prototype.preventDefault);
  75536. goog.exportProperty(
  75537. ol.Object.Event.prototype,
  75538. 'stopPropagation',
  75539. ol.Object.Event.prototype.stopPropagation);
  75540. goog.exportProperty(
  75541. ol.Overlay.prototype,
  75542. 'get',
  75543. ol.Overlay.prototype.get);
  75544. goog.exportProperty(
  75545. ol.Overlay.prototype,
  75546. 'getKeys',
  75547. ol.Overlay.prototype.getKeys);
  75548. goog.exportProperty(
  75549. ol.Overlay.prototype,
  75550. 'getProperties',
  75551. ol.Overlay.prototype.getProperties);
  75552. goog.exportProperty(
  75553. ol.Overlay.prototype,
  75554. 'set',
  75555. ol.Overlay.prototype.set);
  75556. goog.exportProperty(
  75557. ol.Overlay.prototype,
  75558. 'setProperties',
  75559. ol.Overlay.prototype.setProperties);
  75560. goog.exportProperty(
  75561. ol.Overlay.prototype,
  75562. 'unset',
  75563. ol.Overlay.prototype.unset);
  75564. goog.exportProperty(
  75565. ol.Overlay.prototype,
  75566. 'changed',
  75567. ol.Overlay.prototype.changed);
  75568. goog.exportProperty(
  75569. ol.Overlay.prototype,
  75570. 'dispatchEvent',
  75571. ol.Overlay.prototype.dispatchEvent);
  75572. goog.exportProperty(
  75573. ol.Overlay.prototype,
  75574. 'getRevision',
  75575. ol.Overlay.prototype.getRevision);
  75576. goog.exportProperty(
  75577. ol.Overlay.prototype,
  75578. 'on',
  75579. ol.Overlay.prototype.on);
  75580. goog.exportProperty(
  75581. ol.Overlay.prototype,
  75582. 'once',
  75583. ol.Overlay.prototype.once);
  75584. goog.exportProperty(
  75585. ol.Overlay.prototype,
  75586. 'un',
  75587. ol.Overlay.prototype.un);
  75588. goog.exportProperty(
  75589. ol.VectorImageTile.prototype,
  75590. 'getTileCoord',
  75591. ol.VectorImageTile.prototype.getTileCoord);
  75592. goog.exportProperty(
  75593. ol.VectorImageTile.prototype,
  75594. 'load',
  75595. ol.VectorImageTile.prototype.load);
  75596. goog.exportProperty(
  75597. ol.VectorTile.prototype,
  75598. 'getTileCoord',
  75599. ol.VectorTile.prototype.getTileCoord);
  75600. goog.exportProperty(
  75601. ol.VectorTile.prototype,
  75602. 'load',
  75603. ol.VectorTile.prototype.load);
  75604. goog.exportProperty(
  75605. ol.View.prototype,
  75606. 'get',
  75607. ol.View.prototype.get);
  75608. goog.exportProperty(
  75609. ol.View.prototype,
  75610. 'getKeys',
  75611. ol.View.prototype.getKeys);
  75612. goog.exportProperty(
  75613. ol.View.prototype,
  75614. 'getProperties',
  75615. ol.View.prototype.getProperties);
  75616. goog.exportProperty(
  75617. ol.View.prototype,
  75618. 'set',
  75619. ol.View.prototype.set);
  75620. goog.exportProperty(
  75621. ol.View.prototype,
  75622. 'setProperties',
  75623. ol.View.prototype.setProperties);
  75624. goog.exportProperty(
  75625. ol.View.prototype,
  75626. 'unset',
  75627. ol.View.prototype.unset);
  75628. goog.exportProperty(
  75629. ol.View.prototype,
  75630. 'changed',
  75631. ol.View.prototype.changed);
  75632. goog.exportProperty(
  75633. ol.View.prototype,
  75634. 'dispatchEvent',
  75635. ol.View.prototype.dispatchEvent);
  75636. goog.exportProperty(
  75637. ol.View.prototype,
  75638. 'getRevision',
  75639. ol.View.prototype.getRevision);
  75640. goog.exportProperty(
  75641. ol.View.prototype,
  75642. 'on',
  75643. ol.View.prototype.on);
  75644. goog.exportProperty(
  75645. ol.View.prototype,
  75646. 'once',
  75647. ol.View.prototype.once);
  75648. goog.exportProperty(
  75649. ol.View.prototype,
  75650. 'un',
  75651. ol.View.prototype.un);
  75652. goog.exportProperty(
  75653. ol.tilegrid.WMTS.prototype,
  75654. 'forEachTileCoord',
  75655. ol.tilegrid.WMTS.prototype.forEachTileCoord);
  75656. goog.exportProperty(
  75657. ol.tilegrid.WMTS.prototype,
  75658. 'getMaxZoom',
  75659. ol.tilegrid.WMTS.prototype.getMaxZoom);
  75660. goog.exportProperty(
  75661. ol.tilegrid.WMTS.prototype,
  75662. 'getMinZoom',
  75663. ol.tilegrid.WMTS.prototype.getMinZoom);
  75664. goog.exportProperty(
  75665. ol.tilegrid.WMTS.prototype,
  75666. 'getOrigin',
  75667. ol.tilegrid.WMTS.prototype.getOrigin);
  75668. goog.exportProperty(
  75669. ol.tilegrid.WMTS.prototype,
  75670. 'getResolution',
  75671. ol.tilegrid.WMTS.prototype.getResolution);
  75672. goog.exportProperty(
  75673. ol.tilegrid.WMTS.prototype,
  75674. 'getResolutions',
  75675. ol.tilegrid.WMTS.prototype.getResolutions);
  75676. goog.exportProperty(
  75677. ol.tilegrid.WMTS.prototype,
  75678. 'getTileCoordExtent',
  75679. ol.tilegrid.WMTS.prototype.getTileCoordExtent);
  75680. goog.exportProperty(
  75681. ol.tilegrid.WMTS.prototype,
  75682. 'getTileCoordForCoordAndResolution',
  75683. ol.tilegrid.WMTS.prototype.getTileCoordForCoordAndResolution);
  75684. goog.exportProperty(
  75685. ol.tilegrid.WMTS.prototype,
  75686. 'getTileCoordForCoordAndZ',
  75687. ol.tilegrid.WMTS.prototype.getTileCoordForCoordAndZ);
  75688. goog.exportProperty(
  75689. ol.tilegrid.WMTS.prototype,
  75690. 'getTileSize',
  75691. ol.tilegrid.WMTS.prototype.getTileSize);
  75692. goog.exportProperty(
  75693. ol.tilegrid.WMTS.prototype,
  75694. 'getZForResolution',
  75695. ol.tilegrid.WMTS.prototype.getZForResolution);
  75696. goog.exportProperty(
  75697. ol.style.RegularShape.prototype,
  75698. 'getOpacity',
  75699. ol.style.RegularShape.prototype.getOpacity);
  75700. goog.exportProperty(
  75701. ol.style.RegularShape.prototype,
  75702. 'getRotateWithView',
  75703. ol.style.RegularShape.prototype.getRotateWithView);
  75704. goog.exportProperty(
  75705. ol.style.RegularShape.prototype,
  75706. 'getRotation',
  75707. ol.style.RegularShape.prototype.getRotation);
  75708. goog.exportProperty(
  75709. ol.style.RegularShape.prototype,
  75710. 'getScale',
  75711. ol.style.RegularShape.prototype.getScale);
  75712. goog.exportProperty(
  75713. ol.style.RegularShape.prototype,
  75714. 'getSnapToPixel',
  75715. ol.style.RegularShape.prototype.getSnapToPixel);
  75716. goog.exportProperty(
  75717. ol.style.RegularShape.prototype,
  75718. 'setOpacity',
  75719. ol.style.RegularShape.prototype.setOpacity);
  75720. goog.exportProperty(
  75721. ol.style.RegularShape.prototype,
  75722. 'setRotation',
  75723. ol.style.RegularShape.prototype.setRotation);
  75724. goog.exportProperty(
  75725. ol.style.RegularShape.prototype,
  75726. 'setScale',
  75727. ol.style.RegularShape.prototype.setScale);
  75728. goog.exportProperty(
  75729. ol.style.Circle.prototype,
  75730. 'clone',
  75731. ol.style.Circle.prototype.clone);
  75732. goog.exportProperty(
  75733. ol.style.Circle.prototype,
  75734. 'getAngle',
  75735. ol.style.Circle.prototype.getAngle);
  75736. goog.exportProperty(
  75737. ol.style.Circle.prototype,
  75738. 'getFill',
  75739. ol.style.Circle.prototype.getFill);
  75740. goog.exportProperty(
  75741. ol.style.Circle.prototype,
  75742. 'getPoints',
  75743. ol.style.Circle.prototype.getPoints);
  75744. goog.exportProperty(
  75745. ol.style.Circle.prototype,
  75746. 'getRadius',
  75747. ol.style.Circle.prototype.getRadius);
  75748. goog.exportProperty(
  75749. ol.style.Circle.prototype,
  75750. 'getRadius2',
  75751. ol.style.Circle.prototype.getRadius2);
  75752. goog.exportProperty(
  75753. ol.style.Circle.prototype,
  75754. 'getStroke',
  75755. ol.style.Circle.prototype.getStroke);
  75756. goog.exportProperty(
  75757. ol.style.Circle.prototype,
  75758. 'getOpacity',
  75759. ol.style.Circle.prototype.getOpacity);
  75760. goog.exportProperty(
  75761. ol.style.Circle.prototype,
  75762. 'getRotateWithView',
  75763. ol.style.Circle.prototype.getRotateWithView);
  75764. goog.exportProperty(
  75765. ol.style.Circle.prototype,
  75766. 'getRotation',
  75767. ol.style.Circle.prototype.getRotation);
  75768. goog.exportProperty(
  75769. ol.style.Circle.prototype,
  75770. 'getScale',
  75771. ol.style.Circle.prototype.getScale);
  75772. goog.exportProperty(
  75773. ol.style.Circle.prototype,
  75774. 'getSnapToPixel',
  75775. ol.style.Circle.prototype.getSnapToPixel);
  75776. goog.exportProperty(
  75777. ol.style.Circle.prototype,
  75778. 'setOpacity',
  75779. ol.style.Circle.prototype.setOpacity);
  75780. goog.exportProperty(
  75781. ol.style.Circle.prototype,
  75782. 'setRotation',
  75783. ol.style.Circle.prototype.setRotation);
  75784. goog.exportProperty(
  75785. ol.style.Circle.prototype,
  75786. 'setScale',
  75787. ol.style.Circle.prototype.setScale);
  75788. goog.exportProperty(
  75789. ol.style.Icon.prototype,
  75790. 'getOpacity',
  75791. ol.style.Icon.prototype.getOpacity);
  75792. goog.exportProperty(
  75793. ol.style.Icon.prototype,
  75794. 'getRotateWithView',
  75795. ol.style.Icon.prototype.getRotateWithView);
  75796. goog.exportProperty(
  75797. ol.style.Icon.prototype,
  75798. 'getRotation',
  75799. ol.style.Icon.prototype.getRotation);
  75800. goog.exportProperty(
  75801. ol.style.Icon.prototype,
  75802. 'getScale',
  75803. ol.style.Icon.prototype.getScale);
  75804. goog.exportProperty(
  75805. ol.style.Icon.prototype,
  75806. 'getSnapToPixel',
  75807. ol.style.Icon.prototype.getSnapToPixel);
  75808. goog.exportProperty(
  75809. ol.style.Icon.prototype,
  75810. 'setOpacity',
  75811. ol.style.Icon.prototype.setOpacity);
  75812. goog.exportProperty(
  75813. ol.style.Icon.prototype,
  75814. 'setRotation',
  75815. ol.style.Icon.prototype.setRotation);
  75816. goog.exportProperty(
  75817. ol.style.Icon.prototype,
  75818. 'setScale',
  75819. ol.style.Icon.prototype.setScale);
  75820. goog.exportProperty(
  75821. ol.source.Source.prototype,
  75822. 'get',
  75823. ol.source.Source.prototype.get);
  75824. goog.exportProperty(
  75825. ol.source.Source.prototype,
  75826. 'getKeys',
  75827. ol.source.Source.prototype.getKeys);
  75828. goog.exportProperty(
  75829. ol.source.Source.prototype,
  75830. 'getProperties',
  75831. ol.source.Source.prototype.getProperties);
  75832. goog.exportProperty(
  75833. ol.source.Source.prototype,
  75834. 'set',
  75835. ol.source.Source.prototype.set);
  75836. goog.exportProperty(
  75837. ol.source.Source.prototype,
  75838. 'setProperties',
  75839. ol.source.Source.prototype.setProperties);
  75840. goog.exportProperty(
  75841. ol.source.Source.prototype,
  75842. 'unset',
  75843. ol.source.Source.prototype.unset);
  75844. goog.exportProperty(
  75845. ol.source.Source.prototype,
  75846. 'changed',
  75847. ol.source.Source.prototype.changed);
  75848. goog.exportProperty(
  75849. ol.source.Source.prototype,
  75850. 'dispatchEvent',
  75851. ol.source.Source.prototype.dispatchEvent);
  75852. goog.exportProperty(
  75853. ol.source.Source.prototype,
  75854. 'getRevision',
  75855. ol.source.Source.prototype.getRevision);
  75856. goog.exportProperty(
  75857. ol.source.Source.prototype,
  75858. 'on',
  75859. ol.source.Source.prototype.on);
  75860. goog.exportProperty(
  75861. ol.source.Source.prototype,
  75862. 'once',
  75863. ol.source.Source.prototype.once);
  75864. goog.exportProperty(
  75865. ol.source.Source.prototype,
  75866. 'un',
  75867. ol.source.Source.prototype.un);
  75868. goog.exportProperty(
  75869. ol.source.Tile.prototype,
  75870. 'getAttributions',
  75871. ol.source.Tile.prototype.getAttributions);
  75872. goog.exportProperty(
  75873. ol.source.Tile.prototype,
  75874. 'getLogo',
  75875. ol.source.Tile.prototype.getLogo);
  75876. goog.exportProperty(
  75877. ol.source.Tile.prototype,
  75878. 'getProjection',
  75879. ol.source.Tile.prototype.getProjection);
  75880. goog.exportProperty(
  75881. ol.source.Tile.prototype,
  75882. 'getState',
  75883. ol.source.Tile.prototype.getState);
  75884. goog.exportProperty(
  75885. ol.source.Tile.prototype,
  75886. 'refresh',
  75887. ol.source.Tile.prototype.refresh);
  75888. goog.exportProperty(
  75889. ol.source.Tile.prototype,
  75890. 'setAttributions',
  75891. ol.source.Tile.prototype.setAttributions);
  75892. goog.exportProperty(
  75893. ol.source.Tile.prototype,
  75894. 'get',
  75895. ol.source.Tile.prototype.get);
  75896. goog.exportProperty(
  75897. ol.source.Tile.prototype,
  75898. 'getKeys',
  75899. ol.source.Tile.prototype.getKeys);
  75900. goog.exportProperty(
  75901. ol.source.Tile.prototype,
  75902. 'getProperties',
  75903. ol.source.Tile.prototype.getProperties);
  75904. goog.exportProperty(
  75905. ol.source.Tile.prototype,
  75906. 'set',
  75907. ol.source.Tile.prototype.set);
  75908. goog.exportProperty(
  75909. ol.source.Tile.prototype,
  75910. 'setProperties',
  75911. ol.source.Tile.prototype.setProperties);
  75912. goog.exportProperty(
  75913. ol.source.Tile.prototype,
  75914. 'unset',
  75915. ol.source.Tile.prototype.unset);
  75916. goog.exportProperty(
  75917. ol.source.Tile.prototype,
  75918. 'changed',
  75919. ol.source.Tile.prototype.changed);
  75920. goog.exportProperty(
  75921. ol.source.Tile.prototype,
  75922. 'dispatchEvent',
  75923. ol.source.Tile.prototype.dispatchEvent);
  75924. goog.exportProperty(
  75925. ol.source.Tile.prototype,
  75926. 'getRevision',
  75927. ol.source.Tile.prototype.getRevision);
  75928. goog.exportProperty(
  75929. ol.source.Tile.prototype,
  75930. 'on',
  75931. ol.source.Tile.prototype.on);
  75932. goog.exportProperty(
  75933. ol.source.Tile.prototype,
  75934. 'once',
  75935. ol.source.Tile.prototype.once);
  75936. goog.exportProperty(
  75937. ol.source.Tile.prototype,
  75938. 'un',
  75939. ol.source.Tile.prototype.un);
  75940. goog.exportProperty(
  75941. ol.source.UrlTile.prototype,
  75942. 'getTileGrid',
  75943. ol.source.UrlTile.prototype.getTileGrid);
  75944. goog.exportProperty(
  75945. ol.source.UrlTile.prototype,
  75946. 'refresh',
  75947. ol.source.UrlTile.prototype.refresh);
  75948. goog.exportProperty(
  75949. ol.source.UrlTile.prototype,
  75950. 'getAttributions',
  75951. ol.source.UrlTile.prototype.getAttributions);
  75952. goog.exportProperty(
  75953. ol.source.UrlTile.prototype,
  75954. 'getLogo',
  75955. ol.source.UrlTile.prototype.getLogo);
  75956. goog.exportProperty(
  75957. ol.source.UrlTile.prototype,
  75958. 'getProjection',
  75959. ol.source.UrlTile.prototype.getProjection);
  75960. goog.exportProperty(
  75961. ol.source.UrlTile.prototype,
  75962. 'getState',
  75963. ol.source.UrlTile.prototype.getState);
  75964. goog.exportProperty(
  75965. ol.source.UrlTile.prototype,
  75966. 'setAttributions',
  75967. ol.source.UrlTile.prototype.setAttributions);
  75968. goog.exportProperty(
  75969. ol.source.UrlTile.prototype,
  75970. 'get',
  75971. ol.source.UrlTile.prototype.get);
  75972. goog.exportProperty(
  75973. ol.source.UrlTile.prototype,
  75974. 'getKeys',
  75975. ol.source.UrlTile.prototype.getKeys);
  75976. goog.exportProperty(
  75977. ol.source.UrlTile.prototype,
  75978. 'getProperties',
  75979. ol.source.UrlTile.prototype.getProperties);
  75980. goog.exportProperty(
  75981. ol.source.UrlTile.prototype,
  75982. 'set',
  75983. ol.source.UrlTile.prototype.set);
  75984. goog.exportProperty(
  75985. ol.source.UrlTile.prototype,
  75986. 'setProperties',
  75987. ol.source.UrlTile.prototype.setProperties);
  75988. goog.exportProperty(
  75989. ol.source.UrlTile.prototype,
  75990. 'unset',
  75991. ol.source.UrlTile.prototype.unset);
  75992. goog.exportProperty(
  75993. ol.source.UrlTile.prototype,
  75994. 'changed',
  75995. ol.source.UrlTile.prototype.changed);
  75996. goog.exportProperty(
  75997. ol.source.UrlTile.prototype,
  75998. 'dispatchEvent',
  75999. ol.source.UrlTile.prototype.dispatchEvent);
  76000. goog.exportProperty(
  76001. ol.source.UrlTile.prototype,
  76002. 'getRevision',
  76003. ol.source.UrlTile.prototype.getRevision);
  76004. goog.exportProperty(
  76005. ol.source.UrlTile.prototype,
  76006. 'on',
  76007. ol.source.UrlTile.prototype.on);
  76008. goog.exportProperty(
  76009. ol.source.UrlTile.prototype,
  76010. 'once',
  76011. ol.source.UrlTile.prototype.once);
  76012. goog.exportProperty(
  76013. ol.source.UrlTile.prototype,
  76014. 'un',
  76015. ol.source.UrlTile.prototype.un);
  76016. goog.exportProperty(
  76017. ol.source.TileImage.prototype,
  76018. 'getTileLoadFunction',
  76019. ol.source.TileImage.prototype.getTileLoadFunction);
  76020. goog.exportProperty(
  76021. ol.source.TileImage.prototype,
  76022. 'getTileUrlFunction',
  76023. ol.source.TileImage.prototype.getTileUrlFunction);
  76024. goog.exportProperty(
  76025. ol.source.TileImage.prototype,
  76026. 'getUrls',
  76027. ol.source.TileImage.prototype.getUrls);
  76028. goog.exportProperty(
  76029. ol.source.TileImage.prototype,
  76030. 'setTileLoadFunction',
  76031. ol.source.TileImage.prototype.setTileLoadFunction);
  76032. goog.exportProperty(
  76033. ol.source.TileImage.prototype,
  76034. 'setTileUrlFunction',
  76035. ol.source.TileImage.prototype.setTileUrlFunction);
  76036. goog.exportProperty(
  76037. ol.source.TileImage.prototype,
  76038. 'setUrl',
  76039. ol.source.TileImage.prototype.setUrl);
  76040. goog.exportProperty(
  76041. ol.source.TileImage.prototype,
  76042. 'setUrls',
  76043. ol.source.TileImage.prototype.setUrls);
  76044. goog.exportProperty(
  76045. ol.source.TileImage.prototype,
  76046. 'getTileGrid',
  76047. ol.source.TileImage.prototype.getTileGrid);
  76048. goog.exportProperty(
  76049. ol.source.TileImage.prototype,
  76050. 'refresh',
  76051. ol.source.TileImage.prototype.refresh);
  76052. goog.exportProperty(
  76053. ol.source.TileImage.prototype,
  76054. 'getAttributions',
  76055. ol.source.TileImage.prototype.getAttributions);
  76056. goog.exportProperty(
  76057. ol.source.TileImage.prototype,
  76058. 'getLogo',
  76059. ol.source.TileImage.prototype.getLogo);
  76060. goog.exportProperty(
  76061. ol.source.TileImage.prototype,
  76062. 'getProjection',
  76063. ol.source.TileImage.prototype.getProjection);
  76064. goog.exportProperty(
  76065. ol.source.TileImage.prototype,
  76066. 'getState',
  76067. ol.source.TileImage.prototype.getState);
  76068. goog.exportProperty(
  76069. ol.source.TileImage.prototype,
  76070. 'setAttributions',
  76071. ol.source.TileImage.prototype.setAttributions);
  76072. goog.exportProperty(
  76073. ol.source.TileImage.prototype,
  76074. 'get',
  76075. ol.source.TileImage.prototype.get);
  76076. goog.exportProperty(
  76077. ol.source.TileImage.prototype,
  76078. 'getKeys',
  76079. ol.source.TileImage.prototype.getKeys);
  76080. goog.exportProperty(
  76081. ol.source.TileImage.prototype,
  76082. 'getProperties',
  76083. ol.source.TileImage.prototype.getProperties);
  76084. goog.exportProperty(
  76085. ol.source.TileImage.prototype,
  76086. 'set',
  76087. ol.source.TileImage.prototype.set);
  76088. goog.exportProperty(
  76089. ol.source.TileImage.prototype,
  76090. 'setProperties',
  76091. ol.source.TileImage.prototype.setProperties);
  76092. goog.exportProperty(
  76093. ol.source.TileImage.prototype,
  76094. 'unset',
  76095. ol.source.TileImage.prototype.unset);
  76096. goog.exportProperty(
  76097. ol.source.TileImage.prototype,
  76098. 'changed',
  76099. ol.source.TileImage.prototype.changed);
  76100. goog.exportProperty(
  76101. ol.source.TileImage.prototype,
  76102. 'dispatchEvent',
  76103. ol.source.TileImage.prototype.dispatchEvent);
  76104. goog.exportProperty(
  76105. ol.source.TileImage.prototype,
  76106. 'getRevision',
  76107. ol.source.TileImage.prototype.getRevision);
  76108. goog.exportProperty(
  76109. ol.source.TileImage.prototype,
  76110. 'on',
  76111. ol.source.TileImage.prototype.on);
  76112. goog.exportProperty(
  76113. ol.source.TileImage.prototype,
  76114. 'once',
  76115. ol.source.TileImage.prototype.once);
  76116. goog.exportProperty(
  76117. ol.source.TileImage.prototype,
  76118. 'un',
  76119. ol.source.TileImage.prototype.un);
  76120. goog.exportProperty(
  76121. ol.source.BingMaps.prototype,
  76122. 'setRenderReprojectionEdges',
  76123. ol.source.BingMaps.prototype.setRenderReprojectionEdges);
  76124. goog.exportProperty(
  76125. ol.source.BingMaps.prototype,
  76126. 'setTileGridForProjection',
  76127. ol.source.BingMaps.prototype.setTileGridForProjection);
  76128. goog.exportProperty(
  76129. ol.source.BingMaps.prototype,
  76130. 'getTileLoadFunction',
  76131. ol.source.BingMaps.prototype.getTileLoadFunction);
  76132. goog.exportProperty(
  76133. ol.source.BingMaps.prototype,
  76134. 'getTileUrlFunction',
  76135. ol.source.BingMaps.prototype.getTileUrlFunction);
  76136. goog.exportProperty(
  76137. ol.source.BingMaps.prototype,
  76138. 'getUrls',
  76139. ol.source.BingMaps.prototype.getUrls);
  76140. goog.exportProperty(
  76141. ol.source.BingMaps.prototype,
  76142. 'setTileLoadFunction',
  76143. ol.source.BingMaps.prototype.setTileLoadFunction);
  76144. goog.exportProperty(
  76145. ol.source.BingMaps.prototype,
  76146. 'setTileUrlFunction',
  76147. ol.source.BingMaps.prototype.setTileUrlFunction);
  76148. goog.exportProperty(
  76149. ol.source.BingMaps.prototype,
  76150. 'setUrl',
  76151. ol.source.BingMaps.prototype.setUrl);
  76152. goog.exportProperty(
  76153. ol.source.BingMaps.prototype,
  76154. 'setUrls',
  76155. ol.source.BingMaps.prototype.setUrls);
  76156. goog.exportProperty(
  76157. ol.source.BingMaps.prototype,
  76158. 'getTileGrid',
  76159. ol.source.BingMaps.prototype.getTileGrid);
  76160. goog.exportProperty(
  76161. ol.source.BingMaps.prototype,
  76162. 'refresh',
  76163. ol.source.BingMaps.prototype.refresh);
  76164. goog.exportProperty(
  76165. ol.source.BingMaps.prototype,
  76166. 'getAttributions',
  76167. ol.source.BingMaps.prototype.getAttributions);
  76168. goog.exportProperty(
  76169. ol.source.BingMaps.prototype,
  76170. 'getLogo',
  76171. ol.source.BingMaps.prototype.getLogo);
  76172. goog.exportProperty(
  76173. ol.source.BingMaps.prototype,
  76174. 'getProjection',
  76175. ol.source.BingMaps.prototype.getProjection);
  76176. goog.exportProperty(
  76177. ol.source.BingMaps.prototype,
  76178. 'getState',
  76179. ol.source.BingMaps.prototype.getState);
  76180. goog.exportProperty(
  76181. ol.source.BingMaps.prototype,
  76182. 'setAttributions',
  76183. ol.source.BingMaps.prototype.setAttributions);
  76184. goog.exportProperty(
  76185. ol.source.BingMaps.prototype,
  76186. 'get',
  76187. ol.source.BingMaps.prototype.get);
  76188. goog.exportProperty(
  76189. ol.source.BingMaps.prototype,
  76190. 'getKeys',
  76191. ol.source.BingMaps.prototype.getKeys);
  76192. goog.exportProperty(
  76193. ol.source.BingMaps.prototype,
  76194. 'getProperties',
  76195. ol.source.BingMaps.prototype.getProperties);
  76196. goog.exportProperty(
  76197. ol.source.BingMaps.prototype,
  76198. 'set',
  76199. ol.source.BingMaps.prototype.set);
  76200. goog.exportProperty(
  76201. ol.source.BingMaps.prototype,
  76202. 'setProperties',
  76203. ol.source.BingMaps.prototype.setProperties);
  76204. goog.exportProperty(
  76205. ol.source.BingMaps.prototype,
  76206. 'unset',
  76207. ol.source.BingMaps.prototype.unset);
  76208. goog.exportProperty(
  76209. ol.source.BingMaps.prototype,
  76210. 'changed',
  76211. ol.source.BingMaps.prototype.changed);
  76212. goog.exportProperty(
  76213. ol.source.BingMaps.prototype,
  76214. 'dispatchEvent',
  76215. ol.source.BingMaps.prototype.dispatchEvent);
  76216. goog.exportProperty(
  76217. ol.source.BingMaps.prototype,
  76218. 'getRevision',
  76219. ol.source.BingMaps.prototype.getRevision);
  76220. goog.exportProperty(
  76221. ol.source.BingMaps.prototype,
  76222. 'on',
  76223. ol.source.BingMaps.prototype.on);
  76224. goog.exportProperty(
  76225. ol.source.BingMaps.prototype,
  76226. 'once',
  76227. ol.source.BingMaps.prototype.once);
  76228. goog.exportProperty(
  76229. ol.source.BingMaps.prototype,
  76230. 'un',
  76231. ol.source.BingMaps.prototype.un);
  76232. goog.exportProperty(
  76233. ol.source.XYZ.prototype,
  76234. 'setRenderReprojectionEdges',
  76235. ol.source.XYZ.prototype.setRenderReprojectionEdges);
  76236. goog.exportProperty(
  76237. ol.source.XYZ.prototype,
  76238. 'setTileGridForProjection',
  76239. ol.source.XYZ.prototype.setTileGridForProjection);
  76240. goog.exportProperty(
  76241. ol.source.XYZ.prototype,
  76242. 'getTileLoadFunction',
  76243. ol.source.XYZ.prototype.getTileLoadFunction);
  76244. goog.exportProperty(
  76245. ol.source.XYZ.prototype,
  76246. 'getTileUrlFunction',
  76247. ol.source.XYZ.prototype.getTileUrlFunction);
  76248. goog.exportProperty(
  76249. ol.source.XYZ.prototype,
  76250. 'getUrls',
  76251. ol.source.XYZ.prototype.getUrls);
  76252. goog.exportProperty(
  76253. ol.source.XYZ.prototype,
  76254. 'setTileLoadFunction',
  76255. ol.source.XYZ.prototype.setTileLoadFunction);
  76256. goog.exportProperty(
  76257. ol.source.XYZ.prototype,
  76258. 'setTileUrlFunction',
  76259. ol.source.XYZ.prototype.setTileUrlFunction);
  76260. goog.exportProperty(
  76261. ol.source.XYZ.prototype,
  76262. 'setUrl',
  76263. ol.source.XYZ.prototype.setUrl);
  76264. goog.exportProperty(
  76265. ol.source.XYZ.prototype,
  76266. 'setUrls',
  76267. ol.source.XYZ.prototype.setUrls);
  76268. goog.exportProperty(
  76269. ol.source.XYZ.prototype,
  76270. 'getTileGrid',
  76271. ol.source.XYZ.prototype.getTileGrid);
  76272. goog.exportProperty(
  76273. ol.source.XYZ.prototype,
  76274. 'refresh',
  76275. ol.source.XYZ.prototype.refresh);
  76276. goog.exportProperty(
  76277. ol.source.XYZ.prototype,
  76278. 'getAttributions',
  76279. ol.source.XYZ.prototype.getAttributions);
  76280. goog.exportProperty(
  76281. ol.source.XYZ.prototype,
  76282. 'getLogo',
  76283. ol.source.XYZ.prototype.getLogo);
  76284. goog.exportProperty(
  76285. ol.source.XYZ.prototype,
  76286. 'getProjection',
  76287. ol.source.XYZ.prototype.getProjection);
  76288. goog.exportProperty(
  76289. ol.source.XYZ.prototype,
  76290. 'getState',
  76291. ol.source.XYZ.prototype.getState);
  76292. goog.exportProperty(
  76293. ol.source.XYZ.prototype,
  76294. 'setAttributions',
  76295. ol.source.XYZ.prototype.setAttributions);
  76296. goog.exportProperty(
  76297. ol.source.XYZ.prototype,
  76298. 'get',
  76299. ol.source.XYZ.prototype.get);
  76300. goog.exportProperty(
  76301. ol.source.XYZ.prototype,
  76302. 'getKeys',
  76303. ol.source.XYZ.prototype.getKeys);
  76304. goog.exportProperty(
  76305. ol.source.XYZ.prototype,
  76306. 'getProperties',
  76307. ol.source.XYZ.prototype.getProperties);
  76308. goog.exportProperty(
  76309. ol.source.XYZ.prototype,
  76310. 'set',
  76311. ol.source.XYZ.prototype.set);
  76312. goog.exportProperty(
  76313. ol.source.XYZ.prototype,
  76314. 'setProperties',
  76315. ol.source.XYZ.prototype.setProperties);
  76316. goog.exportProperty(
  76317. ol.source.XYZ.prototype,
  76318. 'unset',
  76319. ol.source.XYZ.prototype.unset);
  76320. goog.exportProperty(
  76321. ol.source.XYZ.prototype,
  76322. 'changed',
  76323. ol.source.XYZ.prototype.changed);
  76324. goog.exportProperty(
  76325. ol.source.XYZ.prototype,
  76326. 'dispatchEvent',
  76327. ol.source.XYZ.prototype.dispatchEvent);
  76328. goog.exportProperty(
  76329. ol.source.XYZ.prototype,
  76330. 'getRevision',
  76331. ol.source.XYZ.prototype.getRevision);
  76332. goog.exportProperty(
  76333. ol.source.XYZ.prototype,
  76334. 'on',
  76335. ol.source.XYZ.prototype.on);
  76336. goog.exportProperty(
  76337. ol.source.XYZ.prototype,
  76338. 'once',
  76339. ol.source.XYZ.prototype.once);
  76340. goog.exportProperty(
  76341. ol.source.XYZ.prototype,
  76342. 'un',
  76343. ol.source.XYZ.prototype.un);
  76344. goog.exportProperty(
  76345. ol.source.CartoDB.prototype,
  76346. 'setRenderReprojectionEdges',
  76347. ol.source.CartoDB.prototype.setRenderReprojectionEdges);
  76348. goog.exportProperty(
  76349. ol.source.CartoDB.prototype,
  76350. 'setTileGridForProjection',
  76351. ol.source.CartoDB.prototype.setTileGridForProjection);
  76352. goog.exportProperty(
  76353. ol.source.CartoDB.prototype,
  76354. 'getTileLoadFunction',
  76355. ol.source.CartoDB.prototype.getTileLoadFunction);
  76356. goog.exportProperty(
  76357. ol.source.CartoDB.prototype,
  76358. 'getTileUrlFunction',
  76359. ol.source.CartoDB.prototype.getTileUrlFunction);
  76360. goog.exportProperty(
  76361. ol.source.CartoDB.prototype,
  76362. 'getUrls',
  76363. ol.source.CartoDB.prototype.getUrls);
  76364. goog.exportProperty(
  76365. ol.source.CartoDB.prototype,
  76366. 'setTileLoadFunction',
  76367. ol.source.CartoDB.prototype.setTileLoadFunction);
  76368. goog.exportProperty(
  76369. ol.source.CartoDB.prototype,
  76370. 'setTileUrlFunction',
  76371. ol.source.CartoDB.prototype.setTileUrlFunction);
  76372. goog.exportProperty(
  76373. ol.source.CartoDB.prototype,
  76374. 'setUrl',
  76375. ol.source.CartoDB.prototype.setUrl);
  76376. goog.exportProperty(
  76377. ol.source.CartoDB.prototype,
  76378. 'setUrls',
  76379. ol.source.CartoDB.prototype.setUrls);
  76380. goog.exportProperty(
  76381. ol.source.CartoDB.prototype,
  76382. 'getTileGrid',
  76383. ol.source.CartoDB.prototype.getTileGrid);
  76384. goog.exportProperty(
  76385. ol.source.CartoDB.prototype,
  76386. 'refresh',
  76387. ol.source.CartoDB.prototype.refresh);
  76388. goog.exportProperty(
  76389. ol.source.CartoDB.prototype,
  76390. 'getAttributions',
  76391. ol.source.CartoDB.prototype.getAttributions);
  76392. goog.exportProperty(
  76393. ol.source.CartoDB.prototype,
  76394. 'getLogo',
  76395. ol.source.CartoDB.prototype.getLogo);
  76396. goog.exportProperty(
  76397. ol.source.CartoDB.prototype,
  76398. 'getProjection',
  76399. ol.source.CartoDB.prototype.getProjection);
  76400. goog.exportProperty(
  76401. ol.source.CartoDB.prototype,
  76402. 'getState',
  76403. ol.source.CartoDB.prototype.getState);
  76404. goog.exportProperty(
  76405. ol.source.CartoDB.prototype,
  76406. 'setAttributions',
  76407. ol.source.CartoDB.prototype.setAttributions);
  76408. goog.exportProperty(
  76409. ol.source.CartoDB.prototype,
  76410. 'get',
  76411. ol.source.CartoDB.prototype.get);
  76412. goog.exportProperty(
  76413. ol.source.CartoDB.prototype,
  76414. 'getKeys',
  76415. ol.source.CartoDB.prototype.getKeys);
  76416. goog.exportProperty(
  76417. ol.source.CartoDB.prototype,
  76418. 'getProperties',
  76419. ol.source.CartoDB.prototype.getProperties);
  76420. goog.exportProperty(
  76421. ol.source.CartoDB.prototype,
  76422. 'set',
  76423. ol.source.CartoDB.prototype.set);
  76424. goog.exportProperty(
  76425. ol.source.CartoDB.prototype,
  76426. 'setProperties',
  76427. ol.source.CartoDB.prototype.setProperties);
  76428. goog.exportProperty(
  76429. ol.source.CartoDB.prototype,
  76430. 'unset',
  76431. ol.source.CartoDB.prototype.unset);
  76432. goog.exportProperty(
  76433. ol.source.CartoDB.prototype,
  76434. 'changed',
  76435. ol.source.CartoDB.prototype.changed);
  76436. goog.exportProperty(
  76437. ol.source.CartoDB.prototype,
  76438. 'dispatchEvent',
  76439. ol.source.CartoDB.prototype.dispatchEvent);
  76440. goog.exportProperty(
  76441. ol.source.CartoDB.prototype,
  76442. 'getRevision',
  76443. ol.source.CartoDB.prototype.getRevision);
  76444. goog.exportProperty(
  76445. ol.source.CartoDB.prototype,
  76446. 'on',
  76447. ol.source.CartoDB.prototype.on);
  76448. goog.exportProperty(
  76449. ol.source.CartoDB.prototype,
  76450. 'once',
  76451. ol.source.CartoDB.prototype.once);
  76452. goog.exportProperty(
  76453. ol.source.CartoDB.prototype,
  76454. 'un',
  76455. ol.source.CartoDB.prototype.un);
  76456. goog.exportProperty(
  76457. ol.source.Vector.prototype,
  76458. 'getAttributions',
  76459. ol.source.Vector.prototype.getAttributions);
  76460. goog.exportProperty(
  76461. ol.source.Vector.prototype,
  76462. 'getLogo',
  76463. ol.source.Vector.prototype.getLogo);
  76464. goog.exportProperty(
  76465. ol.source.Vector.prototype,
  76466. 'getProjection',
  76467. ol.source.Vector.prototype.getProjection);
  76468. goog.exportProperty(
  76469. ol.source.Vector.prototype,
  76470. 'getState',
  76471. ol.source.Vector.prototype.getState);
  76472. goog.exportProperty(
  76473. ol.source.Vector.prototype,
  76474. 'refresh',
  76475. ol.source.Vector.prototype.refresh);
  76476. goog.exportProperty(
  76477. ol.source.Vector.prototype,
  76478. 'setAttributions',
  76479. ol.source.Vector.prototype.setAttributions);
  76480. goog.exportProperty(
  76481. ol.source.Vector.prototype,
  76482. 'get',
  76483. ol.source.Vector.prototype.get);
  76484. goog.exportProperty(
  76485. ol.source.Vector.prototype,
  76486. 'getKeys',
  76487. ol.source.Vector.prototype.getKeys);
  76488. goog.exportProperty(
  76489. ol.source.Vector.prototype,
  76490. 'getProperties',
  76491. ol.source.Vector.prototype.getProperties);
  76492. goog.exportProperty(
  76493. ol.source.Vector.prototype,
  76494. 'set',
  76495. ol.source.Vector.prototype.set);
  76496. goog.exportProperty(
  76497. ol.source.Vector.prototype,
  76498. 'setProperties',
  76499. ol.source.Vector.prototype.setProperties);
  76500. goog.exportProperty(
  76501. ol.source.Vector.prototype,
  76502. 'unset',
  76503. ol.source.Vector.prototype.unset);
  76504. goog.exportProperty(
  76505. ol.source.Vector.prototype,
  76506. 'changed',
  76507. ol.source.Vector.prototype.changed);
  76508. goog.exportProperty(
  76509. ol.source.Vector.prototype,
  76510. 'dispatchEvent',
  76511. ol.source.Vector.prototype.dispatchEvent);
  76512. goog.exportProperty(
  76513. ol.source.Vector.prototype,
  76514. 'getRevision',
  76515. ol.source.Vector.prototype.getRevision);
  76516. goog.exportProperty(
  76517. ol.source.Vector.prototype,
  76518. 'on',
  76519. ol.source.Vector.prototype.on);
  76520. goog.exportProperty(
  76521. ol.source.Vector.prototype,
  76522. 'once',
  76523. ol.source.Vector.prototype.once);
  76524. goog.exportProperty(
  76525. ol.source.Vector.prototype,
  76526. 'un',
  76527. ol.source.Vector.prototype.un);
  76528. goog.exportProperty(
  76529. ol.source.Cluster.prototype,
  76530. 'addFeature',
  76531. ol.source.Cluster.prototype.addFeature);
  76532. goog.exportProperty(
  76533. ol.source.Cluster.prototype,
  76534. 'addFeatures',
  76535. ol.source.Cluster.prototype.addFeatures);
  76536. goog.exportProperty(
  76537. ol.source.Cluster.prototype,
  76538. 'clear',
  76539. ol.source.Cluster.prototype.clear);
  76540. goog.exportProperty(
  76541. ol.source.Cluster.prototype,
  76542. 'forEachFeature',
  76543. ol.source.Cluster.prototype.forEachFeature);
  76544. goog.exportProperty(
  76545. ol.source.Cluster.prototype,
  76546. 'forEachFeatureInExtent',
  76547. ol.source.Cluster.prototype.forEachFeatureInExtent);
  76548. goog.exportProperty(
  76549. ol.source.Cluster.prototype,
  76550. 'forEachFeatureIntersectingExtent',
  76551. ol.source.Cluster.prototype.forEachFeatureIntersectingExtent);
  76552. goog.exportProperty(
  76553. ol.source.Cluster.prototype,
  76554. 'getFeaturesCollection',
  76555. ol.source.Cluster.prototype.getFeaturesCollection);
  76556. goog.exportProperty(
  76557. ol.source.Cluster.prototype,
  76558. 'getFeatures',
  76559. ol.source.Cluster.prototype.getFeatures);
  76560. goog.exportProperty(
  76561. ol.source.Cluster.prototype,
  76562. 'getFeaturesAtCoordinate',
  76563. ol.source.Cluster.prototype.getFeaturesAtCoordinate);
  76564. goog.exportProperty(
  76565. ol.source.Cluster.prototype,
  76566. 'getFeaturesInExtent',
  76567. ol.source.Cluster.prototype.getFeaturesInExtent);
  76568. goog.exportProperty(
  76569. ol.source.Cluster.prototype,
  76570. 'getClosestFeatureToCoordinate',
  76571. ol.source.Cluster.prototype.getClosestFeatureToCoordinate);
  76572. goog.exportProperty(
  76573. ol.source.Cluster.prototype,
  76574. 'getExtent',
  76575. ol.source.Cluster.prototype.getExtent);
  76576. goog.exportProperty(
  76577. ol.source.Cluster.prototype,
  76578. 'getFeatureById',
  76579. ol.source.Cluster.prototype.getFeatureById);
  76580. goog.exportProperty(
  76581. ol.source.Cluster.prototype,
  76582. 'getFormat',
  76583. ol.source.Cluster.prototype.getFormat);
  76584. goog.exportProperty(
  76585. ol.source.Cluster.prototype,
  76586. 'getUrl',
  76587. ol.source.Cluster.prototype.getUrl);
  76588. goog.exportProperty(
  76589. ol.source.Cluster.prototype,
  76590. 'removeLoadedExtent',
  76591. ol.source.Cluster.prototype.removeLoadedExtent);
  76592. goog.exportProperty(
  76593. ol.source.Cluster.prototype,
  76594. 'removeFeature',
  76595. ol.source.Cluster.prototype.removeFeature);
  76596. goog.exportProperty(
  76597. ol.source.Cluster.prototype,
  76598. 'setLoader',
  76599. ol.source.Cluster.prototype.setLoader);
  76600. goog.exportProperty(
  76601. ol.source.Cluster.prototype,
  76602. 'getAttributions',
  76603. ol.source.Cluster.prototype.getAttributions);
  76604. goog.exportProperty(
  76605. ol.source.Cluster.prototype,
  76606. 'getLogo',
  76607. ol.source.Cluster.prototype.getLogo);
  76608. goog.exportProperty(
  76609. ol.source.Cluster.prototype,
  76610. 'getProjection',
  76611. ol.source.Cluster.prototype.getProjection);
  76612. goog.exportProperty(
  76613. ol.source.Cluster.prototype,
  76614. 'getState',
  76615. ol.source.Cluster.prototype.getState);
  76616. goog.exportProperty(
  76617. ol.source.Cluster.prototype,
  76618. 'refresh',
  76619. ol.source.Cluster.prototype.refresh);
  76620. goog.exportProperty(
  76621. ol.source.Cluster.prototype,
  76622. 'setAttributions',
  76623. ol.source.Cluster.prototype.setAttributions);
  76624. goog.exportProperty(
  76625. ol.source.Cluster.prototype,
  76626. 'get',
  76627. ol.source.Cluster.prototype.get);
  76628. goog.exportProperty(
  76629. ol.source.Cluster.prototype,
  76630. 'getKeys',
  76631. ol.source.Cluster.prototype.getKeys);
  76632. goog.exportProperty(
  76633. ol.source.Cluster.prototype,
  76634. 'getProperties',
  76635. ol.source.Cluster.prototype.getProperties);
  76636. goog.exportProperty(
  76637. ol.source.Cluster.prototype,
  76638. 'set',
  76639. ol.source.Cluster.prototype.set);
  76640. goog.exportProperty(
  76641. ol.source.Cluster.prototype,
  76642. 'setProperties',
  76643. ol.source.Cluster.prototype.setProperties);
  76644. goog.exportProperty(
  76645. ol.source.Cluster.prototype,
  76646. 'unset',
  76647. ol.source.Cluster.prototype.unset);
  76648. goog.exportProperty(
  76649. ol.source.Cluster.prototype,
  76650. 'changed',
  76651. ol.source.Cluster.prototype.changed);
  76652. goog.exportProperty(
  76653. ol.source.Cluster.prototype,
  76654. 'dispatchEvent',
  76655. ol.source.Cluster.prototype.dispatchEvent);
  76656. goog.exportProperty(
  76657. ol.source.Cluster.prototype,
  76658. 'getRevision',
  76659. ol.source.Cluster.prototype.getRevision);
  76660. goog.exportProperty(
  76661. ol.source.Cluster.prototype,
  76662. 'on',
  76663. ol.source.Cluster.prototype.on);
  76664. goog.exportProperty(
  76665. ol.source.Cluster.prototype,
  76666. 'once',
  76667. ol.source.Cluster.prototype.once);
  76668. goog.exportProperty(
  76669. ol.source.Cluster.prototype,
  76670. 'un',
  76671. ol.source.Cluster.prototype.un);
  76672. goog.exportProperty(
  76673. ol.source.Image.prototype,
  76674. 'getAttributions',
  76675. ol.source.Image.prototype.getAttributions);
  76676. goog.exportProperty(
  76677. ol.source.Image.prototype,
  76678. 'getLogo',
  76679. ol.source.Image.prototype.getLogo);
  76680. goog.exportProperty(
  76681. ol.source.Image.prototype,
  76682. 'getProjection',
  76683. ol.source.Image.prototype.getProjection);
  76684. goog.exportProperty(
  76685. ol.source.Image.prototype,
  76686. 'getState',
  76687. ol.source.Image.prototype.getState);
  76688. goog.exportProperty(
  76689. ol.source.Image.prototype,
  76690. 'refresh',
  76691. ol.source.Image.prototype.refresh);
  76692. goog.exportProperty(
  76693. ol.source.Image.prototype,
  76694. 'setAttributions',
  76695. ol.source.Image.prototype.setAttributions);
  76696. goog.exportProperty(
  76697. ol.source.Image.prototype,
  76698. 'get',
  76699. ol.source.Image.prototype.get);
  76700. goog.exportProperty(
  76701. ol.source.Image.prototype,
  76702. 'getKeys',
  76703. ol.source.Image.prototype.getKeys);
  76704. goog.exportProperty(
  76705. ol.source.Image.prototype,
  76706. 'getProperties',
  76707. ol.source.Image.prototype.getProperties);
  76708. goog.exportProperty(
  76709. ol.source.Image.prototype,
  76710. 'set',
  76711. ol.source.Image.prototype.set);
  76712. goog.exportProperty(
  76713. ol.source.Image.prototype,
  76714. 'setProperties',
  76715. ol.source.Image.prototype.setProperties);
  76716. goog.exportProperty(
  76717. ol.source.Image.prototype,
  76718. 'unset',
  76719. ol.source.Image.prototype.unset);
  76720. goog.exportProperty(
  76721. ol.source.Image.prototype,
  76722. 'changed',
  76723. ol.source.Image.prototype.changed);
  76724. goog.exportProperty(
  76725. ol.source.Image.prototype,
  76726. 'dispatchEvent',
  76727. ol.source.Image.prototype.dispatchEvent);
  76728. goog.exportProperty(
  76729. ol.source.Image.prototype,
  76730. 'getRevision',
  76731. ol.source.Image.prototype.getRevision);
  76732. goog.exportProperty(
  76733. ol.source.Image.prototype,
  76734. 'on',
  76735. ol.source.Image.prototype.on);
  76736. goog.exportProperty(
  76737. ol.source.Image.prototype,
  76738. 'once',
  76739. ol.source.Image.prototype.once);
  76740. goog.exportProperty(
  76741. ol.source.Image.prototype,
  76742. 'un',
  76743. ol.source.Image.prototype.un);
  76744. goog.exportProperty(
  76745. ol.source.Image.Event.prototype,
  76746. 'type',
  76747. ol.source.Image.Event.prototype.type);
  76748. goog.exportProperty(
  76749. ol.source.Image.Event.prototype,
  76750. 'target',
  76751. ol.source.Image.Event.prototype.target);
  76752. goog.exportProperty(
  76753. ol.source.Image.Event.prototype,
  76754. 'preventDefault',
  76755. ol.source.Image.Event.prototype.preventDefault);
  76756. goog.exportProperty(
  76757. ol.source.Image.Event.prototype,
  76758. 'stopPropagation',
  76759. ol.source.Image.Event.prototype.stopPropagation);
  76760. goog.exportProperty(
  76761. ol.source.ImageArcGISRest.prototype,
  76762. 'getAttributions',
  76763. ol.source.ImageArcGISRest.prototype.getAttributions);
  76764. goog.exportProperty(
  76765. ol.source.ImageArcGISRest.prototype,
  76766. 'getLogo',
  76767. ol.source.ImageArcGISRest.prototype.getLogo);
  76768. goog.exportProperty(
  76769. ol.source.ImageArcGISRest.prototype,
  76770. 'getProjection',
  76771. ol.source.ImageArcGISRest.prototype.getProjection);
  76772. goog.exportProperty(
  76773. ol.source.ImageArcGISRest.prototype,
  76774. 'getState',
  76775. ol.source.ImageArcGISRest.prototype.getState);
  76776. goog.exportProperty(
  76777. ol.source.ImageArcGISRest.prototype,
  76778. 'refresh',
  76779. ol.source.ImageArcGISRest.prototype.refresh);
  76780. goog.exportProperty(
  76781. ol.source.ImageArcGISRest.prototype,
  76782. 'setAttributions',
  76783. ol.source.ImageArcGISRest.prototype.setAttributions);
  76784. goog.exportProperty(
  76785. ol.source.ImageArcGISRest.prototype,
  76786. 'get',
  76787. ol.source.ImageArcGISRest.prototype.get);
  76788. goog.exportProperty(
  76789. ol.source.ImageArcGISRest.prototype,
  76790. 'getKeys',
  76791. ol.source.ImageArcGISRest.prototype.getKeys);
  76792. goog.exportProperty(
  76793. ol.source.ImageArcGISRest.prototype,
  76794. 'getProperties',
  76795. ol.source.ImageArcGISRest.prototype.getProperties);
  76796. goog.exportProperty(
  76797. ol.source.ImageArcGISRest.prototype,
  76798. 'set',
  76799. ol.source.ImageArcGISRest.prototype.set);
  76800. goog.exportProperty(
  76801. ol.source.ImageArcGISRest.prototype,
  76802. 'setProperties',
  76803. ol.source.ImageArcGISRest.prototype.setProperties);
  76804. goog.exportProperty(
  76805. ol.source.ImageArcGISRest.prototype,
  76806. 'unset',
  76807. ol.source.ImageArcGISRest.prototype.unset);
  76808. goog.exportProperty(
  76809. ol.source.ImageArcGISRest.prototype,
  76810. 'changed',
  76811. ol.source.ImageArcGISRest.prototype.changed);
  76812. goog.exportProperty(
  76813. ol.source.ImageArcGISRest.prototype,
  76814. 'dispatchEvent',
  76815. ol.source.ImageArcGISRest.prototype.dispatchEvent);
  76816. goog.exportProperty(
  76817. ol.source.ImageArcGISRest.prototype,
  76818. 'getRevision',
  76819. ol.source.ImageArcGISRest.prototype.getRevision);
  76820. goog.exportProperty(
  76821. ol.source.ImageArcGISRest.prototype,
  76822. 'on',
  76823. ol.source.ImageArcGISRest.prototype.on);
  76824. goog.exportProperty(
  76825. ol.source.ImageArcGISRest.prototype,
  76826. 'once',
  76827. ol.source.ImageArcGISRest.prototype.once);
  76828. goog.exportProperty(
  76829. ol.source.ImageArcGISRest.prototype,
  76830. 'un',
  76831. ol.source.ImageArcGISRest.prototype.un);
  76832. goog.exportProperty(
  76833. ol.source.ImageCanvas.prototype,
  76834. 'getAttributions',
  76835. ol.source.ImageCanvas.prototype.getAttributions);
  76836. goog.exportProperty(
  76837. ol.source.ImageCanvas.prototype,
  76838. 'getLogo',
  76839. ol.source.ImageCanvas.prototype.getLogo);
  76840. goog.exportProperty(
  76841. ol.source.ImageCanvas.prototype,
  76842. 'getProjection',
  76843. ol.source.ImageCanvas.prototype.getProjection);
  76844. goog.exportProperty(
  76845. ol.source.ImageCanvas.prototype,
  76846. 'getState',
  76847. ol.source.ImageCanvas.prototype.getState);
  76848. goog.exportProperty(
  76849. ol.source.ImageCanvas.prototype,
  76850. 'refresh',
  76851. ol.source.ImageCanvas.prototype.refresh);
  76852. goog.exportProperty(
  76853. ol.source.ImageCanvas.prototype,
  76854. 'setAttributions',
  76855. ol.source.ImageCanvas.prototype.setAttributions);
  76856. goog.exportProperty(
  76857. ol.source.ImageCanvas.prototype,
  76858. 'get',
  76859. ol.source.ImageCanvas.prototype.get);
  76860. goog.exportProperty(
  76861. ol.source.ImageCanvas.prototype,
  76862. 'getKeys',
  76863. ol.source.ImageCanvas.prototype.getKeys);
  76864. goog.exportProperty(
  76865. ol.source.ImageCanvas.prototype,
  76866. 'getProperties',
  76867. ol.source.ImageCanvas.prototype.getProperties);
  76868. goog.exportProperty(
  76869. ol.source.ImageCanvas.prototype,
  76870. 'set',
  76871. ol.source.ImageCanvas.prototype.set);
  76872. goog.exportProperty(
  76873. ol.source.ImageCanvas.prototype,
  76874. 'setProperties',
  76875. ol.source.ImageCanvas.prototype.setProperties);
  76876. goog.exportProperty(
  76877. ol.source.ImageCanvas.prototype,
  76878. 'unset',
  76879. ol.source.ImageCanvas.prototype.unset);
  76880. goog.exportProperty(
  76881. ol.source.ImageCanvas.prototype,
  76882. 'changed',
  76883. ol.source.ImageCanvas.prototype.changed);
  76884. goog.exportProperty(
  76885. ol.source.ImageCanvas.prototype,
  76886. 'dispatchEvent',
  76887. ol.source.ImageCanvas.prototype.dispatchEvent);
  76888. goog.exportProperty(
  76889. ol.source.ImageCanvas.prototype,
  76890. 'getRevision',
  76891. ol.source.ImageCanvas.prototype.getRevision);
  76892. goog.exportProperty(
  76893. ol.source.ImageCanvas.prototype,
  76894. 'on',
  76895. ol.source.ImageCanvas.prototype.on);
  76896. goog.exportProperty(
  76897. ol.source.ImageCanvas.prototype,
  76898. 'once',
  76899. ol.source.ImageCanvas.prototype.once);
  76900. goog.exportProperty(
  76901. ol.source.ImageCanvas.prototype,
  76902. 'un',
  76903. ol.source.ImageCanvas.prototype.un);
  76904. goog.exportProperty(
  76905. ol.source.ImageMapGuide.prototype,
  76906. 'getAttributions',
  76907. ol.source.ImageMapGuide.prototype.getAttributions);
  76908. goog.exportProperty(
  76909. ol.source.ImageMapGuide.prototype,
  76910. 'getLogo',
  76911. ol.source.ImageMapGuide.prototype.getLogo);
  76912. goog.exportProperty(
  76913. ol.source.ImageMapGuide.prototype,
  76914. 'getProjection',
  76915. ol.source.ImageMapGuide.prototype.getProjection);
  76916. goog.exportProperty(
  76917. ol.source.ImageMapGuide.prototype,
  76918. 'getState',
  76919. ol.source.ImageMapGuide.prototype.getState);
  76920. goog.exportProperty(
  76921. ol.source.ImageMapGuide.prototype,
  76922. 'refresh',
  76923. ol.source.ImageMapGuide.prototype.refresh);
  76924. goog.exportProperty(
  76925. ol.source.ImageMapGuide.prototype,
  76926. 'setAttributions',
  76927. ol.source.ImageMapGuide.prototype.setAttributions);
  76928. goog.exportProperty(
  76929. ol.source.ImageMapGuide.prototype,
  76930. 'get',
  76931. ol.source.ImageMapGuide.prototype.get);
  76932. goog.exportProperty(
  76933. ol.source.ImageMapGuide.prototype,
  76934. 'getKeys',
  76935. ol.source.ImageMapGuide.prototype.getKeys);
  76936. goog.exportProperty(
  76937. ol.source.ImageMapGuide.prototype,
  76938. 'getProperties',
  76939. ol.source.ImageMapGuide.prototype.getProperties);
  76940. goog.exportProperty(
  76941. ol.source.ImageMapGuide.prototype,
  76942. 'set',
  76943. ol.source.ImageMapGuide.prototype.set);
  76944. goog.exportProperty(
  76945. ol.source.ImageMapGuide.prototype,
  76946. 'setProperties',
  76947. ol.source.ImageMapGuide.prototype.setProperties);
  76948. goog.exportProperty(
  76949. ol.source.ImageMapGuide.prototype,
  76950. 'unset',
  76951. ol.source.ImageMapGuide.prototype.unset);
  76952. goog.exportProperty(
  76953. ol.source.ImageMapGuide.prototype,
  76954. 'changed',
  76955. ol.source.ImageMapGuide.prototype.changed);
  76956. goog.exportProperty(
  76957. ol.source.ImageMapGuide.prototype,
  76958. 'dispatchEvent',
  76959. ol.source.ImageMapGuide.prototype.dispatchEvent);
  76960. goog.exportProperty(
  76961. ol.source.ImageMapGuide.prototype,
  76962. 'getRevision',
  76963. ol.source.ImageMapGuide.prototype.getRevision);
  76964. goog.exportProperty(
  76965. ol.source.ImageMapGuide.prototype,
  76966. 'on',
  76967. ol.source.ImageMapGuide.prototype.on);
  76968. goog.exportProperty(
  76969. ol.source.ImageMapGuide.prototype,
  76970. 'once',
  76971. ol.source.ImageMapGuide.prototype.once);
  76972. goog.exportProperty(
  76973. ol.source.ImageMapGuide.prototype,
  76974. 'un',
  76975. ol.source.ImageMapGuide.prototype.un);
  76976. goog.exportProperty(
  76977. ol.source.ImageStatic.prototype,
  76978. 'getAttributions',
  76979. ol.source.ImageStatic.prototype.getAttributions);
  76980. goog.exportProperty(
  76981. ol.source.ImageStatic.prototype,
  76982. 'getLogo',
  76983. ol.source.ImageStatic.prototype.getLogo);
  76984. goog.exportProperty(
  76985. ol.source.ImageStatic.prototype,
  76986. 'getProjection',
  76987. ol.source.ImageStatic.prototype.getProjection);
  76988. goog.exportProperty(
  76989. ol.source.ImageStatic.prototype,
  76990. 'getState',
  76991. ol.source.ImageStatic.prototype.getState);
  76992. goog.exportProperty(
  76993. ol.source.ImageStatic.prototype,
  76994. 'refresh',
  76995. ol.source.ImageStatic.prototype.refresh);
  76996. goog.exportProperty(
  76997. ol.source.ImageStatic.prototype,
  76998. 'setAttributions',
  76999. ol.source.ImageStatic.prototype.setAttributions);
  77000. goog.exportProperty(
  77001. ol.source.ImageStatic.prototype,
  77002. 'get',
  77003. ol.source.ImageStatic.prototype.get);
  77004. goog.exportProperty(
  77005. ol.source.ImageStatic.prototype,
  77006. 'getKeys',
  77007. ol.source.ImageStatic.prototype.getKeys);
  77008. goog.exportProperty(
  77009. ol.source.ImageStatic.prototype,
  77010. 'getProperties',
  77011. ol.source.ImageStatic.prototype.getProperties);
  77012. goog.exportProperty(
  77013. ol.source.ImageStatic.prototype,
  77014. 'set',
  77015. ol.source.ImageStatic.prototype.set);
  77016. goog.exportProperty(
  77017. ol.source.ImageStatic.prototype,
  77018. 'setProperties',
  77019. ol.source.ImageStatic.prototype.setProperties);
  77020. goog.exportProperty(
  77021. ol.source.ImageStatic.prototype,
  77022. 'unset',
  77023. ol.source.ImageStatic.prototype.unset);
  77024. goog.exportProperty(
  77025. ol.source.ImageStatic.prototype,
  77026. 'changed',
  77027. ol.source.ImageStatic.prototype.changed);
  77028. goog.exportProperty(
  77029. ol.source.ImageStatic.prototype,
  77030. 'dispatchEvent',
  77031. ol.source.ImageStatic.prototype.dispatchEvent);
  77032. goog.exportProperty(
  77033. ol.source.ImageStatic.prototype,
  77034. 'getRevision',
  77035. ol.source.ImageStatic.prototype.getRevision);
  77036. goog.exportProperty(
  77037. ol.source.ImageStatic.prototype,
  77038. 'on',
  77039. ol.source.ImageStatic.prototype.on);
  77040. goog.exportProperty(
  77041. ol.source.ImageStatic.prototype,
  77042. 'once',
  77043. ol.source.ImageStatic.prototype.once);
  77044. goog.exportProperty(
  77045. ol.source.ImageStatic.prototype,
  77046. 'un',
  77047. ol.source.ImageStatic.prototype.un);
  77048. goog.exportProperty(
  77049. ol.source.ImageVector.prototype,
  77050. 'getAttributions',
  77051. ol.source.ImageVector.prototype.getAttributions);
  77052. goog.exportProperty(
  77053. ol.source.ImageVector.prototype,
  77054. 'getLogo',
  77055. ol.source.ImageVector.prototype.getLogo);
  77056. goog.exportProperty(
  77057. ol.source.ImageVector.prototype,
  77058. 'getProjection',
  77059. ol.source.ImageVector.prototype.getProjection);
  77060. goog.exportProperty(
  77061. ol.source.ImageVector.prototype,
  77062. 'getState',
  77063. ol.source.ImageVector.prototype.getState);
  77064. goog.exportProperty(
  77065. ol.source.ImageVector.prototype,
  77066. 'refresh',
  77067. ol.source.ImageVector.prototype.refresh);
  77068. goog.exportProperty(
  77069. ol.source.ImageVector.prototype,
  77070. 'setAttributions',
  77071. ol.source.ImageVector.prototype.setAttributions);
  77072. goog.exportProperty(
  77073. ol.source.ImageVector.prototype,
  77074. 'get',
  77075. ol.source.ImageVector.prototype.get);
  77076. goog.exportProperty(
  77077. ol.source.ImageVector.prototype,
  77078. 'getKeys',
  77079. ol.source.ImageVector.prototype.getKeys);
  77080. goog.exportProperty(
  77081. ol.source.ImageVector.prototype,
  77082. 'getProperties',
  77083. ol.source.ImageVector.prototype.getProperties);
  77084. goog.exportProperty(
  77085. ol.source.ImageVector.prototype,
  77086. 'set',
  77087. ol.source.ImageVector.prototype.set);
  77088. goog.exportProperty(
  77089. ol.source.ImageVector.prototype,
  77090. 'setProperties',
  77091. ol.source.ImageVector.prototype.setProperties);
  77092. goog.exportProperty(
  77093. ol.source.ImageVector.prototype,
  77094. 'unset',
  77095. ol.source.ImageVector.prototype.unset);
  77096. goog.exportProperty(
  77097. ol.source.ImageVector.prototype,
  77098. 'changed',
  77099. ol.source.ImageVector.prototype.changed);
  77100. goog.exportProperty(
  77101. ol.source.ImageVector.prototype,
  77102. 'dispatchEvent',
  77103. ol.source.ImageVector.prototype.dispatchEvent);
  77104. goog.exportProperty(
  77105. ol.source.ImageVector.prototype,
  77106. 'getRevision',
  77107. ol.source.ImageVector.prototype.getRevision);
  77108. goog.exportProperty(
  77109. ol.source.ImageVector.prototype,
  77110. 'on',
  77111. ol.source.ImageVector.prototype.on);
  77112. goog.exportProperty(
  77113. ol.source.ImageVector.prototype,
  77114. 'once',
  77115. ol.source.ImageVector.prototype.once);
  77116. goog.exportProperty(
  77117. ol.source.ImageVector.prototype,
  77118. 'un',
  77119. ol.source.ImageVector.prototype.un);
  77120. goog.exportProperty(
  77121. ol.source.ImageWMS.prototype,
  77122. 'getAttributions',
  77123. ol.source.ImageWMS.prototype.getAttributions);
  77124. goog.exportProperty(
  77125. ol.source.ImageWMS.prototype,
  77126. 'getLogo',
  77127. ol.source.ImageWMS.prototype.getLogo);
  77128. goog.exportProperty(
  77129. ol.source.ImageWMS.prototype,
  77130. 'getProjection',
  77131. ol.source.ImageWMS.prototype.getProjection);
  77132. goog.exportProperty(
  77133. ol.source.ImageWMS.prototype,
  77134. 'getState',
  77135. ol.source.ImageWMS.prototype.getState);
  77136. goog.exportProperty(
  77137. ol.source.ImageWMS.prototype,
  77138. 'refresh',
  77139. ol.source.ImageWMS.prototype.refresh);
  77140. goog.exportProperty(
  77141. ol.source.ImageWMS.prototype,
  77142. 'setAttributions',
  77143. ol.source.ImageWMS.prototype.setAttributions);
  77144. goog.exportProperty(
  77145. ol.source.ImageWMS.prototype,
  77146. 'get',
  77147. ol.source.ImageWMS.prototype.get);
  77148. goog.exportProperty(
  77149. ol.source.ImageWMS.prototype,
  77150. 'getKeys',
  77151. ol.source.ImageWMS.prototype.getKeys);
  77152. goog.exportProperty(
  77153. ol.source.ImageWMS.prototype,
  77154. 'getProperties',
  77155. ol.source.ImageWMS.prototype.getProperties);
  77156. goog.exportProperty(
  77157. ol.source.ImageWMS.prototype,
  77158. 'set',
  77159. ol.source.ImageWMS.prototype.set);
  77160. goog.exportProperty(
  77161. ol.source.ImageWMS.prototype,
  77162. 'setProperties',
  77163. ol.source.ImageWMS.prototype.setProperties);
  77164. goog.exportProperty(
  77165. ol.source.ImageWMS.prototype,
  77166. 'unset',
  77167. ol.source.ImageWMS.prototype.unset);
  77168. goog.exportProperty(
  77169. ol.source.ImageWMS.prototype,
  77170. 'changed',
  77171. ol.source.ImageWMS.prototype.changed);
  77172. goog.exportProperty(
  77173. ol.source.ImageWMS.prototype,
  77174. 'dispatchEvent',
  77175. ol.source.ImageWMS.prototype.dispatchEvent);
  77176. goog.exportProperty(
  77177. ol.source.ImageWMS.prototype,
  77178. 'getRevision',
  77179. ol.source.ImageWMS.prototype.getRevision);
  77180. goog.exportProperty(
  77181. ol.source.ImageWMS.prototype,
  77182. 'on',
  77183. ol.source.ImageWMS.prototype.on);
  77184. goog.exportProperty(
  77185. ol.source.ImageWMS.prototype,
  77186. 'once',
  77187. ol.source.ImageWMS.prototype.once);
  77188. goog.exportProperty(
  77189. ol.source.ImageWMS.prototype,
  77190. 'un',
  77191. ol.source.ImageWMS.prototype.un);
  77192. goog.exportProperty(
  77193. ol.source.OSM.prototype,
  77194. 'setRenderReprojectionEdges',
  77195. ol.source.OSM.prototype.setRenderReprojectionEdges);
  77196. goog.exportProperty(
  77197. ol.source.OSM.prototype,
  77198. 'setTileGridForProjection',
  77199. ol.source.OSM.prototype.setTileGridForProjection);
  77200. goog.exportProperty(
  77201. ol.source.OSM.prototype,
  77202. 'getTileLoadFunction',
  77203. ol.source.OSM.prototype.getTileLoadFunction);
  77204. goog.exportProperty(
  77205. ol.source.OSM.prototype,
  77206. 'getTileUrlFunction',
  77207. ol.source.OSM.prototype.getTileUrlFunction);
  77208. goog.exportProperty(
  77209. ol.source.OSM.prototype,
  77210. 'getUrls',
  77211. ol.source.OSM.prototype.getUrls);
  77212. goog.exportProperty(
  77213. ol.source.OSM.prototype,
  77214. 'setTileLoadFunction',
  77215. ol.source.OSM.prototype.setTileLoadFunction);
  77216. goog.exportProperty(
  77217. ol.source.OSM.prototype,
  77218. 'setTileUrlFunction',
  77219. ol.source.OSM.prototype.setTileUrlFunction);
  77220. goog.exportProperty(
  77221. ol.source.OSM.prototype,
  77222. 'setUrl',
  77223. ol.source.OSM.prototype.setUrl);
  77224. goog.exportProperty(
  77225. ol.source.OSM.prototype,
  77226. 'setUrls',
  77227. ol.source.OSM.prototype.setUrls);
  77228. goog.exportProperty(
  77229. ol.source.OSM.prototype,
  77230. 'getTileGrid',
  77231. ol.source.OSM.prototype.getTileGrid);
  77232. goog.exportProperty(
  77233. ol.source.OSM.prototype,
  77234. 'refresh',
  77235. ol.source.OSM.prototype.refresh);
  77236. goog.exportProperty(
  77237. ol.source.OSM.prototype,
  77238. 'getAttributions',
  77239. ol.source.OSM.prototype.getAttributions);
  77240. goog.exportProperty(
  77241. ol.source.OSM.prototype,
  77242. 'getLogo',
  77243. ol.source.OSM.prototype.getLogo);
  77244. goog.exportProperty(
  77245. ol.source.OSM.prototype,
  77246. 'getProjection',
  77247. ol.source.OSM.prototype.getProjection);
  77248. goog.exportProperty(
  77249. ol.source.OSM.prototype,
  77250. 'getState',
  77251. ol.source.OSM.prototype.getState);
  77252. goog.exportProperty(
  77253. ol.source.OSM.prototype,
  77254. 'setAttributions',
  77255. ol.source.OSM.prototype.setAttributions);
  77256. goog.exportProperty(
  77257. ol.source.OSM.prototype,
  77258. 'get',
  77259. ol.source.OSM.prototype.get);
  77260. goog.exportProperty(
  77261. ol.source.OSM.prototype,
  77262. 'getKeys',
  77263. ol.source.OSM.prototype.getKeys);
  77264. goog.exportProperty(
  77265. ol.source.OSM.prototype,
  77266. 'getProperties',
  77267. ol.source.OSM.prototype.getProperties);
  77268. goog.exportProperty(
  77269. ol.source.OSM.prototype,
  77270. 'set',
  77271. ol.source.OSM.prototype.set);
  77272. goog.exportProperty(
  77273. ol.source.OSM.prototype,
  77274. 'setProperties',
  77275. ol.source.OSM.prototype.setProperties);
  77276. goog.exportProperty(
  77277. ol.source.OSM.prototype,
  77278. 'unset',
  77279. ol.source.OSM.prototype.unset);
  77280. goog.exportProperty(
  77281. ol.source.OSM.prototype,
  77282. 'changed',
  77283. ol.source.OSM.prototype.changed);
  77284. goog.exportProperty(
  77285. ol.source.OSM.prototype,
  77286. 'dispatchEvent',
  77287. ol.source.OSM.prototype.dispatchEvent);
  77288. goog.exportProperty(
  77289. ol.source.OSM.prototype,
  77290. 'getRevision',
  77291. ol.source.OSM.prototype.getRevision);
  77292. goog.exportProperty(
  77293. ol.source.OSM.prototype,
  77294. 'on',
  77295. ol.source.OSM.prototype.on);
  77296. goog.exportProperty(
  77297. ol.source.OSM.prototype,
  77298. 'once',
  77299. ol.source.OSM.prototype.once);
  77300. goog.exportProperty(
  77301. ol.source.OSM.prototype,
  77302. 'un',
  77303. ol.source.OSM.prototype.un);
  77304. goog.exportProperty(
  77305. ol.source.Raster.prototype,
  77306. 'getAttributions',
  77307. ol.source.Raster.prototype.getAttributions);
  77308. goog.exportProperty(
  77309. ol.source.Raster.prototype,
  77310. 'getLogo',
  77311. ol.source.Raster.prototype.getLogo);
  77312. goog.exportProperty(
  77313. ol.source.Raster.prototype,
  77314. 'getProjection',
  77315. ol.source.Raster.prototype.getProjection);
  77316. goog.exportProperty(
  77317. ol.source.Raster.prototype,
  77318. 'getState',
  77319. ol.source.Raster.prototype.getState);
  77320. goog.exportProperty(
  77321. ol.source.Raster.prototype,
  77322. 'refresh',
  77323. ol.source.Raster.prototype.refresh);
  77324. goog.exportProperty(
  77325. ol.source.Raster.prototype,
  77326. 'setAttributions',
  77327. ol.source.Raster.prototype.setAttributions);
  77328. goog.exportProperty(
  77329. ol.source.Raster.prototype,
  77330. 'get',
  77331. ol.source.Raster.prototype.get);
  77332. goog.exportProperty(
  77333. ol.source.Raster.prototype,
  77334. 'getKeys',
  77335. ol.source.Raster.prototype.getKeys);
  77336. goog.exportProperty(
  77337. ol.source.Raster.prototype,
  77338. 'getProperties',
  77339. ol.source.Raster.prototype.getProperties);
  77340. goog.exportProperty(
  77341. ol.source.Raster.prototype,
  77342. 'set',
  77343. ol.source.Raster.prototype.set);
  77344. goog.exportProperty(
  77345. ol.source.Raster.prototype,
  77346. 'setProperties',
  77347. ol.source.Raster.prototype.setProperties);
  77348. goog.exportProperty(
  77349. ol.source.Raster.prototype,
  77350. 'unset',
  77351. ol.source.Raster.prototype.unset);
  77352. goog.exportProperty(
  77353. ol.source.Raster.prototype,
  77354. 'changed',
  77355. ol.source.Raster.prototype.changed);
  77356. goog.exportProperty(
  77357. ol.source.Raster.prototype,
  77358. 'dispatchEvent',
  77359. ol.source.Raster.prototype.dispatchEvent);
  77360. goog.exportProperty(
  77361. ol.source.Raster.prototype,
  77362. 'getRevision',
  77363. ol.source.Raster.prototype.getRevision);
  77364. goog.exportProperty(
  77365. ol.source.Raster.prototype,
  77366. 'on',
  77367. ol.source.Raster.prototype.on);
  77368. goog.exportProperty(
  77369. ol.source.Raster.prototype,
  77370. 'once',
  77371. ol.source.Raster.prototype.once);
  77372. goog.exportProperty(
  77373. ol.source.Raster.prototype,
  77374. 'un',
  77375. ol.source.Raster.prototype.un);
  77376. goog.exportProperty(
  77377. ol.source.Raster.Event.prototype,
  77378. 'type',
  77379. ol.source.Raster.Event.prototype.type);
  77380. goog.exportProperty(
  77381. ol.source.Raster.Event.prototype,
  77382. 'target',
  77383. ol.source.Raster.Event.prototype.target);
  77384. goog.exportProperty(
  77385. ol.source.Raster.Event.prototype,
  77386. 'preventDefault',
  77387. ol.source.Raster.Event.prototype.preventDefault);
  77388. goog.exportProperty(
  77389. ol.source.Raster.Event.prototype,
  77390. 'stopPropagation',
  77391. ol.source.Raster.Event.prototype.stopPropagation);
  77392. goog.exportProperty(
  77393. ol.source.Stamen.prototype,
  77394. 'setRenderReprojectionEdges',
  77395. ol.source.Stamen.prototype.setRenderReprojectionEdges);
  77396. goog.exportProperty(
  77397. ol.source.Stamen.prototype,
  77398. 'setTileGridForProjection',
  77399. ol.source.Stamen.prototype.setTileGridForProjection);
  77400. goog.exportProperty(
  77401. ol.source.Stamen.prototype,
  77402. 'getTileLoadFunction',
  77403. ol.source.Stamen.prototype.getTileLoadFunction);
  77404. goog.exportProperty(
  77405. ol.source.Stamen.prototype,
  77406. 'getTileUrlFunction',
  77407. ol.source.Stamen.prototype.getTileUrlFunction);
  77408. goog.exportProperty(
  77409. ol.source.Stamen.prototype,
  77410. 'getUrls',
  77411. ol.source.Stamen.prototype.getUrls);
  77412. goog.exportProperty(
  77413. ol.source.Stamen.prototype,
  77414. 'setTileLoadFunction',
  77415. ol.source.Stamen.prototype.setTileLoadFunction);
  77416. goog.exportProperty(
  77417. ol.source.Stamen.prototype,
  77418. 'setTileUrlFunction',
  77419. ol.source.Stamen.prototype.setTileUrlFunction);
  77420. goog.exportProperty(
  77421. ol.source.Stamen.prototype,
  77422. 'setUrl',
  77423. ol.source.Stamen.prototype.setUrl);
  77424. goog.exportProperty(
  77425. ol.source.Stamen.prototype,
  77426. 'setUrls',
  77427. ol.source.Stamen.prototype.setUrls);
  77428. goog.exportProperty(
  77429. ol.source.Stamen.prototype,
  77430. 'getTileGrid',
  77431. ol.source.Stamen.prototype.getTileGrid);
  77432. goog.exportProperty(
  77433. ol.source.Stamen.prototype,
  77434. 'refresh',
  77435. ol.source.Stamen.prototype.refresh);
  77436. goog.exportProperty(
  77437. ol.source.Stamen.prototype,
  77438. 'getAttributions',
  77439. ol.source.Stamen.prototype.getAttributions);
  77440. goog.exportProperty(
  77441. ol.source.Stamen.prototype,
  77442. 'getLogo',
  77443. ol.source.Stamen.prototype.getLogo);
  77444. goog.exportProperty(
  77445. ol.source.Stamen.prototype,
  77446. 'getProjection',
  77447. ol.source.Stamen.prototype.getProjection);
  77448. goog.exportProperty(
  77449. ol.source.Stamen.prototype,
  77450. 'getState',
  77451. ol.source.Stamen.prototype.getState);
  77452. goog.exportProperty(
  77453. ol.source.Stamen.prototype,
  77454. 'setAttributions',
  77455. ol.source.Stamen.prototype.setAttributions);
  77456. goog.exportProperty(
  77457. ol.source.Stamen.prototype,
  77458. 'get',
  77459. ol.source.Stamen.prototype.get);
  77460. goog.exportProperty(
  77461. ol.source.Stamen.prototype,
  77462. 'getKeys',
  77463. ol.source.Stamen.prototype.getKeys);
  77464. goog.exportProperty(
  77465. ol.source.Stamen.prototype,
  77466. 'getProperties',
  77467. ol.source.Stamen.prototype.getProperties);
  77468. goog.exportProperty(
  77469. ol.source.Stamen.prototype,
  77470. 'set',
  77471. ol.source.Stamen.prototype.set);
  77472. goog.exportProperty(
  77473. ol.source.Stamen.prototype,
  77474. 'setProperties',
  77475. ol.source.Stamen.prototype.setProperties);
  77476. goog.exportProperty(
  77477. ol.source.Stamen.prototype,
  77478. 'unset',
  77479. ol.source.Stamen.prototype.unset);
  77480. goog.exportProperty(
  77481. ol.source.Stamen.prototype,
  77482. 'changed',
  77483. ol.source.Stamen.prototype.changed);
  77484. goog.exportProperty(
  77485. ol.source.Stamen.prototype,
  77486. 'dispatchEvent',
  77487. ol.source.Stamen.prototype.dispatchEvent);
  77488. goog.exportProperty(
  77489. ol.source.Stamen.prototype,
  77490. 'getRevision',
  77491. ol.source.Stamen.prototype.getRevision);
  77492. goog.exportProperty(
  77493. ol.source.Stamen.prototype,
  77494. 'on',
  77495. ol.source.Stamen.prototype.on);
  77496. goog.exportProperty(
  77497. ol.source.Stamen.prototype,
  77498. 'once',
  77499. ol.source.Stamen.prototype.once);
  77500. goog.exportProperty(
  77501. ol.source.Stamen.prototype,
  77502. 'un',
  77503. ol.source.Stamen.prototype.un);
  77504. goog.exportProperty(
  77505. ol.source.Tile.Event.prototype,
  77506. 'type',
  77507. ol.source.Tile.Event.prototype.type);
  77508. goog.exportProperty(
  77509. ol.source.Tile.Event.prototype,
  77510. 'target',
  77511. ol.source.Tile.Event.prototype.target);
  77512. goog.exportProperty(
  77513. ol.source.Tile.Event.prototype,
  77514. 'preventDefault',
  77515. ol.source.Tile.Event.prototype.preventDefault);
  77516. goog.exportProperty(
  77517. ol.source.Tile.Event.prototype,
  77518. 'stopPropagation',
  77519. ol.source.Tile.Event.prototype.stopPropagation);
  77520. goog.exportProperty(
  77521. ol.source.TileArcGISRest.prototype,
  77522. 'setRenderReprojectionEdges',
  77523. ol.source.TileArcGISRest.prototype.setRenderReprojectionEdges);
  77524. goog.exportProperty(
  77525. ol.source.TileArcGISRest.prototype,
  77526. 'setTileGridForProjection',
  77527. ol.source.TileArcGISRest.prototype.setTileGridForProjection);
  77528. goog.exportProperty(
  77529. ol.source.TileArcGISRest.prototype,
  77530. 'getTileLoadFunction',
  77531. ol.source.TileArcGISRest.prototype.getTileLoadFunction);
  77532. goog.exportProperty(
  77533. ol.source.TileArcGISRest.prototype,
  77534. 'getTileUrlFunction',
  77535. ol.source.TileArcGISRest.prototype.getTileUrlFunction);
  77536. goog.exportProperty(
  77537. ol.source.TileArcGISRest.prototype,
  77538. 'getUrls',
  77539. ol.source.TileArcGISRest.prototype.getUrls);
  77540. goog.exportProperty(
  77541. ol.source.TileArcGISRest.prototype,
  77542. 'setTileLoadFunction',
  77543. ol.source.TileArcGISRest.prototype.setTileLoadFunction);
  77544. goog.exportProperty(
  77545. ol.source.TileArcGISRest.prototype,
  77546. 'setTileUrlFunction',
  77547. ol.source.TileArcGISRest.prototype.setTileUrlFunction);
  77548. goog.exportProperty(
  77549. ol.source.TileArcGISRest.prototype,
  77550. 'setUrl',
  77551. ol.source.TileArcGISRest.prototype.setUrl);
  77552. goog.exportProperty(
  77553. ol.source.TileArcGISRest.prototype,
  77554. 'setUrls',
  77555. ol.source.TileArcGISRest.prototype.setUrls);
  77556. goog.exportProperty(
  77557. ol.source.TileArcGISRest.prototype,
  77558. 'getTileGrid',
  77559. ol.source.TileArcGISRest.prototype.getTileGrid);
  77560. goog.exportProperty(
  77561. ol.source.TileArcGISRest.prototype,
  77562. 'refresh',
  77563. ol.source.TileArcGISRest.prototype.refresh);
  77564. goog.exportProperty(
  77565. ol.source.TileArcGISRest.prototype,
  77566. 'getAttributions',
  77567. ol.source.TileArcGISRest.prototype.getAttributions);
  77568. goog.exportProperty(
  77569. ol.source.TileArcGISRest.prototype,
  77570. 'getLogo',
  77571. ol.source.TileArcGISRest.prototype.getLogo);
  77572. goog.exportProperty(
  77573. ol.source.TileArcGISRest.prototype,
  77574. 'getProjection',
  77575. ol.source.TileArcGISRest.prototype.getProjection);
  77576. goog.exportProperty(
  77577. ol.source.TileArcGISRest.prototype,
  77578. 'getState',
  77579. ol.source.TileArcGISRest.prototype.getState);
  77580. goog.exportProperty(
  77581. ol.source.TileArcGISRest.prototype,
  77582. 'setAttributions',
  77583. ol.source.TileArcGISRest.prototype.setAttributions);
  77584. goog.exportProperty(
  77585. ol.source.TileArcGISRest.prototype,
  77586. 'get',
  77587. ol.source.TileArcGISRest.prototype.get);
  77588. goog.exportProperty(
  77589. ol.source.TileArcGISRest.prototype,
  77590. 'getKeys',
  77591. ol.source.TileArcGISRest.prototype.getKeys);
  77592. goog.exportProperty(
  77593. ol.source.TileArcGISRest.prototype,
  77594. 'getProperties',
  77595. ol.source.TileArcGISRest.prototype.getProperties);
  77596. goog.exportProperty(
  77597. ol.source.TileArcGISRest.prototype,
  77598. 'set',
  77599. ol.source.TileArcGISRest.prototype.set);
  77600. goog.exportProperty(
  77601. ol.source.TileArcGISRest.prototype,
  77602. 'setProperties',
  77603. ol.source.TileArcGISRest.prototype.setProperties);
  77604. goog.exportProperty(
  77605. ol.source.TileArcGISRest.prototype,
  77606. 'unset',
  77607. ol.source.TileArcGISRest.prototype.unset);
  77608. goog.exportProperty(
  77609. ol.source.TileArcGISRest.prototype,
  77610. 'changed',
  77611. ol.source.TileArcGISRest.prototype.changed);
  77612. goog.exportProperty(
  77613. ol.source.TileArcGISRest.prototype,
  77614. 'dispatchEvent',
  77615. ol.source.TileArcGISRest.prototype.dispatchEvent);
  77616. goog.exportProperty(
  77617. ol.source.TileArcGISRest.prototype,
  77618. 'getRevision',
  77619. ol.source.TileArcGISRest.prototype.getRevision);
  77620. goog.exportProperty(
  77621. ol.source.TileArcGISRest.prototype,
  77622. 'on',
  77623. ol.source.TileArcGISRest.prototype.on);
  77624. goog.exportProperty(
  77625. ol.source.TileArcGISRest.prototype,
  77626. 'once',
  77627. ol.source.TileArcGISRest.prototype.once);
  77628. goog.exportProperty(
  77629. ol.source.TileArcGISRest.prototype,
  77630. 'un',
  77631. ol.source.TileArcGISRest.prototype.un);
  77632. goog.exportProperty(
  77633. ol.source.TileDebug.prototype,
  77634. 'getTileGrid',
  77635. ol.source.TileDebug.prototype.getTileGrid);
  77636. goog.exportProperty(
  77637. ol.source.TileDebug.prototype,
  77638. 'refresh',
  77639. ol.source.TileDebug.prototype.refresh);
  77640. goog.exportProperty(
  77641. ol.source.TileDebug.prototype,
  77642. 'getAttributions',
  77643. ol.source.TileDebug.prototype.getAttributions);
  77644. goog.exportProperty(
  77645. ol.source.TileDebug.prototype,
  77646. 'getLogo',
  77647. ol.source.TileDebug.prototype.getLogo);
  77648. goog.exportProperty(
  77649. ol.source.TileDebug.prototype,
  77650. 'getProjection',
  77651. ol.source.TileDebug.prototype.getProjection);
  77652. goog.exportProperty(
  77653. ol.source.TileDebug.prototype,
  77654. 'getState',
  77655. ol.source.TileDebug.prototype.getState);
  77656. goog.exportProperty(
  77657. ol.source.TileDebug.prototype,
  77658. 'setAttributions',
  77659. ol.source.TileDebug.prototype.setAttributions);
  77660. goog.exportProperty(
  77661. ol.source.TileDebug.prototype,
  77662. 'get',
  77663. ol.source.TileDebug.prototype.get);
  77664. goog.exportProperty(
  77665. ol.source.TileDebug.prototype,
  77666. 'getKeys',
  77667. ol.source.TileDebug.prototype.getKeys);
  77668. goog.exportProperty(
  77669. ol.source.TileDebug.prototype,
  77670. 'getProperties',
  77671. ol.source.TileDebug.prototype.getProperties);
  77672. goog.exportProperty(
  77673. ol.source.TileDebug.prototype,
  77674. 'set',
  77675. ol.source.TileDebug.prototype.set);
  77676. goog.exportProperty(
  77677. ol.source.TileDebug.prototype,
  77678. 'setProperties',
  77679. ol.source.TileDebug.prototype.setProperties);
  77680. goog.exportProperty(
  77681. ol.source.TileDebug.prototype,
  77682. 'unset',
  77683. ol.source.TileDebug.prototype.unset);
  77684. goog.exportProperty(
  77685. ol.source.TileDebug.prototype,
  77686. 'changed',
  77687. ol.source.TileDebug.prototype.changed);
  77688. goog.exportProperty(
  77689. ol.source.TileDebug.prototype,
  77690. 'dispatchEvent',
  77691. ol.source.TileDebug.prototype.dispatchEvent);
  77692. goog.exportProperty(
  77693. ol.source.TileDebug.prototype,
  77694. 'getRevision',
  77695. ol.source.TileDebug.prototype.getRevision);
  77696. goog.exportProperty(
  77697. ol.source.TileDebug.prototype,
  77698. 'on',
  77699. ol.source.TileDebug.prototype.on);
  77700. goog.exportProperty(
  77701. ol.source.TileDebug.prototype,
  77702. 'once',
  77703. ol.source.TileDebug.prototype.once);
  77704. goog.exportProperty(
  77705. ol.source.TileDebug.prototype,
  77706. 'un',
  77707. ol.source.TileDebug.prototype.un);
  77708. goog.exportProperty(
  77709. ol.source.TileJSON.prototype,
  77710. 'setRenderReprojectionEdges',
  77711. ol.source.TileJSON.prototype.setRenderReprojectionEdges);
  77712. goog.exportProperty(
  77713. ol.source.TileJSON.prototype,
  77714. 'setTileGridForProjection',
  77715. ol.source.TileJSON.prototype.setTileGridForProjection);
  77716. goog.exportProperty(
  77717. ol.source.TileJSON.prototype,
  77718. 'getTileLoadFunction',
  77719. ol.source.TileJSON.prototype.getTileLoadFunction);
  77720. goog.exportProperty(
  77721. ol.source.TileJSON.prototype,
  77722. 'getTileUrlFunction',
  77723. ol.source.TileJSON.prototype.getTileUrlFunction);
  77724. goog.exportProperty(
  77725. ol.source.TileJSON.prototype,
  77726. 'getUrls',
  77727. ol.source.TileJSON.prototype.getUrls);
  77728. goog.exportProperty(
  77729. ol.source.TileJSON.prototype,
  77730. 'setTileLoadFunction',
  77731. ol.source.TileJSON.prototype.setTileLoadFunction);
  77732. goog.exportProperty(
  77733. ol.source.TileJSON.prototype,
  77734. 'setTileUrlFunction',
  77735. ol.source.TileJSON.prototype.setTileUrlFunction);
  77736. goog.exportProperty(
  77737. ol.source.TileJSON.prototype,
  77738. 'setUrl',
  77739. ol.source.TileJSON.prototype.setUrl);
  77740. goog.exportProperty(
  77741. ol.source.TileJSON.prototype,
  77742. 'setUrls',
  77743. ol.source.TileJSON.prototype.setUrls);
  77744. goog.exportProperty(
  77745. ol.source.TileJSON.prototype,
  77746. 'getTileGrid',
  77747. ol.source.TileJSON.prototype.getTileGrid);
  77748. goog.exportProperty(
  77749. ol.source.TileJSON.prototype,
  77750. 'refresh',
  77751. ol.source.TileJSON.prototype.refresh);
  77752. goog.exportProperty(
  77753. ol.source.TileJSON.prototype,
  77754. 'getAttributions',
  77755. ol.source.TileJSON.prototype.getAttributions);
  77756. goog.exportProperty(
  77757. ol.source.TileJSON.prototype,
  77758. 'getLogo',
  77759. ol.source.TileJSON.prototype.getLogo);
  77760. goog.exportProperty(
  77761. ol.source.TileJSON.prototype,
  77762. 'getProjection',
  77763. ol.source.TileJSON.prototype.getProjection);
  77764. goog.exportProperty(
  77765. ol.source.TileJSON.prototype,
  77766. 'getState',
  77767. ol.source.TileJSON.prototype.getState);
  77768. goog.exportProperty(
  77769. ol.source.TileJSON.prototype,
  77770. 'setAttributions',
  77771. ol.source.TileJSON.prototype.setAttributions);
  77772. goog.exportProperty(
  77773. ol.source.TileJSON.prototype,
  77774. 'get',
  77775. ol.source.TileJSON.prototype.get);
  77776. goog.exportProperty(
  77777. ol.source.TileJSON.prototype,
  77778. 'getKeys',
  77779. ol.source.TileJSON.prototype.getKeys);
  77780. goog.exportProperty(
  77781. ol.source.TileJSON.prototype,
  77782. 'getProperties',
  77783. ol.source.TileJSON.prototype.getProperties);
  77784. goog.exportProperty(
  77785. ol.source.TileJSON.prototype,
  77786. 'set',
  77787. ol.source.TileJSON.prototype.set);
  77788. goog.exportProperty(
  77789. ol.source.TileJSON.prototype,
  77790. 'setProperties',
  77791. ol.source.TileJSON.prototype.setProperties);
  77792. goog.exportProperty(
  77793. ol.source.TileJSON.prototype,
  77794. 'unset',
  77795. ol.source.TileJSON.prototype.unset);
  77796. goog.exportProperty(
  77797. ol.source.TileJSON.prototype,
  77798. 'changed',
  77799. ol.source.TileJSON.prototype.changed);
  77800. goog.exportProperty(
  77801. ol.source.TileJSON.prototype,
  77802. 'dispatchEvent',
  77803. ol.source.TileJSON.prototype.dispatchEvent);
  77804. goog.exportProperty(
  77805. ol.source.TileJSON.prototype,
  77806. 'getRevision',
  77807. ol.source.TileJSON.prototype.getRevision);
  77808. goog.exportProperty(
  77809. ol.source.TileJSON.prototype,
  77810. 'on',
  77811. ol.source.TileJSON.prototype.on);
  77812. goog.exportProperty(
  77813. ol.source.TileJSON.prototype,
  77814. 'once',
  77815. ol.source.TileJSON.prototype.once);
  77816. goog.exportProperty(
  77817. ol.source.TileJSON.prototype,
  77818. 'un',
  77819. ol.source.TileJSON.prototype.un);
  77820. goog.exportProperty(
  77821. ol.source.TileUTFGrid.prototype,
  77822. 'getTileGrid',
  77823. ol.source.TileUTFGrid.prototype.getTileGrid);
  77824. goog.exportProperty(
  77825. ol.source.TileUTFGrid.prototype,
  77826. 'refresh',
  77827. ol.source.TileUTFGrid.prototype.refresh);
  77828. goog.exportProperty(
  77829. ol.source.TileUTFGrid.prototype,
  77830. 'getAttributions',
  77831. ol.source.TileUTFGrid.prototype.getAttributions);
  77832. goog.exportProperty(
  77833. ol.source.TileUTFGrid.prototype,
  77834. 'getLogo',
  77835. ol.source.TileUTFGrid.prototype.getLogo);
  77836. goog.exportProperty(
  77837. ol.source.TileUTFGrid.prototype,
  77838. 'getProjection',
  77839. ol.source.TileUTFGrid.prototype.getProjection);
  77840. goog.exportProperty(
  77841. ol.source.TileUTFGrid.prototype,
  77842. 'getState',
  77843. ol.source.TileUTFGrid.prototype.getState);
  77844. goog.exportProperty(
  77845. ol.source.TileUTFGrid.prototype,
  77846. 'setAttributions',
  77847. ol.source.TileUTFGrid.prototype.setAttributions);
  77848. goog.exportProperty(
  77849. ol.source.TileUTFGrid.prototype,
  77850. 'get',
  77851. ol.source.TileUTFGrid.prototype.get);
  77852. goog.exportProperty(
  77853. ol.source.TileUTFGrid.prototype,
  77854. 'getKeys',
  77855. ol.source.TileUTFGrid.prototype.getKeys);
  77856. goog.exportProperty(
  77857. ol.source.TileUTFGrid.prototype,
  77858. 'getProperties',
  77859. ol.source.TileUTFGrid.prototype.getProperties);
  77860. goog.exportProperty(
  77861. ol.source.TileUTFGrid.prototype,
  77862. 'set',
  77863. ol.source.TileUTFGrid.prototype.set);
  77864. goog.exportProperty(
  77865. ol.source.TileUTFGrid.prototype,
  77866. 'setProperties',
  77867. ol.source.TileUTFGrid.prototype.setProperties);
  77868. goog.exportProperty(
  77869. ol.source.TileUTFGrid.prototype,
  77870. 'unset',
  77871. ol.source.TileUTFGrid.prototype.unset);
  77872. goog.exportProperty(
  77873. ol.source.TileUTFGrid.prototype,
  77874. 'changed',
  77875. ol.source.TileUTFGrid.prototype.changed);
  77876. goog.exportProperty(
  77877. ol.source.TileUTFGrid.prototype,
  77878. 'dispatchEvent',
  77879. ol.source.TileUTFGrid.prototype.dispatchEvent);
  77880. goog.exportProperty(
  77881. ol.source.TileUTFGrid.prototype,
  77882. 'getRevision',
  77883. ol.source.TileUTFGrid.prototype.getRevision);
  77884. goog.exportProperty(
  77885. ol.source.TileUTFGrid.prototype,
  77886. 'on',
  77887. ol.source.TileUTFGrid.prototype.on);
  77888. goog.exportProperty(
  77889. ol.source.TileUTFGrid.prototype,
  77890. 'once',
  77891. ol.source.TileUTFGrid.prototype.once);
  77892. goog.exportProperty(
  77893. ol.source.TileUTFGrid.prototype,
  77894. 'un',
  77895. ol.source.TileUTFGrid.prototype.un);
  77896. goog.exportProperty(
  77897. ol.source.TileWMS.prototype,
  77898. 'setRenderReprojectionEdges',
  77899. ol.source.TileWMS.prototype.setRenderReprojectionEdges);
  77900. goog.exportProperty(
  77901. ol.source.TileWMS.prototype,
  77902. 'setTileGridForProjection',
  77903. ol.source.TileWMS.prototype.setTileGridForProjection);
  77904. goog.exportProperty(
  77905. ol.source.TileWMS.prototype,
  77906. 'getTileLoadFunction',
  77907. ol.source.TileWMS.prototype.getTileLoadFunction);
  77908. goog.exportProperty(
  77909. ol.source.TileWMS.prototype,
  77910. 'getTileUrlFunction',
  77911. ol.source.TileWMS.prototype.getTileUrlFunction);
  77912. goog.exportProperty(
  77913. ol.source.TileWMS.prototype,
  77914. 'getUrls',
  77915. ol.source.TileWMS.prototype.getUrls);
  77916. goog.exportProperty(
  77917. ol.source.TileWMS.prototype,
  77918. 'setTileLoadFunction',
  77919. ol.source.TileWMS.prototype.setTileLoadFunction);
  77920. goog.exportProperty(
  77921. ol.source.TileWMS.prototype,
  77922. 'setTileUrlFunction',
  77923. ol.source.TileWMS.prototype.setTileUrlFunction);
  77924. goog.exportProperty(
  77925. ol.source.TileWMS.prototype,
  77926. 'setUrl',
  77927. ol.source.TileWMS.prototype.setUrl);
  77928. goog.exportProperty(
  77929. ol.source.TileWMS.prototype,
  77930. 'setUrls',
  77931. ol.source.TileWMS.prototype.setUrls);
  77932. goog.exportProperty(
  77933. ol.source.TileWMS.prototype,
  77934. 'getTileGrid',
  77935. ol.source.TileWMS.prototype.getTileGrid);
  77936. goog.exportProperty(
  77937. ol.source.TileWMS.prototype,
  77938. 'refresh',
  77939. ol.source.TileWMS.prototype.refresh);
  77940. goog.exportProperty(
  77941. ol.source.TileWMS.prototype,
  77942. 'getAttributions',
  77943. ol.source.TileWMS.prototype.getAttributions);
  77944. goog.exportProperty(
  77945. ol.source.TileWMS.prototype,
  77946. 'getLogo',
  77947. ol.source.TileWMS.prototype.getLogo);
  77948. goog.exportProperty(
  77949. ol.source.TileWMS.prototype,
  77950. 'getProjection',
  77951. ol.source.TileWMS.prototype.getProjection);
  77952. goog.exportProperty(
  77953. ol.source.TileWMS.prototype,
  77954. 'getState',
  77955. ol.source.TileWMS.prototype.getState);
  77956. goog.exportProperty(
  77957. ol.source.TileWMS.prototype,
  77958. 'setAttributions',
  77959. ol.source.TileWMS.prototype.setAttributions);
  77960. goog.exportProperty(
  77961. ol.source.TileWMS.prototype,
  77962. 'get',
  77963. ol.source.TileWMS.prototype.get);
  77964. goog.exportProperty(
  77965. ol.source.TileWMS.prototype,
  77966. 'getKeys',
  77967. ol.source.TileWMS.prototype.getKeys);
  77968. goog.exportProperty(
  77969. ol.source.TileWMS.prototype,
  77970. 'getProperties',
  77971. ol.source.TileWMS.prototype.getProperties);
  77972. goog.exportProperty(
  77973. ol.source.TileWMS.prototype,
  77974. 'set',
  77975. ol.source.TileWMS.prototype.set);
  77976. goog.exportProperty(
  77977. ol.source.TileWMS.prototype,
  77978. 'setProperties',
  77979. ol.source.TileWMS.prototype.setProperties);
  77980. goog.exportProperty(
  77981. ol.source.TileWMS.prototype,
  77982. 'unset',
  77983. ol.source.TileWMS.prototype.unset);
  77984. goog.exportProperty(
  77985. ol.source.TileWMS.prototype,
  77986. 'changed',
  77987. ol.source.TileWMS.prototype.changed);
  77988. goog.exportProperty(
  77989. ol.source.TileWMS.prototype,
  77990. 'dispatchEvent',
  77991. ol.source.TileWMS.prototype.dispatchEvent);
  77992. goog.exportProperty(
  77993. ol.source.TileWMS.prototype,
  77994. 'getRevision',
  77995. ol.source.TileWMS.prototype.getRevision);
  77996. goog.exportProperty(
  77997. ol.source.TileWMS.prototype,
  77998. 'on',
  77999. ol.source.TileWMS.prototype.on);
  78000. goog.exportProperty(
  78001. ol.source.TileWMS.prototype,
  78002. 'once',
  78003. ol.source.TileWMS.prototype.once);
  78004. goog.exportProperty(
  78005. ol.source.TileWMS.prototype,
  78006. 'un',
  78007. ol.source.TileWMS.prototype.un);
  78008. goog.exportProperty(
  78009. ol.source.Vector.Event.prototype,
  78010. 'type',
  78011. ol.source.Vector.Event.prototype.type);
  78012. goog.exportProperty(
  78013. ol.source.Vector.Event.prototype,
  78014. 'target',
  78015. ol.source.Vector.Event.prototype.target);
  78016. goog.exportProperty(
  78017. ol.source.Vector.Event.prototype,
  78018. 'preventDefault',
  78019. ol.source.Vector.Event.prototype.preventDefault);
  78020. goog.exportProperty(
  78021. ol.source.Vector.Event.prototype,
  78022. 'stopPropagation',
  78023. ol.source.Vector.Event.prototype.stopPropagation);
  78024. goog.exportProperty(
  78025. ol.source.VectorTile.prototype,
  78026. 'getTileLoadFunction',
  78027. ol.source.VectorTile.prototype.getTileLoadFunction);
  78028. goog.exportProperty(
  78029. ol.source.VectorTile.prototype,
  78030. 'getTileUrlFunction',
  78031. ol.source.VectorTile.prototype.getTileUrlFunction);
  78032. goog.exportProperty(
  78033. ol.source.VectorTile.prototype,
  78034. 'getUrls',
  78035. ol.source.VectorTile.prototype.getUrls);
  78036. goog.exportProperty(
  78037. ol.source.VectorTile.prototype,
  78038. 'setTileLoadFunction',
  78039. ol.source.VectorTile.prototype.setTileLoadFunction);
  78040. goog.exportProperty(
  78041. ol.source.VectorTile.prototype,
  78042. 'setTileUrlFunction',
  78043. ol.source.VectorTile.prototype.setTileUrlFunction);
  78044. goog.exportProperty(
  78045. ol.source.VectorTile.prototype,
  78046. 'setUrl',
  78047. ol.source.VectorTile.prototype.setUrl);
  78048. goog.exportProperty(
  78049. ol.source.VectorTile.prototype,
  78050. 'setUrls',
  78051. ol.source.VectorTile.prototype.setUrls);
  78052. goog.exportProperty(
  78053. ol.source.VectorTile.prototype,
  78054. 'getTileGrid',
  78055. ol.source.VectorTile.prototype.getTileGrid);
  78056. goog.exportProperty(
  78057. ol.source.VectorTile.prototype,
  78058. 'refresh',
  78059. ol.source.VectorTile.prototype.refresh);
  78060. goog.exportProperty(
  78061. ol.source.VectorTile.prototype,
  78062. 'getAttributions',
  78063. ol.source.VectorTile.prototype.getAttributions);
  78064. goog.exportProperty(
  78065. ol.source.VectorTile.prototype,
  78066. 'getLogo',
  78067. ol.source.VectorTile.prototype.getLogo);
  78068. goog.exportProperty(
  78069. ol.source.VectorTile.prototype,
  78070. 'getProjection',
  78071. ol.source.VectorTile.prototype.getProjection);
  78072. goog.exportProperty(
  78073. ol.source.VectorTile.prototype,
  78074. 'getState',
  78075. ol.source.VectorTile.prototype.getState);
  78076. goog.exportProperty(
  78077. ol.source.VectorTile.prototype,
  78078. 'setAttributions',
  78079. ol.source.VectorTile.prototype.setAttributions);
  78080. goog.exportProperty(
  78081. ol.source.VectorTile.prototype,
  78082. 'get',
  78083. ol.source.VectorTile.prototype.get);
  78084. goog.exportProperty(
  78085. ol.source.VectorTile.prototype,
  78086. 'getKeys',
  78087. ol.source.VectorTile.prototype.getKeys);
  78088. goog.exportProperty(
  78089. ol.source.VectorTile.prototype,
  78090. 'getProperties',
  78091. ol.source.VectorTile.prototype.getProperties);
  78092. goog.exportProperty(
  78093. ol.source.VectorTile.prototype,
  78094. 'set',
  78095. ol.source.VectorTile.prototype.set);
  78096. goog.exportProperty(
  78097. ol.source.VectorTile.prototype,
  78098. 'setProperties',
  78099. ol.source.VectorTile.prototype.setProperties);
  78100. goog.exportProperty(
  78101. ol.source.VectorTile.prototype,
  78102. 'unset',
  78103. ol.source.VectorTile.prototype.unset);
  78104. goog.exportProperty(
  78105. ol.source.VectorTile.prototype,
  78106. 'changed',
  78107. ol.source.VectorTile.prototype.changed);
  78108. goog.exportProperty(
  78109. ol.source.VectorTile.prototype,
  78110. 'dispatchEvent',
  78111. ol.source.VectorTile.prototype.dispatchEvent);
  78112. goog.exportProperty(
  78113. ol.source.VectorTile.prototype,
  78114. 'getRevision',
  78115. ol.source.VectorTile.prototype.getRevision);
  78116. goog.exportProperty(
  78117. ol.source.VectorTile.prototype,
  78118. 'on',
  78119. ol.source.VectorTile.prototype.on);
  78120. goog.exportProperty(
  78121. ol.source.VectorTile.prototype,
  78122. 'once',
  78123. ol.source.VectorTile.prototype.once);
  78124. goog.exportProperty(
  78125. ol.source.VectorTile.prototype,
  78126. 'un',
  78127. ol.source.VectorTile.prototype.un);
  78128. goog.exportProperty(
  78129. ol.source.WMTS.prototype,
  78130. 'setRenderReprojectionEdges',
  78131. ol.source.WMTS.prototype.setRenderReprojectionEdges);
  78132. goog.exportProperty(
  78133. ol.source.WMTS.prototype,
  78134. 'setTileGridForProjection',
  78135. ol.source.WMTS.prototype.setTileGridForProjection);
  78136. goog.exportProperty(
  78137. ol.source.WMTS.prototype,
  78138. 'getTileLoadFunction',
  78139. ol.source.WMTS.prototype.getTileLoadFunction);
  78140. goog.exportProperty(
  78141. ol.source.WMTS.prototype,
  78142. 'getTileUrlFunction',
  78143. ol.source.WMTS.prototype.getTileUrlFunction);
  78144. goog.exportProperty(
  78145. ol.source.WMTS.prototype,
  78146. 'getUrls',
  78147. ol.source.WMTS.prototype.getUrls);
  78148. goog.exportProperty(
  78149. ol.source.WMTS.prototype,
  78150. 'setTileLoadFunction',
  78151. ol.source.WMTS.prototype.setTileLoadFunction);
  78152. goog.exportProperty(
  78153. ol.source.WMTS.prototype,
  78154. 'setTileUrlFunction',
  78155. ol.source.WMTS.prototype.setTileUrlFunction);
  78156. goog.exportProperty(
  78157. ol.source.WMTS.prototype,
  78158. 'setUrl',
  78159. ol.source.WMTS.prototype.setUrl);
  78160. goog.exportProperty(
  78161. ol.source.WMTS.prototype,
  78162. 'setUrls',
  78163. ol.source.WMTS.prototype.setUrls);
  78164. goog.exportProperty(
  78165. ol.source.WMTS.prototype,
  78166. 'getTileGrid',
  78167. ol.source.WMTS.prototype.getTileGrid);
  78168. goog.exportProperty(
  78169. ol.source.WMTS.prototype,
  78170. 'refresh',
  78171. ol.source.WMTS.prototype.refresh);
  78172. goog.exportProperty(
  78173. ol.source.WMTS.prototype,
  78174. 'getAttributions',
  78175. ol.source.WMTS.prototype.getAttributions);
  78176. goog.exportProperty(
  78177. ol.source.WMTS.prototype,
  78178. 'getLogo',
  78179. ol.source.WMTS.prototype.getLogo);
  78180. goog.exportProperty(
  78181. ol.source.WMTS.prototype,
  78182. 'getProjection',
  78183. ol.source.WMTS.prototype.getProjection);
  78184. goog.exportProperty(
  78185. ol.source.WMTS.prototype,
  78186. 'getState',
  78187. ol.source.WMTS.prototype.getState);
  78188. goog.exportProperty(
  78189. ol.source.WMTS.prototype,
  78190. 'setAttributions',
  78191. ol.source.WMTS.prototype.setAttributions);
  78192. goog.exportProperty(
  78193. ol.source.WMTS.prototype,
  78194. 'get',
  78195. ol.source.WMTS.prototype.get);
  78196. goog.exportProperty(
  78197. ol.source.WMTS.prototype,
  78198. 'getKeys',
  78199. ol.source.WMTS.prototype.getKeys);
  78200. goog.exportProperty(
  78201. ol.source.WMTS.prototype,
  78202. 'getProperties',
  78203. ol.source.WMTS.prototype.getProperties);
  78204. goog.exportProperty(
  78205. ol.source.WMTS.prototype,
  78206. 'set',
  78207. ol.source.WMTS.prototype.set);
  78208. goog.exportProperty(
  78209. ol.source.WMTS.prototype,
  78210. 'setProperties',
  78211. ol.source.WMTS.prototype.setProperties);
  78212. goog.exportProperty(
  78213. ol.source.WMTS.prototype,
  78214. 'unset',
  78215. ol.source.WMTS.prototype.unset);
  78216. goog.exportProperty(
  78217. ol.source.WMTS.prototype,
  78218. 'changed',
  78219. ol.source.WMTS.prototype.changed);
  78220. goog.exportProperty(
  78221. ol.source.WMTS.prototype,
  78222. 'dispatchEvent',
  78223. ol.source.WMTS.prototype.dispatchEvent);
  78224. goog.exportProperty(
  78225. ol.source.WMTS.prototype,
  78226. 'getRevision',
  78227. ol.source.WMTS.prototype.getRevision);
  78228. goog.exportProperty(
  78229. ol.source.WMTS.prototype,
  78230. 'on',
  78231. ol.source.WMTS.prototype.on);
  78232. goog.exportProperty(
  78233. ol.source.WMTS.prototype,
  78234. 'once',
  78235. ol.source.WMTS.prototype.once);
  78236. goog.exportProperty(
  78237. ol.source.WMTS.prototype,
  78238. 'un',
  78239. ol.source.WMTS.prototype.un);
  78240. goog.exportProperty(
  78241. ol.source.Zoomify.prototype,
  78242. 'setRenderReprojectionEdges',
  78243. ol.source.Zoomify.prototype.setRenderReprojectionEdges);
  78244. goog.exportProperty(
  78245. ol.source.Zoomify.prototype,
  78246. 'setTileGridForProjection',
  78247. ol.source.Zoomify.prototype.setTileGridForProjection);
  78248. goog.exportProperty(
  78249. ol.source.Zoomify.prototype,
  78250. 'getTileLoadFunction',
  78251. ol.source.Zoomify.prototype.getTileLoadFunction);
  78252. goog.exportProperty(
  78253. ol.source.Zoomify.prototype,
  78254. 'getTileUrlFunction',
  78255. ol.source.Zoomify.prototype.getTileUrlFunction);
  78256. goog.exportProperty(
  78257. ol.source.Zoomify.prototype,
  78258. 'getUrls',
  78259. ol.source.Zoomify.prototype.getUrls);
  78260. goog.exportProperty(
  78261. ol.source.Zoomify.prototype,
  78262. 'setTileLoadFunction',
  78263. ol.source.Zoomify.prototype.setTileLoadFunction);
  78264. goog.exportProperty(
  78265. ol.source.Zoomify.prototype,
  78266. 'setTileUrlFunction',
  78267. ol.source.Zoomify.prototype.setTileUrlFunction);
  78268. goog.exportProperty(
  78269. ol.source.Zoomify.prototype,
  78270. 'setUrl',
  78271. ol.source.Zoomify.prototype.setUrl);
  78272. goog.exportProperty(
  78273. ol.source.Zoomify.prototype,
  78274. 'setUrls',
  78275. ol.source.Zoomify.prototype.setUrls);
  78276. goog.exportProperty(
  78277. ol.source.Zoomify.prototype,
  78278. 'getTileGrid',
  78279. ol.source.Zoomify.prototype.getTileGrid);
  78280. goog.exportProperty(
  78281. ol.source.Zoomify.prototype,
  78282. 'refresh',
  78283. ol.source.Zoomify.prototype.refresh);
  78284. goog.exportProperty(
  78285. ol.source.Zoomify.prototype,
  78286. 'getAttributions',
  78287. ol.source.Zoomify.prototype.getAttributions);
  78288. goog.exportProperty(
  78289. ol.source.Zoomify.prototype,
  78290. 'getLogo',
  78291. ol.source.Zoomify.prototype.getLogo);
  78292. goog.exportProperty(
  78293. ol.source.Zoomify.prototype,
  78294. 'getProjection',
  78295. ol.source.Zoomify.prototype.getProjection);
  78296. goog.exportProperty(
  78297. ol.source.Zoomify.prototype,
  78298. 'getState',
  78299. ol.source.Zoomify.prototype.getState);
  78300. goog.exportProperty(
  78301. ol.source.Zoomify.prototype,
  78302. 'setAttributions',
  78303. ol.source.Zoomify.prototype.setAttributions);
  78304. goog.exportProperty(
  78305. ol.source.Zoomify.prototype,
  78306. 'get',
  78307. ol.source.Zoomify.prototype.get);
  78308. goog.exportProperty(
  78309. ol.source.Zoomify.prototype,
  78310. 'getKeys',
  78311. ol.source.Zoomify.prototype.getKeys);
  78312. goog.exportProperty(
  78313. ol.source.Zoomify.prototype,
  78314. 'getProperties',
  78315. ol.source.Zoomify.prototype.getProperties);
  78316. goog.exportProperty(
  78317. ol.source.Zoomify.prototype,
  78318. 'set',
  78319. ol.source.Zoomify.prototype.set);
  78320. goog.exportProperty(
  78321. ol.source.Zoomify.prototype,
  78322. 'setProperties',
  78323. ol.source.Zoomify.prototype.setProperties);
  78324. goog.exportProperty(
  78325. ol.source.Zoomify.prototype,
  78326. 'unset',
  78327. ol.source.Zoomify.prototype.unset);
  78328. goog.exportProperty(
  78329. ol.source.Zoomify.prototype,
  78330. 'changed',
  78331. ol.source.Zoomify.prototype.changed);
  78332. goog.exportProperty(
  78333. ol.source.Zoomify.prototype,
  78334. 'dispatchEvent',
  78335. ol.source.Zoomify.prototype.dispatchEvent);
  78336. goog.exportProperty(
  78337. ol.source.Zoomify.prototype,
  78338. 'getRevision',
  78339. ol.source.Zoomify.prototype.getRevision);
  78340. goog.exportProperty(
  78341. ol.source.Zoomify.prototype,
  78342. 'on',
  78343. ol.source.Zoomify.prototype.on);
  78344. goog.exportProperty(
  78345. ol.source.Zoomify.prototype,
  78346. 'once',
  78347. ol.source.Zoomify.prototype.once);
  78348. goog.exportProperty(
  78349. ol.source.Zoomify.prototype,
  78350. 'un',
  78351. ol.source.Zoomify.prototype.un);
  78352. goog.exportProperty(
  78353. ol.reproj.Tile.prototype,
  78354. 'getTileCoord',
  78355. ol.reproj.Tile.prototype.getTileCoord);
  78356. goog.exportProperty(
  78357. ol.reproj.Tile.prototype,
  78358. 'load',
  78359. ol.reproj.Tile.prototype.load);
  78360. goog.exportProperty(
  78361. ol.renderer.Layer.prototype,
  78362. 'changed',
  78363. ol.renderer.Layer.prototype.changed);
  78364. goog.exportProperty(
  78365. ol.renderer.Layer.prototype,
  78366. 'dispatchEvent',
  78367. ol.renderer.Layer.prototype.dispatchEvent);
  78368. goog.exportProperty(
  78369. ol.renderer.Layer.prototype,
  78370. 'getRevision',
  78371. ol.renderer.Layer.prototype.getRevision);
  78372. goog.exportProperty(
  78373. ol.renderer.Layer.prototype,
  78374. 'on',
  78375. ol.renderer.Layer.prototype.on);
  78376. goog.exportProperty(
  78377. ol.renderer.Layer.prototype,
  78378. 'once',
  78379. ol.renderer.Layer.prototype.once);
  78380. goog.exportProperty(
  78381. ol.renderer.Layer.prototype,
  78382. 'un',
  78383. ol.renderer.Layer.prototype.un);
  78384. goog.exportProperty(
  78385. ol.renderer.webgl.Layer.prototype,
  78386. 'changed',
  78387. ol.renderer.webgl.Layer.prototype.changed);
  78388. goog.exportProperty(
  78389. ol.renderer.webgl.Layer.prototype,
  78390. 'dispatchEvent',
  78391. ol.renderer.webgl.Layer.prototype.dispatchEvent);
  78392. goog.exportProperty(
  78393. ol.renderer.webgl.Layer.prototype,
  78394. 'getRevision',
  78395. ol.renderer.webgl.Layer.prototype.getRevision);
  78396. goog.exportProperty(
  78397. ol.renderer.webgl.Layer.prototype,
  78398. 'on',
  78399. ol.renderer.webgl.Layer.prototype.on);
  78400. goog.exportProperty(
  78401. ol.renderer.webgl.Layer.prototype,
  78402. 'once',
  78403. ol.renderer.webgl.Layer.prototype.once);
  78404. goog.exportProperty(
  78405. ol.renderer.webgl.Layer.prototype,
  78406. 'un',
  78407. ol.renderer.webgl.Layer.prototype.un);
  78408. goog.exportProperty(
  78409. ol.renderer.webgl.ImageLayer.prototype,
  78410. 'changed',
  78411. ol.renderer.webgl.ImageLayer.prototype.changed);
  78412. goog.exportProperty(
  78413. ol.renderer.webgl.ImageLayer.prototype,
  78414. 'dispatchEvent',
  78415. ol.renderer.webgl.ImageLayer.prototype.dispatchEvent);
  78416. goog.exportProperty(
  78417. ol.renderer.webgl.ImageLayer.prototype,
  78418. 'getRevision',
  78419. ol.renderer.webgl.ImageLayer.prototype.getRevision);
  78420. goog.exportProperty(
  78421. ol.renderer.webgl.ImageLayer.prototype,
  78422. 'on',
  78423. ol.renderer.webgl.ImageLayer.prototype.on);
  78424. goog.exportProperty(
  78425. ol.renderer.webgl.ImageLayer.prototype,
  78426. 'once',
  78427. ol.renderer.webgl.ImageLayer.prototype.once);
  78428. goog.exportProperty(
  78429. ol.renderer.webgl.ImageLayer.prototype,
  78430. 'un',
  78431. ol.renderer.webgl.ImageLayer.prototype.un);
  78432. goog.exportProperty(
  78433. ol.renderer.webgl.TileLayer.prototype,
  78434. 'changed',
  78435. ol.renderer.webgl.TileLayer.prototype.changed);
  78436. goog.exportProperty(
  78437. ol.renderer.webgl.TileLayer.prototype,
  78438. 'dispatchEvent',
  78439. ol.renderer.webgl.TileLayer.prototype.dispatchEvent);
  78440. goog.exportProperty(
  78441. ol.renderer.webgl.TileLayer.prototype,
  78442. 'getRevision',
  78443. ol.renderer.webgl.TileLayer.prototype.getRevision);
  78444. goog.exportProperty(
  78445. ol.renderer.webgl.TileLayer.prototype,
  78446. 'on',
  78447. ol.renderer.webgl.TileLayer.prototype.on);
  78448. goog.exportProperty(
  78449. ol.renderer.webgl.TileLayer.prototype,
  78450. 'once',
  78451. ol.renderer.webgl.TileLayer.prototype.once);
  78452. goog.exportProperty(
  78453. ol.renderer.webgl.TileLayer.prototype,
  78454. 'un',
  78455. ol.renderer.webgl.TileLayer.prototype.un);
  78456. goog.exportProperty(
  78457. ol.renderer.webgl.VectorLayer.prototype,
  78458. 'changed',
  78459. ol.renderer.webgl.VectorLayer.prototype.changed);
  78460. goog.exportProperty(
  78461. ol.renderer.webgl.VectorLayer.prototype,
  78462. 'dispatchEvent',
  78463. ol.renderer.webgl.VectorLayer.prototype.dispatchEvent);
  78464. goog.exportProperty(
  78465. ol.renderer.webgl.VectorLayer.prototype,
  78466. 'getRevision',
  78467. ol.renderer.webgl.VectorLayer.prototype.getRevision);
  78468. goog.exportProperty(
  78469. ol.renderer.webgl.VectorLayer.prototype,
  78470. 'on',
  78471. ol.renderer.webgl.VectorLayer.prototype.on);
  78472. goog.exportProperty(
  78473. ol.renderer.webgl.VectorLayer.prototype,
  78474. 'once',
  78475. ol.renderer.webgl.VectorLayer.prototype.once);
  78476. goog.exportProperty(
  78477. ol.renderer.webgl.VectorLayer.prototype,
  78478. 'un',
  78479. ol.renderer.webgl.VectorLayer.prototype.un);
  78480. goog.exportProperty(
  78481. ol.renderer.canvas.Layer.prototype,
  78482. 'changed',
  78483. ol.renderer.canvas.Layer.prototype.changed);
  78484. goog.exportProperty(
  78485. ol.renderer.canvas.Layer.prototype,
  78486. 'dispatchEvent',
  78487. ol.renderer.canvas.Layer.prototype.dispatchEvent);
  78488. goog.exportProperty(
  78489. ol.renderer.canvas.Layer.prototype,
  78490. 'getRevision',
  78491. ol.renderer.canvas.Layer.prototype.getRevision);
  78492. goog.exportProperty(
  78493. ol.renderer.canvas.Layer.prototype,
  78494. 'on',
  78495. ol.renderer.canvas.Layer.prototype.on);
  78496. goog.exportProperty(
  78497. ol.renderer.canvas.Layer.prototype,
  78498. 'once',
  78499. ol.renderer.canvas.Layer.prototype.once);
  78500. goog.exportProperty(
  78501. ol.renderer.canvas.Layer.prototype,
  78502. 'un',
  78503. ol.renderer.canvas.Layer.prototype.un);
  78504. goog.exportProperty(
  78505. ol.renderer.canvas.IntermediateCanvas.prototype,
  78506. 'changed',
  78507. ol.renderer.canvas.IntermediateCanvas.prototype.changed);
  78508. goog.exportProperty(
  78509. ol.renderer.canvas.IntermediateCanvas.prototype,
  78510. 'dispatchEvent',
  78511. ol.renderer.canvas.IntermediateCanvas.prototype.dispatchEvent);
  78512. goog.exportProperty(
  78513. ol.renderer.canvas.IntermediateCanvas.prototype,
  78514. 'getRevision',
  78515. ol.renderer.canvas.IntermediateCanvas.prototype.getRevision);
  78516. goog.exportProperty(
  78517. ol.renderer.canvas.IntermediateCanvas.prototype,
  78518. 'on',
  78519. ol.renderer.canvas.IntermediateCanvas.prototype.on);
  78520. goog.exportProperty(
  78521. ol.renderer.canvas.IntermediateCanvas.prototype,
  78522. 'once',
  78523. ol.renderer.canvas.IntermediateCanvas.prototype.once);
  78524. goog.exportProperty(
  78525. ol.renderer.canvas.IntermediateCanvas.prototype,
  78526. 'un',
  78527. ol.renderer.canvas.IntermediateCanvas.prototype.un);
  78528. goog.exportProperty(
  78529. ol.renderer.canvas.ImageLayer.prototype,
  78530. 'changed',
  78531. ol.renderer.canvas.ImageLayer.prototype.changed);
  78532. goog.exportProperty(
  78533. ol.renderer.canvas.ImageLayer.prototype,
  78534. 'dispatchEvent',
  78535. ol.renderer.canvas.ImageLayer.prototype.dispatchEvent);
  78536. goog.exportProperty(
  78537. ol.renderer.canvas.ImageLayer.prototype,
  78538. 'getRevision',
  78539. ol.renderer.canvas.ImageLayer.prototype.getRevision);
  78540. goog.exportProperty(
  78541. ol.renderer.canvas.ImageLayer.prototype,
  78542. 'on',
  78543. ol.renderer.canvas.ImageLayer.prototype.on);
  78544. goog.exportProperty(
  78545. ol.renderer.canvas.ImageLayer.prototype,
  78546. 'once',
  78547. ol.renderer.canvas.ImageLayer.prototype.once);
  78548. goog.exportProperty(
  78549. ol.renderer.canvas.ImageLayer.prototype,
  78550. 'un',
  78551. ol.renderer.canvas.ImageLayer.prototype.un);
  78552. goog.exportProperty(
  78553. ol.renderer.canvas.TileLayer.prototype,
  78554. 'changed',
  78555. ol.renderer.canvas.TileLayer.prototype.changed);
  78556. goog.exportProperty(
  78557. ol.renderer.canvas.TileLayer.prototype,
  78558. 'dispatchEvent',
  78559. ol.renderer.canvas.TileLayer.prototype.dispatchEvent);
  78560. goog.exportProperty(
  78561. ol.renderer.canvas.TileLayer.prototype,
  78562. 'getRevision',
  78563. ol.renderer.canvas.TileLayer.prototype.getRevision);
  78564. goog.exportProperty(
  78565. ol.renderer.canvas.TileLayer.prototype,
  78566. 'on',
  78567. ol.renderer.canvas.TileLayer.prototype.on);
  78568. goog.exportProperty(
  78569. ol.renderer.canvas.TileLayer.prototype,
  78570. 'once',
  78571. ol.renderer.canvas.TileLayer.prototype.once);
  78572. goog.exportProperty(
  78573. ol.renderer.canvas.TileLayer.prototype,
  78574. 'un',
  78575. ol.renderer.canvas.TileLayer.prototype.un);
  78576. goog.exportProperty(
  78577. ol.renderer.canvas.VectorLayer.prototype,
  78578. 'changed',
  78579. ol.renderer.canvas.VectorLayer.prototype.changed);
  78580. goog.exportProperty(
  78581. ol.renderer.canvas.VectorLayer.prototype,
  78582. 'dispatchEvent',
  78583. ol.renderer.canvas.VectorLayer.prototype.dispatchEvent);
  78584. goog.exportProperty(
  78585. ol.renderer.canvas.VectorLayer.prototype,
  78586. 'getRevision',
  78587. ol.renderer.canvas.VectorLayer.prototype.getRevision);
  78588. goog.exportProperty(
  78589. ol.renderer.canvas.VectorLayer.prototype,
  78590. 'on',
  78591. ol.renderer.canvas.VectorLayer.prototype.on);
  78592. goog.exportProperty(
  78593. ol.renderer.canvas.VectorLayer.prototype,
  78594. 'once',
  78595. ol.renderer.canvas.VectorLayer.prototype.once);
  78596. goog.exportProperty(
  78597. ol.renderer.canvas.VectorLayer.prototype,
  78598. 'un',
  78599. ol.renderer.canvas.VectorLayer.prototype.un);
  78600. goog.exportProperty(
  78601. ol.renderer.canvas.VectorTileLayer.prototype,
  78602. 'changed',
  78603. ol.renderer.canvas.VectorTileLayer.prototype.changed);
  78604. goog.exportProperty(
  78605. ol.renderer.canvas.VectorTileLayer.prototype,
  78606. 'dispatchEvent',
  78607. ol.renderer.canvas.VectorTileLayer.prototype.dispatchEvent);
  78608. goog.exportProperty(
  78609. ol.renderer.canvas.VectorTileLayer.prototype,
  78610. 'getRevision',
  78611. ol.renderer.canvas.VectorTileLayer.prototype.getRevision);
  78612. goog.exportProperty(
  78613. ol.renderer.canvas.VectorTileLayer.prototype,
  78614. 'on',
  78615. ol.renderer.canvas.VectorTileLayer.prototype.on);
  78616. goog.exportProperty(
  78617. ol.renderer.canvas.VectorTileLayer.prototype,
  78618. 'once',
  78619. ol.renderer.canvas.VectorTileLayer.prototype.once);
  78620. goog.exportProperty(
  78621. ol.renderer.canvas.VectorTileLayer.prototype,
  78622. 'un',
  78623. ol.renderer.canvas.VectorTileLayer.prototype.un);
  78624. goog.exportProperty(
  78625. ol.render.Event.prototype,
  78626. 'type',
  78627. ol.render.Event.prototype.type);
  78628. goog.exportProperty(
  78629. ol.render.Event.prototype,
  78630. 'target',
  78631. ol.render.Event.prototype.target);
  78632. goog.exportProperty(
  78633. ol.render.Event.prototype,
  78634. 'preventDefault',
  78635. ol.render.Event.prototype.preventDefault);
  78636. goog.exportProperty(
  78637. ol.render.Event.prototype,
  78638. 'stopPropagation',
  78639. ol.render.Event.prototype.stopPropagation);
  78640. goog.exportProperty(
  78641. ol.pointer.PointerEvent.prototype,
  78642. 'type',
  78643. ol.pointer.PointerEvent.prototype.type);
  78644. goog.exportProperty(
  78645. ol.pointer.PointerEvent.prototype,
  78646. 'target',
  78647. ol.pointer.PointerEvent.prototype.target);
  78648. goog.exportProperty(
  78649. ol.pointer.PointerEvent.prototype,
  78650. 'preventDefault',
  78651. ol.pointer.PointerEvent.prototype.preventDefault);
  78652. goog.exportProperty(
  78653. ol.pointer.PointerEvent.prototype,
  78654. 'stopPropagation',
  78655. ol.pointer.PointerEvent.prototype.stopPropagation);
  78656. goog.exportProperty(
  78657. ol.layer.Base.prototype,
  78658. 'get',
  78659. ol.layer.Base.prototype.get);
  78660. goog.exportProperty(
  78661. ol.layer.Base.prototype,
  78662. 'getKeys',
  78663. ol.layer.Base.prototype.getKeys);
  78664. goog.exportProperty(
  78665. ol.layer.Base.prototype,
  78666. 'getProperties',
  78667. ol.layer.Base.prototype.getProperties);
  78668. goog.exportProperty(
  78669. ol.layer.Base.prototype,
  78670. 'set',
  78671. ol.layer.Base.prototype.set);
  78672. goog.exportProperty(
  78673. ol.layer.Base.prototype,
  78674. 'setProperties',
  78675. ol.layer.Base.prototype.setProperties);
  78676. goog.exportProperty(
  78677. ol.layer.Base.prototype,
  78678. 'unset',
  78679. ol.layer.Base.prototype.unset);
  78680. goog.exportProperty(
  78681. ol.layer.Base.prototype,
  78682. 'changed',
  78683. ol.layer.Base.prototype.changed);
  78684. goog.exportProperty(
  78685. ol.layer.Base.prototype,
  78686. 'dispatchEvent',
  78687. ol.layer.Base.prototype.dispatchEvent);
  78688. goog.exportProperty(
  78689. ol.layer.Base.prototype,
  78690. 'getRevision',
  78691. ol.layer.Base.prototype.getRevision);
  78692. goog.exportProperty(
  78693. ol.layer.Base.prototype,
  78694. 'on',
  78695. ol.layer.Base.prototype.on);
  78696. goog.exportProperty(
  78697. ol.layer.Base.prototype,
  78698. 'once',
  78699. ol.layer.Base.prototype.once);
  78700. goog.exportProperty(
  78701. ol.layer.Base.prototype,
  78702. 'un',
  78703. ol.layer.Base.prototype.un);
  78704. goog.exportProperty(
  78705. ol.layer.Group.prototype,
  78706. 'getExtent',
  78707. ol.layer.Group.prototype.getExtent);
  78708. goog.exportProperty(
  78709. ol.layer.Group.prototype,
  78710. 'getMaxResolution',
  78711. ol.layer.Group.prototype.getMaxResolution);
  78712. goog.exportProperty(
  78713. ol.layer.Group.prototype,
  78714. 'getMinResolution',
  78715. ol.layer.Group.prototype.getMinResolution);
  78716. goog.exportProperty(
  78717. ol.layer.Group.prototype,
  78718. 'getOpacity',
  78719. ol.layer.Group.prototype.getOpacity);
  78720. goog.exportProperty(
  78721. ol.layer.Group.prototype,
  78722. 'getVisible',
  78723. ol.layer.Group.prototype.getVisible);
  78724. goog.exportProperty(
  78725. ol.layer.Group.prototype,
  78726. 'getZIndex',
  78727. ol.layer.Group.prototype.getZIndex);
  78728. goog.exportProperty(
  78729. ol.layer.Group.prototype,
  78730. 'setExtent',
  78731. ol.layer.Group.prototype.setExtent);
  78732. goog.exportProperty(
  78733. ol.layer.Group.prototype,
  78734. 'setMaxResolution',
  78735. ol.layer.Group.prototype.setMaxResolution);
  78736. goog.exportProperty(
  78737. ol.layer.Group.prototype,
  78738. 'setMinResolution',
  78739. ol.layer.Group.prototype.setMinResolution);
  78740. goog.exportProperty(
  78741. ol.layer.Group.prototype,
  78742. 'setOpacity',
  78743. ol.layer.Group.prototype.setOpacity);
  78744. goog.exportProperty(
  78745. ol.layer.Group.prototype,
  78746. 'setVisible',
  78747. ol.layer.Group.prototype.setVisible);
  78748. goog.exportProperty(
  78749. ol.layer.Group.prototype,
  78750. 'setZIndex',
  78751. ol.layer.Group.prototype.setZIndex);
  78752. goog.exportProperty(
  78753. ol.layer.Group.prototype,
  78754. 'get',
  78755. ol.layer.Group.prototype.get);
  78756. goog.exportProperty(
  78757. ol.layer.Group.prototype,
  78758. 'getKeys',
  78759. ol.layer.Group.prototype.getKeys);
  78760. goog.exportProperty(
  78761. ol.layer.Group.prototype,
  78762. 'getProperties',
  78763. ol.layer.Group.prototype.getProperties);
  78764. goog.exportProperty(
  78765. ol.layer.Group.prototype,
  78766. 'set',
  78767. ol.layer.Group.prototype.set);
  78768. goog.exportProperty(
  78769. ol.layer.Group.prototype,
  78770. 'setProperties',
  78771. ol.layer.Group.prototype.setProperties);
  78772. goog.exportProperty(
  78773. ol.layer.Group.prototype,
  78774. 'unset',
  78775. ol.layer.Group.prototype.unset);
  78776. goog.exportProperty(
  78777. ol.layer.Group.prototype,
  78778. 'changed',
  78779. ol.layer.Group.prototype.changed);
  78780. goog.exportProperty(
  78781. ol.layer.Group.prototype,
  78782. 'dispatchEvent',
  78783. ol.layer.Group.prototype.dispatchEvent);
  78784. goog.exportProperty(
  78785. ol.layer.Group.prototype,
  78786. 'getRevision',
  78787. ol.layer.Group.prototype.getRevision);
  78788. goog.exportProperty(
  78789. ol.layer.Group.prototype,
  78790. 'on',
  78791. ol.layer.Group.prototype.on);
  78792. goog.exportProperty(
  78793. ol.layer.Group.prototype,
  78794. 'once',
  78795. ol.layer.Group.prototype.once);
  78796. goog.exportProperty(
  78797. ol.layer.Group.prototype,
  78798. 'un',
  78799. ol.layer.Group.prototype.un);
  78800. goog.exportProperty(
  78801. ol.layer.Layer.prototype,
  78802. 'getExtent',
  78803. ol.layer.Layer.prototype.getExtent);
  78804. goog.exportProperty(
  78805. ol.layer.Layer.prototype,
  78806. 'getMaxResolution',
  78807. ol.layer.Layer.prototype.getMaxResolution);
  78808. goog.exportProperty(
  78809. ol.layer.Layer.prototype,
  78810. 'getMinResolution',
  78811. ol.layer.Layer.prototype.getMinResolution);
  78812. goog.exportProperty(
  78813. ol.layer.Layer.prototype,
  78814. 'getOpacity',
  78815. ol.layer.Layer.prototype.getOpacity);
  78816. goog.exportProperty(
  78817. ol.layer.Layer.prototype,
  78818. 'getVisible',
  78819. ol.layer.Layer.prototype.getVisible);
  78820. goog.exportProperty(
  78821. ol.layer.Layer.prototype,
  78822. 'getZIndex',
  78823. ol.layer.Layer.prototype.getZIndex);
  78824. goog.exportProperty(
  78825. ol.layer.Layer.prototype,
  78826. 'setExtent',
  78827. ol.layer.Layer.prototype.setExtent);
  78828. goog.exportProperty(
  78829. ol.layer.Layer.prototype,
  78830. 'setMaxResolution',
  78831. ol.layer.Layer.prototype.setMaxResolution);
  78832. goog.exportProperty(
  78833. ol.layer.Layer.prototype,
  78834. 'setMinResolution',
  78835. ol.layer.Layer.prototype.setMinResolution);
  78836. goog.exportProperty(
  78837. ol.layer.Layer.prototype,
  78838. 'setOpacity',
  78839. ol.layer.Layer.prototype.setOpacity);
  78840. goog.exportProperty(
  78841. ol.layer.Layer.prototype,
  78842. 'setVisible',
  78843. ol.layer.Layer.prototype.setVisible);
  78844. goog.exportProperty(
  78845. ol.layer.Layer.prototype,
  78846. 'setZIndex',
  78847. ol.layer.Layer.prototype.setZIndex);
  78848. goog.exportProperty(
  78849. ol.layer.Layer.prototype,
  78850. 'get',
  78851. ol.layer.Layer.prototype.get);
  78852. goog.exportProperty(
  78853. ol.layer.Layer.prototype,
  78854. 'getKeys',
  78855. ol.layer.Layer.prototype.getKeys);
  78856. goog.exportProperty(
  78857. ol.layer.Layer.prototype,
  78858. 'getProperties',
  78859. ol.layer.Layer.prototype.getProperties);
  78860. goog.exportProperty(
  78861. ol.layer.Layer.prototype,
  78862. 'set',
  78863. ol.layer.Layer.prototype.set);
  78864. goog.exportProperty(
  78865. ol.layer.Layer.prototype,
  78866. 'setProperties',
  78867. ol.layer.Layer.prototype.setProperties);
  78868. goog.exportProperty(
  78869. ol.layer.Layer.prototype,
  78870. 'unset',
  78871. ol.layer.Layer.prototype.unset);
  78872. goog.exportProperty(
  78873. ol.layer.Layer.prototype,
  78874. 'changed',
  78875. ol.layer.Layer.prototype.changed);
  78876. goog.exportProperty(
  78877. ol.layer.Layer.prototype,
  78878. 'dispatchEvent',
  78879. ol.layer.Layer.prototype.dispatchEvent);
  78880. goog.exportProperty(
  78881. ol.layer.Layer.prototype,
  78882. 'getRevision',
  78883. ol.layer.Layer.prototype.getRevision);
  78884. goog.exportProperty(
  78885. ol.layer.Layer.prototype,
  78886. 'on',
  78887. ol.layer.Layer.prototype.on);
  78888. goog.exportProperty(
  78889. ol.layer.Layer.prototype,
  78890. 'once',
  78891. ol.layer.Layer.prototype.once);
  78892. goog.exportProperty(
  78893. ol.layer.Layer.prototype,
  78894. 'un',
  78895. ol.layer.Layer.prototype.un);
  78896. goog.exportProperty(
  78897. ol.layer.Vector.prototype,
  78898. 'setMap',
  78899. ol.layer.Vector.prototype.setMap);
  78900. goog.exportProperty(
  78901. ol.layer.Vector.prototype,
  78902. 'setSource',
  78903. ol.layer.Vector.prototype.setSource);
  78904. goog.exportProperty(
  78905. ol.layer.Vector.prototype,
  78906. 'getExtent',
  78907. ol.layer.Vector.prototype.getExtent);
  78908. goog.exportProperty(
  78909. ol.layer.Vector.prototype,
  78910. 'getMaxResolution',
  78911. ol.layer.Vector.prototype.getMaxResolution);
  78912. goog.exportProperty(
  78913. ol.layer.Vector.prototype,
  78914. 'getMinResolution',
  78915. ol.layer.Vector.prototype.getMinResolution);
  78916. goog.exportProperty(
  78917. ol.layer.Vector.prototype,
  78918. 'getOpacity',
  78919. ol.layer.Vector.prototype.getOpacity);
  78920. goog.exportProperty(
  78921. ol.layer.Vector.prototype,
  78922. 'getVisible',
  78923. ol.layer.Vector.prototype.getVisible);
  78924. goog.exportProperty(
  78925. ol.layer.Vector.prototype,
  78926. 'getZIndex',
  78927. ol.layer.Vector.prototype.getZIndex);
  78928. goog.exportProperty(
  78929. ol.layer.Vector.prototype,
  78930. 'setExtent',
  78931. ol.layer.Vector.prototype.setExtent);
  78932. goog.exportProperty(
  78933. ol.layer.Vector.prototype,
  78934. 'setMaxResolution',
  78935. ol.layer.Vector.prototype.setMaxResolution);
  78936. goog.exportProperty(
  78937. ol.layer.Vector.prototype,
  78938. 'setMinResolution',
  78939. ol.layer.Vector.prototype.setMinResolution);
  78940. goog.exportProperty(
  78941. ol.layer.Vector.prototype,
  78942. 'setOpacity',
  78943. ol.layer.Vector.prototype.setOpacity);
  78944. goog.exportProperty(
  78945. ol.layer.Vector.prototype,
  78946. 'setVisible',
  78947. ol.layer.Vector.prototype.setVisible);
  78948. goog.exportProperty(
  78949. ol.layer.Vector.prototype,
  78950. 'setZIndex',
  78951. ol.layer.Vector.prototype.setZIndex);
  78952. goog.exportProperty(
  78953. ol.layer.Vector.prototype,
  78954. 'get',
  78955. ol.layer.Vector.prototype.get);
  78956. goog.exportProperty(
  78957. ol.layer.Vector.prototype,
  78958. 'getKeys',
  78959. ol.layer.Vector.prototype.getKeys);
  78960. goog.exportProperty(
  78961. ol.layer.Vector.prototype,
  78962. 'getProperties',
  78963. ol.layer.Vector.prototype.getProperties);
  78964. goog.exportProperty(
  78965. ol.layer.Vector.prototype,
  78966. 'set',
  78967. ol.layer.Vector.prototype.set);
  78968. goog.exportProperty(
  78969. ol.layer.Vector.prototype,
  78970. 'setProperties',
  78971. ol.layer.Vector.prototype.setProperties);
  78972. goog.exportProperty(
  78973. ol.layer.Vector.prototype,
  78974. 'unset',
  78975. ol.layer.Vector.prototype.unset);
  78976. goog.exportProperty(
  78977. ol.layer.Vector.prototype,
  78978. 'changed',
  78979. ol.layer.Vector.prototype.changed);
  78980. goog.exportProperty(
  78981. ol.layer.Vector.prototype,
  78982. 'dispatchEvent',
  78983. ol.layer.Vector.prototype.dispatchEvent);
  78984. goog.exportProperty(
  78985. ol.layer.Vector.prototype,
  78986. 'getRevision',
  78987. ol.layer.Vector.prototype.getRevision);
  78988. goog.exportProperty(
  78989. ol.layer.Vector.prototype,
  78990. 'on',
  78991. ol.layer.Vector.prototype.on);
  78992. goog.exportProperty(
  78993. ol.layer.Vector.prototype,
  78994. 'once',
  78995. ol.layer.Vector.prototype.once);
  78996. goog.exportProperty(
  78997. ol.layer.Vector.prototype,
  78998. 'un',
  78999. ol.layer.Vector.prototype.un);
  79000. goog.exportProperty(
  79001. ol.layer.Heatmap.prototype,
  79002. 'getSource',
  79003. ol.layer.Heatmap.prototype.getSource);
  79004. goog.exportProperty(
  79005. ol.layer.Heatmap.prototype,
  79006. 'getStyle',
  79007. ol.layer.Heatmap.prototype.getStyle);
  79008. goog.exportProperty(
  79009. ol.layer.Heatmap.prototype,
  79010. 'getStyleFunction',
  79011. ol.layer.Heatmap.prototype.getStyleFunction);
  79012. goog.exportProperty(
  79013. ol.layer.Heatmap.prototype,
  79014. 'setStyle',
  79015. ol.layer.Heatmap.prototype.setStyle);
  79016. goog.exportProperty(
  79017. ol.layer.Heatmap.prototype,
  79018. 'setMap',
  79019. ol.layer.Heatmap.prototype.setMap);
  79020. goog.exportProperty(
  79021. ol.layer.Heatmap.prototype,
  79022. 'setSource',
  79023. ol.layer.Heatmap.prototype.setSource);
  79024. goog.exportProperty(
  79025. ol.layer.Heatmap.prototype,
  79026. 'getExtent',
  79027. ol.layer.Heatmap.prototype.getExtent);
  79028. goog.exportProperty(
  79029. ol.layer.Heatmap.prototype,
  79030. 'getMaxResolution',
  79031. ol.layer.Heatmap.prototype.getMaxResolution);
  79032. goog.exportProperty(
  79033. ol.layer.Heatmap.prototype,
  79034. 'getMinResolution',
  79035. ol.layer.Heatmap.prototype.getMinResolution);
  79036. goog.exportProperty(
  79037. ol.layer.Heatmap.prototype,
  79038. 'getOpacity',
  79039. ol.layer.Heatmap.prototype.getOpacity);
  79040. goog.exportProperty(
  79041. ol.layer.Heatmap.prototype,
  79042. 'getVisible',
  79043. ol.layer.Heatmap.prototype.getVisible);
  79044. goog.exportProperty(
  79045. ol.layer.Heatmap.prototype,
  79046. 'getZIndex',
  79047. ol.layer.Heatmap.prototype.getZIndex);
  79048. goog.exportProperty(
  79049. ol.layer.Heatmap.prototype,
  79050. 'setExtent',
  79051. ol.layer.Heatmap.prototype.setExtent);
  79052. goog.exportProperty(
  79053. ol.layer.Heatmap.prototype,
  79054. 'setMaxResolution',
  79055. ol.layer.Heatmap.prototype.setMaxResolution);
  79056. goog.exportProperty(
  79057. ol.layer.Heatmap.prototype,
  79058. 'setMinResolution',
  79059. ol.layer.Heatmap.prototype.setMinResolution);
  79060. goog.exportProperty(
  79061. ol.layer.Heatmap.prototype,
  79062. 'setOpacity',
  79063. ol.layer.Heatmap.prototype.setOpacity);
  79064. goog.exportProperty(
  79065. ol.layer.Heatmap.prototype,
  79066. 'setVisible',
  79067. ol.layer.Heatmap.prototype.setVisible);
  79068. goog.exportProperty(
  79069. ol.layer.Heatmap.prototype,
  79070. 'setZIndex',
  79071. ol.layer.Heatmap.prototype.setZIndex);
  79072. goog.exportProperty(
  79073. ol.layer.Heatmap.prototype,
  79074. 'get',
  79075. ol.layer.Heatmap.prototype.get);
  79076. goog.exportProperty(
  79077. ol.layer.Heatmap.prototype,
  79078. 'getKeys',
  79079. ol.layer.Heatmap.prototype.getKeys);
  79080. goog.exportProperty(
  79081. ol.layer.Heatmap.prototype,
  79082. 'getProperties',
  79083. ol.layer.Heatmap.prototype.getProperties);
  79084. goog.exportProperty(
  79085. ol.layer.Heatmap.prototype,
  79086. 'set',
  79087. ol.layer.Heatmap.prototype.set);
  79088. goog.exportProperty(
  79089. ol.layer.Heatmap.prototype,
  79090. 'setProperties',
  79091. ol.layer.Heatmap.prototype.setProperties);
  79092. goog.exportProperty(
  79093. ol.layer.Heatmap.prototype,
  79094. 'unset',
  79095. ol.layer.Heatmap.prototype.unset);
  79096. goog.exportProperty(
  79097. ol.layer.Heatmap.prototype,
  79098. 'changed',
  79099. ol.layer.Heatmap.prototype.changed);
  79100. goog.exportProperty(
  79101. ol.layer.Heatmap.prototype,
  79102. 'dispatchEvent',
  79103. ol.layer.Heatmap.prototype.dispatchEvent);
  79104. goog.exportProperty(
  79105. ol.layer.Heatmap.prototype,
  79106. 'getRevision',
  79107. ol.layer.Heatmap.prototype.getRevision);
  79108. goog.exportProperty(
  79109. ol.layer.Heatmap.prototype,
  79110. 'on',
  79111. ol.layer.Heatmap.prototype.on);
  79112. goog.exportProperty(
  79113. ol.layer.Heatmap.prototype,
  79114. 'once',
  79115. ol.layer.Heatmap.prototype.once);
  79116. goog.exportProperty(
  79117. ol.layer.Heatmap.prototype,
  79118. 'un',
  79119. ol.layer.Heatmap.prototype.un);
  79120. goog.exportProperty(
  79121. ol.layer.Image.prototype,
  79122. 'setMap',
  79123. ol.layer.Image.prototype.setMap);
  79124. goog.exportProperty(
  79125. ol.layer.Image.prototype,
  79126. 'setSource',
  79127. ol.layer.Image.prototype.setSource);
  79128. goog.exportProperty(
  79129. ol.layer.Image.prototype,
  79130. 'getExtent',
  79131. ol.layer.Image.prototype.getExtent);
  79132. goog.exportProperty(
  79133. ol.layer.Image.prototype,
  79134. 'getMaxResolution',
  79135. ol.layer.Image.prototype.getMaxResolution);
  79136. goog.exportProperty(
  79137. ol.layer.Image.prototype,
  79138. 'getMinResolution',
  79139. ol.layer.Image.prototype.getMinResolution);
  79140. goog.exportProperty(
  79141. ol.layer.Image.prototype,
  79142. 'getOpacity',
  79143. ol.layer.Image.prototype.getOpacity);
  79144. goog.exportProperty(
  79145. ol.layer.Image.prototype,
  79146. 'getVisible',
  79147. ol.layer.Image.prototype.getVisible);
  79148. goog.exportProperty(
  79149. ol.layer.Image.prototype,
  79150. 'getZIndex',
  79151. ol.layer.Image.prototype.getZIndex);
  79152. goog.exportProperty(
  79153. ol.layer.Image.prototype,
  79154. 'setExtent',
  79155. ol.layer.Image.prototype.setExtent);
  79156. goog.exportProperty(
  79157. ol.layer.Image.prototype,
  79158. 'setMaxResolution',
  79159. ol.layer.Image.prototype.setMaxResolution);
  79160. goog.exportProperty(
  79161. ol.layer.Image.prototype,
  79162. 'setMinResolution',
  79163. ol.layer.Image.prototype.setMinResolution);
  79164. goog.exportProperty(
  79165. ol.layer.Image.prototype,
  79166. 'setOpacity',
  79167. ol.layer.Image.prototype.setOpacity);
  79168. goog.exportProperty(
  79169. ol.layer.Image.prototype,
  79170. 'setVisible',
  79171. ol.layer.Image.prototype.setVisible);
  79172. goog.exportProperty(
  79173. ol.layer.Image.prototype,
  79174. 'setZIndex',
  79175. ol.layer.Image.prototype.setZIndex);
  79176. goog.exportProperty(
  79177. ol.layer.Image.prototype,
  79178. 'get',
  79179. ol.layer.Image.prototype.get);
  79180. goog.exportProperty(
  79181. ol.layer.Image.prototype,
  79182. 'getKeys',
  79183. ol.layer.Image.prototype.getKeys);
  79184. goog.exportProperty(
  79185. ol.layer.Image.prototype,
  79186. 'getProperties',
  79187. ol.layer.Image.prototype.getProperties);
  79188. goog.exportProperty(
  79189. ol.layer.Image.prototype,
  79190. 'set',
  79191. ol.layer.Image.prototype.set);
  79192. goog.exportProperty(
  79193. ol.layer.Image.prototype,
  79194. 'setProperties',
  79195. ol.layer.Image.prototype.setProperties);
  79196. goog.exportProperty(
  79197. ol.layer.Image.prototype,
  79198. 'unset',
  79199. ol.layer.Image.prototype.unset);
  79200. goog.exportProperty(
  79201. ol.layer.Image.prototype,
  79202. 'changed',
  79203. ol.layer.Image.prototype.changed);
  79204. goog.exportProperty(
  79205. ol.layer.Image.prototype,
  79206. 'dispatchEvent',
  79207. ol.layer.Image.prototype.dispatchEvent);
  79208. goog.exportProperty(
  79209. ol.layer.Image.prototype,
  79210. 'getRevision',
  79211. ol.layer.Image.prototype.getRevision);
  79212. goog.exportProperty(
  79213. ol.layer.Image.prototype,
  79214. 'on',
  79215. ol.layer.Image.prototype.on);
  79216. goog.exportProperty(
  79217. ol.layer.Image.prototype,
  79218. 'once',
  79219. ol.layer.Image.prototype.once);
  79220. goog.exportProperty(
  79221. ol.layer.Image.prototype,
  79222. 'un',
  79223. ol.layer.Image.prototype.un);
  79224. goog.exportProperty(
  79225. ol.layer.Tile.prototype,
  79226. 'setMap',
  79227. ol.layer.Tile.prototype.setMap);
  79228. goog.exportProperty(
  79229. ol.layer.Tile.prototype,
  79230. 'setSource',
  79231. ol.layer.Tile.prototype.setSource);
  79232. goog.exportProperty(
  79233. ol.layer.Tile.prototype,
  79234. 'getExtent',
  79235. ol.layer.Tile.prototype.getExtent);
  79236. goog.exportProperty(
  79237. ol.layer.Tile.prototype,
  79238. 'getMaxResolution',
  79239. ol.layer.Tile.prototype.getMaxResolution);
  79240. goog.exportProperty(
  79241. ol.layer.Tile.prototype,
  79242. 'getMinResolution',
  79243. ol.layer.Tile.prototype.getMinResolution);
  79244. goog.exportProperty(
  79245. ol.layer.Tile.prototype,
  79246. 'getOpacity',
  79247. ol.layer.Tile.prototype.getOpacity);
  79248. goog.exportProperty(
  79249. ol.layer.Tile.prototype,
  79250. 'getVisible',
  79251. ol.layer.Tile.prototype.getVisible);
  79252. goog.exportProperty(
  79253. ol.layer.Tile.prototype,
  79254. 'getZIndex',
  79255. ol.layer.Tile.prototype.getZIndex);
  79256. goog.exportProperty(
  79257. ol.layer.Tile.prototype,
  79258. 'setExtent',
  79259. ol.layer.Tile.prototype.setExtent);
  79260. goog.exportProperty(
  79261. ol.layer.Tile.prototype,
  79262. 'setMaxResolution',
  79263. ol.layer.Tile.prototype.setMaxResolution);
  79264. goog.exportProperty(
  79265. ol.layer.Tile.prototype,
  79266. 'setMinResolution',
  79267. ol.layer.Tile.prototype.setMinResolution);
  79268. goog.exportProperty(
  79269. ol.layer.Tile.prototype,
  79270. 'setOpacity',
  79271. ol.layer.Tile.prototype.setOpacity);
  79272. goog.exportProperty(
  79273. ol.layer.Tile.prototype,
  79274. 'setVisible',
  79275. ol.layer.Tile.prototype.setVisible);
  79276. goog.exportProperty(
  79277. ol.layer.Tile.prototype,
  79278. 'setZIndex',
  79279. ol.layer.Tile.prototype.setZIndex);
  79280. goog.exportProperty(
  79281. ol.layer.Tile.prototype,
  79282. 'get',
  79283. ol.layer.Tile.prototype.get);
  79284. goog.exportProperty(
  79285. ol.layer.Tile.prototype,
  79286. 'getKeys',
  79287. ol.layer.Tile.prototype.getKeys);
  79288. goog.exportProperty(
  79289. ol.layer.Tile.prototype,
  79290. 'getProperties',
  79291. ol.layer.Tile.prototype.getProperties);
  79292. goog.exportProperty(
  79293. ol.layer.Tile.prototype,
  79294. 'set',
  79295. ol.layer.Tile.prototype.set);
  79296. goog.exportProperty(
  79297. ol.layer.Tile.prototype,
  79298. 'setProperties',
  79299. ol.layer.Tile.prototype.setProperties);
  79300. goog.exportProperty(
  79301. ol.layer.Tile.prototype,
  79302. 'unset',
  79303. ol.layer.Tile.prototype.unset);
  79304. goog.exportProperty(
  79305. ol.layer.Tile.prototype,
  79306. 'changed',
  79307. ol.layer.Tile.prototype.changed);
  79308. goog.exportProperty(
  79309. ol.layer.Tile.prototype,
  79310. 'dispatchEvent',
  79311. ol.layer.Tile.prototype.dispatchEvent);
  79312. goog.exportProperty(
  79313. ol.layer.Tile.prototype,
  79314. 'getRevision',
  79315. ol.layer.Tile.prototype.getRevision);
  79316. goog.exportProperty(
  79317. ol.layer.Tile.prototype,
  79318. 'on',
  79319. ol.layer.Tile.prototype.on);
  79320. goog.exportProperty(
  79321. ol.layer.Tile.prototype,
  79322. 'once',
  79323. ol.layer.Tile.prototype.once);
  79324. goog.exportProperty(
  79325. ol.layer.Tile.prototype,
  79326. 'un',
  79327. ol.layer.Tile.prototype.un);
  79328. goog.exportProperty(
  79329. ol.layer.VectorTile.prototype,
  79330. 'getStyle',
  79331. ol.layer.VectorTile.prototype.getStyle);
  79332. goog.exportProperty(
  79333. ol.layer.VectorTile.prototype,
  79334. 'getStyleFunction',
  79335. ol.layer.VectorTile.prototype.getStyleFunction);
  79336. goog.exportProperty(
  79337. ol.layer.VectorTile.prototype,
  79338. 'setStyle',
  79339. ol.layer.VectorTile.prototype.setStyle);
  79340. goog.exportProperty(
  79341. ol.layer.VectorTile.prototype,
  79342. 'setMap',
  79343. ol.layer.VectorTile.prototype.setMap);
  79344. goog.exportProperty(
  79345. ol.layer.VectorTile.prototype,
  79346. 'setSource',
  79347. ol.layer.VectorTile.prototype.setSource);
  79348. goog.exportProperty(
  79349. ol.layer.VectorTile.prototype,
  79350. 'getExtent',
  79351. ol.layer.VectorTile.prototype.getExtent);
  79352. goog.exportProperty(
  79353. ol.layer.VectorTile.prototype,
  79354. 'getMaxResolution',
  79355. ol.layer.VectorTile.prototype.getMaxResolution);
  79356. goog.exportProperty(
  79357. ol.layer.VectorTile.prototype,
  79358. 'getMinResolution',
  79359. ol.layer.VectorTile.prototype.getMinResolution);
  79360. goog.exportProperty(
  79361. ol.layer.VectorTile.prototype,
  79362. 'getOpacity',
  79363. ol.layer.VectorTile.prototype.getOpacity);
  79364. goog.exportProperty(
  79365. ol.layer.VectorTile.prototype,
  79366. 'getVisible',
  79367. ol.layer.VectorTile.prototype.getVisible);
  79368. goog.exportProperty(
  79369. ol.layer.VectorTile.prototype,
  79370. 'getZIndex',
  79371. ol.layer.VectorTile.prototype.getZIndex);
  79372. goog.exportProperty(
  79373. ol.layer.VectorTile.prototype,
  79374. 'setExtent',
  79375. ol.layer.VectorTile.prototype.setExtent);
  79376. goog.exportProperty(
  79377. ol.layer.VectorTile.prototype,
  79378. 'setMaxResolution',
  79379. ol.layer.VectorTile.prototype.setMaxResolution);
  79380. goog.exportProperty(
  79381. ol.layer.VectorTile.prototype,
  79382. 'setMinResolution',
  79383. ol.layer.VectorTile.prototype.setMinResolution);
  79384. goog.exportProperty(
  79385. ol.layer.VectorTile.prototype,
  79386. 'setOpacity',
  79387. ol.layer.VectorTile.prototype.setOpacity);
  79388. goog.exportProperty(
  79389. ol.layer.VectorTile.prototype,
  79390. 'setVisible',
  79391. ol.layer.VectorTile.prototype.setVisible);
  79392. goog.exportProperty(
  79393. ol.layer.VectorTile.prototype,
  79394. 'setZIndex',
  79395. ol.layer.VectorTile.prototype.setZIndex);
  79396. goog.exportProperty(
  79397. ol.layer.VectorTile.prototype,
  79398. 'get',
  79399. ol.layer.VectorTile.prototype.get);
  79400. goog.exportProperty(
  79401. ol.layer.VectorTile.prototype,
  79402. 'getKeys',
  79403. ol.layer.VectorTile.prototype.getKeys);
  79404. goog.exportProperty(
  79405. ol.layer.VectorTile.prototype,
  79406. 'getProperties',
  79407. ol.layer.VectorTile.prototype.getProperties);
  79408. goog.exportProperty(
  79409. ol.layer.VectorTile.prototype,
  79410. 'set',
  79411. ol.layer.VectorTile.prototype.set);
  79412. goog.exportProperty(
  79413. ol.layer.VectorTile.prototype,
  79414. 'setProperties',
  79415. ol.layer.VectorTile.prototype.setProperties);
  79416. goog.exportProperty(
  79417. ol.layer.VectorTile.prototype,
  79418. 'unset',
  79419. ol.layer.VectorTile.prototype.unset);
  79420. goog.exportProperty(
  79421. ol.layer.VectorTile.prototype,
  79422. 'changed',
  79423. ol.layer.VectorTile.prototype.changed);
  79424. goog.exportProperty(
  79425. ol.layer.VectorTile.prototype,
  79426. 'dispatchEvent',
  79427. ol.layer.VectorTile.prototype.dispatchEvent);
  79428. goog.exportProperty(
  79429. ol.layer.VectorTile.prototype,
  79430. 'getRevision',
  79431. ol.layer.VectorTile.prototype.getRevision);
  79432. goog.exportProperty(
  79433. ol.layer.VectorTile.prototype,
  79434. 'on',
  79435. ol.layer.VectorTile.prototype.on);
  79436. goog.exportProperty(
  79437. ol.layer.VectorTile.prototype,
  79438. 'once',
  79439. ol.layer.VectorTile.prototype.once);
  79440. goog.exportProperty(
  79441. ol.layer.VectorTile.prototype,
  79442. 'un',
  79443. ol.layer.VectorTile.prototype.un);
  79444. goog.exportProperty(
  79445. ol.interaction.Interaction.prototype,
  79446. 'get',
  79447. ol.interaction.Interaction.prototype.get);
  79448. goog.exportProperty(
  79449. ol.interaction.Interaction.prototype,
  79450. 'getKeys',
  79451. ol.interaction.Interaction.prototype.getKeys);
  79452. goog.exportProperty(
  79453. ol.interaction.Interaction.prototype,
  79454. 'getProperties',
  79455. ol.interaction.Interaction.prototype.getProperties);
  79456. goog.exportProperty(
  79457. ol.interaction.Interaction.prototype,
  79458. 'set',
  79459. ol.interaction.Interaction.prototype.set);
  79460. goog.exportProperty(
  79461. ol.interaction.Interaction.prototype,
  79462. 'setProperties',
  79463. ol.interaction.Interaction.prototype.setProperties);
  79464. goog.exportProperty(
  79465. ol.interaction.Interaction.prototype,
  79466. 'unset',
  79467. ol.interaction.Interaction.prototype.unset);
  79468. goog.exportProperty(
  79469. ol.interaction.Interaction.prototype,
  79470. 'changed',
  79471. ol.interaction.Interaction.prototype.changed);
  79472. goog.exportProperty(
  79473. ol.interaction.Interaction.prototype,
  79474. 'dispatchEvent',
  79475. ol.interaction.Interaction.prototype.dispatchEvent);
  79476. goog.exportProperty(
  79477. ol.interaction.Interaction.prototype,
  79478. 'getRevision',
  79479. ol.interaction.Interaction.prototype.getRevision);
  79480. goog.exportProperty(
  79481. ol.interaction.Interaction.prototype,
  79482. 'on',
  79483. ol.interaction.Interaction.prototype.on);
  79484. goog.exportProperty(
  79485. ol.interaction.Interaction.prototype,
  79486. 'once',
  79487. ol.interaction.Interaction.prototype.once);
  79488. goog.exportProperty(
  79489. ol.interaction.Interaction.prototype,
  79490. 'un',
  79491. ol.interaction.Interaction.prototype.un);
  79492. goog.exportProperty(
  79493. ol.interaction.DoubleClickZoom.prototype,
  79494. 'getActive',
  79495. ol.interaction.DoubleClickZoom.prototype.getActive);
  79496. goog.exportProperty(
  79497. ol.interaction.DoubleClickZoom.prototype,
  79498. 'getMap',
  79499. ol.interaction.DoubleClickZoom.prototype.getMap);
  79500. goog.exportProperty(
  79501. ol.interaction.DoubleClickZoom.prototype,
  79502. 'setActive',
  79503. ol.interaction.DoubleClickZoom.prototype.setActive);
  79504. goog.exportProperty(
  79505. ol.interaction.DoubleClickZoom.prototype,
  79506. 'get',
  79507. ol.interaction.DoubleClickZoom.prototype.get);
  79508. goog.exportProperty(
  79509. ol.interaction.DoubleClickZoom.prototype,
  79510. 'getKeys',
  79511. ol.interaction.DoubleClickZoom.prototype.getKeys);
  79512. goog.exportProperty(
  79513. ol.interaction.DoubleClickZoom.prototype,
  79514. 'getProperties',
  79515. ol.interaction.DoubleClickZoom.prototype.getProperties);
  79516. goog.exportProperty(
  79517. ol.interaction.DoubleClickZoom.prototype,
  79518. 'set',
  79519. ol.interaction.DoubleClickZoom.prototype.set);
  79520. goog.exportProperty(
  79521. ol.interaction.DoubleClickZoom.prototype,
  79522. 'setProperties',
  79523. ol.interaction.DoubleClickZoom.prototype.setProperties);
  79524. goog.exportProperty(
  79525. ol.interaction.DoubleClickZoom.prototype,
  79526. 'unset',
  79527. ol.interaction.DoubleClickZoom.prototype.unset);
  79528. goog.exportProperty(
  79529. ol.interaction.DoubleClickZoom.prototype,
  79530. 'changed',
  79531. ol.interaction.DoubleClickZoom.prototype.changed);
  79532. goog.exportProperty(
  79533. ol.interaction.DoubleClickZoom.prototype,
  79534. 'dispatchEvent',
  79535. ol.interaction.DoubleClickZoom.prototype.dispatchEvent);
  79536. goog.exportProperty(
  79537. ol.interaction.DoubleClickZoom.prototype,
  79538. 'getRevision',
  79539. ol.interaction.DoubleClickZoom.prototype.getRevision);
  79540. goog.exportProperty(
  79541. ol.interaction.DoubleClickZoom.prototype,
  79542. 'on',
  79543. ol.interaction.DoubleClickZoom.prototype.on);
  79544. goog.exportProperty(
  79545. ol.interaction.DoubleClickZoom.prototype,
  79546. 'once',
  79547. ol.interaction.DoubleClickZoom.prototype.once);
  79548. goog.exportProperty(
  79549. ol.interaction.DoubleClickZoom.prototype,
  79550. 'un',
  79551. ol.interaction.DoubleClickZoom.prototype.un);
  79552. goog.exportProperty(
  79553. ol.interaction.DragAndDrop.prototype,
  79554. 'getActive',
  79555. ol.interaction.DragAndDrop.prototype.getActive);
  79556. goog.exportProperty(
  79557. ol.interaction.DragAndDrop.prototype,
  79558. 'getMap',
  79559. ol.interaction.DragAndDrop.prototype.getMap);
  79560. goog.exportProperty(
  79561. ol.interaction.DragAndDrop.prototype,
  79562. 'setActive',
  79563. ol.interaction.DragAndDrop.prototype.setActive);
  79564. goog.exportProperty(
  79565. ol.interaction.DragAndDrop.prototype,
  79566. 'get',
  79567. ol.interaction.DragAndDrop.prototype.get);
  79568. goog.exportProperty(
  79569. ol.interaction.DragAndDrop.prototype,
  79570. 'getKeys',
  79571. ol.interaction.DragAndDrop.prototype.getKeys);
  79572. goog.exportProperty(
  79573. ol.interaction.DragAndDrop.prototype,
  79574. 'getProperties',
  79575. ol.interaction.DragAndDrop.prototype.getProperties);
  79576. goog.exportProperty(
  79577. ol.interaction.DragAndDrop.prototype,
  79578. 'set',
  79579. ol.interaction.DragAndDrop.prototype.set);
  79580. goog.exportProperty(
  79581. ol.interaction.DragAndDrop.prototype,
  79582. 'setProperties',
  79583. ol.interaction.DragAndDrop.prototype.setProperties);
  79584. goog.exportProperty(
  79585. ol.interaction.DragAndDrop.prototype,
  79586. 'unset',
  79587. ol.interaction.DragAndDrop.prototype.unset);
  79588. goog.exportProperty(
  79589. ol.interaction.DragAndDrop.prototype,
  79590. 'changed',
  79591. ol.interaction.DragAndDrop.prototype.changed);
  79592. goog.exportProperty(
  79593. ol.interaction.DragAndDrop.prototype,
  79594. 'dispatchEvent',
  79595. ol.interaction.DragAndDrop.prototype.dispatchEvent);
  79596. goog.exportProperty(
  79597. ol.interaction.DragAndDrop.prototype,
  79598. 'getRevision',
  79599. ol.interaction.DragAndDrop.prototype.getRevision);
  79600. goog.exportProperty(
  79601. ol.interaction.DragAndDrop.prototype,
  79602. 'on',
  79603. ol.interaction.DragAndDrop.prototype.on);
  79604. goog.exportProperty(
  79605. ol.interaction.DragAndDrop.prototype,
  79606. 'once',
  79607. ol.interaction.DragAndDrop.prototype.once);
  79608. goog.exportProperty(
  79609. ol.interaction.DragAndDrop.prototype,
  79610. 'un',
  79611. ol.interaction.DragAndDrop.prototype.un);
  79612. goog.exportProperty(
  79613. ol.interaction.DragAndDrop.Event.prototype,
  79614. 'type',
  79615. ol.interaction.DragAndDrop.Event.prototype.type);
  79616. goog.exportProperty(
  79617. ol.interaction.DragAndDrop.Event.prototype,
  79618. 'target',
  79619. ol.interaction.DragAndDrop.Event.prototype.target);
  79620. goog.exportProperty(
  79621. ol.interaction.DragAndDrop.Event.prototype,
  79622. 'preventDefault',
  79623. ol.interaction.DragAndDrop.Event.prototype.preventDefault);
  79624. goog.exportProperty(
  79625. ol.interaction.DragAndDrop.Event.prototype,
  79626. 'stopPropagation',
  79627. ol.interaction.DragAndDrop.Event.prototype.stopPropagation);
  79628. goog.exportProperty(
  79629. ol.interaction.Pointer.prototype,
  79630. 'getActive',
  79631. ol.interaction.Pointer.prototype.getActive);
  79632. goog.exportProperty(
  79633. ol.interaction.Pointer.prototype,
  79634. 'getMap',
  79635. ol.interaction.Pointer.prototype.getMap);
  79636. goog.exportProperty(
  79637. ol.interaction.Pointer.prototype,
  79638. 'setActive',
  79639. ol.interaction.Pointer.prototype.setActive);
  79640. goog.exportProperty(
  79641. ol.interaction.Pointer.prototype,
  79642. 'get',
  79643. ol.interaction.Pointer.prototype.get);
  79644. goog.exportProperty(
  79645. ol.interaction.Pointer.prototype,
  79646. 'getKeys',
  79647. ol.interaction.Pointer.prototype.getKeys);
  79648. goog.exportProperty(
  79649. ol.interaction.Pointer.prototype,
  79650. 'getProperties',
  79651. ol.interaction.Pointer.prototype.getProperties);
  79652. goog.exportProperty(
  79653. ol.interaction.Pointer.prototype,
  79654. 'set',
  79655. ol.interaction.Pointer.prototype.set);
  79656. goog.exportProperty(
  79657. ol.interaction.Pointer.prototype,
  79658. 'setProperties',
  79659. ol.interaction.Pointer.prototype.setProperties);
  79660. goog.exportProperty(
  79661. ol.interaction.Pointer.prototype,
  79662. 'unset',
  79663. ol.interaction.Pointer.prototype.unset);
  79664. goog.exportProperty(
  79665. ol.interaction.Pointer.prototype,
  79666. 'changed',
  79667. ol.interaction.Pointer.prototype.changed);
  79668. goog.exportProperty(
  79669. ol.interaction.Pointer.prototype,
  79670. 'dispatchEvent',
  79671. ol.interaction.Pointer.prototype.dispatchEvent);
  79672. goog.exportProperty(
  79673. ol.interaction.Pointer.prototype,
  79674. 'getRevision',
  79675. ol.interaction.Pointer.prototype.getRevision);
  79676. goog.exportProperty(
  79677. ol.interaction.Pointer.prototype,
  79678. 'on',
  79679. ol.interaction.Pointer.prototype.on);
  79680. goog.exportProperty(
  79681. ol.interaction.Pointer.prototype,
  79682. 'once',
  79683. ol.interaction.Pointer.prototype.once);
  79684. goog.exportProperty(
  79685. ol.interaction.Pointer.prototype,
  79686. 'un',
  79687. ol.interaction.Pointer.prototype.un);
  79688. goog.exportProperty(
  79689. ol.interaction.DragBox.prototype,
  79690. 'getActive',
  79691. ol.interaction.DragBox.prototype.getActive);
  79692. goog.exportProperty(
  79693. ol.interaction.DragBox.prototype,
  79694. 'getMap',
  79695. ol.interaction.DragBox.prototype.getMap);
  79696. goog.exportProperty(
  79697. ol.interaction.DragBox.prototype,
  79698. 'setActive',
  79699. ol.interaction.DragBox.prototype.setActive);
  79700. goog.exportProperty(
  79701. ol.interaction.DragBox.prototype,
  79702. 'get',
  79703. ol.interaction.DragBox.prototype.get);
  79704. goog.exportProperty(
  79705. ol.interaction.DragBox.prototype,
  79706. 'getKeys',
  79707. ol.interaction.DragBox.prototype.getKeys);
  79708. goog.exportProperty(
  79709. ol.interaction.DragBox.prototype,
  79710. 'getProperties',
  79711. ol.interaction.DragBox.prototype.getProperties);
  79712. goog.exportProperty(
  79713. ol.interaction.DragBox.prototype,
  79714. 'set',
  79715. ol.interaction.DragBox.prototype.set);
  79716. goog.exportProperty(
  79717. ol.interaction.DragBox.prototype,
  79718. 'setProperties',
  79719. ol.interaction.DragBox.prototype.setProperties);
  79720. goog.exportProperty(
  79721. ol.interaction.DragBox.prototype,
  79722. 'unset',
  79723. ol.interaction.DragBox.prototype.unset);
  79724. goog.exportProperty(
  79725. ol.interaction.DragBox.prototype,
  79726. 'changed',
  79727. ol.interaction.DragBox.prototype.changed);
  79728. goog.exportProperty(
  79729. ol.interaction.DragBox.prototype,
  79730. 'dispatchEvent',
  79731. ol.interaction.DragBox.prototype.dispatchEvent);
  79732. goog.exportProperty(
  79733. ol.interaction.DragBox.prototype,
  79734. 'getRevision',
  79735. ol.interaction.DragBox.prototype.getRevision);
  79736. goog.exportProperty(
  79737. ol.interaction.DragBox.prototype,
  79738. 'on',
  79739. ol.interaction.DragBox.prototype.on);
  79740. goog.exportProperty(
  79741. ol.interaction.DragBox.prototype,
  79742. 'once',
  79743. ol.interaction.DragBox.prototype.once);
  79744. goog.exportProperty(
  79745. ol.interaction.DragBox.prototype,
  79746. 'un',
  79747. ol.interaction.DragBox.prototype.un);
  79748. goog.exportProperty(
  79749. ol.interaction.DragBox.Event.prototype,
  79750. 'type',
  79751. ol.interaction.DragBox.Event.prototype.type);
  79752. goog.exportProperty(
  79753. ol.interaction.DragBox.Event.prototype,
  79754. 'target',
  79755. ol.interaction.DragBox.Event.prototype.target);
  79756. goog.exportProperty(
  79757. ol.interaction.DragBox.Event.prototype,
  79758. 'preventDefault',
  79759. ol.interaction.DragBox.Event.prototype.preventDefault);
  79760. goog.exportProperty(
  79761. ol.interaction.DragBox.Event.prototype,
  79762. 'stopPropagation',
  79763. ol.interaction.DragBox.Event.prototype.stopPropagation);
  79764. goog.exportProperty(
  79765. ol.interaction.DragPan.prototype,
  79766. 'getActive',
  79767. ol.interaction.DragPan.prototype.getActive);
  79768. goog.exportProperty(
  79769. ol.interaction.DragPan.prototype,
  79770. 'getMap',
  79771. ol.interaction.DragPan.prototype.getMap);
  79772. goog.exportProperty(
  79773. ol.interaction.DragPan.prototype,
  79774. 'setActive',
  79775. ol.interaction.DragPan.prototype.setActive);
  79776. goog.exportProperty(
  79777. ol.interaction.DragPan.prototype,
  79778. 'get',
  79779. ol.interaction.DragPan.prototype.get);
  79780. goog.exportProperty(
  79781. ol.interaction.DragPan.prototype,
  79782. 'getKeys',
  79783. ol.interaction.DragPan.prototype.getKeys);
  79784. goog.exportProperty(
  79785. ol.interaction.DragPan.prototype,
  79786. 'getProperties',
  79787. ol.interaction.DragPan.prototype.getProperties);
  79788. goog.exportProperty(
  79789. ol.interaction.DragPan.prototype,
  79790. 'set',
  79791. ol.interaction.DragPan.prototype.set);
  79792. goog.exportProperty(
  79793. ol.interaction.DragPan.prototype,
  79794. 'setProperties',
  79795. ol.interaction.DragPan.prototype.setProperties);
  79796. goog.exportProperty(
  79797. ol.interaction.DragPan.prototype,
  79798. 'unset',
  79799. ol.interaction.DragPan.prototype.unset);
  79800. goog.exportProperty(
  79801. ol.interaction.DragPan.prototype,
  79802. 'changed',
  79803. ol.interaction.DragPan.prototype.changed);
  79804. goog.exportProperty(
  79805. ol.interaction.DragPan.prototype,
  79806. 'dispatchEvent',
  79807. ol.interaction.DragPan.prototype.dispatchEvent);
  79808. goog.exportProperty(
  79809. ol.interaction.DragPan.prototype,
  79810. 'getRevision',
  79811. ol.interaction.DragPan.prototype.getRevision);
  79812. goog.exportProperty(
  79813. ol.interaction.DragPan.prototype,
  79814. 'on',
  79815. ol.interaction.DragPan.prototype.on);
  79816. goog.exportProperty(
  79817. ol.interaction.DragPan.prototype,
  79818. 'once',
  79819. ol.interaction.DragPan.prototype.once);
  79820. goog.exportProperty(
  79821. ol.interaction.DragPan.prototype,
  79822. 'un',
  79823. ol.interaction.DragPan.prototype.un);
  79824. goog.exportProperty(
  79825. ol.interaction.DragRotate.prototype,
  79826. 'getActive',
  79827. ol.interaction.DragRotate.prototype.getActive);
  79828. goog.exportProperty(
  79829. ol.interaction.DragRotate.prototype,
  79830. 'getMap',
  79831. ol.interaction.DragRotate.prototype.getMap);
  79832. goog.exportProperty(
  79833. ol.interaction.DragRotate.prototype,
  79834. 'setActive',
  79835. ol.interaction.DragRotate.prototype.setActive);
  79836. goog.exportProperty(
  79837. ol.interaction.DragRotate.prototype,
  79838. 'get',
  79839. ol.interaction.DragRotate.prototype.get);
  79840. goog.exportProperty(
  79841. ol.interaction.DragRotate.prototype,
  79842. 'getKeys',
  79843. ol.interaction.DragRotate.prototype.getKeys);
  79844. goog.exportProperty(
  79845. ol.interaction.DragRotate.prototype,
  79846. 'getProperties',
  79847. ol.interaction.DragRotate.prototype.getProperties);
  79848. goog.exportProperty(
  79849. ol.interaction.DragRotate.prototype,
  79850. 'set',
  79851. ol.interaction.DragRotate.prototype.set);
  79852. goog.exportProperty(
  79853. ol.interaction.DragRotate.prototype,
  79854. 'setProperties',
  79855. ol.interaction.DragRotate.prototype.setProperties);
  79856. goog.exportProperty(
  79857. ol.interaction.DragRotate.prototype,
  79858. 'unset',
  79859. ol.interaction.DragRotate.prototype.unset);
  79860. goog.exportProperty(
  79861. ol.interaction.DragRotate.prototype,
  79862. 'changed',
  79863. ol.interaction.DragRotate.prototype.changed);
  79864. goog.exportProperty(
  79865. ol.interaction.DragRotate.prototype,
  79866. 'dispatchEvent',
  79867. ol.interaction.DragRotate.prototype.dispatchEvent);
  79868. goog.exportProperty(
  79869. ol.interaction.DragRotate.prototype,
  79870. 'getRevision',
  79871. ol.interaction.DragRotate.prototype.getRevision);
  79872. goog.exportProperty(
  79873. ol.interaction.DragRotate.prototype,
  79874. 'on',
  79875. ol.interaction.DragRotate.prototype.on);
  79876. goog.exportProperty(
  79877. ol.interaction.DragRotate.prototype,
  79878. 'once',
  79879. ol.interaction.DragRotate.prototype.once);
  79880. goog.exportProperty(
  79881. ol.interaction.DragRotate.prototype,
  79882. 'un',
  79883. ol.interaction.DragRotate.prototype.un);
  79884. goog.exportProperty(
  79885. ol.interaction.DragRotateAndZoom.prototype,
  79886. 'getActive',
  79887. ol.interaction.DragRotateAndZoom.prototype.getActive);
  79888. goog.exportProperty(
  79889. ol.interaction.DragRotateAndZoom.prototype,
  79890. 'getMap',
  79891. ol.interaction.DragRotateAndZoom.prototype.getMap);
  79892. goog.exportProperty(
  79893. ol.interaction.DragRotateAndZoom.prototype,
  79894. 'setActive',
  79895. ol.interaction.DragRotateAndZoom.prototype.setActive);
  79896. goog.exportProperty(
  79897. ol.interaction.DragRotateAndZoom.prototype,
  79898. 'get',
  79899. ol.interaction.DragRotateAndZoom.prototype.get);
  79900. goog.exportProperty(
  79901. ol.interaction.DragRotateAndZoom.prototype,
  79902. 'getKeys',
  79903. ol.interaction.DragRotateAndZoom.prototype.getKeys);
  79904. goog.exportProperty(
  79905. ol.interaction.DragRotateAndZoom.prototype,
  79906. 'getProperties',
  79907. ol.interaction.DragRotateAndZoom.prototype.getProperties);
  79908. goog.exportProperty(
  79909. ol.interaction.DragRotateAndZoom.prototype,
  79910. 'set',
  79911. ol.interaction.DragRotateAndZoom.prototype.set);
  79912. goog.exportProperty(
  79913. ol.interaction.DragRotateAndZoom.prototype,
  79914. 'setProperties',
  79915. ol.interaction.DragRotateAndZoom.prototype.setProperties);
  79916. goog.exportProperty(
  79917. ol.interaction.DragRotateAndZoom.prototype,
  79918. 'unset',
  79919. ol.interaction.DragRotateAndZoom.prototype.unset);
  79920. goog.exportProperty(
  79921. ol.interaction.DragRotateAndZoom.prototype,
  79922. 'changed',
  79923. ol.interaction.DragRotateAndZoom.prototype.changed);
  79924. goog.exportProperty(
  79925. ol.interaction.DragRotateAndZoom.prototype,
  79926. 'dispatchEvent',
  79927. ol.interaction.DragRotateAndZoom.prototype.dispatchEvent);
  79928. goog.exportProperty(
  79929. ol.interaction.DragRotateAndZoom.prototype,
  79930. 'getRevision',
  79931. ol.interaction.DragRotateAndZoom.prototype.getRevision);
  79932. goog.exportProperty(
  79933. ol.interaction.DragRotateAndZoom.prototype,
  79934. 'on',
  79935. ol.interaction.DragRotateAndZoom.prototype.on);
  79936. goog.exportProperty(
  79937. ol.interaction.DragRotateAndZoom.prototype,
  79938. 'once',
  79939. ol.interaction.DragRotateAndZoom.prototype.once);
  79940. goog.exportProperty(
  79941. ol.interaction.DragRotateAndZoom.prototype,
  79942. 'un',
  79943. ol.interaction.DragRotateAndZoom.prototype.un);
  79944. goog.exportProperty(
  79945. ol.interaction.DragZoom.prototype,
  79946. 'getGeometry',
  79947. ol.interaction.DragZoom.prototype.getGeometry);
  79948. goog.exportProperty(
  79949. ol.interaction.DragZoom.prototype,
  79950. 'getActive',
  79951. ol.interaction.DragZoom.prototype.getActive);
  79952. goog.exportProperty(
  79953. ol.interaction.DragZoom.prototype,
  79954. 'getMap',
  79955. ol.interaction.DragZoom.prototype.getMap);
  79956. goog.exportProperty(
  79957. ol.interaction.DragZoom.prototype,
  79958. 'setActive',
  79959. ol.interaction.DragZoom.prototype.setActive);
  79960. goog.exportProperty(
  79961. ol.interaction.DragZoom.prototype,
  79962. 'get',
  79963. ol.interaction.DragZoom.prototype.get);
  79964. goog.exportProperty(
  79965. ol.interaction.DragZoom.prototype,
  79966. 'getKeys',
  79967. ol.interaction.DragZoom.prototype.getKeys);
  79968. goog.exportProperty(
  79969. ol.interaction.DragZoom.prototype,
  79970. 'getProperties',
  79971. ol.interaction.DragZoom.prototype.getProperties);
  79972. goog.exportProperty(
  79973. ol.interaction.DragZoom.prototype,
  79974. 'set',
  79975. ol.interaction.DragZoom.prototype.set);
  79976. goog.exportProperty(
  79977. ol.interaction.DragZoom.prototype,
  79978. 'setProperties',
  79979. ol.interaction.DragZoom.prototype.setProperties);
  79980. goog.exportProperty(
  79981. ol.interaction.DragZoom.prototype,
  79982. 'unset',
  79983. ol.interaction.DragZoom.prototype.unset);
  79984. goog.exportProperty(
  79985. ol.interaction.DragZoom.prototype,
  79986. 'changed',
  79987. ol.interaction.DragZoom.prototype.changed);
  79988. goog.exportProperty(
  79989. ol.interaction.DragZoom.prototype,
  79990. 'dispatchEvent',
  79991. ol.interaction.DragZoom.prototype.dispatchEvent);
  79992. goog.exportProperty(
  79993. ol.interaction.DragZoom.prototype,
  79994. 'getRevision',
  79995. ol.interaction.DragZoom.prototype.getRevision);
  79996. goog.exportProperty(
  79997. ol.interaction.DragZoom.prototype,
  79998. 'on',
  79999. ol.interaction.DragZoom.prototype.on);
  80000. goog.exportProperty(
  80001. ol.interaction.DragZoom.prototype,
  80002. 'once',
  80003. ol.interaction.DragZoom.prototype.once);
  80004. goog.exportProperty(
  80005. ol.interaction.DragZoom.prototype,
  80006. 'un',
  80007. ol.interaction.DragZoom.prototype.un);
  80008. goog.exportProperty(
  80009. ol.interaction.Draw.prototype,
  80010. 'getActive',
  80011. ol.interaction.Draw.prototype.getActive);
  80012. goog.exportProperty(
  80013. ol.interaction.Draw.prototype,
  80014. 'getMap',
  80015. ol.interaction.Draw.prototype.getMap);
  80016. goog.exportProperty(
  80017. ol.interaction.Draw.prototype,
  80018. 'setActive',
  80019. ol.interaction.Draw.prototype.setActive);
  80020. goog.exportProperty(
  80021. ol.interaction.Draw.prototype,
  80022. 'get',
  80023. ol.interaction.Draw.prototype.get);
  80024. goog.exportProperty(
  80025. ol.interaction.Draw.prototype,
  80026. 'getKeys',
  80027. ol.interaction.Draw.prototype.getKeys);
  80028. goog.exportProperty(
  80029. ol.interaction.Draw.prototype,
  80030. 'getProperties',
  80031. ol.interaction.Draw.prototype.getProperties);
  80032. goog.exportProperty(
  80033. ol.interaction.Draw.prototype,
  80034. 'set',
  80035. ol.interaction.Draw.prototype.set);
  80036. goog.exportProperty(
  80037. ol.interaction.Draw.prototype,
  80038. 'setProperties',
  80039. ol.interaction.Draw.prototype.setProperties);
  80040. goog.exportProperty(
  80041. ol.interaction.Draw.prototype,
  80042. 'unset',
  80043. ol.interaction.Draw.prototype.unset);
  80044. goog.exportProperty(
  80045. ol.interaction.Draw.prototype,
  80046. 'changed',
  80047. ol.interaction.Draw.prototype.changed);
  80048. goog.exportProperty(
  80049. ol.interaction.Draw.prototype,
  80050. 'dispatchEvent',
  80051. ol.interaction.Draw.prototype.dispatchEvent);
  80052. goog.exportProperty(
  80053. ol.interaction.Draw.prototype,
  80054. 'getRevision',
  80055. ol.interaction.Draw.prototype.getRevision);
  80056. goog.exportProperty(
  80057. ol.interaction.Draw.prototype,
  80058. 'on',
  80059. ol.interaction.Draw.prototype.on);
  80060. goog.exportProperty(
  80061. ol.interaction.Draw.prototype,
  80062. 'once',
  80063. ol.interaction.Draw.prototype.once);
  80064. goog.exportProperty(
  80065. ol.interaction.Draw.prototype,
  80066. 'un',
  80067. ol.interaction.Draw.prototype.un);
  80068. goog.exportProperty(
  80069. ol.interaction.Draw.Event.prototype,
  80070. 'type',
  80071. ol.interaction.Draw.Event.prototype.type);
  80072. goog.exportProperty(
  80073. ol.interaction.Draw.Event.prototype,
  80074. 'target',
  80075. ol.interaction.Draw.Event.prototype.target);
  80076. goog.exportProperty(
  80077. ol.interaction.Draw.Event.prototype,
  80078. 'preventDefault',
  80079. ol.interaction.Draw.Event.prototype.preventDefault);
  80080. goog.exportProperty(
  80081. ol.interaction.Draw.Event.prototype,
  80082. 'stopPropagation',
  80083. ol.interaction.Draw.Event.prototype.stopPropagation);
  80084. goog.exportProperty(
  80085. ol.interaction.Extent.prototype,
  80086. 'getActive',
  80087. ol.interaction.Extent.prototype.getActive);
  80088. goog.exportProperty(
  80089. ol.interaction.Extent.prototype,
  80090. 'getMap',
  80091. ol.interaction.Extent.prototype.getMap);
  80092. goog.exportProperty(
  80093. ol.interaction.Extent.prototype,
  80094. 'setActive',
  80095. ol.interaction.Extent.prototype.setActive);
  80096. goog.exportProperty(
  80097. ol.interaction.Extent.prototype,
  80098. 'get',
  80099. ol.interaction.Extent.prototype.get);
  80100. goog.exportProperty(
  80101. ol.interaction.Extent.prototype,
  80102. 'getKeys',
  80103. ol.interaction.Extent.prototype.getKeys);
  80104. goog.exportProperty(
  80105. ol.interaction.Extent.prototype,
  80106. 'getProperties',
  80107. ol.interaction.Extent.prototype.getProperties);
  80108. goog.exportProperty(
  80109. ol.interaction.Extent.prototype,
  80110. 'set',
  80111. ol.interaction.Extent.prototype.set);
  80112. goog.exportProperty(
  80113. ol.interaction.Extent.prototype,
  80114. 'setProperties',
  80115. ol.interaction.Extent.prototype.setProperties);
  80116. goog.exportProperty(
  80117. ol.interaction.Extent.prototype,
  80118. 'unset',
  80119. ol.interaction.Extent.prototype.unset);
  80120. goog.exportProperty(
  80121. ol.interaction.Extent.prototype,
  80122. 'changed',
  80123. ol.interaction.Extent.prototype.changed);
  80124. goog.exportProperty(
  80125. ol.interaction.Extent.prototype,
  80126. 'dispatchEvent',
  80127. ol.interaction.Extent.prototype.dispatchEvent);
  80128. goog.exportProperty(
  80129. ol.interaction.Extent.prototype,
  80130. 'getRevision',
  80131. ol.interaction.Extent.prototype.getRevision);
  80132. goog.exportProperty(
  80133. ol.interaction.Extent.prototype,
  80134. 'on',
  80135. ol.interaction.Extent.prototype.on);
  80136. goog.exportProperty(
  80137. ol.interaction.Extent.prototype,
  80138. 'once',
  80139. ol.interaction.Extent.prototype.once);
  80140. goog.exportProperty(
  80141. ol.interaction.Extent.prototype,
  80142. 'un',
  80143. ol.interaction.Extent.prototype.un);
  80144. goog.exportProperty(
  80145. ol.interaction.Extent.Event.prototype,
  80146. 'type',
  80147. ol.interaction.Extent.Event.prototype.type);
  80148. goog.exportProperty(
  80149. ol.interaction.Extent.Event.prototype,
  80150. 'target',
  80151. ol.interaction.Extent.Event.prototype.target);
  80152. goog.exportProperty(
  80153. ol.interaction.Extent.Event.prototype,
  80154. 'preventDefault',
  80155. ol.interaction.Extent.Event.prototype.preventDefault);
  80156. goog.exportProperty(
  80157. ol.interaction.Extent.Event.prototype,
  80158. 'stopPropagation',
  80159. ol.interaction.Extent.Event.prototype.stopPropagation);
  80160. goog.exportProperty(
  80161. ol.interaction.KeyboardPan.prototype,
  80162. 'getActive',
  80163. ol.interaction.KeyboardPan.prototype.getActive);
  80164. goog.exportProperty(
  80165. ol.interaction.KeyboardPan.prototype,
  80166. 'getMap',
  80167. ol.interaction.KeyboardPan.prototype.getMap);
  80168. goog.exportProperty(
  80169. ol.interaction.KeyboardPan.prototype,
  80170. 'setActive',
  80171. ol.interaction.KeyboardPan.prototype.setActive);
  80172. goog.exportProperty(
  80173. ol.interaction.KeyboardPan.prototype,
  80174. 'get',
  80175. ol.interaction.KeyboardPan.prototype.get);
  80176. goog.exportProperty(
  80177. ol.interaction.KeyboardPan.prototype,
  80178. 'getKeys',
  80179. ol.interaction.KeyboardPan.prototype.getKeys);
  80180. goog.exportProperty(
  80181. ol.interaction.KeyboardPan.prototype,
  80182. 'getProperties',
  80183. ol.interaction.KeyboardPan.prototype.getProperties);
  80184. goog.exportProperty(
  80185. ol.interaction.KeyboardPan.prototype,
  80186. 'set',
  80187. ol.interaction.KeyboardPan.prototype.set);
  80188. goog.exportProperty(
  80189. ol.interaction.KeyboardPan.prototype,
  80190. 'setProperties',
  80191. ol.interaction.KeyboardPan.prototype.setProperties);
  80192. goog.exportProperty(
  80193. ol.interaction.KeyboardPan.prototype,
  80194. 'unset',
  80195. ol.interaction.KeyboardPan.prototype.unset);
  80196. goog.exportProperty(
  80197. ol.interaction.KeyboardPan.prototype,
  80198. 'changed',
  80199. ol.interaction.KeyboardPan.prototype.changed);
  80200. goog.exportProperty(
  80201. ol.interaction.KeyboardPan.prototype,
  80202. 'dispatchEvent',
  80203. ol.interaction.KeyboardPan.prototype.dispatchEvent);
  80204. goog.exportProperty(
  80205. ol.interaction.KeyboardPan.prototype,
  80206. 'getRevision',
  80207. ol.interaction.KeyboardPan.prototype.getRevision);
  80208. goog.exportProperty(
  80209. ol.interaction.KeyboardPan.prototype,
  80210. 'on',
  80211. ol.interaction.KeyboardPan.prototype.on);
  80212. goog.exportProperty(
  80213. ol.interaction.KeyboardPan.prototype,
  80214. 'once',
  80215. ol.interaction.KeyboardPan.prototype.once);
  80216. goog.exportProperty(
  80217. ol.interaction.KeyboardPan.prototype,
  80218. 'un',
  80219. ol.interaction.KeyboardPan.prototype.un);
  80220. goog.exportProperty(
  80221. ol.interaction.KeyboardZoom.prototype,
  80222. 'getActive',
  80223. ol.interaction.KeyboardZoom.prototype.getActive);
  80224. goog.exportProperty(
  80225. ol.interaction.KeyboardZoom.prototype,
  80226. 'getMap',
  80227. ol.interaction.KeyboardZoom.prototype.getMap);
  80228. goog.exportProperty(
  80229. ol.interaction.KeyboardZoom.prototype,
  80230. 'setActive',
  80231. ol.interaction.KeyboardZoom.prototype.setActive);
  80232. goog.exportProperty(
  80233. ol.interaction.KeyboardZoom.prototype,
  80234. 'get',
  80235. ol.interaction.KeyboardZoom.prototype.get);
  80236. goog.exportProperty(
  80237. ol.interaction.KeyboardZoom.prototype,
  80238. 'getKeys',
  80239. ol.interaction.KeyboardZoom.prototype.getKeys);
  80240. goog.exportProperty(
  80241. ol.interaction.KeyboardZoom.prototype,
  80242. 'getProperties',
  80243. ol.interaction.KeyboardZoom.prototype.getProperties);
  80244. goog.exportProperty(
  80245. ol.interaction.KeyboardZoom.prototype,
  80246. 'set',
  80247. ol.interaction.KeyboardZoom.prototype.set);
  80248. goog.exportProperty(
  80249. ol.interaction.KeyboardZoom.prototype,
  80250. 'setProperties',
  80251. ol.interaction.KeyboardZoom.prototype.setProperties);
  80252. goog.exportProperty(
  80253. ol.interaction.KeyboardZoom.prototype,
  80254. 'unset',
  80255. ol.interaction.KeyboardZoom.prototype.unset);
  80256. goog.exportProperty(
  80257. ol.interaction.KeyboardZoom.prototype,
  80258. 'changed',
  80259. ol.interaction.KeyboardZoom.prototype.changed);
  80260. goog.exportProperty(
  80261. ol.interaction.KeyboardZoom.prototype,
  80262. 'dispatchEvent',
  80263. ol.interaction.KeyboardZoom.prototype.dispatchEvent);
  80264. goog.exportProperty(
  80265. ol.interaction.KeyboardZoom.prototype,
  80266. 'getRevision',
  80267. ol.interaction.KeyboardZoom.prototype.getRevision);
  80268. goog.exportProperty(
  80269. ol.interaction.KeyboardZoom.prototype,
  80270. 'on',
  80271. ol.interaction.KeyboardZoom.prototype.on);
  80272. goog.exportProperty(
  80273. ol.interaction.KeyboardZoom.prototype,
  80274. 'once',
  80275. ol.interaction.KeyboardZoom.prototype.once);
  80276. goog.exportProperty(
  80277. ol.interaction.KeyboardZoom.prototype,
  80278. 'un',
  80279. ol.interaction.KeyboardZoom.prototype.un);
  80280. goog.exportProperty(
  80281. ol.interaction.Modify.prototype,
  80282. 'getActive',
  80283. ol.interaction.Modify.prototype.getActive);
  80284. goog.exportProperty(
  80285. ol.interaction.Modify.prototype,
  80286. 'getMap',
  80287. ol.interaction.Modify.prototype.getMap);
  80288. goog.exportProperty(
  80289. ol.interaction.Modify.prototype,
  80290. 'setActive',
  80291. ol.interaction.Modify.prototype.setActive);
  80292. goog.exportProperty(
  80293. ol.interaction.Modify.prototype,
  80294. 'get',
  80295. ol.interaction.Modify.prototype.get);
  80296. goog.exportProperty(
  80297. ol.interaction.Modify.prototype,
  80298. 'getKeys',
  80299. ol.interaction.Modify.prototype.getKeys);
  80300. goog.exportProperty(
  80301. ol.interaction.Modify.prototype,
  80302. 'getProperties',
  80303. ol.interaction.Modify.prototype.getProperties);
  80304. goog.exportProperty(
  80305. ol.interaction.Modify.prototype,
  80306. 'set',
  80307. ol.interaction.Modify.prototype.set);
  80308. goog.exportProperty(
  80309. ol.interaction.Modify.prototype,
  80310. 'setProperties',
  80311. ol.interaction.Modify.prototype.setProperties);
  80312. goog.exportProperty(
  80313. ol.interaction.Modify.prototype,
  80314. 'unset',
  80315. ol.interaction.Modify.prototype.unset);
  80316. goog.exportProperty(
  80317. ol.interaction.Modify.prototype,
  80318. 'changed',
  80319. ol.interaction.Modify.prototype.changed);
  80320. goog.exportProperty(
  80321. ol.interaction.Modify.prototype,
  80322. 'dispatchEvent',
  80323. ol.interaction.Modify.prototype.dispatchEvent);
  80324. goog.exportProperty(
  80325. ol.interaction.Modify.prototype,
  80326. 'getRevision',
  80327. ol.interaction.Modify.prototype.getRevision);
  80328. goog.exportProperty(
  80329. ol.interaction.Modify.prototype,
  80330. 'on',
  80331. ol.interaction.Modify.prototype.on);
  80332. goog.exportProperty(
  80333. ol.interaction.Modify.prototype,
  80334. 'once',
  80335. ol.interaction.Modify.prototype.once);
  80336. goog.exportProperty(
  80337. ol.interaction.Modify.prototype,
  80338. 'un',
  80339. ol.interaction.Modify.prototype.un);
  80340. goog.exportProperty(
  80341. ol.interaction.Modify.Event.prototype,
  80342. 'type',
  80343. ol.interaction.Modify.Event.prototype.type);
  80344. goog.exportProperty(
  80345. ol.interaction.Modify.Event.prototype,
  80346. 'target',
  80347. ol.interaction.Modify.Event.prototype.target);
  80348. goog.exportProperty(
  80349. ol.interaction.Modify.Event.prototype,
  80350. 'preventDefault',
  80351. ol.interaction.Modify.Event.prototype.preventDefault);
  80352. goog.exportProperty(
  80353. ol.interaction.Modify.Event.prototype,
  80354. 'stopPropagation',
  80355. ol.interaction.Modify.Event.prototype.stopPropagation);
  80356. goog.exportProperty(
  80357. ol.interaction.MouseWheelZoom.prototype,
  80358. 'getActive',
  80359. ol.interaction.MouseWheelZoom.prototype.getActive);
  80360. goog.exportProperty(
  80361. ol.interaction.MouseWheelZoom.prototype,
  80362. 'getMap',
  80363. ol.interaction.MouseWheelZoom.prototype.getMap);
  80364. goog.exportProperty(
  80365. ol.interaction.MouseWheelZoom.prototype,
  80366. 'setActive',
  80367. ol.interaction.MouseWheelZoom.prototype.setActive);
  80368. goog.exportProperty(
  80369. ol.interaction.MouseWheelZoom.prototype,
  80370. 'get',
  80371. ol.interaction.MouseWheelZoom.prototype.get);
  80372. goog.exportProperty(
  80373. ol.interaction.MouseWheelZoom.prototype,
  80374. 'getKeys',
  80375. ol.interaction.MouseWheelZoom.prototype.getKeys);
  80376. goog.exportProperty(
  80377. ol.interaction.MouseWheelZoom.prototype,
  80378. 'getProperties',
  80379. ol.interaction.MouseWheelZoom.prototype.getProperties);
  80380. goog.exportProperty(
  80381. ol.interaction.MouseWheelZoom.prototype,
  80382. 'set',
  80383. ol.interaction.MouseWheelZoom.prototype.set);
  80384. goog.exportProperty(
  80385. ol.interaction.MouseWheelZoom.prototype,
  80386. 'setProperties',
  80387. ol.interaction.MouseWheelZoom.prototype.setProperties);
  80388. goog.exportProperty(
  80389. ol.interaction.MouseWheelZoom.prototype,
  80390. 'unset',
  80391. ol.interaction.MouseWheelZoom.prototype.unset);
  80392. goog.exportProperty(
  80393. ol.interaction.MouseWheelZoom.prototype,
  80394. 'changed',
  80395. ol.interaction.MouseWheelZoom.prototype.changed);
  80396. goog.exportProperty(
  80397. ol.interaction.MouseWheelZoom.prototype,
  80398. 'dispatchEvent',
  80399. ol.interaction.MouseWheelZoom.prototype.dispatchEvent);
  80400. goog.exportProperty(
  80401. ol.interaction.MouseWheelZoom.prototype,
  80402. 'getRevision',
  80403. ol.interaction.MouseWheelZoom.prototype.getRevision);
  80404. goog.exportProperty(
  80405. ol.interaction.MouseWheelZoom.prototype,
  80406. 'on',
  80407. ol.interaction.MouseWheelZoom.prototype.on);
  80408. goog.exportProperty(
  80409. ol.interaction.MouseWheelZoom.prototype,
  80410. 'once',
  80411. ol.interaction.MouseWheelZoom.prototype.once);
  80412. goog.exportProperty(
  80413. ol.interaction.MouseWheelZoom.prototype,
  80414. 'un',
  80415. ol.interaction.MouseWheelZoom.prototype.un);
  80416. goog.exportProperty(
  80417. ol.interaction.PinchRotate.prototype,
  80418. 'getActive',
  80419. ol.interaction.PinchRotate.prototype.getActive);
  80420. goog.exportProperty(
  80421. ol.interaction.PinchRotate.prototype,
  80422. 'getMap',
  80423. ol.interaction.PinchRotate.prototype.getMap);
  80424. goog.exportProperty(
  80425. ol.interaction.PinchRotate.prototype,
  80426. 'setActive',
  80427. ol.interaction.PinchRotate.prototype.setActive);
  80428. goog.exportProperty(
  80429. ol.interaction.PinchRotate.prototype,
  80430. 'get',
  80431. ol.interaction.PinchRotate.prototype.get);
  80432. goog.exportProperty(
  80433. ol.interaction.PinchRotate.prototype,
  80434. 'getKeys',
  80435. ol.interaction.PinchRotate.prototype.getKeys);
  80436. goog.exportProperty(
  80437. ol.interaction.PinchRotate.prototype,
  80438. 'getProperties',
  80439. ol.interaction.PinchRotate.prototype.getProperties);
  80440. goog.exportProperty(
  80441. ol.interaction.PinchRotate.prototype,
  80442. 'set',
  80443. ol.interaction.PinchRotate.prototype.set);
  80444. goog.exportProperty(
  80445. ol.interaction.PinchRotate.prototype,
  80446. 'setProperties',
  80447. ol.interaction.PinchRotate.prototype.setProperties);
  80448. goog.exportProperty(
  80449. ol.interaction.PinchRotate.prototype,
  80450. 'unset',
  80451. ol.interaction.PinchRotate.prototype.unset);
  80452. goog.exportProperty(
  80453. ol.interaction.PinchRotate.prototype,
  80454. 'changed',
  80455. ol.interaction.PinchRotate.prototype.changed);
  80456. goog.exportProperty(
  80457. ol.interaction.PinchRotate.prototype,
  80458. 'dispatchEvent',
  80459. ol.interaction.PinchRotate.prototype.dispatchEvent);
  80460. goog.exportProperty(
  80461. ol.interaction.PinchRotate.prototype,
  80462. 'getRevision',
  80463. ol.interaction.PinchRotate.prototype.getRevision);
  80464. goog.exportProperty(
  80465. ol.interaction.PinchRotate.prototype,
  80466. 'on',
  80467. ol.interaction.PinchRotate.prototype.on);
  80468. goog.exportProperty(
  80469. ol.interaction.PinchRotate.prototype,
  80470. 'once',
  80471. ol.interaction.PinchRotate.prototype.once);
  80472. goog.exportProperty(
  80473. ol.interaction.PinchRotate.prototype,
  80474. 'un',
  80475. ol.interaction.PinchRotate.prototype.un);
  80476. goog.exportProperty(
  80477. ol.interaction.PinchZoom.prototype,
  80478. 'getActive',
  80479. ol.interaction.PinchZoom.prototype.getActive);
  80480. goog.exportProperty(
  80481. ol.interaction.PinchZoom.prototype,
  80482. 'getMap',
  80483. ol.interaction.PinchZoom.prototype.getMap);
  80484. goog.exportProperty(
  80485. ol.interaction.PinchZoom.prototype,
  80486. 'setActive',
  80487. ol.interaction.PinchZoom.prototype.setActive);
  80488. goog.exportProperty(
  80489. ol.interaction.PinchZoom.prototype,
  80490. 'get',
  80491. ol.interaction.PinchZoom.prototype.get);
  80492. goog.exportProperty(
  80493. ol.interaction.PinchZoom.prototype,
  80494. 'getKeys',
  80495. ol.interaction.PinchZoom.prototype.getKeys);
  80496. goog.exportProperty(
  80497. ol.interaction.PinchZoom.prototype,
  80498. 'getProperties',
  80499. ol.interaction.PinchZoom.prototype.getProperties);
  80500. goog.exportProperty(
  80501. ol.interaction.PinchZoom.prototype,
  80502. 'set',
  80503. ol.interaction.PinchZoom.prototype.set);
  80504. goog.exportProperty(
  80505. ol.interaction.PinchZoom.prototype,
  80506. 'setProperties',
  80507. ol.interaction.PinchZoom.prototype.setProperties);
  80508. goog.exportProperty(
  80509. ol.interaction.PinchZoom.prototype,
  80510. 'unset',
  80511. ol.interaction.PinchZoom.prototype.unset);
  80512. goog.exportProperty(
  80513. ol.interaction.PinchZoom.prototype,
  80514. 'changed',
  80515. ol.interaction.PinchZoom.prototype.changed);
  80516. goog.exportProperty(
  80517. ol.interaction.PinchZoom.prototype,
  80518. 'dispatchEvent',
  80519. ol.interaction.PinchZoom.prototype.dispatchEvent);
  80520. goog.exportProperty(
  80521. ol.interaction.PinchZoom.prototype,
  80522. 'getRevision',
  80523. ol.interaction.PinchZoom.prototype.getRevision);
  80524. goog.exportProperty(
  80525. ol.interaction.PinchZoom.prototype,
  80526. 'on',
  80527. ol.interaction.PinchZoom.prototype.on);
  80528. goog.exportProperty(
  80529. ol.interaction.PinchZoom.prototype,
  80530. 'once',
  80531. ol.interaction.PinchZoom.prototype.once);
  80532. goog.exportProperty(
  80533. ol.interaction.PinchZoom.prototype,
  80534. 'un',
  80535. ol.interaction.PinchZoom.prototype.un);
  80536. goog.exportProperty(
  80537. ol.interaction.Select.prototype,
  80538. 'getActive',
  80539. ol.interaction.Select.prototype.getActive);
  80540. goog.exportProperty(
  80541. ol.interaction.Select.prototype,
  80542. 'getMap',
  80543. ol.interaction.Select.prototype.getMap);
  80544. goog.exportProperty(
  80545. ol.interaction.Select.prototype,
  80546. 'setActive',
  80547. ol.interaction.Select.prototype.setActive);
  80548. goog.exportProperty(
  80549. ol.interaction.Select.prototype,
  80550. 'get',
  80551. ol.interaction.Select.prototype.get);
  80552. goog.exportProperty(
  80553. ol.interaction.Select.prototype,
  80554. 'getKeys',
  80555. ol.interaction.Select.prototype.getKeys);
  80556. goog.exportProperty(
  80557. ol.interaction.Select.prototype,
  80558. 'getProperties',
  80559. ol.interaction.Select.prototype.getProperties);
  80560. goog.exportProperty(
  80561. ol.interaction.Select.prototype,
  80562. 'set',
  80563. ol.interaction.Select.prototype.set);
  80564. goog.exportProperty(
  80565. ol.interaction.Select.prototype,
  80566. 'setProperties',
  80567. ol.interaction.Select.prototype.setProperties);
  80568. goog.exportProperty(
  80569. ol.interaction.Select.prototype,
  80570. 'unset',
  80571. ol.interaction.Select.prototype.unset);
  80572. goog.exportProperty(
  80573. ol.interaction.Select.prototype,
  80574. 'changed',
  80575. ol.interaction.Select.prototype.changed);
  80576. goog.exportProperty(
  80577. ol.interaction.Select.prototype,
  80578. 'dispatchEvent',
  80579. ol.interaction.Select.prototype.dispatchEvent);
  80580. goog.exportProperty(
  80581. ol.interaction.Select.prototype,
  80582. 'getRevision',
  80583. ol.interaction.Select.prototype.getRevision);
  80584. goog.exportProperty(
  80585. ol.interaction.Select.prototype,
  80586. 'on',
  80587. ol.interaction.Select.prototype.on);
  80588. goog.exportProperty(
  80589. ol.interaction.Select.prototype,
  80590. 'once',
  80591. ol.interaction.Select.prototype.once);
  80592. goog.exportProperty(
  80593. ol.interaction.Select.prototype,
  80594. 'un',
  80595. ol.interaction.Select.prototype.un);
  80596. goog.exportProperty(
  80597. ol.interaction.Select.Event.prototype,
  80598. 'type',
  80599. ol.interaction.Select.Event.prototype.type);
  80600. goog.exportProperty(
  80601. ol.interaction.Select.Event.prototype,
  80602. 'target',
  80603. ol.interaction.Select.Event.prototype.target);
  80604. goog.exportProperty(
  80605. ol.interaction.Select.Event.prototype,
  80606. 'preventDefault',
  80607. ol.interaction.Select.Event.prototype.preventDefault);
  80608. goog.exportProperty(
  80609. ol.interaction.Select.Event.prototype,
  80610. 'stopPropagation',
  80611. ol.interaction.Select.Event.prototype.stopPropagation);
  80612. goog.exportProperty(
  80613. ol.interaction.Snap.prototype,
  80614. 'getActive',
  80615. ol.interaction.Snap.prototype.getActive);
  80616. goog.exportProperty(
  80617. ol.interaction.Snap.prototype,
  80618. 'getMap',
  80619. ol.interaction.Snap.prototype.getMap);
  80620. goog.exportProperty(
  80621. ol.interaction.Snap.prototype,
  80622. 'setActive',
  80623. ol.interaction.Snap.prototype.setActive);
  80624. goog.exportProperty(
  80625. ol.interaction.Snap.prototype,
  80626. 'get',
  80627. ol.interaction.Snap.prototype.get);
  80628. goog.exportProperty(
  80629. ol.interaction.Snap.prototype,
  80630. 'getKeys',
  80631. ol.interaction.Snap.prototype.getKeys);
  80632. goog.exportProperty(
  80633. ol.interaction.Snap.prototype,
  80634. 'getProperties',
  80635. ol.interaction.Snap.prototype.getProperties);
  80636. goog.exportProperty(
  80637. ol.interaction.Snap.prototype,
  80638. 'set',
  80639. ol.interaction.Snap.prototype.set);
  80640. goog.exportProperty(
  80641. ol.interaction.Snap.prototype,
  80642. 'setProperties',
  80643. ol.interaction.Snap.prototype.setProperties);
  80644. goog.exportProperty(
  80645. ol.interaction.Snap.prototype,
  80646. 'unset',
  80647. ol.interaction.Snap.prototype.unset);
  80648. goog.exportProperty(
  80649. ol.interaction.Snap.prototype,
  80650. 'changed',
  80651. ol.interaction.Snap.prototype.changed);
  80652. goog.exportProperty(
  80653. ol.interaction.Snap.prototype,
  80654. 'dispatchEvent',
  80655. ol.interaction.Snap.prototype.dispatchEvent);
  80656. goog.exportProperty(
  80657. ol.interaction.Snap.prototype,
  80658. 'getRevision',
  80659. ol.interaction.Snap.prototype.getRevision);
  80660. goog.exportProperty(
  80661. ol.interaction.Snap.prototype,
  80662. 'on',
  80663. ol.interaction.Snap.prototype.on);
  80664. goog.exportProperty(
  80665. ol.interaction.Snap.prototype,
  80666. 'once',
  80667. ol.interaction.Snap.prototype.once);
  80668. goog.exportProperty(
  80669. ol.interaction.Snap.prototype,
  80670. 'un',
  80671. ol.interaction.Snap.prototype.un);
  80672. goog.exportProperty(
  80673. ol.interaction.Translate.prototype,
  80674. 'getActive',
  80675. ol.interaction.Translate.prototype.getActive);
  80676. goog.exportProperty(
  80677. ol.interaction.Translate.prototype,
  80678. 'getMap',
  80679. ol.interaction.Translate.prototype.getMap);
  80680. goog.exportProperty(
  80681. ol.interaction.Translate.prototype,
  80682. 'setActive',
  80683. ol.interaction.Translate.prototype.setActive);
  80684. goog.exportProperty(
  80685. ol.interaction.Translate.prototype,
  80686. 'get',
  80687. ol.interaction.Translate.prototype.get);
  80688. goog.exportProperty(
  80689. ol.interaction.Translate.prototype,
  80690. 'getKeys',
  80691. ol.interaction.Translate.prototype.getKeys);
  80692. goog.exportProperty(
  80693. ol.interaction.Translate.prototype,
  80694. 'getProperties',
  80695. ol.interaction.Translate.prototype.getProperties);
  80696. goog.exportProperty(
  80697. ol.interaction.Translate.prototype,
  80698. 'set',
  80699. ol.interaction.Translate.prototype.set);
  80700. goog.exportProperty(
  80701. ol.interaction.Translate.prototype,
  80702. 'setProperties',
  80703. ol.interaction.Translate.prototype.setProperties);
  80704. goog.exportProperty(
  80705. ol.interaction.Translate.prototype,
  80706. 'unset',
  80707. ol.interaction.Translate.prototype.unset);
  80708. goog.exportProperty(
  80709. ol.interaction.Translate.prototype,
  80710. 'changed',
  80711. ol.interaction.Translate.prototype.changed);
  80712. goog.exportProperty(
  80713. ol.interaction.Translate.prototype,
  80714. 'dispatchEvent',
  80715. ol.interaction.Translate.prototype.dispatchEvent);
  80716. goog.exportProperty(
  80717. ol.interaction.Translate.prototype,
  80718. 'getRevision',
  80719. ol.interaction.Translate.prototype.getRevision);
  80720. goog.exportProperty(
  80721. ol.interaction.Translate.prototype,
  80722. 'on',
  80723. ol.interaction.Translate.prototype.on);
  80724. goog.exportProperty(
  80725. ol.interaction.Translate.prototype,
  80726. 'once',
  80727. ol.interaction.Translate.prototype.once);
  80728. goog.exportProperty(
  80729. ol.interaction.Translate.prototype,
  80730. 'un',
  80731. ol.interaction.Translate.prototype.un);
  80732. goog.exportProperty(
  80733. ol.interaction.Translate.Event.prototype,
  80734. 'type',
  80735. ol.interaction.Translate.Event.prototype.type);
  80736. goog.exportProperty(
  80737. ol.interaction.Translate.Event.prototype,
  80738. 'target',
  80739. ol.interaction.Translate.Event.prototype.target);
  80740. goog.exportProperty(
  80741. ol.interaction.Translate.Event.prototype,
  80742. 'preventDefault',
  80743. ol.interaction.Translate.Event.prototype.preventDefault);
  80744. goog.exportProperty(
  80745. ol.interaction.Translate.Event.prototype,
  80746. 'stopPropagation',
  80747. ol.interaction.Translate.Event.prototype.stopPropagation);
  80748. goog.exportProperty(
  80749. ol.geom.Geometry.prototype,
  80750. 'get',
  80751. ol.geom.Geometry.prototype.get);
  80752. goog.exportProperty(
  80753. ol.geom.Geometry.prototype,
  80754. 'getKeys',
  80755. ol.geom.Geometry.prototype.getKeys);
  80756. goog.exportProperty(
  80757. ol.geom.Geometry.prototype,
  80758. 'getProperties',
  80759. ol.geom.Geometry.prototype.getProperties);
  80760. goog.exportProperty(
  80761. ol.geom.Geometry.prototype,
  80762. 'set',
  80763. ol.geom.Geometry.prototype.set);
  80764. goog.exportProperty(
  80765. ol.geom.Geometry.prototype,
  80766. 'setProperties',
  80767. ol.geom.Geometry.prototype.setProperties);
  80768. goog.exportProperty(
  80769. ol.geom.Geometry.prototype,
  80770. 'unset',
  80771. ol.geom.Geometry.prototype.unset);
  80772. goog.exportProperty(
  80773. ol.geom.Geometry.prototype,
  80774. 'changed',
  80775. ol.geom.Geometry.prototype.changed);
  80776. goog.exportProperty(
  80777. ol.geom.Geometry.prototype,
  80778. 'dispatchEvent',
  80779. ol.geom.Geometry.prototype.dispatchEvent);
  80780. goog.exportProperty(
  80781. ol.geom.Geometry.prototype,
  80782. 'getRevision',
  80783. ol.geom.Geometry.prototype.getRevision);
  80784. goog.exportProperty(
  80785. ol.geom.Geometry.prototype,
  80786. 'on',
  80787. ol.geom.Geometry.prototype.on);
  80788. goog.exportProperty(
  80789. ol.geom.Geometry.prototype,
  80790. 'once',
  80791. ol.geom.Geometry.prototype.once);
  80792. goog.exportProperty(
  80793. ol.geom.Geometry.prototype,
  80794. 'un',
  80795. ol.geom.Geometry.prototype.un);
  80796. goog.exportProperty(
  80797. ol.geom.SimpleGeometry.prototype,
  80798. 'getClosestPoint',
  80799. ol.geom.SimpleGeometry.prototype.getClosestPoint);
  80800. goog.exportProperty(
  80801. ol.geom.SimpleGeometry.prototype,
  80802. 'intersectsCoordinate',
  80803. ol.geom.SimpleGeometry.prototype.intersectsCoordinate);
  80804. goog.exportProperty(
  80805. ol.geom.SimpleGeometry.prototype,
  80806. 'getExtent',
  80807. ol.geom.SimpleGeometry.prototype.getExtent);
  80808. goog.exportProperty(
  80809. ol.geom.SimpleGeometry.prototype,
  80810. 'rotate',
  80811. ol.geom.SimpleGeometry.prototype.rotate);
  80812. goog.exportProperty(
  80813. ol.geom.SimpleGeometry.prototype,
  80814. 'scale',
  80815. ol.geom.SimpleGeometry.prototype.scale);
  80816. goog.exportProperty(
  80817. ol.geom.SimpleGeometry.prototype,
  80818. 'simplify',
  80819. ol.geom.SimpleGeometry.prototype.simplify);
  80820. goog.exportProperty(
  80821. ol.geom.SimpleGeometry.prototype,
  80822. 'transform',
  80823. ol.geom.SimpleGeometry.prototype.transform);
  80824. goog.exportProperty(
  80825. ol.geom.SimpleGeometry.prototype,
  80826. 'get',
  80827. ol.geom.SimpleGeometry.prototype.get);
  80828. goog.exportProperty(
  80829. ol.geom.SimpleGeometry.prototype,
  80830. 'getKeys',
  80831. ol.geom.SimpleGeometry.prototype.getKeys);
  80832. goog.exportProperty(
  80833. ol.geom.SimpleGeometry.prototype,
  80834. 'getProperties',
  80835. ol.geom.SimpleGeometry.prototype.getProperties);
  80836. goog.exportProperty(
  80837. ol.geom.SimpleGeometry.prototype,
  80838. 'set',
  80839. ol.geom.SimpleGeometry.prototype.set);
  80840. goog.exportProperty(
  80841. ol.geom.SimpleGeometry.prototype,
  80842. 'setProperties',
  80843. ol.geom.SimpleGeometry.prototype.setProperties);
  80844. goog.exportProperty(
  80845. ol.geom.SimpleGeometry.prototype,
  80846. 'unset',
  80847. ol.geom.SimpleGeometry.prototype.unset);
  80848. goog.exportProperty(
  80849. ol.geom.SimpleGeometry.prototype,
  80850. 'changed',
  80851. ol.geom.SimpleGeometry.prototype.changed);
  80852. goog.exportProperty(
  80853. ol.geom.SimpleGeometry.prototype,
  80854. 'dispatchEvent',
  80855. ol.geom.SimpleGeometry.prototype.dispatchEvent);
  80856. goog.exportProperty(
  80857. ol.geom.SimpleGeometry.prototype,
  80858. 'getRevision',
  80859. ol.geom.SimpleGeometry.prototype.getRevision);
  80860. goog.exportProperty(
  80861. ol.geom.SimpleGeometry.prototype,
  80862. 'on',
  80863. ol.geom.SimpleGeometry.prototype.on);
  80864. goog.exportProperty(
  80865. ol.geom.SimpleGeometry.prototype,
  80866. 'once',
  80867. ol.geom.SimpleGeometry.prototype.once);
  80868. goog.exportProperty(
  80869. ol.geom.SimpleGeometry.prototype,
  80870. 'un',
  80871. ol.geom.SimpleGeometry.prototype.un);
  80872. goog.exportProperty(
  80873. ol.geom.Circle.prototype,
  80874. 'getFirstCoordinate',
  80875. ol.geom.Circle.prototype.getFirstCoordinate);
  80876. goog.exportProperty(
  80877. ol.geom.Circle.prototype,
  80878. 'getLastCoordinate',
  80879. ol.geom.Circle.prototype.getLastCoordinate);
  80880. goog.exportProperty(
  80881. ol.geom.Circle.prototype,
  80882. 'getLayout',
  80883. ol.geom.Circle.prototype.getLayout);
  80884. goog.exportProperty(
  80885. ol.geom.Circle.prototype,
  80886. 'rotate',
  80887. ol.geom.Circle.prototype.rotate);
  80888. goog.exportProperty(
  80889. ol.geom.Circle.prototype,
  80890. 'scale',
  80891. ol.geom.Circle.prototype.scale);
  80892. goog.exportProperty(
  80893. ol.geom.Circle.prototype,
  80894. 'getClosestPoint',
  80895. ol.geom.Circle.prototype.getClosestPoint);
  80896. goog.exportProperty(
  80897. ol.geom.Circle.prototype,
  80898. 'intersectsCoordinate',
  80899. ol.geom.Circle.prototype.intersectsCoordinate);
  80900. goog.exportProperty(
  80901. ol.geom.Circle.prototype,
  80902. 'getExtent',
  80903. ol.geom.Circle.prototype.getExtent);
  80904. goog.exportProperty(
  80905. ol.geom.Circle.prototype,
  80906. 'simplify',
  80907. ol.geom.Circle.prototype.simplify);
  80908. goog.exportProperty(
  80909. ol.geom.Circle.prototype,
  80910. 'get',
  80911. ol.geom.Circle.prototype.get);
  80912. goog.exportProperty(
  80913. ol.geom.Circle.prototype,
  80914. 'getKeys',
  80915. ol.geom.Circle.prototype.getKeys);
  80916. goog.exportProperty(
  80917. ol.geom.Circle.prototype,
  80918. 'getProperties',
  80919. ol.geom.Circle.prototype.getProperties);
  80920. goog.exportProperty(
  80921. ol.geom.Circle.prototype,
  80922. 'set',
  80923. ol.geom.Circle.prototype.set);
  80924. goog.exportProperty(
  80925. ol.geom.Circle.prototype,
  80926. 'setProperties',
  80927. ol.geom.Circle.prototype.setProperties);
  80928. goog.exportProperty(
  80929. ol.geom.Circle.prototype,
  80930. 'unset',
  80931. ol.geom.Circle.prototype.unset);
  80932. goog.exportProperty(
  80933. ol.geom.Circle.prototype,
  80934. 'changed',
  80935. ol.geom.Circle.prototype.changed);
  80936. goog.exportProperty(
  80937. ol.geom.Circle.prototype,
  80938. 'dispatchEvent',
  80939. ol.geom.Circle.prototype.dispatchEvent);
  80940. goog.exportProperty(
  80941. ol.geom.Circle.prototype,
  80942. 'getRevision',
  80943. ol.geom.Circle.prototype.getRevision);
  80944. goog.exportProperty(
  80945. ol.geom.Circle.prototype,
  80946. 'on',
  80947. ol.geom.Circle.prototype.on);
  80948. goog.exportProperty(
  80949. ol.geom.Circle.prototype,
  80950. 'once',
  80951. ol.geom.Circle.prototype.once);
  80952. goog.exportProperty(
  80953. ol.geom.Circle.prototype,
  80954. 'un',
  80955. ol.geom.Circle.prototype.un);
  80956. goog.exportProperty(
  80957. ol.geom.GeometryCollection.prototype,
  80958. 'getClosestPoint',
  80959. ol.geom.GeometryCollection.prototype.getClosestPoint);
  80960. goog.exportProperty(
  80961. ol.geom.GeometryCollection.prototype,
  80962. 'intersectsCoordinate',
  80963. ol.geom.GeometryCollection.prototype.intersectsCoordinate);
  80964. goog.exportProperty(
  80965. ol.geom.GeometryCollection.prototype,
  80966. 'getExtent',
  80967. ol.geom.GeometryCollection.prototype.getExtent);
  80968. goog.exportProperty(
  80969. ol.geom.GeometryCollection.prototype,
  80970. 'rotate',
  80971. ol.geom.GeometryCollection.prototype.rotate);
  80972. goog.exportProperty(
  80973. ol.geom.GeometryCollection.prototype,
  80974. 'scale',
  80975. ol.geom.GeometryCollection.prototype.scale);
  80976. goog.exportProperty(
  80977. ol.geom.GeometryCollection.prototype,
  80978. 'simplify',
  80979. ol.geom.GeometryCollection.prototype.simplify);
  80980. goog.exportProperty(
  80981. ol.geom.GeometryCollection.prototype,
  80982. 'transform',
  80983. ol.geom.GeometryCollection.prototype.transform);
  80984. goog.exportProperty(
  80985. ol.geom.GeometryCollection.prototype,
  80986. 'get',
  80987. ol.geom.GeometryCollection.prototype.get);
  80988. goog.exportProperty(
  80989. ol.geom.GeometryCollection.prototype,
  80990. 'getKeys',
  80991. ol.geom.GeometryCollection.prototype.getKeys);
  80992. goog.exportProperty(
  80993. ol.geom.GeometryCollection.prototype,
  80994. 'getProperties',
  80995. ol.geom.GeometryCollection.prototype.getProperties);
  80996. goog.exportProperty(
  80997. ol.geom.GeometryCollection.prototype,
  80998. 'set',
  80999. ol.geom.GeometryCollection.prototype.set);
  81000. goog.exportProperty(
  81001. ol.geom.GeometryCollection.prototype,
  81002. 'setProperties',
  81003. ol.geom.GeometryCollection.prototype.setProperties);
  81004. goog.exportProperty(
  81005. ol.geom.GeometryCollection.prototype,
  81006. 'unset',
  81007. ol.geom.GeometryCollection.prototype.unset);
  81008. goog.exportProperty(
  81009. ol.geom.GeometryCollection.prototype,
  81010. 'changed',
  81011. ol.geom.GeometryCollection.prototype.changed);
  81012. goog.exportProperty(
  81013. ol.geom.GeometryCollection.prototype,
  81014. 'dispatchEvent',
  81015. ol.geom.GeometryCollection.prototype.dispatchEvent);
  81016. goog.exportProperty(
  81017. ol.geom.GeometryCollection.prototype,
  81018. 'getRevision',
  81019. ol.geom.GeometryCollection.prototype.getRevision);
  81020. goog.exportProperty(
  81021. ol.geom.GeometryCollection.prototype,
  81022. 'on',
  81023. ol.geom.GeometryCollection.prototype.on);
  81024. goog.exportProperty(
  81025. ol.geom.GeometryCollection.prototype,
  81026. 'once',
  81027. ol.geom.GeometryCollection.prototype.once);
  81028. goog.exportProperty(
  81029. ol.geom.GeometryCollection.prototype,
  81030. 'un',
  81031. ol.geom.GeometryCollection.prototype.un);
  81032. goog.exportProperty(
  81033. ol.geom.LinearRing.prototype,
  81034. 'getFirstCoordinate',
  81035. ol.geom.LinearRing.prototype.getFirstCoordinate);
  81036. goog.exportProperty(
  81037. ol.geom.LinearRing.prototype,
  81038. 'getLastCoordinate',
  81039. ol.geom.LinearRing.prototype.getLastCoordinate);
  81040. goog.exportProperty(
  81041. ol.geom.LinearRing.prototype,
  81042. 'getLayout',
  81043. ol.geom.LinearRing.prototype.getLayout);
  81044. goog.exportProperty(
  81045. ol.geom.LinearRing.prototype,
  81046. 'rotate',
  81047. ol.geom.LinearRing.prototype.rotate);
  81048. goog.exportProperty(
  81049. ol.geom.LinearRing.prototype,
  81050. 'scale',
  81051. ol.geom.LinearRing.prototype.scale);
  81052. goog.exportProperty(
  81053. ol.geom.LinearRing.prototype,
  81054. 'getClosestPoint',
  81055. ol.geom.LinearRing.prototype.getClosestPoint);
  81056. goog.exportProperty(
  81057. ol.geom.LinearRing.prototype,
  81058. 'intersectsCoordinate',
  81059. ol.geom.LinearRing.prototype.intersectsCoordinate);
  81060. goog.exportProperty(
  81061. ol.geom.LinearRing.prototype,
  81062. 'getExtent',
  81063. ol.geom.LinearRing.prototype.getExtent);
  81064. goog.exportProperty(
  81065. ol.geom.LinearRing.prototype,
  81066. 'simplify',
  81067. ol.geom.LinearRing.prototype.simplify);
  81068. goog.exportProperty(
  81069. ol.geom.LinearRing.prototype,
  81070. 'transform',
  81071. ol.geom.LinearRing.prototype.transform);
  81072. goog.exportProperty(
  81073. ol.geom.LinearRing.prototype,
  81074. 'get',
  81075. ol.geom.LinearRing.prototype.get);
  81076. goog.exportProperty(
  81077. ol.geom.LinearRing.prototype,
  81078. 'getKeys',
  81079. ol.geom.LinearRing.prototype.getKeys);
  81080. goog.exportProperty(
  81081. ol.geom.LinearRing.prototype,
  81082. 'getProperties',
  81083. ol.geom.LinearRing.prototype.getProperties);
  81084. goog.exportProperty(
  81085. ol.geom.LinearRing.prototype,
  81086. 'set',
  81087. ol.geom.LinearRing.prototype.set);
  81088. goog.exportProperty(
  81089. ol.geom.LinearRing.prototype,
  81090. 'setProperties',
  81091. ol.geom.LinearRing.prototype.setProperties);
  81092. goog.exportProperty(
  81093. ol.geom.LinearRing.prototype,
  81094. 'unset',
  81095. ol.geom.LinearRing.prototype.unset);
  81096. goog.exportProperty(
  81097. ol.geom.LinearRing.prototype,
  81098. 'changed',
  81099. ol.geom.LinearRing.prototype.changed);
  81100. goog.exportProperty(
  81101. ol.geom.LinearRing.prototype,
  81102. 'dispatchEvent',
  81103. ol.geom.LinearRing.prototype.dispatchEvent);
  81104. goog.exportProperty(
  81105. ol.geom.LinearRing.prototype,
  81106. 'getRevision',
  81107. ol.geom.LinearRing.prototype.getRevision);
  81108. goog.exportProperty(
  81109. ol.geom.LinearRing.prototype,
  81110. 'on',
  81111. ol.geom.LinearRing.prototype.on);
  81112. goog.exportProperty(
  81113. ol.geom.LinearRing.prototype,
  81114. 'once',
  81115. ol.geom.LinearRing.prototype.once);
  81116. goog.exportProperty(
  81117. ol.geom.LinearRing.prototype,
  81118. 'un',
  81119. ol.geom.LinearRing.prototype.un);
  81120. goog.exportProperty(
  81121. ol.geom.LineString.prototype,
  81122. 'getFirstCoordinate',
  81123. ol.geom.LineString.prototype.getFirstCoordinate);
  81124. goog.exportProperty(
  81125. ol.geom.LineString.prototype,
  81126. 'getLastCoordinate',
  81127. ol.geom.LineString.prototype.getLastCoordinate);
  81128. goog.exportProperty(
  81129. ol.geom.LineString.prototype,
  81130. 'getLayout',
  81131. ol.geom.LineString.prototype.getLayout);
  81132. goog.exportProperty(
  81133. ol.geom.LineString.prototype,
  81134. 'rotate',
  81135. ol.geom.LineString.prototype.rotate);
  81136. goog.exportProperty(
  81137. ol.geom.LineString.prototype,
  81138. 'scale',
  81139. ol.geom.LineString.prototype.scale);
  81140. goog.exportProperty(
  81141. ol.geom.LineString.prototype,
  81142. 'getClosestPoint',
  81143. ol.geom.LineString.prototype.getClosestPoint);
  81144. goog.exportProperty(
  81145. ol.geom.LineString.prototype,
  81146. 'intersectsCoordinate',
  81147. ol.geom.LineString.prototype.intersectsCoordinate);
  81148. goog.exportProperty(
  81149. ol.geom.LineString.prototype,
  81150. 'getExtent',
  81151. ol.geom.LineString.prototype.getExtent);
  81152. goog.exportProperty(
  81153. ol.geom.LineString.prototype,
  81154. 'simplify',
  81155. ol.geom.LineString.prototype.simplify);
  81156. goog.exportProperty(
  81157. ol.geom.LineString.prototype,
  81158. 'transform',
  81159. ol.geom.LineString.prototype.transform);
  81160. goog.exportProperty(
  81161. ol.geom.LineString.prototype,
  81162. 'get',
  81163. ol.geom.LineString.prototype.get);
  81164. goog.exportProperty(
  81165. ol.geom.LineString.prototype,
  81166. 'getKeys',
  81167. ol.geom.LineString.prototype.getKeys);
  81168. goog.exportProperty(
  81169. ol.geom.LineString.prototype,
  81170. 'getProperties',
  81171. ol.geom.LineString.prototype.getProperties);
  81172. goog.exportProperty(
  81173. ol.geom.LineString.prototype,
  81174. 'set',
  81175. ol.geom.LineString.prototype.set);
  81176. goog.exportProperty(
  81177. ol.geom.LineString.prototype,
  81178. 'setProperties',
  81179. ol.geom.LineString.prototype.setProperties);
  81180. goog.exportProperty(
  81181. ol.geom.LineString.prototype,
  81182. 'unset',
  81183. ol.geom.LineString.prototype.unset);
  81184. goog.exportProperty(
  81185. ol.geom.LineString.prototype,
  81186. 'changed',
  81187. ol.geom.LineString.prototype.changed);
  81188. goog.exportProperty(
  81189. ol.geom.LineString.prototype,
  81190. 'dispatchEvent',
  81191. ol.geom.LineString.prototype.dispatchEvent);
  81192. goog.exportProperty(
  81193. ol.geom.LineString.prototype,
  81194. 'getRevision',
  81195. ol.geom.LineString.prototype.getRevision);
  81196. goog.exportProperty(
  81197. ol.geom.LineString.prototype,
  81198. 'on',
  81199. ol.geom.LineString.prototype.on);
  81200. goog.exportProperty(
  81201. ol.geom.LineString.prototype,
  81202. 'once',
  81203. ol.geom.LineString.prototype.once);
  81204. goog.exportProperty(
  81205. ol.geom.LineString.prototype,
  81206. 'un',
  81207. ol.geom.LineString.prototype.un);
  81208. goog.exportProperty(
  81209. ol.geom.MultiLineString.prototype,
  81210. 'getFirstCoordinate',
  81211. ol.geom.MultiLineString.prototype.getFirstCoordinate);
  81212. goog.exportProperty(
  81213. ol.geom.MultiLineString.prototype,
  81214. 'getLastCoordinate',
  81215. ol.geom.MultiLineString.prototype.getLastCoordinate);
  81216. goog.exportProperty(
  81217. ol.geom.MultiLineString.prototype,
  81218. 'getLayout',
  81219. ol.geom.MultiLineString.prototype.getLayout);
  81220. goog.exportProperty(
  81221. ol.geom.MultiLineString.prototype,
  81222. 'rotate',
  81223. ol.geom.MultiLineString.prototype.rotate);
  81224. goog.exportProperty(
  81225. ol.geom.MultiLineString.prototype,
  81226. 'scale',
  81227. ol.geom.MultiLineString.prototype.scale);
  81228. goog.exportProperty(
  81229. ol.geom.MultiLineString.prototype,
  81230. 'getClosestPoint',
  81231. ol.geom.MultiLineString.prototype.getClosestPoint);
  81232. goog.exportProperty(
  81233. ol.geom.MultiLineString.prototype,
  81234. 'intersectsCoordinate',
  81235. ol.geom.MultiLineString.prototype.intersectsCoordinate);
  81236. goog.exportProperty(
  81237. ol.geom.MultiLineString.prototype,
  81238. 'getExtent',
  81239. ol.geom.MultiLineString.prototype.getExtent);
  81240. goog.exportProperty(
  81241. ol.geom.MultiLineString.prototype,
  81242. 'simplify',
  81243. ol.geom.MultiLineString.prototype.simplify);
  81244. goog.exportProperty(
  81245. ol.geom.MultiLineString.prototype,
  81246. 'transform',
  81247. ol.geom.MultiLineString.prototype.transform);
  81248. goog.exportProperty(
  81249. ol.geom.MultiLineString.prototype,
  81250. 'get',
  81251. ol.geom.MultiLineString.prototype.get);
  81252. goog.exportProperty(
  81253. ol.geom.MultiLineString.prototype,
  81254. 'getKeys',
  81255. ol.geom.MultiLineString.prototype.getKeys);
  81256. goog.exportProperty(
  81257. ol.geom.MultiLineString.prototype,
  81258. 'getProperties',
  81259. ol.geom.MultiLineString.prototype.getProperties);
  81260. goog.exportProperty(
  81261. ol.geom.MultiLineString.prototype,
  81262. 'set',
  81263. ol.geom.MultiLineString.prototype.set);
  81264. goog.exportProperty(
  81265. ol.geom.MultiLineString.prototype,
  81266. 'setProperties',
  81267. ol.geom.MultiLineString.prototype.setProperties);
  81268. goog.exportProperty(
  81269. ol.geom.MultiLineString.prototype,
  81270. 'unset',
  81271. ol.geom.MultiLineString.prototype.unset);
  81272. goog.exportProperty(
  81273. ol.geom.MultiLineString.prototype,
  81274. 'changed',
  81275. ol.geom.MultiLineString.prototype.changed);
  81276. goog.exportProperty(
  81277. ol.geom.MultiLineString.prototype,
  81278. 'dispatchEvent',
  81279. ol.geom.MultiLineString.prototype.dispatchEvent);
  81280. goog.exportProperty(
  81281. ol.geom.MultiLineString.prototype,
  81282. 'getRevision',
  81283. ol.geom.MultiLineString.prototype.getRevision);
  81284. goog.exportProperty(
  81285. ol.geom.MultiLineString.prototype,
  81286. 'on',
  81287. ol.geom.MultiLineString.prototype.on);
  81288. goog.exportProperty(
  81289. ol.geom.MultiLineString.prototype,
  81290. 'once',
  81291. ol.geom.MultiLineString.prototype.once);
  81292. goog.exportProperty(
  81293. ol.geom.MultiLineString.prototype,
  81294. 'un',
  81295. ol.geom.MultiLineString.prototype.un);
  81296. goog.exportProperty(
  81297. ol.geom.MultiPoint.prototype,
  81298. 'getFirstCoordinate',
  81299. ol.geom.MultiPoint.prototype.getFirstCoordinate);
  81300. goog.exportProperty(
  81301. ol.geom.MultiPoint.prototype,
  81302. 'getLastCoordinate',
  81303. ol.geom.MultiPoint.prototype.getLastCoordinate);
  81304. goog.exportProperty(
  81305. ol.geom.MultiPoint.prototype,
  81306. 'getLayout',
  81307. ol.geom.MultiPoint.prototype.getLayout);
  81308. goog.exportProperty(
  81309. ol.geom.MultiPoint.prototype,
  81310. 'rotate',
  81311. ol.geom.MultiPoint.prototype.rotate);
  81312. goog.exportProperty(
  81313. ol.geom.MultiPoint.prototype,
  81314. 'scale',
  81315. ol.geom.MultiPoint.prototype.scale);
  81316. goog.exportProperty(
  81317. ol.geom.MultiPoint.prototype,
  81318. 'getClosestPoint',
  81319. ol.geom.MultiPoint.prototype.getClosestPoint);
  81320. goog.exportProperty(
  81321. ol.geom.MultiPoint.prototype,
  81322. 'intersectsCoordinate',
  81323. ol.geom.MultiPoint.prototype.intersectsCoordinate);
  81324. goog.exportProperty(
  81325. ol.geom.MultiPoint.prototype,
  81326. 'getExtent',
  81327. ol.geom.MultiPoint.prototype.getExtent);
  81328. goog.exportProperty(
  81329. ol.geom.MultiPoint.prototype,
  81330. 'simplify',
  81331. ol.geom.MultiPoint.prototype.simplify);
  81332. goog.exportProperty(
  81333. ol.geom.MultiPoint.prototype,
  81334. 'transform',
  81335. ol.geom.MultiPoint.prototype.transform);
  81336. goog.exportProperty(
  81337. ol.geom.MultiPoint.prototype,
  81338. 'get',
  81339. ol.geom.MultiPoint.prototype.get);
  81340. goog.exportProperty(
  81341. ol.geom.MultiPoint.prototype,
  81342. 'getKeys',
  81343. ol.geom.MultiPoint.prototype.getKeys);
  81344. goog.exportProperty(
  81345. ol.geom.MultiPoint.prototype,
  81346. 'getProperties',
  81347. ol.geom.MultiPoint.prototype.getProperties);
  81348. goog.exportProperty(
  81349. ol.geom.MultiPoint.prototype,
  81350. 'set',
  81351. ol.geom.MultiPoint.prototype.set);
  81352. goog.exportProperty(
  81353. ol.geom.MultiPoint.prototype,
  81354. 'setProperties',
  81355. ol.geom.MultiPoint.prototype.setProperties);
  81356. goog.exportProperty(
  81357. ol.geom.MultiPoint.prototype,
  81358. 'unset',
  81359. ol.geom.MultiPoint.prototype.unset);
  81360. goog.exportProperty(
  81361. ol.geom.MultiPoint.prototype,
  81362. 'changed',
  81363. ol.geom.MultiPoint.prototype.changed);
  81364. goog.exportProperty(
  81365. ol.geom.MultiPoint.prototype,
  81366. 'dispatchEvent',
  81367. ol.geom.MultiPoint.prototype.dispatchEvent);
  81368. goog.exportProperty(
  81369. ol.geom.MultiPoint.prototype,
  81370. 'getRevision',
  81371. ol.geom.MultiPoint.prototype.getRevision);
  81372. goog.exportProperty(
  81373. ol.geom.MultiPoint.prototype,
  81374. 'on',
  81375. ol.geom.MultiPoint.prototype.on);
  81376. goog.exportProperty(
  81377. ol.geom.MultiPoint.prototype,
  81378. 'once',
  81379. ol.geom.MultiPoint.prototype.once);
  81380. goog.exportProperty(
  81381. ol.geom.MultiPoint.prototype,
  81382. 'un',
  81383. ol.geom.MultiPoint.prototype.un);
  81384. goog.exportProperty(
  81385. ol.geom.MultiPolygon.prototype,
  81386. 'getFirstCoordinate',
  81387. ol.geom.MultiPolygon.prototype.getFirstCoordinate);
  81388. goog.exportProperty(
  81389. ol.geom.MultiPolygon.prototype,
  81390. 'getLastCoordinate',
  81391. ol.geom.MultiPolygon.prototype.getLastCoordinate);
  81392. goog.exportProperty(
  81393. ol.geom.MultiPolygon.prototype,
  81394. 'getLayout',
  81395. ol.geom.MultiPolygon.prototype.getLayout);
  81396. goog.exportProperty(
  81397. ol.geom.MultiPolygon.prototype,
  81398. 'rotate',
  81399. ol.geom.MultiPolygon.prototype.rotate);
  81400. goog.exportProperty(
  81401. ol.geom.MultiPolygon.prototype,
  81402. 'scale',
  81403. ol.geom.MultiPolygon.prototype.scale);
  81404. goog.exportProperty(
  81405. ol.geom.MultiPolygon.prototype,
  81406. 'getClosestPoint',
  81407. ol.geom.MultiPolygon.prototype.getClosestPoint);
  81408. goog.exportProperty(
  81409. ol.geom.MultiPolygon.prototype,
  81410. 'intersectsCoordinate',
  81411. ol.geom.MultiPolygon.prototype.intersectsCoordinate);
  81412. goog.exportProperty(
  81413. ol.geom.MultiPolygon.prototype,
  81414. 'getExtent',
  81415. ol.geom.MultiPolygon.prototype.getExtent);
  81416. goog.exportProperty(
  81417. ol.geom.MultiPolygon.prototype,
  81418. 'simplify',
  81419. ol.geom.MultiPolygon.prototype.simplify);
  81420. goog.exportProperty(
  81421. ol.geom.MultiPolygon.prototype,
  81422. 'transform',
  81423. ol.geom.MultiPolygon.prototype.transform);
  81424. goog.exportProperty(
  81425. ol.geom.MultiPolygon.prototype,
  81426. 'get',
  81427. ol.geom.MultiPolygon.prototype.get);
  81428. goog.exportProperty(
  81429. ol.geom.MultiPolygon.prototype,
  81430. 'getKeys',
  81431. ol.geom.MultiPolygon.prototype.getKeys);
  81432. goog.exportProperty(
  81433. ol.geom.MultiPolygon.prototype,
  81434. 'getProperties',
  81435. ol.geom.MultiPolygon.prototype.getProperties);
  81436. goog.exportProperty(
  81437. ol.geom.MultiPolygon.prototype,
  81438. 'set',
  81439. ol.geom.MultiPolygon.prototype.set);
  81440. goog.exportProperty(
  81441. ol.geom.MultiPolygon.prototype,
  81442. 'setProperties',
  81443. ol.geom.MultiPolygon.prototype.setProperties);
  81444. goog.exportProperty(
  81445. ol.geom.MultiPolygon.prototype,
  81446. 'unset',
  81447. ol.geom.MultiPolygon.prototype.unset);
  81448. goog.exportProperty(
  81449. ol.geom.MultiPolygon.prototype,
  81450. 'changed',
  81451. ol.geom.MultiPolygon.prototype.changed);
  81452. goog.exportProperty(
  81453. ol.geom.MultiPolygon.prototype,
  81454. 'dispatchEvent',
  81455. ol.geom.MultiPolygon.prototype.dispatchEvent);
  81456. goog.exportProperty(
  81457. ol.geom.MultiPolygon.prototype,
  81458. 'getRevision',
  81459. ol.geom.MultiPolygon.prototype.getRevision);
  81460. goog.exportProperty(
  81461. ol.geom.MultiPolygon.prototype,
  81462. 'on',
  81463. ol.geom.MultiPolygon.prototype.on);
  81464. goog.exportProperty(
  81465. ol.geom.MultiPolygon.prototype,
  81466. 'once',
  81467. ol.geom.MultiPolygon.prototype.once);
  81468. goog.exportProperty(
  81469. ol.geom.MultiPolygon.prototype,
  81470. 'un',
  81471. ol.geom.MultiPolygon.prototype.un);
  81472. goog.exportProperty(
  81473. ol.geom.Point.prototype,
  81474. 'getFirstCoordinate',
  81475. ol.geom.Point.prototype.getFirstCoordinate);
  81476. goog.exportProperty(
  81477. ol.geom.Point.prototype,
  81478. 'getLastCoordinate',
  81479. ol.geom.Point.prototype.getLastCoordinate);
  81480. goog.exportProperty(
  81481. ol.geom.Point.prototype,
  81482. 'getLayout',
  81483. ol.geom.Point.prototype.getLayout);
  81484. goog.exportProperty(
  81485. ol.geom.Point.prototype,
  81486. 'rotate',
  81487. ol.geom.Point.prototype.rotate);
  81488. goog.exportProperty(
  81489. ol.geom.Point.prototype,
  81490. 'scale',
  81491. ol.geom.Point.prototype.scale);
  81492. goog.exportProperty(
  81493. ol.geom.Point.prototype,
  81494. 'getClosestPoint',
  81495. ol.geom.Point.prototype.getClosestPoint);
  81496. goog.exportProperty(
  81497. ol.geom.Point.prototype,
  81498. 'intersectsCoordinate',
  81499. ol.geom.Point.prototype.intersectsCoordinate);
  81500. goog.exportProperty(
  81501. ol.geom.Point.prototype,
  81502. 'getExtent',
  81503. ol.geom.Point.prototype.getExtent);
  81504. goog.exportProperty(
  81505. ol.geom.Point.prototype,
  81506. 'simplify',
  81507. ol.geom.Point.prototype.simplify);
  81508. goog.exportProperty(
  81509. ol.geom.Point.prototype,
  81510. 'transform',
  81511. ol.geom.Point.prototype.transform);
  81512. goog.exportProperty(
  81513. ol.geom.Point.prototype,
  81514. 'get',
  81515. ol.geom.Point.prototype.get);
  81516. goog.exportProperty(
  81517. ol.geom.Point.prototype,
  81518. 'getKeys',
  81519. ol.geom.Point.prototype.getKeys);
  81520. goog.exportProperty(
  81521. ol.geom.Point.prototype,
  81522. 'getProperties',
  81523. ol.geom.Point.prototype.getProperties);
  81524. goog.exportProperty(
  81525. ol.geom.Point.prototype,
  81526. 'set',
  81527. ol.geom.Point.prototype.set);
  81528. goog.exportProperty(
  81529. ol.geom.Point.prototype,
  81530. 'setProperties',
  81531. ol.geom.Point.prototype.setProperties);
  81532. goog.exportProperty(
  81533. ol.geom.Point.prototype,
  81534. 'unset',
  81535. ol.geom.Point.prototype.unset);
  81536. goog.exportProperty(
  81537. ol.geom.Point.prototype,
  81538. 'changed',
  81539. ol.geom.Point.prototype.changed);
  81540. goog.exportProperty(
  81541. ol.geom.Point.prototype,
  81542. 'dispatchEvent',
  81543. ol.geom.Point.prototype.dispatchEvent);
  81544. goog.exportProperty(
  81545. ol.geom.Point.prototype,
  81546. 'getRevision',
  81547. ol.geom.Point.prototype.getRevision);
  81548. goog.exportProperty(
  81549. ol.geom.Point.prototype,
  81550. 'on',
  81551. ol.geom.Point.prototype.on);
  81552. goog.exportProperty(
  81553. ol.geom.Point.prototype,
  81554. 'once',
  81555. ol.geom.Point.prototype.once);
  81556. goog.exportProperty(
  81557. ol.geom.Point.prototype,
  81558. 'un',
  81559. ol.geom.Point.prototype.un);
  81560. goog.exportProperty(
  81561. ol.geom.Polygon.prototype,
  81562. 'getFirstCoordinate',
  81563. ol.geom.Polygon.prototype.getFirstCoordinate);
  81564. goog.exportProperty(
  81565. ol.geom.Polygon.prototype,
  81566. 'getLastCoordinate',
  81567. ol.geom.Polygon.prototype.getLastCoordinate);
  81568. goog.exportProperty(
  81569. ol.geom.Polygon.prototype,
  81570. 'getLayout',
  81571. ol.geom.Polygon.prototype.getLayout);
  81572. goog.exportProperty(
  81573. ol.geom.Polygon.prototype,
  81574. 'rotate',
  81575. ol.geom.Polygon.prototype.rotate);
  81576. goog.exportProperty(
  81577. ol.geom.Polygon.prototype,
  81578. 'scale',
  81579. ol.geom.Polygon.prototype.scale);
  81580. goog.exportProperty(
  81581. ol.geom.Polygon.prototype,
  81582. 'getClosestPoint',
  81583. ol.geom.Polygon.prototype.getClosestPoint);
  81584. goog.exportProperty(
  81585. ol.geom.Polygon.prototype,
  81586. 'intersectsCoordinate',
  81587. ol.geom.Polygon.prototype.intersectsCoordinate);
  81588. goog.exportProperty(
  81589. ol.geom.Polygon.prototype,
  81590. 'getExtent',
  81591. ol.geom.Polygon.prototype.getExtent);
  81592. goog.exportProperty(
  81593. ol.geom.Polygon.prototype,
  81594. 'simplify',
  81595. ol.geom.Polygon.prototype.simplify);
  81596. goog.exportProperty(
  81597. ol.geom.Polygon.prototype,
  81598. 'transform',
  81599. ol.geom.Polygon.prototype.transform);
  81600. goog.exportProperty(
  81601. ol.geom.Polygon.prototype,
  81602. 'get',
  81603. ol.geom.Polygon.prototype.get);
  81604. goog.exportProperty(
  81605. ol.geom.Polygon.prototype,
  81606. 'getKeys',
  81607. ol.geom.Polygon.prototype.getKeys);
  81608. goog.exportProperty(
  81609. ol.geom.Polygon.prototype,
  81610. 'getProperties',
  81611. ol.geom.Polygon.prototype.getProperties);
  81612. goog.exportProperty(
  81613. ol.geom.Polygon.prototype,
  81614. 'set',
  81615. ol.geom.Polygon.prototype.set);
  81616. goog.exportProperty(
  81617. ol.geom.Polygon.prototype,
  81618. 'setProperties',
  81619. ol.geom.Polygon.prototype.setProperties);
  81620. goog.exportProperty(
  81621. ol.geom.Polygon.prototype,
  81622. 'unset',
  81623. ol.geom.Polygon.prototype.unset);
  81624. goog.exportProperty(
  81625. ol.geom.Polygon.prototype,
  81626. 'changed',
  81627. ol.geom.Polygon.prototype.changed);
  81628. goog.exportProperty(
  81629. ol.geom.Polygon.prototype,
  81630. 'dispatchEvent',
  81631. ol.geom.Polygon.prototype.dispatchEvent);
  81632. goog.exportProperty(
  81633. ol.geom.Polygon.prototype,
  81634. 'getRevision',
  81635. ol.geom.Polygon.prototype.getRevision);
  81636. goog.exportProperty(
  81637. ol.geom.Polygon.prototype,
  81638. 'on',
  81639. ol.geom.Polygon.prototype.on);
  81640. goog.exportProperty(
  81641. ol.geom.Polygon.prototype,
  81642. 'once',
  81643. ol.geom.Polygon.prototype.once);
  81644. goog.exportProperty(
  81645. ol.geom.Polygon.prototype,
  81646. 'un',
  81647. ol.geom.Polygon.prototype.un);
  81648. goog.exportProperty(
  81649. ol.format.GML.prototype,
  81650. 'readFeatures',
  81651. ol.format.GML.prototype.readFeatures);
  81652. goog.exportProperty(
  81653. ol.format.GML2.prototype,
  81654. 'readFeatures',
  81655. ol.format.GML2.prototype.readFeatures);
  81656. goog.exportProperty(
  81657. ol.format.GML3.prototype,
  81658. 'readFeatures',
  81659. ol.format.GML3.prototype.readFeatures);
  81660. goog.exportProperty(
  81661. ol.control.Control.prototype,
  81662. 'get',
  81663. ol.control.Control.prototype.get);
  81664. goog.exportProperty(
  81665. ol.control.Control.prototype,
  81666. 'getKeys',
  81667. ol.control.Control.prototype.getKeys);
  81668. goog.exportProperty(
  81669. ol.control.Control.prototype,
  81670. 'getProperties',
  81671. ol.control.Control.prototype.getProperties);
  81672. goog.exportProperty(
  81673. ol.control.Control.prototype,
  81674. 'set',
  81675. ol.control.Control.prototype.set);
  81676. goog.exportProperty(
  81677. ol.control.Control.prototype,
  81678. 'setProperties',
  81679. ol.control.Control.prototype.setProperties);
  81680. goog.exportProperty(
  81681. ol.control.Control.prototype,
  81682. 'unset',
  81683. ol.control.Control.prototype.unset);
  81684. goog.exportProperty(
  81685. ol.control.Control.prototype,
  81686. 'changed',
  81687. ol.control.Control.prototype.changed);
  81688. goog.exportProperty(
  81689. ol.control.Control.prototype,
  81690. 'dispatchEvent',
  81691. ol.control.Control.prototype.dispatchEvent);
  81692. goog.exportProperty(
  81693. ol.control.Control.prototype,
  81694. 'getRevision',
  81695. ol.control.Control.prototype.getRevision);
  81696. goog.exportProperty(
  81697. ol.control.Control.prototype,
  81698. 'on',
  81699. ol.control.Control.prototype.on);
  81700. goog.exportProperty(
  81701. ol.control.Control.prototype,
  81702. 'once',
  81703. ol.control.Control.prototype.once);
  81704. goog.exportProperty(
  81705. ol.control.Control.prototype,
  81706. 'un',
  81707. ol.control.Control.prototype.un);
  81708. goog.exportProperty(
  81709. ol.control.Attribution.prototype,
  81710. 'getMap',
  81711. ol.control.Attribution.prototype.getMap);
  81712. goog.exportProperty(
  81713. ol.control.Attribution.prototype,
  81714. 'setMap',
  81715. ol.control.Attribution.prototype.setMap);
  81716. goog.exportProperty(
  81717. ol.control.Attribution.prototype,
  81718. 'setTarget',
  81719. ol.control.Attribution.prototype.setTarget);
  81720. goog.exportProperty(
  81721. ol.control.Attribution.prototype,
  81722. 'get',
  81723. ol.control.Attribution.prototype.get);
  81724. goog.exportProperty(
  81725. ol.control.Attribution.prototype,
  81726. 'getKeys',
  81727. ol.control.Attribution.prototype.getKeys);
  81728. goog.exportProperty(
  81729. ol.control.Attribution.prototype,
  81730. 'getProperties',
  81731. ol.control.Attribution.prototype.getProperties);
  81732. goog.exportProperty(
  81733. ol.control.Attribution.prototype,
  81734. 'set',
  81735. ol.control.Attribution.prototype.set);
  81736. goog.exportProperty(
  81737. ol.control.Attribution.prototype,
  81738. 'setProperties',
  81739. ol.control.Attribution.prototype.setProperties);
  81740. goog.exportProperty(
  81741. ol.control.Attribution.prototype,
  81742. 'unset',
  81743. ol.control.Attribution.prototype.unset);
  81744. goog.exportProperty(
  81745. ol.control.Attribution.prototype,
  81746. 'changed',
  81747. ol.control.Attribution.prototype.changed);
  81748. goog.exportProperty(
  81749. ol.control.Attribution.prototype,
  81750. 'dispatchEvent',
  81751. ol.control.Attribution.prototype.dispatchEvent);
  81752. goog.exportProperty(
  81753. ol.control.Attribution.prototype,
  81754. 'getRevision',
  81755. ol.control.Attribution.prototype.getRevision);
  81756. goog.exportProperty(
  81757. ol.control.Attribution.prototype,
  81758. 'on',
  81759. ol.control.Attribution.prototype.on);
  81760. goog.exportProperty(
  81761. ol.control.Attribution.prototype,
  81762. 'once',
  81763. ol.control.Attribution.prototype.once);
  81764. goog.exportProperty(
  81765. ol.control.Attribution.prototype,
  81766. 'un',
  81767. ol.control.Attribution.prototype.un);
  81768. goog.exportProperty(
  81769. ol.control.FullScreen.prototype,
  81770. 'getMap',
  81771. ol.control.FullScreen.prototype.getMap);
  81772. goog.exportProperty(
  81773. ol.control.FullScreen.prototype,
  81774. 'setMap',
  81775. ol.control.FullScreen.prototype.setMap);
  81776. goog.exportProperty(
  81777. ol.control.FullScreen.prototype,
  81778. 'setTarget',
  81779. ol.control.FullScreen.prototype.setTarget);
  81780. goog.exportProperty(
  81781. ol.control.FullScreen.prototype,
  81782. 'get',
  81783. ol.control.FullScreen.prototype.get);
  81784. goog.exportProperty(
  81785. ol.control.FullScreen.prototype,
  81786. 'getKeys',
  81787. ol.control.FullScreen.prototype.getKeys);
  81788. goog.exportProperty(
  81789. ol.control.FullScreen.prototype,
  81790. 'getProperties',
  81791. ol.control.FullScreen.prototype.getProperties);
  81792. goog.exportProperty(
  81793. ol.control.FullScreen.prototype,
  81794. 'set',
  81795. ol.control.FullScreen.prototype.set);
  81796. goog.exportProperty(
  81797. ol.control.FullScreen.prototype,
  81798. 'setProperties',
  81799. ol.control.FullScreen.prototype.setProperties);
  81800. goog.exportProperty(
  81801. ol.control.FullScreen.prototype,
  81802. 'unset',
  81803. ol.control.FullScreen.prototype.unset);
  81804. goog.exportProperty(
  81805. ol.control.FullScreen.prototype,
  81806. 'changed',
  81807. ol.control.FullScreen.prototype.changed);
  81808. goog.exportProperty(
  81809. ol.control.FullScreen.prototype,
  81810. 'dispatchEvent',
  81811. ol.control.FullScreen.prototype.dispatchEvent);
  81812. goog.exportProperty(
  81813. ol.control.FullScreen.prototype,
  81814. 'getRevision',
  81815. ol.control.FullScreen.prototype.getRevision);
  81816. goog.exportProperty(
  81817. ol.control.FullScreen.prototype,
  81818. 'on',
  81819. ol.control.FullScreen.prototype.on);
  81820. goog.exportProperty(
  81821. ol.control.FullScreen.prototype,
  81822. 'once',
  81823. ol.control.FullScreen.prototype.once);
  81824. goog.exportProperty(
  81825. ol.control.FullScreen.prototype,
  81826. 'un',
  81827. ol.control.FullScreen.prototype.un);
  81828. goog.exportProperty(
  81829. ol.control.MousePosition.prototype,
  81830. 'getMap',
  81831. ol.control.MousePosition.prototype.getMap);
  81832. goog.exportProperty(
  81833. ol.control.MousePosition.prototype,
  81834. 'setMap',
  81835. ol.control.MousePosition.prototype.setMap);
  81836. goog.exportProperty(
  81837. ol.control.MousePosition.prototype,
  81838. 'setTarget',
  81839. ol.control.MousePosition.prototype.setTarget);
  81840. goog.exportProperty(
  81841. ol.control.MousePosition.prototype,
  81842. 'get',
  81843. ol.control.MousePosition.prototype.get);
  81844. goog.exportProperty(
  81845. ol.control.MousePosition.prototype,
  81846. 'getKeys',
  81847. ol.control.MousePosition.prototype.getKeys);
  81848. goog.exportProperty(
  81849. ol.control.MousePosition.prototype,
  81850. 'getProperties',
  81851. ol.control.MousePosition.prototype.getProperties);
  81852. goog.exportProperty(
  81853. ol.control.MousePosition.prototype,
  81854. 'set',
  81855. ol.control.MousePosition.prototype.set);
  81856. goog.exportProperty(
  81857. ol.control.MousePosition.prototype,
  81858. 'setProperties',
  81859. ol.control.MousePosition.prototype.setProperties);
  81860. goog.exportProperty(
  81861. ol.control.MousePosition.prototype,
  81862. 'unset',
  81863. ol.control.MousePosition.prototype.unset);
  81864. goog.exportProperty(
  81865. ol.control.MousePosition.prototype,
  81866. 'changed',
  81867. ol.control.MousePosition.prototype.changed);
  81868. goog.exportProperty(
  81869. ol.control.MousePosition.prototype,
  81870. 'dispatchEvent',
  81871. ol.control.MousePosition.prototype.dispatchEvent);
  81872. goog.exportProperty(
  81873. ol.control.MousePosition.prototype,
  81874. 'getRevision',
  81875. ol.control.MousePosition.prototype.getRevision);
  81876. goog.exportProperty(
  81877. ol.control.MousePosition.prototype,
  81878. 'on',
  81879. ol.control.MousePosition.prototype.on);
  81880. goog.exportProperty(
  81881. ol.control.MousePosition.prototype,
  81882. 'once',
  81883. ol.control.MousePosition.prototype.once);
  81884. goog.exportProperty(
  81885. ol.control.MousePosition.prototype,
  81886. 'un',
  81887. ol.control.MousePosition.prototype.un);
  81888. goog.exportProperty(
  81889. ol.control.OverviewMap.prototype,
  81890. 'getMap',
  81891. ol.control.OverviewMap.prototype.getMap);
  81892. goog.exportProperty(
  81893. ol.control.OverviewMap.prototype,
  81894. 'setMap',
  81895. ol.control.OverviewMap.prototype.setMap);
  81896. goog.exportProperty(
  81897. ol.control.OverviewMap.prototype,
  81898. 'setTarget',
  81899. ol.control.OverviewMap.prototype.setTarget);
  81900. goog.exportProperty(
  81901. ol.control.OverviewMap.prototype,
  81902. 'get',
  81903. ol.control.OverviewMap.prototype.get);
  81904. goog.exportProperty(
  81905. ol.control.OverviewMap.prototype,
  81906. 'getKeys',
  81907. ol.control.OverviewMap.prototype.getKeys);
  81908. goog.exportProperty(
  81909. ol.control.OverviewMap.prototype,
  81910. 'getProperties',
  81911. ol.control.OverviewMap.prototype.getProperties);
  81912. goog.exportProperty(
  81913. ol.control.OverviewMap.prototype,
  81914. 'set',
  81915. ol.control.OverviewMap.prototype.set);
  81916. goog.exportProperty(
  81917. ol.control.OverviewMap.prototype,
  81918. 'setProperties',
  81919. ol.control.OverviewMap.prototype.setProperties);
  81920. goog.exportProperty(
  81921. ol.control.OverviewMap.prototype,
  81922. 'unset',
  81923. ol.control.OverviewMap.prototype.unset);
  81924. goog.exportProperty(
  81925. ol.control.OverviewMap.prototype,
  81926. 'changed',
  81927. ol.control.OverviewMap.prototype.changed);
  81928. goog.exportProperty(
  81929. ol.control.OverviewMap.prototype,
  81930. 'dispatchEvent',
  81931. ol.control.OverviewMap.prototype.dispatchEvent);
  81932. goog.exportProperty(
  81933. ol.control.OverviewMap.prototype,
  81934. 'getRevision',
  81935. ol.control.OverviewMap.prototype.getRevision);
  81936. goog.exportProperty(
  81937. ol.control.OverviewMap.prototype,
  81938. 'on',
  81939. ol.control.OverviewMap.prototype.on);
  81940. goog.exportProperty(
  81941. ol.control.OverviewMap.prototype,
  81942. 'once',
  81943. ol.control.OverviewMap.prototype.once);
  81944. goog.exportProperty(
  81945. ol.control.OverviewMap.prototype,
  81946. 'un',
  81947. ol.control.OverviewMap.prototype.un);
  81948. goog.exportProperty(
  81949. ol.control.Rotate.prototype,
  81950. 'getMap',
  81951. ol.control.Rotate.prototype.getMap);
  81952. goog.exportProperty(
  81953. ol.control.Rotate.prototype,
  81954. 'setMap',
  81955. ol.control.Rotate.prototype.setMap);
  81956. goog.exportProperty(
  81957. ol.control.Rotate.prototype,
  81958. 'setTarget',
  81959. ol.control.Rotate.prototype.setTarget);
  81960. goog.exportProperty(
  81961. ol.control.Rotate.prototype,
  81962. 'get',
  81963. ol.control.Rotate.prototype.get);
  81964. goog.exportProperty(
  81965. ol.control.Rotate.prototype,
  81966. 'getKeys',
  81967. ol.control.Rotate.prototype.getKeys);
  81968. goog.exportProperty(
  81969. ol.control.Rotate.prototype,
  81970. 'getProperties',
  81971. ol.control.Rotate.prototype.getProperties);
  81972. goog.exportProperty(
  81973. ol.control.Rotate.prototype,
  81974. 'set',
  81975. ol.control.Rotate.prototype.set);
  81976. goog.exportProperty(
  81977. ol.control.Rotate.prototype,
  81978. 'setProperties',
  81979. ol.control.Rotate.prototype.setProperties);
  81980. goog.exportProperty(
  81981. ol.control.Rotate.prototype,
  81982. 'unset',
  81983. ol.control.Rotate.prototype.unset);
  81984. goog.exportProperty(
  81985. ol.control.Rotate.prototype,
  81986. 'changed',
  81987. ol.control.Rotate.prototype.changed);
  81988. goog.exportProperty(
  81989. ol.control.Rotate.prototype,
  81990. 'dispatchEvent',
  81991. ol.control.Rotate.prototype.dispatchEvent);
  81992. goog.exportProperty(
  81993. ol.control.Rotate.prototype,
  81994. 'getRevision',
  81995. ol.control.Rotate.prototype.getRevision);
  81996. goog.exportProperty(
  81997. ol.control.Rotate.prototype,
  81998. 'on',
  81999. ol.control.Rotate.prototype.on);
  82000. goog.exportProperty(
  82001. ol.control.Rotate.prototype,
  82002. 'once',
  82003. ol.control.Rotate.prototype.once);
  82004. goog.exportProperty(
  82005. ol.control.Rotate.prototype,
  82006. 'un',
  82007. ol.control.Rotate.prototype.un);
  82008. goog.exportProperty(
  82009. ol.control.ScaleLine.prototype,
  82010. 'getMap',
  82011. ol.control.ScaleLine.prototype.getMap);
  82012. goog.exportProperty(
  82013. ol.control.ScaleLine.prototype,
  82014. 'setMap',
  82015. ol.control.ScaleLine.prototype.setMap);
  82016. goog.exportProperty(
  82017. ol.control.ScaleLine.prototype,
  82018. 'setTarget',
  82019. ol.control.ScaleLine.prototype.setTarget);
  82020. goog.exportProperty(
  82021. ol.control.ScaleLine.prototype,
  82022. 'get',
  82023. ol.control.ScaleLine.prototype.get);
  82024. goog.exportProperty(
  82025. ol.control.ScaleLine.prototype,
  82026. 'getKeys',
  82027. ol.control.ScaleLine.prototype.getKeys);
  82028. goog.exportProperty(
  82029. ol.control.ScaleLine.prototype,
  82030. 'getProperties',
  82031. ol.control.ScaleLine.prototype.getProperties);
  82032. goog.exportProperty(
  82033. ol.control.ScaleLine.prototype,
  82034. 'set',
  82035. ol.control.ScaleLine.prototype.set);
  82036. goog.exportProperty(
  82037. ol.control.ScaleLine.prototype,
  82038. 'setProperties',
  82039. ol.control.ScaleLine.prototype.setProperties);
  82040. goog.exportProperty(
  82041. ol.control.ScaleLine.prototype,
  82042. 'unset',
  82043. ol.control.ScaleLine.prototype.unset);
  82044. goog.exportProperty(
  82045. ol.control.ScaleLine.prototype,
  82046. 'changed',
  82047. ol.control.ScaleLine.prototype.changed);
  82048. goog.exportProperty(
  82049. ol.control.ScaleLine.prototype,
  82050. 'dispatchEvent',
  82051. ol.control.ScaleLine.prototype.dispatchEvent);
  82052. goog.exportProperty(
  82053. ol.control.ScaleLine.prototype,
  82054. 'getRevision',
  82055. ol.control.ScaleLine.prototype.getRevision);
  82056. goog.exportProperty(
  82057. ol.control.ScaleLine.prototype,
  82058. 'on',
  82059. ol.control.ScaleLine.prototype.on);
  82060. goog.exportProperty(
  82061. ol.control.ScaleLine.prototype,
  82062. 'once',
  82063. ol.control.ScaleLine.prototype.once);
  82064. goog.exportProperty(
  82065. ol.control.ScaleLine.prototype,
  82066. 'un',
  82067. ol.control.ScaleLine.prototype.un);
  82068. goog.exportProperty(
  82069. ol.control.Zoom.prototype,
  82070. 'getMap',
  82071. ol.control.Zoom.prototype.getMap);
  82072. goog.exportProperty(
  82073. ol.control.Zoom.prototype,
  82074. 'setMap',
  82075. ol.control.Zoom.prototype.setMap);
  82076. goog.exportProperty(
  82077. ol.control.Zoom.prototype,
  82078. 'setTarget',
  82079. ol.control.Zoom.prototype.setTarget);
  82080. goog.exportProperty(
  82081. ol.control.Zoom.prototype,
  82082. 'get',
  82083. ol.control.Zoom.prototype.get);
  82084. goog.exportProperty(
  82085. ol.control.Zoom.prototype,
  82086. 'getKeys',
  82087. ol.control.Zoom.prototype.getKeys);
  82088. goog.exportProperty(
  82089. ol.control.Zoom.prototype,
  82090. 'getProperties',
  82091. ol.control.Zoom.prototype.getProperties);
  82092. goog.exportProperty(
  82093. ol.control.Zoom.prototype,
  82094. 'set',
  82095. ol.control.Zoom.prototype.set);
  82096. goog.exportProperty(
  82097. ol.control.Zoom.prototype,
  82098. 'setProperties',
  82099. ol.control.Zoom.prototype.setProperties);
  82100. goog.exportProperty(
  82101. ol.control.Zoom.prototype,
  82102. 'unset',
  82103. ol.control.Zoom.prototype.unset);
  82104. goog.exportProperty(
  82105. ol.control.Zoom.prototype,
  82106. 'changed',
  82107. ol.control.Zoom.prototype.changed);
  82108. goog.exportProperty(
  82109. ol.control.Zoom.prototype,
  82110. 'dispatchEvent',
  82111. ol.control.Zoom.prototype.dispatchEvent);
  82112. goog.exportProperty(
  82113. ol.control.Zoom.prototype,
  82114. 'getRevision',
  82115. ol.control.Zoom.prototype.getRevision);
  82116. goog.exportProperty(
  82117. ol.control.Zoom.prototype,
  82118. 'on',
  82119. ol.control.Zoom.prototype.on);
  82120. goog.exportProperty(
  82121. ol.control.Zoom.prototype,
  82122. 'once',
  82123. ol.control.Zoom.prototype.once);
  82124. goog.exportProperty(
  82125. ol.control.Zoom.prototype,
  82126. 'un',
  82127. ol.control.Zoom.prototype.un);
  82128. goog.exportProperty(
  82129. ol.control.ZoomSlider.prototype,
  82130. 'getMap',
  82131. ol.control.ZoomSlider.prototype.getMap);
  82132. goog.exportProperty(
  82133. ol.control.ZoomSlider.prototype,
  82134. 'setMap',
  82135. ol.control.ZoomSlider.prototype.setMap);
  82136. goog.exportProperty(
  82137. ol.control.ZoomSlider.prototype,
  82138. 'setTarget',
  82139. ol.control.ZoomSlider.prototype.setTarget);
  82140. goog.exportProperty(
  82141. ol.control.ZoomSlider.prototype,
  82142. 'get',
  82143. ol.control.ZoomSlider.prototype.get);
  82144. goog.exportProperty(
  82145. ol.control.ZoomSlider.prototype,
  82146. 'getKeys',
  82147. ol.control.ZoomSlider.prototype.getKeys);
  82148. goog.exportProperty(
  82149. ol.control.ZoomSlider.prototype,
  82150. 'getProperties',
  82151. ol.control.ZoomSlider.prototype.getProperties);
  82152. goog.exportProperty(
  82153. ol.control.ZoomSlider.prototype,
  82154. 'set',
  82155. ol.control.ZoomSlider.prototype.set);
  82156. goog.exportProperty(
  82157. ol.control.ZoomSlider.prototype,
  82158. 'setProperties',
  82159. ol.control.ZoomSlider.prototype.setProperties);
  82160. goog.exportProperty(
  82161. ol.control.ZoomSlider.prototype,
  82162. 'unset',
  82163. ol.control.ZoomSlider.prototype.unset);
  82164. goog.exportProperty(
  82165. ol.control.ZoomSlider.prototype,
  82166. 'changed',
  82167. ol.control.ZoomSlider.prototype.changed);
  82168. goog.exportProperty(
  82169. ol.control.ZoomSlider.prototype,
  82170. 'dispatchEvent',
  82171. ol.control.ZoomSlider.prototype.dispatchEvent);
  82172. goog.exportProperty(
  82173. ol.control.ZoomSlider.prototype,
  82174. 'getRevision',
  82175. ol.control.ZoomSlider.prototype.getRevision);
  82176. goog.exportProperty(
  82177. ol.control.ZoomSlider.prototype,
  82178. 'on',
  82179. ol.control.ZoomSlider.prototype.on);
  82180. goog.exportProperty(
  82181. ol.control.ZoomSlider.prototype,
  82182. 'once',
  82183. ol.control.ZoomSlider.prototype.once);
  82184. goog.exportProperty(
  82185. ol.control.ZoomSlider.prototype,
  82186. 'un',
  82187. ol.control.ZoomSlider.prototype.un);
  82188. goog.exportProperty(
  82189. ol.control.ZoomToExtent.prototype,
  82190. 'getMap',
  82191. ol.control.ZoomToExtent.prototype.getMap);
  82192. goog.exportProperty(
  82193. ol.control.ZoomToExtent.prototype,
  82194. 'setMap',
  82195. ol.control.ZoomToExtent.prototype.setMap);
  82196. goog.exportProperty(
  82197. ol.control.ZoomToExtent.prototype,
  82198. 'setTarget',
  82199. ol.control.ZoomToExtent.prototype.setTarget);
  82200. goog.exportProperty(
  82201. ol.control.ZoomToExtent.prototype,
  82202. 'get',
  82203. ol.control.ZoomToExtent.prototype.get);
  82204. goog.exportProperty(
  82205. ol.control.ZoomToExtent.prototype,
  82206. 'getKeys',
  82207. ol.control.ZoomToExtent.prototype.getKeys);
  82208. goog.exportProperty(
  82209. ol.control.ZoomToExtent.prototype,
  82210. 'getProperties',
  82211. ol.control.ZoomToExtent.prototype.getProperties);
  82212. goog.exportProperty(
  82213. ol.control.ZoomToExtent.prototype,
  82214. 'set',
  82215. ol.control.ZoomToExtent.prototype.set);
  82216. goog.exportProperty(
  82217. ol.control.ZoomToExtent.prototype,
  82218. 'setProperties',
  82219. ol.control.ZoomToExtent.prototype.setProperties);
  82220. goog.exportProperty(
  82221. ol.control.ZoomToExtent.prototype,
  82222. 'unset',
  82223. ol.control.ZoomToExtent.prototype.unset);
  82224. goog.exportProperty(
  82225. ol.control.ZoomToExtent.prototype,
  82226. 'changed',
  82227. ol.control.ZoomToExtent.prototype.changed);
  82228. goog.exportProperty(
  82229. ol.control.ZoomToExtent.prototype,
  82230. 'dispatchEvent',
  82231. ol.control.ZoomToExtent.prototype.dispatchEvent);
  82232. goog.exportProperty(
  82233. ol.control.ZoomToExtent.prototype,
  82234. 'getRevision',
  82235. ol.control.ZoomToExtent.prototype.getRevision);
  82236. goog.exportProperty(
  82237. ol.control.ZoomToExtent.prototype,
  82238. 'on',
  82239. ol.control.ZoomToExtent.prototype.on);
  82240. goog.exportProperty(
  82241. ol.control.ZoomToExtent.prototype,
  82242. 'once',
  82243. ol.control.ZoomToExtent.prototype.once);
  82244. goog.exportProperty(
  82245. ol.control.ZoomToExtent.prototype,
  82246. 'un',
  82247. ol.control.ZoomToExtent.prototype.un);
  82248. ol.VERSION = 'v4.6.5';
  82249. OPENLAYERS.ol = ol;
  82250. return OPENLAYERS.ol;
  82251. }));