deprecated.js 176 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842
  1. /**
  2. * @requires OpenLayers/BaseTypes/Class.js
  3. * @requires OpenLayers/Util.js
  4. * @requires OpenLayers/Control.js
  5. * @requires OpenLayers/Format.js
  6. * @requires OpenLayers/Request.js
  7. * @requires OpenLayers/Layer/WMS.js
  8. * @requires OpenLayers/Layer/MapServer.js
  9. * @requires OpenLayers/Tile.js
  10. * @requires OpenLayers/Request/XMLHttpRequest.js
  11. * @requires OpenLayers/Layer/Vector.js
  12. * @requires OpenLayers/Layer/Markers.js
  13. * @requires OpenLayers/Console.js
  14. * @requires OpenLayers/Lang.js
  15. * @requires OpenLayers/Feature.js
  16. * @requires OpenLayers/Layer/EventPane.js
  17. * @requires OpenLayers/Layer/FixedZoomLevels.js
  18. * @requires OpenLayers/Layer/SphericalMercator.js
  19. * @requires OpenLayers/Protocol.js
  20. * @requires OpenLayers/Format/JSON.js
  21. * @requires OpenLayers/Format/WKT.js
  22. * @requires OpenLayers/Format/XML.js
  23. * @requires OpenLayers/Geometry.js
  24. * @requires OpenLayers/Renderer/Elements.js
  25. * @requires OpenLayers/Popup/Anchored.js
  26. * @requires Rico/Corner.js
  27. */
  28. /**
  29. * About: Deprecated
  30. * The deprecated.js script includes all methods, properties, and constructors
  31. * that are not supported as part of the long-term API. If you use any of
  32. * these, you have to explicitly include this script in your application.
  33. *
  34. * For example:
  35. * (code)
  36. * <script src="deprecated.js" type="text/javascript"></script>
  37. * (end)
  38. *
  39. * You are strongly encouraged to avoid using deprecated functionality. The
  40. * documentation here should point you to the supported alternatives.
  41. */
  42. /**
  43. * Namespace: OpenLayers.Class
  44. */
  45. /**
  46. * Property: isPrototype
  47. * *Deprecated*. This is no longer needed and will be removed at 3.0.
  48. */
  49. OpenLayers.Class.isPrototype = function () {};
  50. /**
  51. * APIFunction: OpenLayers.create
  52. * *Deprecated*. Old method to create an OpenLayers style class. Use the
  53. * <OpenLayers.Class> constructor instead.
  54. *
  55. * Returns:
  56. * An OpenLayers class
  57. */
  58. OpenLayers.Class.create = function() {
  59. return function() {
  60. if (arguments && arguments[0] != OpenLayers.Class.isPrototype) {
  61. this.initialize.apply(this, arguments);
  62. }
  63. };
  64. };
  65. /**
  66. * APIFunction: inherit
  67. * *Deprecated*. Old method to inherit from one or more OpenLayers style
  68. * classes. Use the <OpenLayers.Class> constructor instead.
  69. *
  70. * Parameters:
  71. * class - One or more classes can be provided as arguments
  72. *
  73. * Returns:
  74. * An object prototype
  75. */
  76. OpenLayers.Class.inherit = function (P) {
  77. var C = function() {
  78. P.call(this);
  79. };
  80. var newArgs = [C].concat(Array.prototype.slice.call(arguments));
  81. OpenLayers.inherit.apply(null, newArgs);
  82. return C.prototype;
  83. };
  84. /**
  85. * Namespace: OpenLayers.Util
  86. */
  87. /**
  88. * Function: clearArray
  89. * *Deprecated*. This function will disappear in 3.0.
  90. * Please use "array.length = 0" instead.
  91. *
  92. * Parameters:
  93. * array - {Array}
  94. */
  95. OpenLayers.Util.clearArray = function(array) {
  96. OpenLayers.Console.warn(
  97. OpenLayers.i18n(
  98. "methodDeprecated", {'newMethod': 'array = []'}
  99. )
  100. );
  101. array.length = 0;
  102. };
  103. /**
  104. * Function: setOpacity
  105. * *Deprecated*. This function has been deprecated. Instead, please use
  106. * <OpenLayers.Util.modifyDOMElement>
  107. * or
  108. * <OpenLayers.Util.modifyAlphaImageDiv>
  109. *
  110. * Set the opacity of a DOM Element
  111. * Note that for this function to work in IE, elements must "have layout"
  112. * according to:
  113. * http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/haslayout.asp
  114. *
  115. * Parameters:
  116. * element - {DOMElement} Set the opacity on this DOM element
  117. * opacity - {Float} Opacity value (0.0 - 1.0)
  118. */
  119. OpenLayers.Util.setOpacity = function(element, opacity) {
  120. OpenLayers.Util.modifyDOMElement(element, null, null, null,
  121. null, null, null, opacity);
  122. };
  123. /**
  124. * Function: safeStopPropagation
  125. * *Deprecated*. This function has been deprecated. Please use directly
  126. * <OpenLayers.Event.stop> passing 'true' as the 2nd
  127. * argument (preventDefault)
  128. *
  129. * Safely stop the propagation of an event *without* preventing
  130. * the default browser action from occurring.
  131. *
  132. * Parameters:
  133. * evt - {Event}
  134. */
  135. OpenLayers.Util.safeStopPropagation = function(evt) {
  136. OpenLayers.Event.stop(evt, true);
  137. };
  138. /**
  139. * Function: getArgs
  140. * *Deprecated*. Will be removed in 3.0. Please use instead
  141. * <OpenLayers.Util.getParameters>
  142. *
  143. * Parameters:
  144. * url - {String} Optional url used to extract the query string.
  145. * If null, query string is taken from page location.
  146. *
  147. * Returns:
  148. * {Object} An object of key/value pairs from the query string.
  149. */
  150. OpenLayers.Util.getArgs = function(url) {
  151. OpenLayers.Console.warn(
  152. OpenLayers.i18n(
  153. "methodDeprecated", {'newMethod': 'OpenLayers.Util.getParameters'}
  154. )
  155. );
  156. return OpenLayers.Util.getParameters(url);
  157. };
  158. /**
  159. * Maintain existing definition of $.
  160. *
  161. * The use of our $-method is deprecated and the mapping of
  162. * OpenLayers.Util.getElement will eventually be removed. Do not depend on
  163. * window.$ being defined by OpenLayers.
  164. */
  165. if(typeof window.$ === "undefined") {
  166. window.$ = OpenLayers.Util.getElement;
  167. }
  168. /**
  169. * Namespace: OpenLayers.Ajax
  170. */
  171. /**
  172. * Function: OpenLayers.nullHandler
  173. * @param {} request
  174. */
  175. OpenLayers.nullHandler = function(request) {
  176. OpenLayers.Console.userError(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText}));
  177. };
  178. /**
  179. * APIFunction: OpenLayers.loadURL
  180. * Background load a document.
  181. * *Deprecated*. Use <OpenLayers.Request.GET> method instead.
  182. *
  183. * Parameters:
  184. * uri - {String} URI of source doc
  185. * params - {String} or {Object} GET params. Either a string in the form
  186. * "?hello=world&foo=bar" (do not forget the leading question mark)
  187. * or an object in the form {'hello': 'world', 'foo': 'bar}
  188. * caller - {Object} object which gets callbacks
  189. * onComplete - {Function} Optional callback for success. The callback
  190. * will be called with this set to caller and will receive the request
  191. * object as an argument. Note that if you do not specify an onComplete
  192. * function, <OpenLayers.nullHandler> will be called (which pops up a
  193. * user friendly error message dialog).
  194. * onFailure - {Function} Optional callback for failure. In the event of
  195. * a failure, the callback will be called with this set to caller and will
  196. * receive the request object as an argument. Note that if you do not
  197. * specify an onComplete function, <OpenLayers.nullHandler> will be called
  198. * (which pops up a user friendly error message dialog).
  199. *
  200. * Returns:
  201. * {<OpenLayers.Request.XMLHttpRequest>} The request object. To abort loading,
  202. * call request.abort().
  203. */
  204. OpenLayers.loadURL = function(uri, params, caller,
  205. onComplete, onFailure) {
  206. if(typeof params == 'string') {
  207. params = OpenLayers.Util.getParameters(params);
  208. }
  209. var success = (onComplete) ? onComplete : OpenLayers.nullHandler;
  210. var failure = (onFailure) ? onFailure : OpenLayers.nullHandler;
  211. return OpenLayers.Request.GET({
  212. url: uri, params: params,
  213. success: success, failure: failure, scope: caller
  214. });
  215. };
  216. /**
  217. * Function: OpenLayers.parseXMLString
  218. * Parse XML into a doc structure
  219. *
  220. * Parameters:
  221. * text - {String}
  222. *
  223. * Returns:
  224. * {?} Parsed AJAX Responsev
  225. */
  226. OpenLayers.parseXMLString = function(text) {
  227. //MS sucks, if the server is bad it dies
  228. var index = text.indexOf('<');
  229. if (index > 0) {
  230. text = text.substring(index);
  231. }
  232. var ajaxResponse = OpenLayers.Util.Try(
  233. function() {
  234. var xmldom = new ActiveXObject('Microsoft.XMLDOM');
  235. xmldom.loadXML(text);
  236. return xmldom;
  237. },
  238. function() {
  239. return new DOMParser().parseFromString(text, 'text/xml');
  240. },
  241. function() {
  242. var req = new XMLHttpRequest();
  243. req.open("GET", "data:" + "text/xml" +
  244. ";charset=utf-8," + encodeURIComponent(text), false);
  245. if (req.overrideMimeType) {
  246. req.overrideMimeType("text/xml");
  247. }
  248. req.send(null);
  249. return req.responseXML;
  250. }
  251. );
  252. return ajaxResponse;
  253. };
  254. OpenLayers.Ajax = {
  255. /**
  256. * Method: emptyFunction
  257. */
  258. emptyFunction: function () {},
  259. /**
  260. * Method: getTransport
  261. *
  262. * Returns:
  263. * {Object} Transport mechanism for whichever browser we're in, or false if
  264. * none available.
  265. */
  266. getTransport: function() {
  267. return OpenLayers.Util.Try(
  268. function() {return new XMLHttpRequest();},
  269. function() {return new ActiveXObject('Msxml2.XMLHTTP');},
  270. function() {return new ActiveXObject('Microsoft.XMLHTTP');}
  271. ) || false;
  272. },
  273. /**
  274. * Property: activeRequestCount
  275. * {Integer}
  276. */
  277. activeRequestCount: 0
  278. };
  279. /**
  280. * Namespace: OpenLayers.Ajax.Responders
  281. * {Object}
  282. */
  283. OpenLayers.Ajax.Responders = {
  284. /**
  285. * Property: responders
  286. * {Array}
  287. */
  288. responders: [],
  289. /**
  290. * Method: register
  291. *
  292. * Parameters:
  293. * responderToAdd - {?}
  294. */
  295. register: function(responderToAdd) {
  296. for (var i = 0; i < this.responders.length; i++){
  297. if (responderToAdd == this.responders[i]){
  298. return;
  299. }
  300. }
  301. this.responders.push(responderToAdd);
  302. },
  303. /**
  304. * Method: unregister
  305. *
  306. * Parameters:
  307. * responderToRemove - {?}
  308. */
  309. unregister: function(responderToRemove) {
  310. OpenLayers.Util.removeItem(this.reponders, responderToRemove);
  311. },
  312. /**
  313. * Method: dispatch
  314. *
  315. * Parameters:
  316. * callback - {?}
  317. * request - {?}
  318. * transport - {?}
  319. */
  320. dispatch: function(callback, request, transport) {
  321. var responder;
  322. for (var i = 0; i < this.responders.length; i++) {
  323. responder = this.responders[i];
  324. if (responder[callback] &&
  325. typeof responder[callback] == 'function') {
  326. try {
  327. responder[callback].apply(responder,
  328. [request, transport]);
  329. } catch (e) {}
  330. }
  331. }
  332. }
  333. };
  334. OpenLayers.Ajax.Responders.register({
  335. /**
  336. * Function: onCreate
  337. */
  338. onCreate: function() {
  339. OpenLayers.Ajax.activeRequestCount++;
  340. },
  341. /**
  342. * Function: onComplete
  343. */
  344. onComplete: function() {
  345. OpenLayers.Ajax.activeRequestCount--;
  346. }
  347. });
  348. /**
  349. * Class: OpenLayers.Ajax.Base
  350. */
  351. OpenLayers.Ajax.Base = OpenLayers.Class({
  352. /**
  353. * Constructor: OpenLayers.Ajax.Base
  354. *
  355. * Parameters:
  356. * options - {Object}
  357. */
  358. initialize: function(options) {
  359. this.options = {
  360. method: 'post',
  361. asynchronous: true,
  362. contentType: 'application/xml',
  363. parameters: ''
  364. };
  365. OpenLayers.Util.extend(this.options, options || {});
  366. this.options.method = this.options.method.toLowerCase();
  367. if (typeof this.options.parameters == 'string') {
  368. this.options.parameters =
  369. OpenLayers.Util.getParameters(this.options.parameters);
  370. }
  371. }
  372. });
  373. /**
  374. * Class: OpenLayers.Ajax.Request
  375. * *Deprecated*. Use <OpenLayers.Request> method instead.
  376. *
  377. * Inherit:
  378. * - <OpenLayers.Ajax.Base>
  379. */
  380. OpenLayers.Ajax.Request = OpenLayers.Class(OpenLayers.Ajax.Base, {
  381. /**
  382. * Property: _complete
  383. *
  384. * {Boolean}
  385. */
  386. _complete: false,
  387. /**
  388. * Constructor: OpenLayers.Ajax.Request
  389. *
  390. * Parameters:
  391. * url - {String}
  392. * options - {Object}
  393. */
  394. initialize: function(url, options) {
  395. OpenLayers.Ajax.Base.prototype.initialize.apply(this, [options]);
  396. if (OpenLayers.ProxyHost && OpenLayers.String.startsWith(url, "http")) {
  397. url = OpenLayers.ProxyHost + encodeURIComponent(url);
  398. }
  399. this.transport = OpenLayers.Ajax.getTransport();
  400. this.request(url);
  401. },
  402. /**
  403. * Method: request
  404. *
  405. * Parameters:
  406. * url - {String}
  407. */
  408. request: function(url) {
  409. this.url = url;
  410. this.method = this.options.method;
  411. var params = OpenLayers.Util.extend({}, this.options.parameters);
  412. if (this.method != 'get' && this.method != 'post') {
  413. // simulate other verbs over post
  414. params['_method'] = this.method;
  415. this.method = 'post';
  416. }
  417. this.parameters = params;
  418. if (params = OpenLayers.Util.getParameterString(params)) {
  419. // when GET, append parameters to URL
  420. if (this.method == 'get') {
  421. this.url += ((this.url.indexOf('?') > -1) ? '&' : '?') + params;
  422. } else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
  423. params += '&_=';
  424. }
  425. }
  426. try {
  427. var response = new OpenLayers.Ajax.Response(this);
  428. if (this.options.onCreate) {
  429. this.options.onCreate(response);
  430. }
  431. OpenLayers.Ajax.Responders.dispatch('onCreate',
  432. this,
  433. response);
  434. this.transport.open(this.method.toUpperCase(),
  435. this.url,
  436. this.options.asynchronous);
  437. if (this.options.asynchronous) {
  438. window.setTimeout(
  439. OpenLayers.Function.bind(this.respondToReadyState, this, 1),
  440. 10);
  441. }
  442. this.transport.onreadystatechange =
  443. OpenLayers.Function.bind(this.onStateChange, this);
  444. this.setRequestHeaders();
  445. this.body = this.method == 'post' ?
  446. (this.options.postBody || params) : null;
  447. this.transport.send(this.body);
  448. // Force Firefox to handle ready state 4 for synchronous requests
  449. if (!this.options.asynchronous &&
  450. this.transport.overrideMimeType) {
  451. this.onStateChange();
  452. }
  453. } catch (e) {
  454. this.dispatchException(e);
  455. }
  456. },
  457. /**
  458. * Method: onStateChange
  459. */
  460. onStateChange: function() {
  461. var readyState = this.transport.readyState;
  462. if (readyState > 1 && !((readyState == 4) && this._complete)) {
  463. this.respondToReadyState(this.transport.readyState);
  464. }
  465. },
  466. /**
  467. * Method: setRequestHeaders
  468. */
  469. setRequestHeaders: function() {
  470. var headers = {
  471. 'X-Requested-With': 'XMLHttpRequest',
  472. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
  473. 'OpenLayers': true
  474. };
  475. if (this.method == 'post') {
  476. headers['Content-type'] = this.options.contentType +
  477. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  478. /* Force "Connection: close" for older Mozilla browsers to work
  479. * around a bug where XMLHttpRequest sends an incorrect
  480. * Content-length header. See Mozilla Bugzilla #246651.
  481. */
  482. if (this.transport.overrideMimeType &&
  483. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) {
  484. headers['Connection'] = 'close';
  485. }
  486. }
  487. // user-defined headers
  488. if (typeof this.options.requestHeaders == 'object') {
  489. var extras = this.options.requestHeaders;
  490. if (typeof extras.push == 'function') {
  491. for (var i = 0, length = extras.length; i < length; i += 2) {
  492. headers[extras[i]] = extras[i+1];
  493. }
  494. } else {
  495. for (var i in extras) {
  496. headers[i] = extras[i];
  497. }
  498. }
  499. }
  500. for (var name in headers) {
  501. this.transport.setRequestHeader(name, headers[name]);
  502. }
  503. },
  504. /**
  505. * Method: success
  506. *
  507. * Returns:
  508. * {Boolean} -
  509. */
  510. success: function() {
  511. var status = this.getStatus();
  512. return !status || (status >=200 && status < 300);
  513. },
  514. /**
  515. * Method: getStatus
  516. *
  517. * Returns:
  518. * {Integer} - Status
  519. */
  520. getStatus: function() {
  521. try {
  522. return this.transport.status || 0;
  523. } catch (e) {
  524. return 0;
  525. }
  526. },
  527. /**
  528. * Method: respondToReadyState
  529. *
  530. * Parameters:
  531. * readyState - {?}
  532. */
  533. respondToReadyState: function(readyState) {
  534. var state = OpenLayers.Ajax.Request.Events[readyState];
  535. var response = new OpenLayers.Ajax.Response(this);
  536. if (state == 'Complete') {
  537. try {
  538. this._complete = true;
  539. (this.options['on' + response.status] ||
  540. this.options['on' + (this.success() ? 'Success' : 'Failure')] ||
  541. OpenLayers.Ajax.emptyFunction)(response);
  542. } catch (e) {
  543. this.dispatchException(e);
  544. }
  545. var contentType = response.getHeader('Content-type');
  546. }
  547. try {
  548. (this.options['on' + state] ||
  549. OpenLayers.Ajax.emptyFunction)(response);
  550. OpenLayers.Ajax.Responders.dispatch('on' + state,
  551. this,
  552. response);
  553. } catch (e) {
  554. this.dispatchException(e);
  555. }
  556. if (state == 'Complete') {
  557. // avoid memory leak in MSIE: clean up
  558. this.transport.onreadystatechange = OpenLayers.Ajax.emptyFunction;
  559. }
  560. },
  561. /**
  562. * Method: getHeader
  563. *
  564. * Parameters:
  565. * name - {String} Header name
  566. *
  567. * Returns:
  568. * {?} - response header for the given name
  569. */
  570. getHeader: function(name) {
  571. try {
  572. return this.transport.getResponseHeader(name);
  573. } catch (e) {
  574. return null;
  575. }
  576. },
  577. /**
  578. * Method: dispatchException
  579. * If the optional onException function is set, execute it
  580. * and then dispatch the call to any other listener registered
  581. * for onException.
  582. *
  583. * If no optional onException function is set, we suspect that
  584. * the user may have also not used
  585. * OpenLayers.Ajax.Responders.register to register a listener
  586. * for the onException call. To make sure that something
  587. * gets done with this exception, only dispatch the call if there
  588. * are listeners.
  589. *
  590. * If you explicitly want to swallow exceptions, set
  591. * request.options.onException to an empty function (function(){})
  592. * or register an empty function with <OpenLayers.Ajax.Responders>
  593. * for onException.
  594. *
  595. * Parameters:
  596. * exception - {?}
  597. */
  598. dispatchException: function(exception) {
  599. var handler = this.options.onException;
  600. if(handler) {
  601. // call options.onException and alert any other listeners
  602. handler(this, exception);
  603. OpenLayers.Ajax.Responders.dispatch('onException', this, exception);
  604. } else {
  605. // check if there are any other listeners
  606. var listener = false;
  607. var responders = OpenLayers.Ajax.Responders.responders;
  608. for (var i = 0; i < responders.length; i++) {
  609. if(responders[i].onException) {
  610. listener = true;
  611. break;
  612. }
  613. }
  614. if(listener) {
  615. // call all listeners
  616. OpenLayers.Ajax.Responders.dispatch('onException', this, exception);
  617. } else {
  618. // let the exception through
  619. throw exception;
  620. }
  621. }
  622. }
  623. });
  624. /**
  625. * Property: Events
  626. * {Array(String)}
  627. */
  628. OpenLayers.Ajax.Request.Events =
  629. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  630. /**
  631. * Class: OpenLayers.Ajax.Response
  632. */
  633. OpenLayers.Ajax.Response = OpenLayers.Class({
  634. /**
  635. * Property: status
  636. *
  637. * {Integer}
  638. */
  639. status: 0,
  640. /**
  641. * Property: statusText
  642. *
  643. * {String}
  644. */
  645. statusText: '',
  646. /**
  647. * Constructor: OpenLayers.Ajax.Response
  648. *
  649. * Parameters:
  650. * request - {Object}
  651. */
  652. initialize: function(request) {
  653. this.request = request;
  654. var transport = this.transport = request.transport,
  655. readyState = this.readyState = transport.readyState;
  656. if ((readyState > 2 &&
  657. !(!!(window.attachEvent && !window.opera))) ||
  658. readyState == 4) {
  659. this.status = this.getStatus();
  660. this.statusText = this.getStatusText();
  661. this.responseText = transport.responseText == null ?
  662. '' : String(transport.responseText);
  663. }
  664. if(readyState == 4) {
  665. var xml = transport.responseXML;
  666. this.responseXML = xml === undefined ? null : xml;
  667. }
  668. },
  669. /**
  670. * Method: getStatus
  671. */
  672. getStatus: OpenLayers.Ajax.Request.prototype.getStatus,
  673. /**
  674. * Method: getStatustext
  675. *
  676. * Returns:
  677. * {String} - statusText
  678. */
  679. getStatusText: function() {
  680. try {
  681. return this.transport.statusText || '';
  682. } catch (e) {
  683. return '';
  684. }
  685. },
  686. /**
  687. * Method: getHeader
  688. */
  689. getHeader: OpenLayers.Ajax.Request.prototype.getHeader,
  690. /**
  691. * Method: getResponseHeader
  692. *
  693. * Returns:
  694. * {?} - response header for given name
  695. */
  696. getResponseHeader: function(name) {
  697. return this.transport.getResponseHeader(name);
  698. }
  699. });
  700. /**
  701. * Function: getElementsByTagNameNS
  702. *
  703. * Parameters:
  704. * parentnode - {?}
  705. * nsuri - {?}
  706. * nsprefix - {?}
  707. * tagname - {?}
  708. *
  709. * Returns:
  710. * {?}
  711. */
  712. OpenLayers.Ajax.getElementsByTagNameNS = function(parentnode, nsuri,
  713. nsprefix, tagname) {
  714. var elem = null;
  715. if (parentnode.getElementsByTagNameNS) {
  716. elem = parentnode.getElementsByTagNameNS(nsuri, tagname);
  717. } else {
  718. elem = parentnode.getElementsByTagName(nsprefix + ':' + tagname);
  719. }
  720. return elem;
  721. };
  722. /**
  723. * Function: serializeXMLToString
  724. * Wrapper function around XMLSerializer, which doesn't exist/work in
  725. * IE/Safari. We need to come up with a way to serialize in those browser:
  726. * for now, these browsers will just fail. #535, #536
  727. *
  728. * Parameters:
  729. * xmldom {XMLNode} xml dom to serialize
  730. *
  731. * Returns:
  732. * {?}
  733. */
  734. OpenLayers.Ajax.serializeXMLToString = function(xmldom) {
  735. var serializer = new XMLSerializer();
  736. var data = serializer.serializeToString(xmldom);
  737. return data;
  738. };
  739. /**
  740. * Namespace: OpenLayers.Element
  741. */
  742. OpenLayers.Util.extend(OpenLayers.Element, {
  743. /**
  744. * APIFunction: hide
  745. * *Deprecated*. Hide element(s) passed in
  746. *
  747. * Parameters:
  748. * element - {DOMElement} Actually user can pass any number of elements
  749. */
  750. hide: function() {
  751. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", {
  752. newMethod: "element.style.display = 'none';"
  753. }));
  754. for (var i=0, len=arguments.length; i<len; i++) {
  755. var element = OpenLayers.Util.getElement(arguments[i]);
  756. if (element) {
  757. element.style.display = 'none';
  758. }
  759. }
  760. },
  761. /**
  762. * APIFunction: show
  763. * *Deprecated*. Show element(s) passed in
  764. *
  765. * Parameters:
  766. * element - {DOMElement} Actually user can pass any number of elements
  767. */
  768. show: function() {
  769. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", {
  770. newMethod: "element.style.display = '';"
  771. }));
  772. for (var i=0, len=arguments.length; i<len; i++) {
  773. var element = OpenLayers.Util.getElement(arguments[i]);
  774. if (element) {
  775. element.style.display = '';
  776. }
  777. }
  778. },
  779. /**
  780. * APIFunction: getDimensions
  781. * *Deprecated*. Returns dimensions of the element passed in.
  782. *
  783. * Parameters:
  784. * element - {DOMElement}
  785. *
  786. * Returns:
  787. * {Object} Object with 'width' and 'height' properties which are the
  788. * dimensions of the element passed in.
  789. */
  790. getDimensions: function(element) {
  791. element = OpenLayers.Util.getElement(element);
  792. if (OpenLayers.Element.getStyle(element, 'display') != 'none') {
  793. return {width: element.offsetWidth, height: element.offsetHeight};
  794. }
  795. // All *Width and *Height properties give 0 on elements with display none,
  796. // so enable the element temporarily
  797. var els = element.style;
  798. var originalVisibility = els.visibility;
  799. var originalPosition = els.position;
  800. var originalDisplay = els.display;
  801. els.visibility = 'hidden';
  802. els.position = 'absolute';
  803. els.display = '';
  804. var originalWidth = element.clientWidth;
  805. var originalHeight = element.clientHeight;
  806. els.display = originalDisplay;
  807. els.position = originalPosition;
  808. els.visibility = originalVisibility;
  809. return {width: originalWidth, height: originalHeight};
  810. }
  811. });
  812. if (!String.prototype.startsWith) {
  813. /**
  814. * APIMethod: String.startsWith
  815. * *Deprecated*. Whether or not a string starts with another string.
  816. *
  817. * Parameters:
  818. * sStart - {String} The string we're testing for.
  819. *
  820. * Returns:
  821. * {Boolean} Whether or not this string starts with the string passed in.
  822. */
  823. String.prototype.startsWith = function(sStart) {
  824. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
  825. {'newMethod':'OpenLayers.String.startsWith'}));
  826. return OpenLayers.String.startsWith(this, sStart);
  827. };
  828. }
  829. if (!String.prototype.contains) {
  830. /**
  831. * APIMethod: String.contains
  832. * *Deprecated*. Whether or not a string contains another string.
  833. *
  834. * Parameters:
  835. * str - {String} The string that we're testing for.
  836. *
  837. * Returns:
  838. * {Boolean} Whether or not this string contains with the string passed in.
  839. */
  840. String.prototype.contains = function(str) {
  841. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
  842. {'newMethod':'OpenLayers.String.contains'}));
  843. return OpenLayers.String.contains(this, str);
  844. };
  845. }
  846. if (!String.prototype.trim) {
  847. /**
  848. * APIMethod: String.trim
  849. * *Deprecated*. Removes leading and trailing whitespace characters from a string.
  850. *
  851. * Returns:
  852. * {String} A trimmed version of the string - all leading and
  853. * trailing spaces removed
  854. */
  855. String.prototype.trim = function() {
  856. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
  857. {'newMethod':'OpenLayers.String.trim'}));
  858. return OpenLayers.String.trim(this);
  859. };
  860. }
  861. if (!String.prototype.camelize) {
  862. /**
  863. * APIMethod: String.camelize
  864. * *Deprecated*. Camel-case a hyphenated string.
  865. * Ex. "chicken-head" becomes "chickenHead", and
  866. * "-chicken-head" becomes "ChickenHead".
  867. *
  868. * Returns:
  869. * {String} The string, camelized
  870. */
  871. String.prototype.camelize = function() {
  872. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
  873. {'newMethod':'OpenLayers.String.camelize'}));
  874. return OpenLayers.String.camelize(this);
  875. };
  876. }
  877. if (!Function.prototype.bind) {
  878. /**
  879. * APIMethod: Function.bind
  880. * *Deprecated*. Bind a function to an object.
  881. * Method to easily create closures with 'this' altered.
  882. *
  883. * Parameters:
  884. * object - {Object} the this parameter
  885. *
  886. * Returns:
  887. * {Function} A closure with 'this' altered to the first
  888. * argument.
  889. */
  890. Function.prototype.bind = function() {
  891. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
  892. {'newMethod':'OpenLayers.Function.bind'}));
  893. // new function takes the same arguments with this function up front
  894. Array.prototype.unshift.apply(arguments, [this]);
  895. return OpenLayers.Function.bind.apply(null, arguments);
  896. };
  897. }
  898. if (!Function.prototype.bindAsEventListener) {
  899. /**
  900. * APIMethod: Function.bindAsEventListener
  901. * *Deprecated*. Bind a function to an object, and configure it to receive the
  902. * event object as first parameter when called.
  903. *
  904. * Parameters:
  905. * object - {Object} A reference to this.
  906. *
  907. * Returns:
  908. * {Function}
  909. */
  910. Function.prototype.bindAsEventListener = function(object) {
  911. OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated",
  912. {'newMethod':'OpenLayers.Function.bindAsEventListener'}));
  913. return OpenLayers.Function.bindAsEventListener(this, object);
  914. };
  915. }
  916. // FIXME: Remove this in 3.0. In 3.0, Event.stop will no longer be provided
  917. // by OpenLayers.
  918. if (window.Event) {
  919. OpenLayers.Util.applyDefaults(window.Event, OpenLayers.Event);
  920. } else {
  921. var Event = OpenLayers.Event;
  922. }
  923. /**
  924. * Namespace: OpenLayers.Tile
  925. */
  926. OpenLayers.Util.extend(OpenLayers.Tile.prototype, {
  927. /**
  928. * Method: getBoundsFromBaseLayer
  929. * Take the pixel locations of the corner of the tile, and pass them to
  930. * the base layer and ask for the location of those pixels, so that
  931. * displaying tiles over Google works fine.
  932. *
  933. * Parameters:
  934. * position - {<OpenLayers.Pixel>}
  935. *
  936. * Returns:
  937. * bounds - {<OpenLayers.Bounds>}
  938. */
  939. getBoundsFromBaseLayer: function(position) {
  940. var msg = OpenLayers.i18n('reprojectDeprecated',
  941. {'layerName':this.layer.name});
  942. OpenLayers.Console.warn(msg);
  943. var topLeft = this.layer.map.getLonLatFromLayerPx(position);
  944. var bottomRightPx = position.clone();
  945. bottomRightPx.x += this.size.w;
  946. bottomRightPx.y += this.size.h;
  947. var bottomRight = this.layer.map.getLonLatFromLayerPx(bottomRightPx);
  948. // Handle the case where the base layer wraps around the date line.
  949. // Google does this, and it breaks WMS servers to request bounds in
  950. // that fashion.
  951. if (topLeft.lon > bottomRight.lon) {
  952. if (topLeft.lon < 0) {
  953. topLeft.lon = -180 - (topLeft.lon+180);
  954. } else {
  955. bottomRight.lon = 180+bottomRight.lon+180;
  956. }
  957. }
  958. var bounds = new OpenLayers.Bounds(topLeft.lon,
  959. bottomRight.lat,
  960. bottomRight.lon,
  961. topLeft.lat);
  962. return bounds;
  963. }
  964. });
  965. /**
  966. * Class: OpenLayers.Control.MouseDefaults
  967. * This class is DEPRECATED in 2.4 and will be removed by 3.0.
  968. * If you need this functionality, use <OpenLayers.Control.Navigation>
  969. * instead!!!
  970. *
  971. * Inherits from:
  972. * - <OpenLayers.Control>
  973. */
  974. OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
  975. /** WARNING WARNING WARNING!!!
  976. This class is DEPRECATED in 2.4 and will be removed by 3.0.
  977. If you need this functionality, use Control.Navigation instead!!! */
  978. /**
  979. * Property: performedDrag
  980. * {Boolean}
  981. */
  982. performedDrag: false,
  983. /**
  984. * Property: wheelObserver
  985. * {Function}
  986. */
  987. wheelObserver: null,
  988. /**
  989. * Constructor: OpenLayers.Control.MouseDefaults
  990. */
  991. initialize: function() {
  992. OpenLayers.Control.prototype.initialize.apply(this, arguments);
  993. },
  994. /**
  995. * APIMethod: destroy
  996. */
  997. destroy: function() {
  998. if (this.handler) {
  999. this.handler.destroy();
  1000. }
  1001. this.handler = null;
  1002. this.map.events.un({
  1003. "click": this.defaultClick,
  1004. "dblclick": this.defaultDblClick,
  1005. "mousedown": this.defaultMouseDown,
  1006. "mouseup": this.defaultMouseUp,
  1007. "mousemove": this.defaultMouseMove,
  1008. "mouseout": this.defaultMouseOut,
  1009. scope: this
  1010. });
  1011. //unregister mousewheel events specifically on the window and document
  1012. OpenLayers.Event.stopObserving(window, "DOMMouseScroll",
  1013. this.wheelObserver);
  1014. OpenLayers.Event.stopObserving(window, "mousewheel",
  1015. this.wheelObserver);
  1016. OpenLayers.Event.stopObserving(document, "mousewheel",
  1017. this.wheelObserver);
  1018. this.wheelObserver = null;
  1019. OpenLayers.Control.prototype.destroy.apply(this, arguments);
  1020. },
  1021. /**
  1022. * Method: draw
  1023. */
  1024. draw: function() {
  1025. this.map.events.on({
  1026. "click": this.defaultClick,
  1027. "dblclick": this.defaultDblClick,
  1028. "mousedown": this.defaultMouseDown,
  1029. "mouseup": this.defaultMouseUp,
  1030. "mousemove": this.defaultMouseMove,
  1031. "mouseout": this.defaultMouseOut,
  1032. scope: this
  1033. });
  1034. this.registerWheelEvents();
  1035. },
  1036. /**
  1037. * Method: registerWheelEvents
  1038. */
  1039. registerWheelEvents: function() {
  1040. this.wheelObserver = OpenLayers.Function.bindAsEventListener(
  1041. this.onWheelEvent, this
  1042. );
  1043. //register mousewheel events specifically on the window and document
  1044. OpenLayers.Event.observe(window, "DOMMouseScroll", this.wheelObserver);
  1045. OpenLayers.Event.observe(window, "mousewheel", this.wheelObserver);
  1046. OpenLayers.Event.observe(document, "mousewheel", this.wheelObserver);
  1047. },
  1048. /**
  1049. * Method: defaultClick
  1050. *
  1051. * Parameters:
  1052. * evt - {Event}
  1053. *
  1054. * Returns:
  1055. * {Boolean}
  1056. */
  1057. defaultClick: function (evt) {
  1058. if (!OpenLayers.Event.isLeftClick(evt)) {
  1059. return;
  1060. }
  1061. var notAfterDrag = !this.performedDrag;
  1062. this.performedDrag = false;
  1063. return notAfterDrag;
  1064. },
  1065. /**
  1066. * Method: defaultDblClick
  1067. *
  1068. * Parameters:
  1069. * evt - {Event}
  1070. */
  1071. defaultDblClick: function (evt) {
  1072. var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
  1073. this.map.setCenter(newCenter, this.map.zoom + 1);
  1074. OpenLayers.Event.stop(evt);
  1075. return false;
  1076. },
  1077. /**
  1078. * Method: defaultMouseDown
  1079. *
  1080. * Parameters:
  1081. * evt - {Event}
  1082. */
  1083. defaultMouseDown: function (evt) {
  1084. if (!OpenLayers.Event.isLeftClick(evt)) {
  1085. return;
  1086. }
  1087. this.mouseDragStart = evt.xy.clone();
  1088. this.performedDrag = false;
  1089. if (evt.shiftKey) {
  1090. this.map.div.style.cursor = "crosshair";
  1091. this.zoomBox = OpenLayers.Util.createDiv('zoomBox',
  1092. this.mouseDragStart,
  1093. null,
  1094. null,
  1095. "absolute",
  1096. "2px solid red");
  1097. this.zoomBox.style.backgroundColor = "white";
  1098. this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
  1099. this.zoomBox.style.opacity = "0.50";
  1100. this.zoomBox.style.fontSize = "1px";
  1101. this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
  1102. this.map.viewPortDiv.appendChild(this.zoomBox);
  1103. }
  1104. document.onselectstart = OpenLayers.Function.False;
  1105. OpenLayers.Event.stop(evt);
  1106. },
  1107. /**
  1108. * Method: defaultMouseMove
  1109. *
  1110. * Parameters:
  1111. * evt - {Event}
  1112. */
  1113. defaultMouseMove: function (evt) {
  1114. // record the mouse position, used in onWheelEvent
  1115. this.mousePosition = evt.xy.clone();
  1116. if (this.mouseDragStart != null) {
  1117. if (this.zoomBox) {
  1118. var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
  1119. var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y);
  1120. this.zoomBox.style.width = Math.max(1, deltaX) + "px";
  1121. this.zoomBox.style.height = Math.max(1, deltaY) + "px";
  1122. if (evt.xy.x < this.mouseDragStart.x) {
  1123. this.zoomBox.style.left = evt.xy.x+"px";
  1124. }
  1125. if (evt.xy.y < this.mouseDragStart.y) {
  1126. this.zoomBox.style.top = evt.xy.y+"px";
  1127. }
  1128. } else {
  1129. var deltaX = this.mouseDragStart.x - evt.xy.x;
  1130. var deltaY = this.mouseDragStart.y - evt.xy.y;
  1131. var size = this.map.getSize();
  1132. var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
  1133. size.h / 2 + deltaY);
  1134. var newCenter = this.map.getLonLatFromViewPortPx( newXY );
  1135. this.map.setCenter(newCenter, null, true);
  1136. this.mouseDragStart = evt.xy.clone();
  1137. this.map.div.style.cursor = "move";
  1138. }
  1139. this.performedDrag = true;
  1140. }
  1141. },
  1142. /**
  1143. * Method: defaultMouseUp
  1144. *
  1145. * Parameters:
  1146. * evt - {<OpenLayers.Event>}
  1147. */
  1148. defaultMouseUp: function (evt) {
  1149. if (!OpenLayers.Event.isLeftClick(evt)) {
  1150. return;
  1151. }
  1152. if (this.zoomBox) {
  1153. this.zoomBoxEnd(evt);
  1154. } else {
  1155. if (this.performedDrag) {
  1156. this.map.setCenter(this.map.center);
  1157. }
  1158. }
  1159. document.onselectstart=null;
  1160. this.mouseDragStart = null;
  1161. this.map.div.style.cursor = "";
  1162. },
  1163. /**
  1164. * Method: defaultMouseOut
  1165. *
  1166. * Parameters:
  1167. * evt - {Event}
  1168. */
  1169. defaultMouseOut: function (evt) {
  1170. if (this.mouseDragStart != null &&
  1171. OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) {
  1172. if (this.zoomBox) {
  1173. this.removeZoomBox();
  1174. }
  1175. this.mouseDragStart = null;
  1176. }
  1177. },
  1178. /**
  1179. * Method: defaultWheelUp
  1180. * User spun scroll wheel up
  1181. *
  1182. */
  1183. defaultWheelUp: function(evt) {
  1184. if (this.map.getZoom() <= this.map.getNumZoomLevels()) {
  1185. this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
  1186. this.map.getZoom() + 1);
  1187. }
  1188. },
  1189. /**
  1190. * Method: defaultWheelDown
  1191. * User spun scroll wheel down
  1192. */
  1193. defaultWheelDown: function(evt) {
  1194. if (this.map.getZoom() > 0) {
  1195. this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
  1196. this.map.getZoom() - 1);
  1197. }
  1198. },
  1199. /**
  1200. * Method: zoomBoxEnd
  1201. * Zoombox function.
  1202. */
  1203. zoomBoxEnd: function(evt) {
  1204. if (this.mouseDragStart != null) {
  1205. if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
  1206. Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
  1207. var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
  1208. var end = this.map.getLonLatFromViewPortPx( evt.xy );
  1209. var top = Math.max(start.lat, end.lat);
  1210. var bottom = Math.min(start.lat, end.lat);
  1211. var left = Math.min(start.lon, end.lon);
  1212. var right = Math.max(start.lon, end.lon);
  1213. var bounds = new OpenLayers.Bounds(left, bottom, right, top);
  1214. this.map.zoomToExtent(bounds);
  1215. } else {
  1216. var end = this.map.getLonLatFromViewPortPx( evt.xy );
  1217. this.map.setCenter(new OpenLayers.LonLat(
  1218. (end.lon),
  1219. (end.lat)
  1220. ), this.map.getZoom() + 1);
  1221. }
  1222. this.removeZoomBox();
  1223. }
  1224. },
  1225. /**
  1226. * Method: removeZoomBox
  1227. * Remove the zoombox from the screen and nullify our reference to it.
  1228. */
  1229. removeZoomBox: function() {
  1230. this.map.viewPortDiv.removeChild(this.zoomBox);
  1231. this.zoomBox = null;
  1232. },
  1233. /**
  1234. * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/
  1235. */
  1236. /**
  1237. * Method: onWheelEvent
  1238. * Catch the wheel event and handle it xbrowserly
  1239. *
  1240. * Parameters:
  1241. * e - {Event}
  1242. */
  1243. onWheelEvent: function(e){
  1244. // first determine whether or not the wheeling was inside the map
  1245. var inMap = false;
  1246. var elem = OpenLayers.Event.element(e);
  1247. while(elem != null) {
  1248. if (this.map && elem == this.map.div) {
  1249. inMap = true;
  1250. break;
  1251. }
  1252. elem = elem.parentNode;
  1253. }
  1254. if (inMap) {
  1255. var delta = 0;
  1256. if (!e) {
  1257. e = window.event;
  1258. }
  1259. if (e.wheelDelta) {
  1260. delta = e.wheelDelta/120;
  1261. if (window.opera && window.opera.version() < 9.2) {
  1262. delta = -delta;
  1263. }
  1264. } else if (e.detail) {
  1265. delta = -e.detail / 3;
  1266. }
  1267. if (delta) {
  1268. // add the mouse position to the event because mozilla has a bug
  1269. // with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179)
  1270. // getLonLatFromViewPortPx(e) returns wrong values
  1271. e.xy = this.mousePosition;
  1272. if (delta < 0) {
  1273. this.defaultWheelDown(e);
  1274. } else {
  1275. this.defaultWheelUp(e);
  1276. }
  1277. }
  1278. //only wheel the map, not the window
  1279. OpenLayers.Event.stop(e);
  1280. }
  1281. },
  1282. CLASS_NAME: "OpenLayers.Control.MouseDefaults"
  1283. });
  1284. /**
  1285. * Class: OpenLayers.Control.MouseToolbar
  1286. * This class is DEPRECATED in 2.4 and will be removed by 3.0.
  1287. * If you need this functionality, use <OpenLayers.Control.NavToolbar>
  1288. * instead!!!
  1289. */
  1290. OpenLayers.Control.MouseToolbar = OpenLayers.Class(
  1291. OpenLayers.Control.MouseDefaults, {
  1292. /**
  1293. * Property: mode
  1294. */
  1295. mode: null,
  1296. /**
  1297. * Property: buttons
  1298. */
  1299. buttons: null,
  1300. /**
  1301. * APIProperty: direction
  1302. * {String} 'vertical' or 'horizontal'
  1303. */
  1304. direction: "vertical",
  1305. /**
  1306. * Property: buttonClicked
  1307. * {String}
  1308. */
  1309. buttonClicked: null,
  1310. /**
  1311. * Constructor: OpenLayers.Control.MouseToolbar
  1312. *
  1313. * Parameters:
  1314. * position - {<OpenLayers.Pixel>}
  1315. * direction - {String}
  1316. */
  1317. initialize: function(position, direction) {
  1318. OpenLayers.Control.prototype.initialize.apply(this, arguments);
  1319. this.position = new OpenLayers.Pixel(OpenLayers.Control.MouseToolbar.X,
  1320. OpenLayers.Control.MouseToolbar.Y);
  1321. if (position) {
  1322. this.position = position;
  1323. }
  1324. if (direction) {
  1325. this.direction = direction;
  1326. }
  1327. this.measureDivs = [];
  1328. },
  1329. /**
  1330. * APIMethod: destroy
  1331. */
  1332. destroy: function() {
  1333. for( var btnId in this.buttons) {
  1334. var btn = this.buttons[btnId];
  1335. btn.map = null;
  1336. btn.events.destroy();
  1337. }
  1338. OpenLayers.Control.MouseDefaults.prototype.destroy.apply(this,
  1339. arguments);
  1340. },
  1341. /**
  1342. * Method: draw
  1343. */
  1344. draw: function() {
  1345. OpenLayers.Control.prototype.draw.apply(this, arguments);
  1346. OpenLayers.Control.MouseDefaults.prototype.draw.apply(this, arguments);
  1347. this.buttons = {};
  1348. var sz = new OpenLayers.Size(28,28);
  1349. var centered = new OpenLayers.Pixel(OpenLayers.Control.MouseToolbar.X,0);
  1350. this._addButton("zoombox", "drag-rectangle-off.png", "drag-rectangle-on.png", centered, sz, "Shift->Drag to zoom to area");
  1351. centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0));
  1352. this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", centered, sz, "Drag the map to pan.");
  1353. centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0));
  1354. this.switchModeTo("pan");
  1355. return this.div;
  1356. },
  1357. /**
  1358. * Method: _addButton
  1359. */
  1360. _addButton:function(id, img, activeImg, xy, sz, title) {
  1361. var imgLocation = OpenLayers.Util.getImageLocation(img);
  1362. var activeImgLocation = OpenLayers.Util.getImageLocation(activeImg);
  1363. // var btn = new ol.AlphaImage("_"+id, imgLocation, xy, sz);
  1364. var btn = OpenLayers.Util.createAlphaImageDiv(
  1365. "OpenLayers_Control_MouseToolbar_" + id,
  1366. xy, sz, imgLocation, "absolute");
  1367. //we want to add the outer div
  1368. this.div.appendChild(btn);
  1369. btn.imgLocation = imgLocation;
  1370. btn.activeImgLocation = activeImgLocation;
  1371. btn.events = new OpenLayers.Events(this, btn, null, true);
  1372. btn.events.on({
  1373. "mousedown": this.buttonDown,
  1374. "mouseup": this.buttonUp,
  1375. "dblclick": OpenLayers.Event.stop,
  1376. scope: this
  1377. });
  1378. btn.action = id;
  1379. btn.title = title;
  1380. btn.alt = title;
  1381. btn.map = this.map;
  1382. //we want to remember/reference the outer div
  1383. this.buttons[id] = btn;
  1384. return btn;
  1385. },
  1386. /**
  1387. * Method: buttonDown
  1388. *
  1389. * Parameters:
  1390. * evt - {Event}
  1391. */
  1392. buttonDown: function(evt) {
  1393. if (!OpenLayers.Event.isLeftClick(evt)) {
  1394. return;
  1395. }
  1396. this.buttonClicked = evt.element.action;
  1397. OpenLayers.Event.stop(evt);
  1398. },
  1399. /**
  1400. * Method: buttonUp
  1401. *
  1402. * Parameters:
  1403. * evt - {Event}
  1404. */
  1405. buttonUp: function(evt) {
  1406. if (!OpenLayers.Event.isLeftClick(evt)) {
  1407. return;
  1408. }
  1409. if (this.buttonClicked != null) {
  1410. if (this.buttonClicked == evt.element.action) {
  1411. this.switchModeTo(evt.element.action);
  1412. }
  1413. OpenLayers.Event.stop(evt);
  1414. this.buttonClicked = null;
  1415. }
  1416. },
  1417. /**
  1418. * Method: defaultDblClick
  1419. *
  1420. * Parameters:
  1421. * evt - {Event}
  1422. */
  1423. defaultDblClick: function (evt) {
  1424. this.switchModeTo("pan");
  1425. this.performedDrag = false;
  1426. var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
  1427. this.map.setCenter(newCenter, this.map.zoom + 1);
  1428. OpenLayers.Event.stop(evt);
  1429. return false;
  1430. },
  1431. /**
  1432. * Method: defaultMouseDown
  1433. *
  1434. * Parameters:
  1435. * evt - {Event}
  1436. */
  1437. defaultMouseDown: function (evt) {
  1438. if (!OpenLayers.Event.isLeftClick(evt)) {
  1439. return;
  1440. }
  1441. this.mouseDragStart = evt.xy.clone();
  1442. this.performedDrag = false;
  1443. this.startViaKeyboard = false;
  1444. if (evt.shiftKey && this.mode !="zoombox") {
  1445. this.switchModeTo("zoombox");
  1446. this.startViaKeyboard = true;
  1447. } else if (evt.altKey && this.mode !="measure") {
  1448. this.switchModeTo("measure");
  1449. } else if (!this.mode) {
  1450. this.switchModeTo("pan");
  1451. }
  1452. switch (this.mode) {
  1453. case "zoombox":
  1454. this.map.div.style.cursor = "crosshair";
  1455. this.zoomBox = OpenLayers.Util.createDiv('zoomBox',
  1456. this.mouseDragStart,
  1457. null,
  1458. null,
  1459. "absolute",
  1460. "2px solid red");
  1461. this.zoomBox.style.backgroundColor = "white";
  1462. this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
  1463. this.zoomBox.style.opacity = "0.50";
  1464. this.zoomBox.style.fontSize = "1px";
  1465. this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
  1466. this.map.viewPortDiv.appendChild(this.zoomBox);
  1467. this.performedDrag = true;
  1468. break;
  1469. case "measure":
  1470. var distance = "";
  1471. if (this.measureStart) {
  1472. var measureEnd = this.map.getLonLatFromViewPortPx(this.mouseDragStart);
  1473. distance = OpenLayers.Util.distVincenty(this.measureStart, measureEnd);
  1474. distance = Math.round(distance * 100) / 100;
  1475. distance = distance + "km";
  1476. this.measureStartBox = this.measureBox;
  1477. }
  1478. this.measureStart = this.map.getLonLatFromViewPortPx(this.mouseDragStart);;
  1479. this.measureBox = OpenLayers.Util.createDiv(null,
  1480. this.mouseDragStart.add(
  1481. -2-parseInt(this.map.layerContainerDiv.style.left),
  1482. -2-parseInt(this.map.layerContainerDiv.style.top)),
  1483. null,
  1484. null,
  1485. "absolute");
  1486. this.measureBox.style.width="4px";
  1487. this.measureBox.style.height="4px";
  1488. this.measureBox.style.fontSize = "1px";
  1489. this.measureBox.style.backgroundColor="red";
  1490. this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
  1491. this.map.layerContainerDiv.appendChild(this.measureBox);
  1492. if (distance) {
  1493. this.measureBoxDistance = OpenLayers.Util.createDiv(null,
  1494. this.mouseDragStart.add(
  1495. -2-parseInt(this.map.layerContainerDiv.style.left),
  1496. 2-parseInt(this.map.layerContainerDiv.style.top)),
  1497. null,
  1498. null,
  1499. "absolute");
  1500. this.measureBoxDistance.innerHTML = distance;
  1501. this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
  1502. this.map.layerContainerDiv.appendChild(this.measureBoxDistance);
  1503. this.measureDivs.push(this.measureBoxDistance);
  1504. }
  1505. this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
  1506. this.map.layerContainerDiv.appendChild(this.measureBox);
  1507. this.measureDivs.push(this.measureBox);
  1508. break;
  1509. default:
  1510. this.map.div.style.cursor = "move";
  1511. break;
  1512. }
  1513. document.onselectstart = OpenLayers.Function.False;
  1514. OpenLayers.Event.stop(evt);
  1515. },
  1516. /**
  1517. * Method: switchModeTo
  1518. *
  1519. * Parameters:
  1520. * mode - {String}
  1521. */
  1522. switchModeTo: function(mode) {
  1523. if (mode != this.mode) {
  1524. if (this.mode && this.buttons[this.mode]) {
  1525. OpenLayers.Util.modifyAlphaImageDiv(this.buttons[this.mode], null, null, null, this.buttons[this.mode].imgLocation);
  1526. }
  1527. if (this.mode == "measure" && mode != "measure") {
  1528. for(var i=0, len=this.measureDivs.length; i<len; i++) {
  1529. if (this.measureDivs[i]) {
  1530. this.map.layerContainerDiv.removeChild(this.measureDivs[i]);
  1531. }
  1532. }
  1533. this.measureDivs = [];
  1534. this.measureStart = null;
  1535. }
  1536. this.mode = mode;
  1537. if (this.buttons[mode]) {
  1538. OpenLayers.Util.modifyAlphaImageDiv(this.buttons[mode], null, null, null, this.buttons[mode].activeImgLocation);
  1539. }
  1540. switch (this.mode) {
  1541. case "zoombox":
  1542. this.map.div.style.cursor = "crosshair";
  1543. break;
  1544. default:
  1545. this.map.div.style.cursor = "";
  1546. break;
  1547. }
  1548. }
  1549. },
  1550. /**
  1551. * Method: leaveMode
  1552. */
  1553. leaveMode: function() {
  1554. this.switchModeTo("pan");
  1555. },
  1556. /**
  1557. * Method: defaultMouseMove
  1558. *
  1559. * Parameters:
  1560. * evt - {Event}
  1561. */
  1562. defaultMouseMove: function (evt) {
  1563. if (this.mouseDragStart != null) {
  1564. switch (this.mode) {
  1565. case "zoombox":
  1566. var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
  1567. var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y);
  1568. this.zoomBox.style.width = Math.max(1, deltaX) + "px";
  1569. this.zoomBox.style.height = Math.max(1, deltaY) + "px";
  1570. if (evt.xy.x < this.mouseDragStart.x) {
  1571. this.zoomBox.style.left = evt.xy.x+"px";
  1572. }
  1573. if (evt.xy.y < this.mouseDragStart.y) {
  1574. this.zoomBox.style.top = evt.xy.y+"px";
  1575. }
  1576. break;
  1577. default:
  1578. var deltaX = this.mouseDragStart.x - evt.xy.x;
  1579. var deltaY = this.mouseDragStart.y - evt.xy.y;
  1580. var size = this.map.getSize();
  1581. var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
  1582. size.h / 2 + deltaY);
  1583. var newCenter = this.map.getLonLatFromViewPortPx( newXY );
  1584. this.map.setCenter(newCenter, null, true);
  1585. this.mouseDragStart = evt.xy.clone();
  1586. }
  1587. this.performedDrag = true;
  1588. }
  1589. },
  1590. /**
  1591. * Method: defaultMouseUp
  1592. *
  1593. * Parameters:
  1594. * evt - {Event}
  1595. */
  1596. defaultMouseUp: function (evt) {
  1597. if (!OpenLayers.Event.isLeftClick(evt)) {
  1598. return;
  1599. }
  1600. switch (this.mode) {
  1601. case "zoombox":
  1602. this.zoomBoxEnd(evt);
  1603. if (this.startViaKeyboard) {
  1604. this.leaveMode();
  1605. }
  1606. break;
  1607. case "pan":
  1608. if (this.performedDrag) {
  1609. this.map.setCenter(this.map.center);
  1610. }
  1611. }
  1612. document.onselectstart = null;
  1613. this.mouseDragStart = null;
  1614. this.map.div.style.cursor = "default";
  1615. },
  1616. /**
  1617. * Method: defaultMouseOut
  1618. *
  1619. * Parameters:
  1620. * evt - {Event}
  1621. */
  1622. defaultMouseOut: function (evt) {
  1623. if (this.mouseDragStart != null
  1624. && OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) {
  1625. if (this.zoomBox) {
  1626. this.removeZoomBox();
  1627. if (this.startViaKeyboard) {
  1628. this.leaveMode();
  1629. }
  1630. }
  1631. this.mouseDragStart = null;
  1632. this.map.div.style.cursor = "default";
  1633. }
  1634. },
  1635. /**
  1636. * Method: defaultClick
  1637. *
  1638. * Parameters:
  1639. * evt - {Event}
  1640. */
  1641. defaultClick: function (evt) {
  1642. if (this.performedDrag) {
  1643. this.performedDrag = false;
  1644. return false;
  1645. }
  1646. },
  1647. CLASS_NAME: "OpenLayers.Control.MouseToolbar"
  1648. });
  1649. OpenLayers.Control.MouseToolbar.X = 6;
  1650. OpenLayers.Control.MouseToolbar.Y = 300;
  1651. /**
  1652. * Class: OpenLayers.Layer.Grid
  1653. */
  1654. OpenLayers.Util.extend(OpenLayers.Layer.Grid.prototype, {
  1655. /**
  1656. * Method: getGridBounds
  1657. * Deprecated. This function will be removed in 3.0. Please use
  1658. * getTilesBounds() instead.
  1659. *
  1660. * Returns:
  1661. * {<OpenLayers.Bounds>} A Bounds object representing the bounds of all the
  1662. * currently loaded tiles (including those partially or not at all seen
  1663. * onscreen)
  1664. */
  1665. getGridBounds: function() {
  1666. var msg = "The getGridBounds() function is deprecated. It will be " +
  1667. "removed in 3.0. Please use getTilesBounds() instead.";
  1668. OpenLayers.Console.warn(msg);
  1669. return this.getTilesBounds();
  1670. }
  1671. });
  1672. /**
  1673. * Class: OpenLayers.Format.XML
  1674. */
  1675. OpenLayers.Util.extend(OpenLayers.Format.XML.prototype, {
  1676. /**
  1677. * APIMethod: concatChildValues
  1678. * *Deprecated*. Use <getChildValue> instead.
  1679. *
  1680. * Concatenate the value of all child nodes if any exist, or return an
  1681. * optional default string. Returns an empty string if no children
  1682. * exist and no default value is supplied. Not optimized for large
  1683. * numbers of child nodes.
  1684. *
  1685. * Parameters:
  1686. * node - {DOMElement} The element used to look for child values.
  1687. * def - {String} Optional string to return in the event that no
  1688. * child exist.
  1689. *
  1690. * Returns:
  1691. * {String} The concatenated value of all child nodes of the given node.
  1692. */
  1693. concatChildValues: function(node, def) {
  1694. var value = "";
  1695. var child = node.firstChild;
  1696. var childValue;
  1697. while(child) {
  1698. childValue = child.nodeValue;
  1699. if(childValue) {
  1700. value += childValue;
  1701. }
  1702. child = child.nextSibling;
  1703. }
  1704. if(value == "" && def != undefined) {
  1705. value = def;
  1706. }
  1707. return value;
  1708. }
  1709. });
  1710. /**
  1711. * Class: OpenLayers.Layer.WMS.Post
  1712. * Instances of OpenLayers.Layer.WMS.Post are used to retrieve data from OGC
  1713. * Web Mapping Services via HTTP-POST (application/x-www-form-urlencoded).
  1714. * Create a new WMS layer with the <OpenLayers.Layer.WMS.Post> constructor.
  1715. *
  1716. * *Deprecated*. Instead of this layer, use <OpenLayers.Layer.WMS> with
  1717. * <OpenLayers.Tile.Image.maxGetUrlLength> configured in the layer's
  1718. * <OpenLayers.Layer.WMS.tileOptions>.
  1719. *
  1720. * Inherits from:
  1721. * - <OpenLayers.Layer.WMS>
  1722. */
  1723. OpenLayers.Layer.WMS.Post = OpenLayers.Class(OpenLayers.Layer.WMS, {
  1724. /**
  1725. * APIProperty: unsupportedBrowsers
  1726. * {Array} Array with browsers, which should use the HTTP-GET protocol
  1727. * instead of HTTP-POST for fetching tiles from a WMS .
  1728. * Defaults to ["mozilla", "firefox", "opera"], because Opera is not able
  1729. * to show transparent images in IFrames and Firefox/Mozilla has some ugly
  1730. * effects of viewport-shaking when panning the map. Both browsers, Opera
  1731. * and Firefox/Mozilla, have no problem with long urls, which is the reason
  1732. * for using POST instead of GET. The strings to pass to this array are
  1733. * the ones returned by <OpenLayers.BROWSER_NAME>.
  1734. */
  1735. unsupportedBrowsers: ["mozilla", "firefox", "opera"],
  1736. /**
  1737. * Property: SUPPORTED_TRANSITIONS
  1738. * {Array}
  1739. * no supported transitions for this type of layer, because it is not
  1740. * possible to modify the initialized tiles (iframes)
  1741. */
  1742. SUPPORTED_TRANSITIONS: [],
  1743. /**
  1744. * Property: usePost
  1745. * {Boolean}
  1746. */
  1747. usePost: null,
  1748. /**
  1749. * Constructor: OpenLayers.Layer.WMS.Post
  1750. * Creates a new WMS layer object.
  1751. *
  1752. * Example:
  1753. * (code)
  1754. * var wms = new OpenLayers.Layer.WMS.Post(
  1755. * "NASA Global Mosaic",
  1756. * "http://wms.jpl.nasa.gov/wms.cgi",
  1757. * {layers: "modis, global_mosaic"});
  1758. * (end)
  1759. *
  1760. * Parameters:
  1761. * name - {String} A name for the layer
  1762. * url - {String} Base url for the WMS
  1763. * (e.g. http://wms.jpl.nasa.gov/wms.cgi)
  1764. * params - {Object} An object with key/value pairs representing the
  1765. * GetMap query string parameters and parameter values.
  1766. * options - {Object} Hashtable of extra options to tag onto the layer.
  1767. */
  1768. initialize: function(name, url, params, options) {
  1769. var newArguments = [];
  1770. newArguments.push(name, url, params, options);
  1771. OpenLayers.Layer.WMS.prototype.initialize.apply(this, newArguments);
  1772. this.usePost = OpenLayers.Util.indexOf(
  1773. this.unsupportedBrowsers, OpenLayers.BROWSER_NAME) == -1;
  1774. },
  1775. /**
  1776. * Method: addTile
  1777. * addTile creates a tile, initializes it and adds it as iframe to the
  1778. * layer div.
  1779. *
  1780. * Parameters:
  1781. * bounds - {<OpenLayers.Bounds>}
  1782. * position - {<OpenLayers.Pixel>}
  1783. *
  1784. * Returns:
  1785. * {<OpenLayers.Tile.Image.IFrame>} The added OpenLayers.Tile.Image.IFrame
  1786. */
  1787. addTile: function(bounds,position) {
  1788. return new OpenLayers.Tile.Image(
  1789. this, position, bounds, null, this.tileSize, {
  1790. maxGetUrlLength: this.usePost ? 0 : null
  1791. });
  1792. },
  1793. CLASS_NAME: 'OpenLayers.Layer.WMS.Post'
  1794. });
  1795. /**
  1796. * Class: OpenLayers.Layer.WMS.Untiled
  1797. * *Deprecated*. To be removed in 3.0. Instead use OpenLayers.Layer.WMS and
  1798. * pass the option 'singleTile' as true.
  1799. *
  1800. * Inherits from:
  1801. * - <OpenLayers.Layer.WMS>
  1802. */
  1803. OpenLayers.Layer.WMS.Untiled = OpenLayers.Class(OpenLayers.Layer.WMS, {
  1804. /**
  1805. * APIProperty: singleTile
  1806. * {singleTile} Always true for untiled.
  1807. */
  1808. singleTile: true,
  1809. /**
  1810. * Constructor: OpenLayers.Layer.WMS.Untiled
  1811. *
  1812. * Parameters:
  1813. * name - {String}
  1814. * url - {String}
  1815. * params - {Object}
  1816. * options - {Object}
  1817. */
  1818. initialize: function(name, url, params, options) {
  1819. OpenLayers.Layer.WMS.prototype.initialize.apply(this, arguments);
  1820. var msg = "The OpenLayers.Layer.WMS.Untiled class is deprecated and " +
  1821. "will be removed in 3.0. Instead, you should use the " +
  1822. "normal OpenLayers.Layer.WMS class, passing it the option " +
  1823. "'singleTile' as true.";
  1824. OpenLayers.Console.warn(msg);
  1825. },
  1826. /**
  1827. * Method: clone
  1828. * Create a clone of this layer
  1829. *
  1830. * Returns:
  1831. * {<OpenLayers.Layer.WMS.Untiled>} An exact clone of this layer
  1832. */
  1833. clone: function (obj) {
  1834. if (obj == null) {
  1835. obj = new OpenLayers.Layer.WMS.Untiled(this.name,
  1836. this.url,
  1837. this.params,
  1838. this.getOptions());
  1839. }
  1840. //get all additions from superclasses
  1841. obj = OpenLayers.Layer.WMS.prototype.clone.apply(this, [obj]);
  1842. // copy/set any non-init, non-simple values here
  1843. return obj;
  1844. },
  1845. CLASS_NAME: "OpenLayers.Layer.WMS.Untiled"
  1846. });
  1847. /**
  1848. * Class: OpenLayers.Layer.MapServer.Untiled
  1849. * *Deprecated*. To be removed in 3.0. Instead use OpenLayers.Layer.MapServer
  1850. * and pass the option 'singleTile' as true.
  1851. *
  1852. * Inherits from:
  1853. * - <OpenLayers.Layer.MapServer>
  1854. */
  1855. OpenLayers.Layer.MapServer.Untiled = OpenLayers.Class(OpenLayers.Layer.MapServer, {
  1856. /**
  1857. * APIProperty: singleTile
  1858. * {singleTile} Always true for untiled.
  1859. */
  1860. singleTile: true,
  1861. /**
  1862. * Constructor: OpenLayers.Layer.MapServer.Untiled
  1863. *
  1864. * Parameters:
  1865. * name - {String}
  1866. * url - {String}
  1867. * params - {Object}
  1868. * options - {Object}
  1869. */
  1870. initialize: function(name, url, params, options) {
  1871. OpenLayers.Layer.MapServer.prototype.initialize.apply(this, arguments);
  1872. var msg = "The OpenLayers.Layer.MapServer.Untiled class is deprecated and " +
  1873. "will be removed in 3.0. Instead, you should use the " +
  1874. "normal OpenLayers.Layer.MapServer class, passing it the option " +
  1875. "'singleTile' as true.";
  1876. OpenLayers.Console.warn(msg);
  1877. },
  1878. /**
  1879. * Method: clone
  1880. * Create a clone of this layer
  1881. *
  1882. * Returns:
  1883. * {<OpenLayers.Layer.MapServer.Untiled>} An exact clone of this layer
  1884. */
  1885. clone: function (obj) {
  1886. if (obj == null) {
  1887. obj = new OpenLayers.Layer.MapServer.Untiled(this.name,
  1888. this.url,
  1889. this.params,
  1890. this.getOptions());
  1891. }
  1892. //get all additions from superclasses
  1893. obj = OpenLayers.Layer.MapServer.prototype.clone.apply(this, [obj]);
  1894. // copy/set any non-init, non-simple values here
  1895. return obj;
  1896. },
  1897. CLASS_NAME: "OpenLayers.Layer.MapServer.Untiled"
  1898. });
  1899. /**
  1900. * Class: OpenLayers.Tile.WFS
  1901. * Instances of OpenLayers.Tile.WFS are used to manage the image tiles
  1902. * used by various layers. Create a new image tile with the
  1903. * <OpenLayers.Tile.WFS> constructor.
  1904. *
  1905. * Inherits from:
  1906. * - <OpenLayers.Tile>
  1907. */
  1908. OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
  1909. /**
  1910. * Property: features
  1911. * {Array(<OpenLayers.Feature>)} list of features in this tile
  1912. */
  1913. features: null,
  1914. /**
  1915. * Property: url
  1916. * {String}
  1917. */
  1918. url: null,
  1919. /**
  1920. * Property: request
  1921. * {<OpenLayers.Request.XMLHttpRequest>}
  1922. */
  1923. request: null,
  1924. /** TBD 3.0 - reorder the parameters to the init function to put URL
  1925. * as last, so we can continue to call tile.initialize()
  1926. * without changing the arguments.
  1927. *
  1928. * Constructor: OpenLayers.Tile.WFS
  1929. * Constructor for a new <OpenLayers.Tile.WFS> instance.
  1930. *
  1931. * Parameters:
  1932. * layer - {<OpenLayers.Layer>} layer that the tile will go in.
  1933. * position - {<OpenLayers.Pixel>}
  1934. * bounds - {<OpenLayers.Bounds>}
  1935. * url - {<String>}
  1936. * size - {<OpenLayers.Size>}
  1937. */
  1938. initialize: function(layer, position, bounds, url, size) {
  1939. OpenLayers.Tile.prototype.initialize.apply(this, arguments);
  1940. this.url = url;
  1941. this.features = [];
  1942. },
  1943. /**
  1944. * APIMethod: destroy
  1945. * nullify references to prevent circular references and memory leaks
  1946. */
  1947. destroy: function() {
  1948. OpenLayers.Tile.prototype.destroy.apply(this, arguments);
  1949. this.destroyAllFeatures();
  1950. this.features = null;
  1951. this.url = null;
  1952. if(this.request) {
  1953. this.request.abort();
  1954. //this.request.destroy();
  1955. this.request = null;
  1956. }
  1957. },
  1958. /**
  1959. * Method: clear
  1960. * Clear the tile of any bounds/position-related data so that it can
  1961. * be reused in a new location.
  1962. */
  1963. clear: function() {
  1964. this.destroyAllFeatures();
  1965. },
  1966. /**
  1967. * Method: draw
  1968. * Check that a tile should be drawn, and load features for it.
  1969. */
  1970. draw:function() {
  1971. if (OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
  1972. if (this.isLoading) {
  1973. //if already loading, send 'reload' instead of 'loadstart'.
  1974. this.events.triggerEvent("reload");
  1975. } else {
  1976. this.isLoading = true;
  1977. this.events.triggerEvent("loadstart");
  1978. }
  1979. this.loadFeaturesForRegion(this.requestSuccess);
  1980. }
  1981. },
  1982. /**
  1983. * Method: loadFeaturesForRegion
  1984. * Abort any pending requests and issue another request for data.
  1985. *
  1986. * Input are function pointers for what to do on success and failure.
  1987. *
  1988. * Parameters:
  1989. * success - {function}
  1990. * failure - {function}
  1991. */
  1992. loadFeaturesForRegion:function(success, failure) {
  1993. if(this.request) {
  1994. this.request.abort();
  1995. }
  1996. this.request = OpenLayers.Request.GET({
  1997. url: this.url,
  1998. success: success,
  1999. failure: failure,
  2000. scope: this
  2001. });
  2002. },
  2003. /**
  2004. * Method: requestSuccess
  2005. * Called on return from request succcess. Adds results via
  2006. * layer.addFeatures in vector mode, addResults otherwise.
  2007. *
  2008. * Parameters:
  2009. * request - {<OpenLayers.Request.XMLHttpRequest>}
  2010. */
  2011. requestSuccess:function(request) {
  2012. if (this.features) {
  2013. var doc = request.responseXML;
  2014. if (!doc || !doc.documentElement) {
  2015. doc = request.responseText;
  2016. }
  2017. if (this.layer.vectorMode) {
  2018. this.layer.addFeatures(this.layer.formatObject.read(doc));
  2019. } else {
  2020. var xml = new OpenLayers.Format.XML();
  2021. if (typeof doc == "string") {
  2022. doc = xml.read(doc);
  2023. }
  2024. var resultFeatures = xml.getElementsByTagNameNS(
  2025. doc, "http://www.opengis.net/gml", "featureMember"
  2026. );
  2027. this.addResults(resultFeatures);
  2028. }
  2029. }
  2030. if (this.events) {
  2031. this.events.triggerEvent("loadend");
  2032. }
  2033. //request produced with success, we can delete the request object.
  2034. //this.request.destroy();
  2035. this.request = null;
  2036. },
  2037. /**
  2038. * Method: addResults
  2039. * Construct new feature via layer featureClass constructor, and add to
  2040. * this.features.
  2041. *
  2042. * Parameters:
  2043. * results - {Object}
  2044. */
  2045. addResults: function(results) {
  2046. for (var i=0; i < results.length; i++) {
  2047. var feature = new this.layer.featureClass(this.layer,
  2048. results[i]);
  2049. this.features.push(feature);
  2050. }
  2051. },
  2052. /**
  2053. * Method: destroyAllFeatures
  2054. * Iterate through and call destroy() on each feature, removing it from
  2055. * the local array
  2056. */
  2057. destroyAllFeatures: function() {
  2058. while(this.features.length > 0) {
  2059. var feature = this.features.shift();
  2060. feature.destroy();
  2061. }
  2062. },
  2063. CLASS_NAME: "OpenLayers.Tile.WFS"
  2064. }
  2065. );
  2066. /**
  2067. * Class: OpenLayers.Feature.WFS
  2068. * WFS handling class, for use as a featureClass on the WFS layer for handling
  2069. * 'point' WFS types. Good for subclassing when creating a custom WFS like
  2070. * XML application.
  2071. *
  2072. * Inherits from:
  2073. * - <OpenLayers.Feature>
  2074. */
  2075. OpenLayers.Feature.WFS = OpenLayers.Class(OpenLayers.Feature, {
  2076. /**
  2077. * Constructor: OpenLayers.Feature.WFS
  2078. * Create a WFS feature.
  2079. *
  2080. * Parameters:
  2081. * layer - {<OpenLayers.Layer>}
  2082. * xmlNode - {XMLNode}
  2083. */
  2084. initialize: function(layer, xmlNode) {
  2085. var newArguments = arguments;
  2086. var data = this.processXMLNode(xmlNode);
  2087. newArguments = new Array(layer, data.lonlat, data);
  2088. OpenLayers.Feature.prototype.initialize.apply(this, newArguments);
  2089. this.createMarker();
  2090. this.layer.addMarker(this.marker);
  2091. },
  2092. /**
  2093. * Method: destroy
  2094. * nullify references to prevent circular references and memory leaks
  2095. */
  2096. destroy: function() {
  2097. if (this.marker != null) {
  2098. this.layer.removeMarker(this.marker);
  2099. }
  2100. OpenLayers.Feature.prototype.destroy.apply(this, arguments);
  2101. },
  2102. /**
  2103. * Method: processXMLNode
  2104. * When passed an xmlNode, parses it for a GML point, and passes
  2105. * back an object describing that point.
  2106. *
  2107. * For subclasses of Feature.WFS, this is the feature to change.
  2108. *
  2109. * Parameters:
  2110. * xmlNode - {XMLNode}
  2111. *
  2112. * Returns:
  2113. * {Object} Data Object with 'id', 'lonlat', and private properties set
  2114. */
  2115. processXMLNode: function(xmlNode) {
  2116. //this should be overridden by subclasses
  2117. // must return an Object with 'id' and 'lonlat' values set
  2118. var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.opengis.net/gml", "gml", "Point");
  2119. var text = OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(point[0], "http://www.opengis.net/gml","gml", "coordinates")[0]);
  2120. var floats = text.split(",");
  2121. return {lonlat: new OpenLayers.LonLat(parseFloat(floats[0]),
  2122. parseFloat(floats[1])),
  2123. id: null};
  2124. },
  2125. CLASS_NAME: "OpenLayers.Feature.WFS"
  2126. });
  2127. /**
  2128. * Class: OpenLayers.Layer.WFS
  2129. * *Deprecated*. To be removed in 3.0. Instead use OpenLayers.Layer.Vector
  2130. * with a Protocol.WFS and one or more Strategies.
  2131. *
  2132. * Inherits from:
  2133. * - <OpenLayers.Layer.Vector>
  2134. * - <OpenLayers.Layer.Markers>
  2135. */
  2136. OpenLayers.Layer.WFS = OpenLayers.Class(
  2137. OpenLayers.Layer.Vector, OpenLayers.Layer.Markers, {
  2138. /**
  2139. * APIProperty: isBaseLayer
  2140. * {Boolean} WFS layer is not a base layer by default.
  2141. */
  2142. isBaseLayer: false,
  2143. /**
  2144. * Property: tile
  2145. * {<OpenLayers.Tile.WFS>}
  2146. */
  2147. tile: null,
  2148. /**
  2149. * APIProperty: ratio
  2150. * {Float} The ratio property determines the size of the serverside query
  2151. * relative to the map viewport size. By default, we load an area twice
  2152. * as big as the map, to allow for panning without immediately reload.
  2153. * Setting this to 1 will cause the area of the WFS request to match
  2154. * the map area exactly. It is recommended to set this to some number
  2155. * at least slightly larger than 1, otherwise accidental clicks can
  2156. * cause a data reload, by moving the map only 1 pixel.
  2157. */
  2158. ratio: 2,
  2159. /**
  2160. * Property: DEFAULT_PARAMS
  2161. * {Object} Hashtable of default key/value parameters
  2162. */
  2163. DEFAULT_PARAMS: { service: "WFS",
  2164. version: "1.0.0",
  2165. request: "GetFeature"
  2166. },
  2167. /**
  2168. * APIProperty: featureClass
  2169. * {<OpenLayers.Feature>} If featureClass is defined, an old-style markers
  2170. * based WFS layer is created instead of a new-style vector layer. If
  2171. * sent, this should be a subclass of OpenLayers.Feature
  2172. */
  2173. featureClass: null,
  2174. /**
  2175. * APIProperty: format
  2176. * {<OpenLayers.Format>} The format you want the data to be parsed with.
  2177. * Must be passed in the constructor. Should be a class, not an instance.
  2178. * This option can only be used if no featureClass is passed / vectorMode
  2179. * is false: if a featureClass is passed, then this parameter is ignored.
  2180. */
  2181. format: null,
  2182. /**
  2183. * Property: formatObject
  2184. * {<OpenLayers.Format>} Internally created/managed format object, used by
  2185. * the Tile to parse data.
  2186. */
  2187. formatObject: null,
  2188. /**
  2189. * APIProperty: formatOptions
  2190. * {Object} Hash of options which should be passed to the format when it is
  2191. * created. Must be passed in the constructor.
  2192. */
  2193. formatOptions: null,
  2194. /**
  2195. * Property: vectorMode
  2196. * {Boolean} Should be calculated automatically. Determines whether the
  2197. * layer is in vector mode or marker mode.
  2198. */
  2199. vectorMode: true,
  2200. /**
  2201. * APIProperty: encodeBBOX
  2202. * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no',
  2203. * but some services want it that way. Default false.
  2204. */
  2205. encodeBBOX: false,
  2206. /**
  2207. * APIProperty: extractAttributes
  2208. * {Boolean} Should the WFS layer parse attributes from the retrieved
  2209. * GML? Defaults to false. If enabled, parsing is slower, but
  2210. * attributes are available in the attributes property of
  2211. * layer features.
  2212. */
  2213. extractAttributes: false,
  2214. /**
  2215. * Constructor: OpenLayers.Layer.WFS
  2216. *
  2217. * Parameters:
  2218. * name - {String}
  2219. * url - {String}
  2220. * params - {Object}
  2221. * options - {Object} Hashtable of extra options to tag onto the layer
  2222. */
  2223. initialize: function(name, url, params, options) {
  2224. if (options == undefined) { options = {}; }
  2225. if (options.featureClass ||
  2226. !OpenLayers.Layer.Vector ||
  2227. !OpenLayers.Feature.Vector) {
  2228. this.vectorMode = false;
  2229. }
  2230. // Uppercase params
  2231. params = OpenLayers.Util.upperCaseObject(params);
  2232. // Turn off error reporting, browsers like Safari may work
  2233. // depending on the setup, and we don't want an unneccesary alert.
  2234. OpenLayers.Util.extend(options, {'reportError': false});
  2235. var newArguments = [];
  2236. newArguments.push(name, options);
  2237. OpenLayers.Layer.Vector.prototype.initialize.apply(this, newArguments);
  2238. if (!this.renderer || !this.vectorMode) {
  2239. this.vectorMode = false;
  2240. if (!options.featureClass) {
  2241. options.featureClass = OpenLayers.Feature.WFS;
  2242. }
  2243. OpenLayers.Layer.Markers.prototype.initialize.apply(this,
  2244. newArguments);
  2245. }
  2246. if (this.params && this.params.typename && !this.options.typename) {
  2247. this.options.typename = this.params.typename;
  2248. }
  2249. if (!this.options.geometry_column) {
  2250. this.options.geometry_column = "the_geom";
  2251. }
  2252. this.params = OpenLayers.Util.applyDefaults(
  2253. params,
  2254. OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
  2255. );
  2256. this.url = url;
  2257. },
  2258. /**
  2259. * APIMethod: destroy
  2260. */
  2261. destroy: function() {
  2262. if (this.vectorMode) {
  2263. OpenLayers.Layer.Vector.prototype.destroy.apply(this, arguments);
  2264. } else {
  2265. OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments);
  2266. }
  2267. if (this.tile) {
  2268. this.tile.destroy();
  2269. }
  2270. this.tile = null;
  2271. this.ratio = null;
  2272. this.featureClass = null;
  2273. this.format = null;
  2274. if (this.formatObject && this.formatObject.destroy) {
  2275. this.formatObject.destroy();
  2276. }
  2277. this.formatObject = null;
  2278. this.formatOptions = null;
  2279. this.vectorMode = null;
  2280. this.encodeBBOX = null;
  2281. this.extractAttributes = null;
  2282. },
  2283. /**
  2284. * Method: setMap
  2285. *
  2286. * Parameters:
  2287. * map - {<OpenLayers.Map>}
  2288. */
  2289. setMap: function(map) {
  2290. if (this.vectorMode) {
  2291. OpenLayers.Layer.Vector.prototype.setMap.apply(this, arguments);
  2292. var options = {
  2293. 'extractAttributes': this.extractAttributes
  2294. };
  2295. OpenLayers.Util.extend(options, this.formatOptions);
  2296. if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
  2297. options.externalProjection = this.projection;
  2298. options.internalProjection = this.map.getProjectionObject();
  2299. }
  2300. this.formatObject = this.format ? new this.format(options) : new OpenLayers.Format.GML(options);
  2301. } else {
  2302. OpenLayers.Layer.Markers.prototype.setMap.apply(this, arguments);
  2303. }
  2304. },
  2305. /**
  2306. * Method: moveTo
  2307. *
  2308. * Parameters:
  2309. * bounds - {<OpenLayers.Bounds>}
  2310. * zoomChanged - {Boolean}
  2311. * dragging - {Boolean}
  2312. */
  2313. moveTo:function(bounds, zoomChanged, dragging) {
  2314. if (this.vectorMode) {
  2315. OpenLayers.Layer.Vector.prototype.moveTo.apply(this, arguments);
  2316. } else {
  2317. OpenLayers.Layer.Markers.prototype.moveTo.apply(this, arguments);
  2318. }
  2319. // don't load wfs features while dragging, wait for drag end
  2320. if (dragging) {
  2321. // TBD try to hide the vector layer while dragging
  2322. // this.setVisibility(false);
  2323. // this will probably help for panning performances
  2324. return false;
  2325. }
  2326. if ( zoomChanged ) {
  2327. if (this.vectorMode) {
  2328. this.renderer.clear();
  2329. }
  2330. }
  2331. //DEPRECATED - REMOVE IN 3.0
  2332. // don't load data if current zoom level doesn't match
  2333. if (this.options.minZoomLevel) {
  2334. OpenLayers.Console.warn(OpenLayers.i18n('minZoomLevelError'));
  2335. if (this.map.getZoom() < this.options.minZoomLevel) {
  2336. return null;
  2337. }
  2338. }
  2339. if (bounds == null) {
  2340. bounds = this.map.getExtent();
  2341. }
  2342. var firstRendering = (this.tile == null);
  2343. //does the new bounds to which we need to move fall outside of the
  2344. // current tile's bounds?
  2345. var outOfBounds = (!firstRendering &&
  2346. !this.tile.bounds.containsBounds(bounds));
  2347. if (zoomChanged || firstRendering || (!dragging && outOfBounds)) {
  2348. //determine new tile bounds
  2349. var center = bounds.getCenterLonLat();
  2350. var tileWidth = bounds.getWidth() * this.ratio;
  2351. var tileHeight = bounds.getHeight() * this.ratio;
  2352. var tileBounds =
  2353. new OpenLayers.Bounds(center.lon - (tileWidth / 2),
  2354. center.lat - (tileHeight / 2),
  2355. center.lon + (tileWidth / 2),
  2356. center.lat + (tileHeight / 2));
  2357. //determine new tile size
  2358. var tileSize = this.map.getSize();
  2359. tileSize.w = tileSize.w * this.ratio;
  2360. tileSize.h = tileSize.h * this.ratio;
  2361. //determine new position (upper left corner of new bounds)
  2362. var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
  2363. var pos = this.map.getLayerPxFromLonLat(ul);
  2364. //formulate request url string
  2365. var url = this.getFullRequestString();
  2366. var params = null;
  2367. // Cant combine "filter" and "BBOX". This is a cheap hack to help
  2368. // people out who can't migrate to the WFS protocol immediately.
  2369. var filter = this.params.filter || this.params.FILTER;
  2370. if (filter) {
  2371. params = {FILTER: filter};
  2372. }
  2373. else {
  2374. params = {BBOX: this.encodeBBOX ? tileBounds.toBBOX()
  2375. : tileBounds.toArray()};
  2376. }
  2377. if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
  2378. var projectedBounds = tileBounds.clone();
  2379. projectedBounds.transform(this.map.getProjectionObject(),
  2380. this.projection);
  2381. if (!filter){
  2382. params.BBOX = this.encodeBBOX ? projectedBounds.toBBOX()
  2383. : projectedBounds.toArray();
  2384. }
  2385. }
  2386. url += "&" + OpenLayers.Util.getParameterString(params);
  2387. if (!this.tile) {
  2388. this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,
  2389. url, tileSize);
  2390. this.addTileMonitoringHooks(this.tile);
  2391. this.tile.draw();
  2392. } else {
  2393. if (this.vectorMode) {
  2394. this.destroyFeatures();
  2395. this.renderer.clear();
  2396. } else {
  2397. this.clearMarkers();
  2398. }
  2399. this.removeTileMonitoringHooks(this.tile);
  2400. this.tile.destroy();
  2401. this.tile = null;
  2402. this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,
  2403. url, tileSize);
  2404. this.addTileMonitoringHooks(this.tile);
  2405. this.tile.draw();
  2406. }
  2407. }
  2408. },
  2409. /**
  2410. * Method: addTileMonitoringHooks
  2411. * This function takes a tile as input and adds the appropriate hooks to
  2412. * the tile so that the layer can keep track of the loading tile
  2413. * (making sure to check that the tile is always the layer's current
  2414. * tile before taking any action).
  2415. *
  2416. * Parameters:
  2417. * tile - {<OpenLayers.Tile>}
  2418. */
  2419. addTileMonitoringHooks: function(tile) {
  2420. tile.onLoadStart = function() {
  2421. //if this is the the layer's current tile, then trigger
  2422. // a 'loadstart'
  2423. if (this == this.layer.tile) {
  2424. this.layer.events.triggerEvent("loadstart");
  2425. }
  2426. };
  2427. tile.events.register("loadstart", tile, tile.onLoadStart);
  2428. tile.onLoadEnd = function() {
  2429. //if this is the the layer's current tile, then trigger
  2430. // a 'tileloaded' and 'loadend'
  2431. if (this == this.layer.tile) {
  2432. this.layer.events.triggerEvent("tileloaded");
  2433. this.layer.events.triggerEvent("loadend");
  2434. }
  2435. };
  2436. tile.events.register("loadend", tile, tile.onLoadEnd);
  2437. tile.events.register("unload", tile, tile.onLoadEnd);
  2438. },
  2439. /**
  2440. * Method: removeTileMonitoringHooks
  2441. * This function takes a tile as input and removes the tile hooks
  2442. * that were added in addTileMonitoringHooks()
  2443. *
  2444. * Parameters:
  2445. * tile - {<OpenLayers.Tile>}
  2446. */
  2447. removeTileMonitoringHooks: function(tile) {
  2448. tile.unload();
  2449. tile.events.un({
  2450. "loadstart": tile.onLoadStart,
  2451. "loadend": tile.onLoadEnd,
  2452. "unload": tile.onLoadEnd,
  2453. scope: tile
  2454. });
  2455. },
  2456. /**
  2457. * Method: onMapResize
  2458. * Call the onMapResize method of the appropriate parent class.
  2459. */
  2460. onMapResize: function() {
  2461. if(this.vectorMode) {
  2462. OpenLayers.Layer.Vector.prototype.onMapResize.apply(this,
  2463. arguments);
  2464. } else {
  2465. OpenLayers.Layer.Markers.prototype.onMapResize.apply(this,
  2466. arguments);
  2467. }
  2468. },
  2469. /**
  2470. * Method: display
  2471. * Call the display method of the appropriate parent class.
  2472. */
  2473. display: function() {
  2474. if(this.vectorMode) {
  2475. OpenLayers.Layer.Vector.prototype.display.apply(this,
  2476. arguments);
  2477. } else {
  2478. OpenLayers.Layer.Markers.prototype.display.apply(this,
  2479. arguments);
  2480. }
  2481. },
  2482. /**
  2483. * APIMethod: mergeNewParams
  2484. * Modify parameters for the layer and redraw.
  2485. *
  2486. * Parameters:
  2487. * newParams - {Object}
  2488. */
  2489. mergeNewParams:function(newParams) {
  2490. var upperParams = OpenLayers.Util.upperCaseObject(newParams);
  2491. var newArguments = [upperParams];
  2492. return OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,
  2493. newArguments);
  2494. },
  2495. /**
  2496. * APIMethod: clone
  2497. *
  2498. * Parameters:
  2499. * obj - {Object}
  2500. *
  2501. * Returns:
  2502. * {<OpenLayers.Layer.WFS>} An exact clone of this OpenLayers.Layer.WFS
  2503. */
  2504. clone: function (obj) {
  2505. if (obj == null) {
  2506. obj = new OpenLayers.Layer.WFS(this.name,
  2507. this.url,
  2508. this.params,
  2509. this.getOptions());
  2510. }
  2511. //get all additions from superclasses
  2512. if (this.vectorMode) {
  2513. obj = OpenLayers.Layer.Vector.prototype.clone.apply(this, [obj]);
  2514. } else {
  2515. obj = OpenLayers.Layer.Markers.prototype.clone.apply(this, [obj]);
  2516. }
  2517. // copy/set any non-init, non-simple values here
  2518. return obj;
  2519. },
  2520. /**
  2521. * APIMethod: getFullRequestString
  2522. * combine the layer's url with its params and these newParams.
  2523. *
  2524. * Add the SRS parameter from 'projection' -- this is probably
  2525. * more eloquently done via a setProjection() method, but this
  2526. * works for now and always.
  2527. *
  2528. * Parameters:
  2529. * newParams - {Object}
  2530. * altUrl - {String} Use this as the url instead of the layer's url
  2531. */
  2532. getFullRequestString:function(newParams, altUrl) {
  2533. var projectionCode = this.projection.getCode() || this.map.getProjection();
  2534. this.params.SRS = (projectionCode == "none") ? null : projectionCode;
  2535. return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
  2536. this, arguments);
  2537. },
  2538. /**
  2539. * APIMethod: commit
  2540. * Write out the data to a WFS server.
  2541. */
  2542. commit: function() {
  2543. if (!this.writer) {
  2544. var options = {};
  2545. if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
  2546. options.externalProjection = this.projection;
  2547. options.internalProjection = this.map.getProjectionObject();
  2548. }
  2549. this.writer = new OpenLayers.Format.WFS(options,this);
  2550. }
  2551. var data = this.writer.write(this.features);
  2552. OpenLayers.Request.POST({
  2553. url: this.url,
  2554. data: data,
  2555. success: this.commitSuccess,
  2556. failure: this.commitFailure,
  2557. scope: this
  2558. });
  2559. },
  2560. /**
  2561. * Method: commitSuccess
  2562. * Called when the Ajax request returns a response
  2563. *
  2564. * Parameters:
  2565. * response - {XmlNode} from server
  2566. */
  2567. commitSuccess: function(request) {
  2568. var response = request.responseText;
  2569. if (response.indexOf('SUCCESS') != -1) {
  2570. this.commitReport(OpenLayers.i18n("commitSuccess", {'response':response}));
  2571. for(var i = 0; i < this.features.length; i++) {
  2572. this.features[i].state = null;
  2573. }
  2574. // TBD redraw the layer or reset the state of features
  2575. // foreach features: set state to null
  2576. } else if (response.indexOf('FAILED') != -1 ||
  2577. response.indexOf('Exception') != -1) {
  2578. this.commitReport(OpenLayers.i18n("commitFailed", {'response':response}));
  2579. }
  2580. },
  2581. /**
  2582. * Method: commitFailure
  2583. * Called when the Ajax request fails
  2584. *
  2585. * Parameters:
  2586. * response - {XmlNode} from server
  2587. */
  2588. commitFailure: function(request) {},
  2589. /**
  2590. * APIMethod: commitReport
  2591. * Called with a 'success' message if the commit succeeded, otherwise
  2592. * a failure message, and the full request text as a second parameter.
  2593. * Override this function to provide custom transaction reporting.
  2594. *
  2595. * string - {String} reporting string
  2596. * response - {String} full XML response
  2597. */
  2598. commitReport: function(string, response) {
  2599. OpenLayers.Console.userError(string);
  2600. },
  2601. /**
  2602. * APIMethod: refresh
  2603. * Refreshes all the features of the layer
  2604. */
  2605. refresh: function() {
  2606. if (this.tile) {
  2607. if (this.vectorMode) {
  2608. this.renderer.clear();
  2609. this.features.length = 0;
  2610. } else {
  2611. this.clearMarkers();
  2612. this.markers.length = 0;
  2613. }
  2614. this.tile.draw();
  2615. }
  2616. },
  2617. /**
  2618. * APIMethod: getDataExtent
  2619. * Calculates the max extent which includes all of the layer data.
  2620. *
  2621. * Returns:
  2622. * {<OpenLayers.Bounds>}
  2623. */
  2624. getDataExtent: function () {
  2625. var extent;
  2626. //get all additions from superclasses
  2627. if (this.vectorMode) {
  2628. extent = OpenLayers.Layer.Vector.prototype.getDataExtent.apply(this);
  2629. } else {
  2630. extent = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(this);
  2631. }
  2632. return extent;
  2633. },
  2634. /**
  2635. * APIMethod: setOpacity
  2636. * Call the setOpacity method of the appropriate parent class to set the
  2637. * opacity.
  2638. *
  2639. * Parameters:
  2640. * opacity - {Float}
  2641. */
  2642. setOpacity: function (opacity) {
  2643. if (this.vectorMode) {
  2644. OpenLayers.Layer.Vector.prototype.setOpacity.apply(this, [opacity]);
  2645. } else {
  2646. OpenLayers.Layer.Markers.prototype.setOpacity.apply(this, [opacity]);
  2647. }
  2648. },
  2649. CLASS_NAME: "OpenLayers.Layer.WFS"
  2650. });
  2651. /**
  2652. * Class: OpenLayers.Layer.VirtualEarth
  2653. * *Deprecated*. Use <OpenLayers.Layer.Bing> instead.
  2654. *
  2655. * Instances of OpenLayers.Layer.VirtualEarth are used to display the data from
  2656. * the Bing Maps AJAX Control (see e.g.
  2657. * http://msdn.microsoft.com/library/bb429619.aspx). Create a VirtualEarth
  2658. * layer with the <OpenLayers.Layer.VirtualEarth> constructor.
  2659. *
  2660. * Inherits from:
  2661. * - <OpenLayers.Layer.EventPane>
  2662. * - <OpenLayers.Layer.FixedZoomLevels>
  2663. */
  2664. OpenLayers.Layer.VirtualEarth = OpenLayers.Class(
  2665. OpenLayers.Layer.EventPane,
  2666. OpenLayers.Layer.FixedZoomLevels, {
  2667. /**
  2668. * Constant: MIN_ZOOM_LEVEL
  2669. * {Integer} 1
  2670. */
  2671. MIN_ZOOM_LEVEL: 1,
  2672. /**
  2673. * Constant: MAX_ZOOM_LEVEL
  2674. * {Integer} 19
  2675. */
  2676. MAX_ZOOM_LEVEL: 19,
  2677. /**
  2678. * Constant: RESOLUTIONS
  2679. * {Array(Float)} Hardcode these resolutions so that they are more closely
  2680. * tied with the standard wms projection
  2681. */
  2682. RESOLUTIONS: [
  2683. 1.40625,
  2684. 0.703125,
  2685. 0.3515625,
  2686. 0.17578125,
  2687. 0.087890625,
  2688. 0.0439453125,
  2689. 0.02197265625,
  2690. 0.010986328125,
  2691. 0.0054931640625,
  2692. 0.00274658203125,
  2693. 0.001373291015625,
  2694. 0.0006866455078125,
  2695. 0.00034332275390625,
  2696. 0.000171661376953125,
  2697. 0.0000858306884765625,
  2698. 0.00004291534423828125,
  2699. 0.00002145767211914062,
  2700. 0.00001072883605957031,
  2701. 0.00000536441802978515
  2702. ],
  2703. /**
  2704. * APIProperty: type
  2705. * {VEMapType}
  2706. */
  2707. type: null,
  2708. /**
  2709. * APIProperty: wrapDateLine
  2710. * {Boolean} Allow user to pan forever east/west. Default is true.
  2711. * Setting this to false only restricts panning if
  2712. * <sphericalMercator> is true.
  2713. */
  2714. wrapDateLine: true,
  2715. /**
  2716. * APIProperty: sphericalMercator
  2717. * {Boolean} Should the map act as a mercator-projected map? This will
  2718. * cause all interactions with the map to be in the actual map
  2719. * projection, which allows support for vector drawing, overlaying
  2720. * other maps, etc.
  2721. */
  2722. sphericalMercator: false,
  2723. /**
  2724. * APIProperty: animationEnabled
  2725. * {Boolean} If set to true, the transition between zoom levels will be
  2726. * animated. Set to false to match the zooming experience of other
  2727. * layer types. Default is true.
  2728. */
  2729. animationEnabled: true,
  2730. /**
  2731. * Constructor: OpenLayers.Layer.VirtualEarth
  2732. * Creates a new instance of a OpenLayers.Layer.VirtualEarth. If you use an
  2733. * instance of OpenLayers.Layer.VirtualEarth in you map, you should set
  2734. * the <OpenLayers.Map> option restrictedExtent to a meaningful value,
  2735. * e.g.:
  2736. * (code)
  2737. * var map = new OpenLayers.Map( 'map', {
  2738. * // other map options
  2739. * restrictedExtent : OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)
  2740. * } );
  2741. *
  2742. * var veLayer = new OpenLayers.Layer.VirtualEarth (
  2743. * "Virtual Earth Layer"
  2744. * );
  2745. *
  2746. * map.addLayer( veLayer );
  2747. * (end)
  2748. *
  2749. * Parameters:
  2750. * name - {String}
  2751. * options - {Object}
  2752. */
  2753. initialize: function(name, options) {
  2754. OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
  2755. OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
  2756. arguments);
  2757. if(this.sphericalMercator) {
  2758. OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
  2759. this.initMercatorParameters();
  2760. }
  2761. },
  2762. /**
  2763. * Method: loadMapObject
  2764. */
  2765. loadMapObject:function() {
  2766. // create div and set to same size as map
  2767. var veDiv = OpenLayers.Util.createDiv(this.name);
  2768. var sz = this.map.getSize();
  2769. veDiv.style.width = sz.w + "px";
  2770. veDiv.style.height = sz.h + "px";
  2771. this.div.appendChild(veDiv);
  2772. try { // crash prevention
  2773. this.mapObject = new VEMap(this.name);
  2774. } catch (e) { }
  2775. if (this.mapObject != null) {
  2776. try { // this is to catch a Mozilla bug without falling apart
  2777. // The fourth argument is whether the map is 'fixed' -- not
  2778. // draggable. See:
  2779. // http://blogs.msdn.com/virtualearth/archive/2007/09/28/locking-a-virtual-earth-map.aspx
  2780. //
  2781. this.mapObject.LoadMap(null, null, this.type, true);
  2782. this.mapObject.AttachEvent("onmousedown", OpenLayers.Function.True);
  2783. } catch (e) { }
  2784. this.mapObject.HideDashboard();
  2785. if(typeof this.mapObject.SetAnimationEnabled == "function") {
  2786. this.mapObject.SetAnimationEnabled(this.animationEnabled);
  2787. }
  2788. }
  2789. //can we do smooth panning? this is an unpublished method, so we need
  2790. // to be careful
  2791. if ( !this.mapObject ||
  2792. !this.mapObject.vemapcontrol ||
  2793. !this.mapObject.vemapcontrol.PanMap ||
  2794. (typeof this.mapObject.vemapcontrol.PanMap != "function")) {
  2795. this.dragPanMapObject = null;
  2796. }
  2797. },
  2798. /**
  2799. * Method: onMapResize
  2800. */
  2801. onMapResize: function() {
  2802. this.mapObject.Resize(this.map.size.w, this.map.size.h);
  2803. },
  2804. /**
  2805. * APIMethod: getWarningHTML
  2806. *
  2807. * Returns:
  2808. * {String} String with information on why layer is broken, how to get
  2809. * it working.
  2810. */
  2811. getWarningHTML:function() {
  2812. return OpenLayers.i18n(
  2813. "getLayerWarning", {'layerType':'VE', 'layerLib':'VirtualEarth'}
  2814. );
  2815. },
  2816. /************************************
  2817. * *
  2818. * MapObject Interface Controls *
  2819. * *
  2820. ************************************/
  2821. // Get&Set Center, Zoom
  2822. /**
  2823. * APIMethod: setMapObjectCenter
  2824. * Set the mapObject to the specified center and zoom
  2825. *
  2826. * Parameters:
  2827. * center - {Object} MapObject LonLat format
  2828. * zoom - {int} MapObject zoom format
  2829. */
  2830. setMapObjectCenter: function(center, zoom) {
  2831. this.mapObject.SetCenterAndZoom(center, zoom);
  2832. },
  2833. /**
  2834. * APIMethod: getMapObjectCenter
  2835. *
  2836. * Returns:
  2837. * {Object} The mapObject's current center in Map Object format
  2838. */
  2839. getMapObjectCenter: function() {
  2840. return this.mapObject.GetCenter();
  2841. },
  2842. /**
  2843. * APIMethod: dragPanMapObject
  2844. *
  2845. * Parameters:
  2846. * dX - {Integer}
  2847. * dY - {Integer}
  2848. */
  2849. dragPanMapObject: function(dX, dY) {
  2850. this.mapObject.vemapcontrol.PanMap(dX, -dY);
  2851. },
  2852. /**
  2853. * APIMethod: getMapObjectZoom
  2854. *
  2855. * Returns:
  2856. * {Integer} The mapObject's current zoom, in Map Object format
  2857. */
  2858. getMapObjectZoom: function() {
  2859. return this.mapObject.GetZoomLevel();
  2860. },
  2861. // LonLat - Pixel Translation
  2862. /**
  2863. * APIMethod: getMapObjectLonLatFromMapObjectPixel
  2864. *
  2865. * Parameters:
  2866. * moPixel - {Object} MapObject Pixel format
  2867. *
  2868. * Returns:
  2869. * {Object} MapObject LonLat translated from MapObject Pixel
  2870. */
  2871. getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
  2872. //the conditional here is to test if we are running the v6 of VE
  2873. return (typeof VEPixel != 'undefined')
  2874. ? this.mapObject.PixelToLatLong(moPixel)
  2875. : this.mapObject.PixelToLatLong(moPixel.x, moPixel.y);
  2876. },
  2877. /**
  2878. * APIMethod: getMapObjectPixelFromMapObjectLonLat
  2879. *
  2880. * Parameters:
  2881. * moLonLat - {Object} MapObject LonLat format
  2882. *
  2883. * Returns:
  2884. * {Object} MapObject Pixel transtlated from MapObject LonLat
  2885. */
  2886. getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
  2887. return this.mapObject.LatLongToPixel(moLonLat);
  2888. },
  2889. /************************************
  2890. * *
  2891. * MapObject Primitives *
  2892. * *
  2893. ************************************/
  2894. // LonLat
  2895. /**
  2896. * APIMethod: getLongitudeFromMapObjectLonLat
  2897. *
  2898. * Parameters:
  2899. * moLonLat - {Object} MapObject LonLat format
  2900. *
  2901. * Returns:
  2902. * {Float} Longitude of the given MapObject LonLat
  2903. */
  2904. getLongitudeFromMapObjectLonLat: function(moLonLat) {
  2905. return this.sphericalMercator ?
  2906. this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lon :
  2907. moLonLat.Longitude;
  2908. },
  2909. /**
  2910. * APIMethod: getLatitudeFromMapObjectLonLat
  2911. *
  2912. * Parameters:
  2913. * moLonLat - {Object} MapObject LonLat format
  2914. *
  2915. * Returns:
  2916. * {Float} Latitude of the given MapObject LonLat
  2917. */
  2918. getLatitudeFromMapObjectLonLat: function(moLonLat) {
  2919. return this.sphericalMercator ?
  2920. this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lat :
  2921. moLonLat.Latitude;
  2922. },
  2923. /**
  2924. * APIMethod: getMapObjectLonLatFromLonLat
  2925. *
  2926. * Parameters:
  2927. * lon - {Float}
  2928. * lat - {Float}
  2929. *
  2930. * Returns:
  2931. * {Object} MapObject LonLat built from lon and lat params
  2932. */
  2933. getMapObjectLonLatFromLonLat: function(lon, lat) {
  2934. var veLatLong;
  2935. if(this.sphericalMercator) {
  2936. var lonlat = this.inverseMercator(lon, lat);
  2937. veLatLong = new VELatLong(lonlat.lat, lonlat.lon);
  2938. } else {
  2939. veLatLong = new VELatLong(lat, lon);
  2940. }
  2941. return veLatLong;
  2942. },
  2943. // Pixel
  2944. /**
  2945. * APIMethod: getXFromMapObjectPixel
  2946. *
  2947. * Parameters:
  2948. * moPixel - {Object} MapObject Pixel format
  2949. *
  2950. * Returns:
  2951. * {Integer} X value of the MapObject Pixel
  2952. */
  2953. getXFromMapObjectPixel: function(moPixel) {
  2954. return moPixel.x;
  2955. },
  2956. /**
  2957. * APIMethod: getYFromMapObjectPixel
  2958. *
  2959. * Parameters:
  2960. * moPixel - {Object} MapObject Pixel format
  2961. *
  2962. * Returns:
  2963. * {Integer} Y value of the MapObject Pixel
  2964. */
  2965. getYFromMapObjectPixel: function(moPixel) {
  2966. return moPixel.y;
  2967. },
  2968. /**
  2969. * APIMethod: getMapObjectPixelFromXY
  2970. *
  2971. * Parameters:
  2972. * x - {Integer}
  2973. * y - {Integer}
  2974. *
  2975. * Returns:
  2976. * {Object} MapObject Pixel from x and y parameters
  2977. */
  2978. getMapObjectPixelFromXY: function(x, y) {
  2979. //the conditional here is to test if we are running the v6 of VE
  2980. return (typeof VEPixel != 'undefined') ? new VEPixel(x, y)
  2981. : new Msn.VE.Pixel(x, y);
  2982. },
  2983. CLASS_NAME: "OpenLayers.Layer.VirtualEarth"
  2984. });
  2985. /*
  2986. * Copyright 2007, Google Inc.
  2987. *
  2988. * Redistribution and use in source and binary forms, with or without
  2989. * modification, are permitted provided that the following conditions are met:
  2990. *
  2991. * 1. Redistributions of source code must retain the above copyright notice,
  2992. * this list of conditions and the following disclaimer.
  2993. * 2. Redistributions in binary form must reproduce the above copyright notice,
  2994. * this list of conditions and the following disclaimer in the documentation
  2995. * and/or other materials provided with the distribution.
  2996. * 3. Neither the name of Google Inc. nor the names of its contributors may be
  2997. * used to endorse or promote products derived from this software without
  2998. * specific prior written permission.
  2999. *
  3000. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  3001. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  3002. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  3003. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  3004. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  3005. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  3006. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  3007. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  3008. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  3009. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3010. *
  3011. * Sets up google.gears.*, which is *the only* supported way to access Gears.
  3012. *
  3013. * Circumvent this file at your own risk!
  3014. *
  3015. * In the future, Gears may automatically define google.gears.* without this
  3016. * file. Gears may use these objects to transparently fix bugs and compatibility
  3017. * issues. Applications that use the code below will continue to work seamlessly
  3018. * when that happens.
  3019. */
  3020. (function() {
  3021. // We are already defined. Hooray!
  3022. if (window.google && google.gears) {
  3023. return;
  3024. }
  3025. var factory = null;
  3026. // Firefox
  3027. if (typeof GearsFactory != 'undefined') {
  3028. factory = new GearsFactory();
  3029. } else {
  3030. // IE
  3031. try {
  3032. factory = new ActiveXObject('Gears.Factory');
  3033. // privateSetGlobalObject is only required and supported on WinCE.
  3034. if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
  3035. factory.privateSetGlobalObject(this);
  3036. }
  3037. } catch (e) {
  3038. // Safari
  3039. if ((typeof navigator.mimeTypes != 'undefined')
  3040. && navigator.mimeTypes["application/x-googlegears"]) {
  3041. factory = document.createElement("object");
  3042. factory.style.display = "none";
  3043. factory.width = 0;
  3044. factory.height = 0;
  3045. factory.type = "application/x-googlegears";
  3046. document.documentElement.appendChild(factory);
  3047. }
  3048. }
  3049. }
  3050. // *Do not* define any objects if Gears is not installed. This mimics the
  3051. // behavior of Gears defining the objects in the future.
  3052. if (!factory) {
  3053. return;
  3054. }
  3055. // Now set up the objects, being careful not to overwrite anything.
  3056. //
  3057. // Note: In Internet Explorer for Windows Mobile, you can't add properties to
  3058. // the window object. However, global objects are automatically added as
  3059. // properties of the window object in all browsers.
  3060. if (!window.google) {
  3061. google = {};
  3062. }
  3063. if (!google.gears) {
  3064. google.gears = {factory: factory};
  3065. }
  3066. })();
  3067. /**
  3068. * Class: OpenLayers.Protocol.SQL
  3069. * Abstract SQL protocol class. Not to be instantiated directly. Use
  3070. * one of the SQL protocol subclasses instead.
  3071. *
  3072. * Inherits from:
  3073. * - <OpenLayers.Protocol>
  3074. */
  3075. OpenLayers.Protocol.SQL = OpenLayers.Class(OpenLayers.Protocol, {
  3076. /**
  3077. * APIProperty: databaseName
  3078. * {String}
  3079. */
  3080. databaseName: 'ol',
  3081. /**
  3082. * APIProperty: tableName
  3083. * Name of the database table into which Features should be saved.
  3084. */
  3085. tableName: "ol_vector_features",
  3086. /**
  3087. * Property: postReadFiltering
  3088. * {Boolean} Whether the filter (if there's one) must be applied after
  3089. * the features have been read from the database; for example the
  3090. * BBOX strategy passes the read method a BBOX spatial filter, if
  3091. * postReadFiltering is true every feature read from the database
  3092. * will go through the BBOX spatial filter, which can be costly;
  3093. * defaults to true.
  3094. */
  3095. postReadFiltering: true,
  3096. /**
  3097. * Constructor: OpenLayers.Protocol.SQL
  3098. */
  3099. initialize: function(options) {
  3100. OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
  3101. },
  3102. /**
  3103. * APIMethod: destroy
  3104. * Clean up the protocol.
  3105. */
  3106. destroy: function() {
  3107. OpenLayers.Protocol.prototype.destroy.apply(this);
  3108. },
  3109. /**
  3110. * APIMethod: supported
  3111. * This should be overridden by specific subclasses
  3112. *
  3113. * Returns:
  3114. * {Boolean} Whether or not the browser supports the SQL backend
  3115. */
  3116. supported: function() {
  3117. return false;
  3118. },
  3119. /**
  3120. * Method: evaluateFilter
  3121. * If postReadFiltering is true evaluate the filter against the feature
  3122. * and return the result of the evaluation, otherwise return true.
  3123. *
  3124. * Parameters:
  3125. * {<OpenLayers.Feature.Vector>} The feature.
  3126. * {<OpenLayers.Filter>} The filter.
  3127. *
  3128. * Returns:
  3129. * {Boolean} true if postReadFiltering if false, the result of the
  3130. * filter evaluation otherwise.
  3131. */
  3132. evaluateFilter: function(feature, filter) {
  3133. return filter && this.postReadFiltering ?
  3134. filter.evaluate(feature) : true;
  3135. },
  3136. CLASS_NAME: "OpenLayers.Protocol.SQL"
  3137. });
  3138. /**
  3139. * Class: OpenLayers.Protocol.SQL.Gears
  3140. * This Protocol stores feature in the browser via the Gears Database module
  3141. * <http://code.google.com/apis/gears/api_database.html>.
  3142. *
  3143. * The main advantage is that all the read, create, update and delete operations
  3144. * can be done offline.
  3145. *
  3146. * Inherits from:
  3147. * - <OpenLayers.Protocol.SQL>
  3148. */
  3149. OpenLayers.Protocol.SQL.Gears = OpenLayers.Class(OpenLayers.Protocol.SQL, {
  3150. /**
  3151. * Property: FID_PREFIX
  3152. * {String}
  3153. */
  3154. FID_PREFIX: '__gears_fid__',
  3155. /**
  3156. * Property: NULL_GEOMETRY
  3157. * {String}
  3158. */
  3159. NULL_GEOMETRY: '__gears_null_geometry__',
  3160. /**
  3161. * Property: NULL_FEATURE_STATE
  3162. * {String}
  3163. */
  3164. NULL_FEATURE_STATE: '__gears_null_feature_state__',
  3165. /**
  3166. * Property: jsonParser
  3167. * {<OpenLayers.Format.JSON>}
  3168. */
  3169. jsonParser: null,
  3170. /**
  3171. * Property: wktParser
  3172. * {<OpenLayers.Format.WKT>}
  3173. */
  3174. wktParser: null,
  3175. /**
  3176. * Property: fidRegExp
  3177. * {RegExp} Regular expression to know whether a feature was
  3178. * created in offline mode.
  3179. */
  3180. fidRegExp: null,
  3181. /**
  3182. * Property: saveFeatureState
  3183. * {Boolean} Whether to save the feature state (<OpenLayers.State>)
  3184. * into the database, defaults to true.
  3185. */
  3186. saveFeatureState: true,
  3187. /**
  3188. * Property: typeOfFid
  3189. * {String} The type of the feature identifier, either "number" or
  3190. * "string", defaults to "string".
  3191. */
  3192. typeOfFid: "string",
  3193. /**
  3194. * Property: db
  3195. * {GearsDatabase}
  3196. */
  3197. db: null,
  3198. /**
  3199. * Constructor: OpenLayers.Protocol.SQL.Gears
  3200. */
  3201. initialize: function(options) {
  3202. if (!this.supported()) {
  3203. return;
  3204. }
  3205. OpenLayers.Protocol.SQL.prototype.initialize.apply(this, [options]);
  3206. this.jsonParser = new OpenLayers.Format.JSON();
  3207. this.wktParser = new OpenLayers.Format.WKT();
  3208. this.fidRegExp = new RegExp('^' + this.FID_PREFIX);
  3209. this.initializeDatabase();
  3210. },
  3211. /**
  3212. * Method: initializeDatabase
  3213. */
  3214. initializeDatabase: function() {
  3215. this.db = google.gears.factory.create('beta.database');
  3216. this.db.open(this.databaseName);
  3217. this.db.execute(
  3218. "CREATE TABLE IF NOT EXISTS " + this.tableName +
  3219. " (fid TEXT UNIQUE, geometry TEXT, properties TEXT," +
  3220. " state TEXT)");
  3221. },
  3222. /**
  3223. * APIMethod: destroy
  3224. * Clean up the protocol.
  3225. */
  3226. destroy: function() {
  3227. this.db.close();
  3228. this.db = null;
  3229. this.jsonParser = null;
  3230. this.wktParser = null;
  3231. OpenLayers.Protocol.SQL.prototype.destroy.apply(this);
  3232. },
  3233. /**
  3234. * APIMethod: supported
  3235. * Determine whether a browser supports Gears
  3236. *
  3237. * Returns:
  3238. * {Boolean} The browser supports Gears
  3239. */
  3240. supported: function() {
  3241. return !!(window.google && google.gears);
  3242. },
  3243. /**
  3244. * APIMethod: read
  3245. * Read all features from the database and return a
  3246. * <OpenLayers.Protocol.Response> instance. If the options parameter
  3247. * contains a callback attribute, the function is called with the response
  3248. * as a parameter.
  3249. *
  3250. * Parameters:
  3251. * options - {Object} Optional object for configuring the request; it
  3252. * can have the {Boolean} property "noFeatureStateReset" which
  3253. * specifies if the state of features read from the Gears
  3254. * database must be reset to null, if "noFeatureStateReset"
  3255. * is undefined or false then each feature's state is reset
  3256. * to null, if "noFeatureStateReset" is true the feature state
  3257. * is preserved.
  3258. *
  3259. * Returns:
  3260. * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
  3261. * object.
  3262. */
  3263. read: function(options) {
  3264. OpenLayers.Protocol.prototype.read.apply(this, arguments);
  3265. options = OpenLayers.Util.applyDefaults(options, this.options);
  3266. var feature, features = [];
  3267. var rs = this.db.execute("SELECT * FROM " + this.tableName);
  3268. while (rs.isValidRow()) {
  3269. feature = this.unfreezeFeature(rs);
  3270. if (this.evaluateFilter(feature, options.filter)) {
  3271. if (!options.noFeatureStateReset) {
  3272. feature.state = null;
  3273. }
  3274. features.push(feature);
  3275. }
  3276. rs.next();
  3277. }
  3278. rs.close();
  3279. var resp = new OpenLayers.Protocol.Response({
  3280. code: OpenLayers.Protocol.Response.SUCCESS,
  3281. requestType: "read",
  3282. features: features
  3283. });
  3284. if (options && options.callback) {
  3285. options.callback.call(options.scope, resp);
  3286. }
  3287. return resp;
  3288. },
  3289. /**
  3290. * Method: unfreezeFeature
  3291. *
  3292. * Parameters:
  3293. * row - {ResultSet}
  3294. *
  3295. * Returns:
  3296. * {<OpenLayers.Feature.Vector>}
  3297. */
  3298. unfreezeFeature: function(row) {
  3299. var feature;
  3300. var wkt = row.fieldByName('geometry');
  3301. if (wkt == this.NULL_GEOMETRY) {
  3302. feature = new OpenLayers.Feature.Vector();
  3303. } else {
  3304. feature = this.wktParser.read(wkt);
  3305. }
  3306. feature.attributes = this.jsonParser.read(
  3307. row.fieldByName('properties'));
  3308. feature.fid = this.extractFidFromField(row.fieldByName('fid'));
  3309. var state = row.fieldByName('state');
  3310. if (state == this.NULL_FEATURE_STATE) {
  3311. state = null;
  3312. }
  3313. feature.state = state;
  3314. return feature;
  3315. },
  3316. /**
  3317. * Method: extractFidFromField
  3318. *
  3319. * Parameters:
  3320. * field - {String}
  3321. *
  3322. * Returns
  3323. * {String} or {Number} The fid.
  3324. */
  3325. extractFidFromField: function(field) {
  3326. if (!field.match(this.fidRegExp) && this.typeOfFid == "number") {
  3327. field = parseFloat(field);
  3328. }
  3329. return field;
  3330. },
  3331. /**
  3332. * APIMethod: create
  3333. * Create new features into the database.
  3334. *
  3335. * Parameters:
  3336. * features - {Array({<OpenLayers.Feature.Vector>})} or
  3337. * {<OpenLayers.Feature.Vector>} The features to create in
  3338. * the database.
  3339. * options - {Object} Optional object for configuring the request.
  3340. *
  3341. * Returns:
  3342. * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
  3343. * object.
  3344. */
  3345. create: function(features, options) {
  3346. options = OpenLayers.Util.applyDefaults(options, this.options);
  3347. var resp = this.createOrUpdate(features);
  3348. resp.requestType = "create";
  3349. if (options && options.callback) {
  3350. options.callback.call(options.scope, resp);
  3351. }
  3352. return resp;
  3353. },
  3354. /**
  3355. * APIMethod: update
  3356. * Construct a request updating modified feature.
  3357. *
  3358. * Parameters:
  3359. * features - {Array({<OpenLayers.Feature.Vector>})} or
  3360. * {<OpenLayers.Feature.Vector>} The features to update in
  3361. * the database.
  3362. * options - {Object} Optional object for configuring the request.
  3363. *
  3364. * Returns:
  3365. * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
  3366. * object.
  3367. */
  3368. update: function(features, options) {
  3369. options = OpenLayers.Util.applyDefaults(options, this.options);
  3370. var resp = this.createOrUpdate(features);
  3371. resp.requestType = "update";
  3372. if (options && options.callback) {
  3373. options.callback.call(options.scope, resp);
  3374. }
  3375. return resp;
  3376. },
  3377. /**
  3378. * Method: createOrUpdate
  3379. * Construct a request for updating or creating features in the
  3380. * database.
  3381. *
  3382. * Parameters:
  3383. * features - {Array({<OpenLayers.Feature.Vector>})} or
  3384. * {<OpenLayers.Feature.Vector>} The feature to create or update
  3385. * in the database.
  3386. *
  3387. * Returns:
  3388. * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
  3389. * object.
  3390. */
  3391. createOrUpdate: function(features) {
  3392. if (!(OpenLayers.Util.isArray(features))) {
  3393. features = [features];
  3394. }
  3395. var i, len = features.length, feature;
  3396. var insertedFeatures = new Array(len);
  3397. for (i = 0; i < len; i++) {
  3398. feature = features[i];
  3399. var params = this.freezeFeature(feature);
  3400. this.db.execute(
  3401. "REPLACE INTO " + this.tableName +
  3402. " (fid, geometry, properties, state)" +
  3403. " VALUES (?, ?, ?, ?)",
  3404. params);
  3405. var clone = feature.clone();
  3406. clone.fid = this.extractFidFromField(params[0]);
  3407. insertedFeatures[i] = clone;
  3408. }
  3409. return new OpenLayers.Protocol.Response({
  3410. code: OpenLayers.Protocol.Response.SUCCESS,
  3411. features: insertedFeatures,
  3412. reqFeatures: features
  3413. });
  3414. },
  3415. /**
  3416. * Method: freezeFeature
  3417. *
  3418. * Parameters:
  3419. * feature - {<OpenLayers.Feature.Vector>}
  3420. * state - {String} The feature state to store in the database.
  3421. *
  3422. * Returns:
  3423. * {Array}
  3424. */
  3425. freezeFeature: function(feature) {
  3426. // 2 notes:
  3427. // - fid might not be a string
  3428. // - getFeatureStateForFreeze needs the feature fid to it's stored
  3429. // in the feature here
  3430. feature.fid = feature.fid != null ?
  3431. "" + feature.fid : OpenLayers.Util.createUniqueID(this.FID_PREFIX);
  3432. var geometry = feature.geometry != null ?
  3433. feature.geometry.toString() : this.NULL_GEOMETRY;
  3434. var properties = this.jsonParser.write(feature.attributes);
  3435. var state = this.getFeatureStateForFreeze(feature);
  3436. return [feature.fid, geometry, properties, state];
  3437. },
  3438. /**
  3439. * Method: getFeatureStateForFreeze
  3440. * Get the state of the feature to store into the database.
  3441. *
  3442. * Parameters:
  3443. * feature - {<OpenLayers.Feature.Vector>} The feature.
  3444. *
  3445. * Returns
  3446. * {String} The state
  3447. */
  3448. getFeatureStateForFreeze: function(feature) {
  3449. var state;
  3450. if (!this.saveFeatureState) {
  3451. state = this.NULL_FEATURE_STATE;
  3452. } else if (this.createdOffline(feature)) {
  3453. // if the feature was created in offline mode, its
  3454. // state must remain INSERT
  3455. state = OpenLayers.State.INSERT;
  3456. } else {
  3457. state = feature.state;
  3458. }
  3459. return state;
  3460. },
  3461. /**
  3462. * APIMethod: delete
  3463. * Delete features from the database.
  3464. *
  3465. * Parameters:
  3466. * features - {Array({<OpenLayers.Feature.Vector>})} or
  3467. * {<OpenLayers.Feature.Vector>}
  3468. * options - {Object} Optional object for configuring the request.
  3469. * This object is modified and should not be reused.
  3470. *
  3471. * Returns:
  3472. * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
  3473. * object.
  3474. */
  3475. "delete": function(features, options) {
  3476. if (!(OpenLayers.Util.isArray(features))) {
  3477. features = [features];
  3478. }
  3479. options = OpenLayers.Util.applyDefaults(options, this.options);
  3480. var i, len, feature;
  3481. for (i = 0, len = features.length; i < len; i++) {
  3482. feature = features[i];
  3483. // if saveFeatureState is set to true and if the feature wasn't created
  3484. // in offline mode we don't delete it in the database but just update
  3485. // it state column
  3486. if (this.saveFeatureState && !this.createdOffline(feature)) {
  3487. var toDelete = feature.clone();
  3488. toDelete.fid = feature.fid;
  3489. if (toDelete.geometry) {
  3490. toDelete.geometry.destroy();
  3491. toDelete.geometry = null;
  3492. }
  3493. toDelete.state = feature.state;
  3494. this.createOrUpdate(toDelete);
  3495. } else {
  3496. this.db.execute(
  3497. "DELETE FROM " + this.tableName +
  3498. " WHERE fid = ?", [feature.fid]);
  3499. }
  3500. }
  3501. var resp = new OpenLayers.Protocol.Response({
  3502. code: OpenLayers.Protocol.Response.SUCCESS,
  3503. requestType: "delete",
  3504. reqFeatures: features
  3505. });
  3506. if (options && options.callback) {
  3507. options.callback.call(options.scope, resp);
  3508. }
  3509. return resp;
  3510. },
  3511. /**
  3512. * Method: createdOffline
  3513. * Returns true if the feature had a feature id when it was created in
  3514. * the Gears database, false otherwise; this is determined by
  3515. * checking the form of the feature's fid value.
  3516. *
  3517. * Parameters:
  3518. * feature - {<OpenLayers.Feature.Vector>}
  3519. *
  3520. * Returns:
  3521. * {Boolean}
  3522. */
  3523. createdOffline: function(feature) {
  3524. return (typeof feature.fid == "string" &&
  3525. !!(feature.fid.match(this.fidRegExp)));
  3526. },
  3527. /**
  3528. * APIMethod: commit
  3529. * Go over the features and for each take action
  3530. * based on the feature state. Possible actions are create,
  3531. * update and delete.
  3532. *
  3533. * Parameters:
  3534. * features - {Array({<OpenLayers.Feature.Vector>})}
  3535. * options - {Object} Object whose possible keys are "create", "update",
  3536. * "delete", "callback" and "scope", the values referenced by the
  3537. * first three are objects as passed to the "create", "update", and
  3538. * "delete" methods, the value referenced by the "callback" key is
  3539. * a function which is called when the commit operation is complete
  3540. * using the scope referenced by the "scope" key.
  3541. *
  3542. * Returns:
  3543. * {Array({<OpenLayers.Protocol.Response>})} An array of
  3544. * <OpenLayers.Protocol.Response> objects, one per request made
  3545. * to the database.
  3546. */
  3547. commit: function(features, options) {
  3548. var opt, resp = [], nRequests = 0, nResponses = 0;
  3549. function callback(resp) {
  3550. if (++nResponses < nRequests) {
  3551. resp.last = false;
  3552. }
  3553. this.callUserCallback(options, resp);
  3554. }
  3555. var feature, toCreate = [], toUpdate = [], toDelete = [];
  3556. for (var i = features.length - 1; i >= 0; i--) {
  3557. feature = features[i];
  3558. switch (feature.state) {
  3559. case OpenLayers.State.INSERT:
  3560. toCreate.push(feature);
  3561. break;
  3562. case OpenLayers.State.UPDATE:
  3563. toUpdate.push(feature);
  3564. break;
  3565. case OpenLayers.State.DELETE:
  3566. toDelete.push(feature);
  3567. break;
  3568. }
  3569. }
  3570. if (toCreate.length > 0) {
  3571. nRequests++;
  3572. opt = OpenLayers.Util.applyDefaults(
  3573. {"callback": callback, "scope": this},
  3574. options.create
  3575. );
  3576. resp.push(this.create(toCreate, opt));
  3577. }
  3578. if (toUpdate.length > 0) {
  3579. nRequests++;
  3580. opt = OpenLayers.Util.applyDefaults(
  3581. {"callback": callback, "scope": this},
  3582. options.update
  3583. );
  3584. resp.push(this.update(toUpdate, opt));
  3585. }
  3586. if (toDelete.length > 0) {
  3587. nRequests++;
  3588. opt = OpenLayers.Util.applyDefaults(
  3589. {"callback": callback, "scope": this},
  3590. options["delete"]
  3591. );
  3592. resp.push(this["delete"](toDelete, opt));
  3593. }
  3594. return resp;
  3595. },
  3596. /**
  3597. * Method: clear
  3598. * Removes all rows of the table.
  3599. */
  3600. clear: function() {
  3601. this.db.execute("DELETE FROM " + this.tableName);
  3602. },
  3603. /**
  3604. * Method: callUserCallback
  3605. * This method is called from within commit each time a request is made
  3606. * to the database, it is responsible for calling the user-supplied
  3607. * callbacks.
  3608. *
  3609. * Parameters:
  3610. * options - {Object} The map of options passed to the commit call.
  3611. * resp - {<OpenLayers.Protocol.Response>}
  3612. */
  3613. callUserCallback: function(options, resp) {
  3614. var opt = options[resp.requestType];
  3615. if (opt && opt.callback) {
  3616. opt.callback.call(opt.scope, resp);
  3617. }
  3618. if (resp.last && options.callback) {
  3619. options.callback.call(options.scope);
  3620. }
  3621. },
  3622. CLASS_NAME: "OpenLayers.Protocol.SQL.Gears"
  3623. });
  3624. /**
  3625. * Class: OpenLayers.Layer.Yahoo
  3626. *
  3627. * Inherits from:
  3628. * - <OpenLayers.Layer.EventPane>
  3629. * - <OpenLayers.Layer.FixedZoomLevels>
  3630. */
  3631. OpenLayers.Layer.Yahoo = OpenLayers.Class(
  3632. OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
  3633. /**
  3634. * Constant: MIN_ZOOM_LEVEL
  3635. * {Integer} 0
  3636. */
  3637. MIN_ZOOM_LEVEL: 0,
  3638. /**
  3639. * Constant: MAX_ZOOM_LEVEL
  3640. * {Integer} 17
  3641. */
  3642. MAX_ZOOM_LEVEL: 17,
  3643. /**
  3644. * Constant: RESOLUTIONS
  3645. * {Array(Float)} Hardcode these resolutions so that they are more closely
  3646. * tied with the standard wms projection
  3647. */
  3648. RESOLUTIONS: [
  3649. 1.40625,
  3650. 0.703125,
  3651. 0.3515625,
  3652. 0.17578125,
  3653. 0.087890625,
  3654. 0.0439453125,
  3655. 0.02197265625,
  3656. 0.010986328125,
  3657. 0.0054931640625,
  3658. 0.00274658203125,
  3659. 0.001373291015625,
  3660. 0.0006866455078125,
  3661. 0.00034332275390625,
  3662. 0.000171661376953125,
  3663. 0.0000858306884765625,
  3664. 0.00004291534423828125,
  3665. 0.00002145767211914062,
  3666. 0.00001072883605957031
  3667. ],
  3668. /**
  3669. * APIProperty: type
  3670. * {YahooMapType}
  3671. */
  3672. type: null,
  3673. /**
  3674. * APIProperty: wrapDateLine
  3675. * {Boolean} Allow user to pan forever east/west. Default is true.
  3676. * Setting this to false only restricts panning if
  3677. * <sphericalMercator> is true.
  3678. */
  3679. wrapDateLine: true,
  3680. /**
  3681. * APIProperty: sphericalMercator
  3682. * {Boolean} Should the map act as a mercator-projected map? This will
  3683. * cause all interactions with the map to be in the actual map projection,
  3684. * which allows support for vector drawing, overlaying other maps, etc.
  3685. */
  3686. sphericalMercator: false,
  3687. /**
  3688. * Constructor: OpenLayers.Layer.Yahoo
  3689. *
  3690. * Parameters:
  3691. * name - {String}
  3692. * options - {Object}
  3693. */
  3694. initialize: function(name, options) {
  3695. OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
  3696. OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
  3697. arguments);
  3698. if(this.sphericalMercator) {
  3699. OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
  3700. this.initMercatorParameters();
  3701. }
  3702. },
  3703. /**
  3704. * Method: loadMapObject
  3705. */
  3706. loadMapObject:function() {
  3707. try { //do not crash!
  3708. var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
  3709. this.mapObject = new YMap(this.div, this.type, size);
  3710. this.mapObject.disableKeyControls();
  3711. this.mapObject.disableDragMap();
  3712. //can we do smooth panning? (moveByXY is not an API function)
  3713. if ( !this.mapObject.moveByXY ||
  3714. (typeof this.mapObject.moveByXY != "function" ) ) {
  3715. this.dragPanMapObject = null;
  3716. }
  3717. } catch(e) {}
  3718. },
  3719. /**
  3720. * Method: onMapResize
  3721. *
  3722. */
  3723. onMapResize: function() {
  3724. try {
  3725. var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
  3726. this.mapObject.resizeTo(size);
  3727. } catch(e) {}
  3728. },
  3729. /**
  3730. * APIMethod: setMap
  3731. * Overridden from EventPane because we need to remove this yahoo event
  3732. * pane which prohibits our drag and drop, and we can only do this
  3733. * once the map has been loaded and centered.
  3734. *
  3735. * Parameters:
  3736. * map - {<OpenLayers.Map>}
  3737. */
  3738. setMap: function(map) {
  3739. OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
  3740. this.map.events.register("moveend", this, this.fixYahooEventPane);
  3741. },
  3742. /**
  3743. * Method: fixYahooEventPane
  3744. * The map has been centered, so the mysterious yahoo eventpane has been
  3745. * added. we remove it so that it doesnt mess with *our* event pane.
  3746. */
  3747. fixYahooEventPane: function() {
  3748. var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv");
  3749. if (yahooEventPane != null) {
  3750. if (yahooEventPane.parentNode != null) {
  3751. yahooEventPane.parentNode.removeChild(yahooEventPane);
  3752. }
  3753. this.map.events.unregister("moveend", this,
  3754. this.fixYahooEventPane);
  3755. }
  3756. },
  3757. /**
  3758. * APIMethod: getWarningHTML
  3759. *
  3760. * Returns:
  3761. * {String} String with information on why layer is broken, how to get
  3762. * it working.
  3763. */
  3764. getWarningHTML:function() {
  3765. return OpenLayers.i18n(
  3766. "getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
  3767. );
  3768. },
  3769. /********************************************************/
  3770. /* */
  3771. /* Translation Functions */
  3772. /* */
  3773. /* The following functions translate GMaps and OL */
  3774. /* formats for Pixel, LonLat, Bounds, and Zoom */
  3775. /* */
  3776. /********************************************************/
  3777. //
  3778. // TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
  3779. //
  3780. /**
  3781. * APIMethod: getOLZoomFromMapObjectZoom
  3782. *
  3783. * Parameters:
  3784. * gZoom - {Integer}
  3785. *
  3786. * Returns:
  3787. * {Integer} An OpenLayers Zoom level, translated from the passed in gZoom
  3788. * Returns null if null value is passed in.
  3789. */
  3790. getOLZoomFromMapObjectZoom: function(moZoom) {
  3791. var zoom = null;
  3792. if (moZoom != null) {
  3793. zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]);
  3794. zoom = 18 - zoom;
  3795. }
  3796. return zoom;
  3797. },
  3798. /**
  3799. * APIMethod: getMapObjectZoomFromOLZoom
  3800. *
  3801. * Parameters:
  3802. * olZoom - {Integer}
  3803. *
  3804. * Returns:
  3805. * {Integer} A MapObject level, translated from the passed in olZoom
  3806. * Returns null if null value is passed in
  3807. */
  3808. getMapObjectZoomFromOLZoom: function(olZoom) {
  3809. var zoom = null;
  3810. if (olZoom != null) {
  3811. zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]);
  3812. zoom = 18 - zoom;
  3813. }
  3814. return zoom;
  3815. },
  3816. /************************************
  3817. * *
  3818. * MapObject Interface Controls *
  3819. * *
  3820. ************************************/
  3821. // Get&Set Center, Zoom
  3822. /**
  3823. * APIMethod: setMapObjectCenter
  3824. * Set the mapObject to the specified center and zoom
  3825. *
  3826. * Parameters:
  3827. * center - {Object} MapObject LonLat format
  3828. * zoom - {int} MapObject zoom format
  3829. */
  3830. setMapObjectCenter: function(center, zoom) {
  3831. this.mapObject.drawZoomAndCenter(center, zoom);
  3832. },
  3833. /**
  3834. * APIMethod: getMapObjectCenter
  3835. *
  3836. * Returns:
  3837. * {Object} The mapObject's current center in Map Object format
  3838. */
  3839. getMapObjectCenter: function() {
  3840. return this.mapObject.getCenterLatLon();
  3841. },
  3842. /**
  3843. * APIMethod: dragPanMapObject
  3844. *
  3845. * Parameters:
  3846. * dX - {Integer}
  3847. * dY - {Integer}
  3848. */
  3849. dragPanMapObject: function(dX, dY) {
  3850. this.mapObject.moveByXY({
  3851. 'x': -dX,
  3852. 'y': dY
  3853. });
  3854. },
  3855. /**
  3856. * APIMethod: getMapObjectZoom
  3857. *
  3858. * Returns:
  3859. * {Integer} The mapObject's current zoom, in Map Object format
  3860. */
  3861. getMapObjectZoom: function() {
  3862. return this.mapObject.getZoomLevel();
  3863. },
  3864. // LonLat - Pixel Translation
  3865. /**
  3866. * APIMethod: getMapObjectLonLatFromMapObjectPixel
  3867. *
  3868. * Parameters:
  3869. * moPixel - {Object} MapObject Pixel format
  3870. *
  3871. * Returns:
  3872. * {Object} MapObject LonLat translated from MapObject Pixel
  3873. */
  3874. getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
  3875. return this.mapObject.convertXYLatLon(moPixel);
  3876. },
  3877. /**
  3878. * APIMethod: getMapObjectPixelFromMapObjectLonLat
  3879. *
  3880. * Parameters:
  3881. * moLonLat - {Object} MapObject LonLat format
  3882. *
  3883. * Returns:
  3884. * {Object} MapObject Pixel transtlated from MapObject LonLat
  3885. */
  3886. getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
  3887. return this.mapObject.convertLatLonXY(moLonLat);
  3888. },
  3889. /************************************
  3890. * *
  3891. * MapObject Primitives *
  3892. * *
  3893. ************************************/
  3894. // LonLat
  3895. /**
  3896. * APIMethod: getLongitudeFromMapObjectLonLat
  3897. *
  3898. * Parameters:
  3899. * moLonLat - {Object} MapObject LonLat format
  3900. *
  3901. * Returns:
  3902. * {Float} Longitude of the given MapObject LonLat
  3903. */
  3904. getLongitudeFromMapObjectLonLat: function(moLonLat) {
  3905. return this.sphericalMercator ?
  3906. this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon :
  3907. moLonLat.Lon;
  3908. },
  3909. /**
  3910. * APIMethod: getLatitudeFromMapObjectLonLat
  3911. *
  3912. * Parameters:
  3913. * moLonLat - {Object} MapObject LonLat format
  3914. *
  3915. * Returns:
  3916. * {Float} Latitude of the given MapObject LonLat
  3917. */
  3918. getLatitudeFromMapObjectLonLat: function(moLonLat) {
  3919. return this.sphericalMercator ?
  3920. this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat :
  3921. moLonLat.Lat;
  3922. },
  3923. /**
  3924. * APIMethod: getMapObjectLonLatFromLonLat
  3925. *
  3926. * Parameters:
  3927. * lon - {Float}
  3928. * lat - {Float}
  3929. *
  3930. * Returns:
  3931. * {Object} MapObject LonLat built from lon and lat params
  3932. */
  3933. getMapObjectLonLatFromLonLat: function(lon, lat) {
  3934. var yLatLong;
  3935. if(this.sphericalMercator) {
  3936. var lonlat = this.inverseMercator(lon, lat);
  3937. yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon);
  3938. } else {
  3939. yLatLong = new YGeoPoint(lat, lon);
  3940. }
  3941. return yLatLong;
  3942. },
  3943. // Pixel
  3944. /**
  3945. * APIMethod: getXFromMapObjectPixel
  3946. *
  3947. * Parameters:
  3948. * moPixel - {Object} MapObject Pixel format
  3949. *
  3950. * Returns:
  3951. * {Integer} X value of the MapObject Pixel
  3952. */
  3953. getXFromMapObjectPixel: function(moPixel) {
  3954. return moPixel.x;
  3955. },
  3956. /**
  3957. * APIMethod: getYFromMapObjectPixel
  3958. *
  3959. * Parameters:
  3960. * moPixel - {Object} MapObject Pixel format
  3961. *
  3962. * Returns:
  3963. * {Integer} Y value of the MapObject Pixel
  3964. */
  3965. getYFromMapObjectPixel: function(moPixel) {
  3966. return moPixel.y;
  3967. },
  3968. /**
  3969. * APIMethod: getMapObjectPixelFromXY
  3970. *
  3971. * Parameters:
  3972. * x - {Integer}
  3973. * y - {Integer}
  3974. *
  3975. * Returns:
  3976. * {Object} MapObject Pixel from x and y parameters
  3977. */
  3978. getMapObjectPixelFromXY: function(x, y) {
  3979. return new YCoordPoint(x, y);
  3980. },
  3981. // Size
  3982. /**
  3983. * APIMethod: getMapObjectSizeFromOLSize
  3984. *
  3985. * Parameters:
  3986. * olSize - {<OpenLayers.Size>}
  3987. *
  3988. * Returns:
  3989. * {Object} MapObject Size from olSize parameter
  3990. */
  3991. getMapObjectSizeFromOLSize: function(olSize) {
  3992. return new YSize(olSize.w, olSize.h);
  3993. },
  3994. CLASS_NAME: "OpenLayers.Layer.Yahoo"
  3995. });
  3996. /**
  3997. * Class: OpenLayers.Layer.GML
  3998. * Create a vector layer by parsing a GML file. The GML file is
  3999. * passed in as a parameter.
  4000. * *Deprecated*. To be removed in 3.0. Instead use OpenLayers.Layer.Vector
  4001. * with Protocol.HTTP and Strategy.Fixed. Provide the protocol with a
  4002. * format parameter to get the parser you want for your data.
  4003. *
  4004. * Inherits from:
  4005. * - <OpenLayers.Layer.Vector>
  4006. */
  4007. OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, {
  4008. /**
  4009. * Property: loaded
  4010. * {Boolean} Flag for whether the GML data has been loaded yet.
  4011. */
  4012. loaded: false,
  4013. /**
  4014. * APIProperty: format
  4015. * {<OpenLayers.Format>} The format you want the data to be parsed with.
  4016. */
  4017. format: null,
  4018. /**
  4019. * APIProperty: formatOptions
  4020. * {Object} Hash of options which should be passed to the format when it is
  4021. * created. Must be passed in the constructor.
  4022. */
  4023. formatOptions: null,
  4024. /**
  4025. * Constructor: OpenLayers.Layer.GML
  4026. * Load and parse a single file on the web, according to the format
  4027. * provided via the 'format' option, defaulting to GML.
  4028. *
  4029. * Parameters:
  4030. * name - {String}
  4031. * url - {String} URL of a GML file.
  4032. * options - {Object} Hashtable of extra options to tag onto the layer.
  4033. */
  4034. initialize: function(name, url, options) {
  4035. var newArguments = [];
  4036. newArguments.push(name, options);
  4037. OpenLayers.Layer.Vector.prototype.initialize.apply(this, newArguments);
  4038. this.url = url;
  4039. },
  4040. /**
  4041. * APIMethod: setVisibility
  4042. * Set the visibility flag for the layer and hide/show&redraw accordingly.
  4043. * Fire event unless otherwise specified
  4044. * GML will be loaded if the layer is being made visible for the first
  4045. * time.
  4046. *
  4047. * Parameters:
  4048. * visible - {Boolean} Whether or not to display the layer
  4049. * (if in range)
  4050. * noEvent - {Boolean}
  4051. */
  4052. setVisibility: function(visibility, noEvent) {
  4053. OpenLayers.Layer.Vector.prototype.setVisibility.apply(this, arguments);
  4054. if(this.visibility && !this.loaded){
  4055. // Load the GML
  4056. this.loadGML();
  4057. }
  4058. },
  4059. /**
  4060. * Method: moveTo
  4061. * If layer is visible and GML has not been loaded, load GML, then load GML
  4062. * and call OpenLayers.Layer.Vector.moveTo() to redraw at the new location.
  4063. *
  4064. * Parameters:
  4065. * bounds - {Object}
  4066. * zoomChanged - {Object}
  4067. * minor - {Object}
  4068. */
  4069. moveTo:function(bounds, zoomChanged, minor) {
  4070. OpenLayers.Layer.Vector.prototype.moveTo.apply(this, arguments);
  4071. // Wait until initialisation is complete before loading GML
  4072. // otherwise we can get a race condition where the root HTML DOM is
  4073. // loaded after the GML is paited.
  4074. // See http://trac.openlayers.org/ticket/404
  4075. if(this.visibility && !this.loaded){
  4076. this.loadGML();
  4077. }
  4078. },
  4079. /**
  4080. * Method: loadGML
  4081. */
  4082. loadGML: function() {
  4083. if (!this.loaded) {
  4084. this.events.triggerEvent("loadstart");
  4085. OpenLayers.Request.GET({
  4086. url: this.url,
  4087. success: this.requestSuccess,
  4088. failure: this.requestFailure,
  4089. scope: this
  4090. });
  4091. this.loaded = true;
  4092. }
  4093. },
  4094. /**
  4095. * Method: setUrl
  4096. * Change the URL and reload the GML
  4097. *
  4098. * Parameters:
  4099. * url - {String} URL of a GML file.
  4100. */
  4101. setUrl:function(url) {
  4102. this.url = url;
  4103. this.destroyFeatures();
  4104. this.loaded = false;
  4105. this.loadGML();
  4106. },
  4107. /**
  4108. * Method: requestSuccess
  4109. * Process GML after it has been loaded.
  4110. * Called by initialize() and loadUrl() after the GML has been loaded.
  4111. *
  4112. * Parameters:
  4113. * request - {String}
  4114. */
  4115. requestSuccess:function(request) {
  4116. var doc = request.responseXML;
  4117. if (!doc || !doc.documentElement) {
  4118. doc = request.responseText;
  4119. }
  4120. var options = {};
  4121. OpenLayers.Util.extend(options, this.formatOptions);
  4122. if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
  4123. options.externalProjection = this.projection;
  4124. options.internalProjection = this.map.getProjectionObject();
  4125. }
  4126. var gml = this.format ? new this.format(options) : new OpenLayers.Format.GML(options);
  4127. this.addFeatures(gml.read(doc));
  4128. this.events.triggerEvent("loadend");
  4129. },
  4130. /**
  4131. * Method: requestFailure
  4132. * Process a failed loading of GML.
  4133. * Called by initialize() and loadUrl() if there was a problem loading GML.
  4134. *
  4135. * Parameters:
  4136. * request - {String}
  4137. */
  4138. requestFailure: function(request) {
  4139. OpenLayers.Console.userError('Error in loading GML file ' + this.url);
  4140. this.events.triggerEvent("loadend");
  4141. },
  4142. CLASS_NAME: "OpenLayers.Layer.GML"
  4143. });
  4144. /**
  4145. * Class: OpenLayers.Geometry.Rectangle
  4146. * This class is *not supported*, and probably isn't what you're looking for.
  4147. * Instead, most users probably want something like:
  4148. * (code)
  4149. * var poly = new OpenLayers.Bounds(0,0,10,10).toGeometry();
  4150. * (end)
  4151. * This will create a rectangular Polygon geometry.
  4152. *
  4153. * Inherits:
  4154. * - <OpenLayers.Geometry>
  4155. */
  4156. OpenLayers.Geometry.Rectangle = OpenLayers.Class(OpenLayers.Geometry, {
  4157. /**
  4158. * Property: x
  4159. * {Float}
  4160. */
  4161. x: null,
  4162. /**
  4163. * Property: y
  4164. * {Float}
  4165. */
  4166. y: null,
  4167. /**
  4168. * Property: width
  4169. * {Float}
  4170. */
  4171. width: null,
  4172. /**
  4173. * Property: height
  4174. * {Float}
  4175. */
  4176. height: null,
  4177. /**
  4178. * Constructor: OpenLayers.Geometry.Rectangle
  4179. *
  4180. * Parameters:
  4181. * points - {Array(<OpenLayers.Geometry.Point>)}
  4182. */
  4183. initialize: function(x, y, width, height) {
  4184. OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
  4185. this.x = x;
  4186. this.y = y;
  4187. this.width = width;
  4188. this.height = height;
  4189. },
  4190. /**
  4191. * Method: calculateBounds
  4192. * Recalculate the bounds for the geometry.
  4193. */
  4194. calculateBounds: function() {
  4195. this.bounds = new OpenLayers.Bounds(this.x, this.y,
  4196. this.x + this.width,
  4197. this.y + this.height);
  4198. },
  4199. /**
  4200. * APIMethod: getLength
  4201. *
  4202. * Returns:
  4203. * {Float} The length of the geometry
  4204. */
  4205. getLength: function() {
  4206. var length = (2 * this.width) + (2 * this.height);
  4207. return length;
  4208. },
  4209. /**
  4210. * APIMethod: getArea
  4211. *
  4212. * Returns:
  4213. * {Float} The area of the geometry
  4214. */
  4215. getArea: function() {
  4216. var area = this.width * this.height;
  4217. return area;
  4218. },
  4219. CLASS_NAME: "OpenLayers.Geometry.Rectangle"
  4220. });
  4221. /**
  4222. * Class: OpenLayers.Renderer.NG
  4223. *
  4224. * Inherits from:
  4225. * - <OpenLayers.Renderer.Elements>
  4226. */
  4227. OpenLayers.Renderer.NG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
  4228. /**
  4229. * Constant: labelNodeType
  4230. * {String} The node type for text label containers. To be defined by
  4231. * subclasses.
  4232. */
  4233. labelNodeType: null,
  4234. /**
  4235. * Constructor: OpenLayers.Renderer.NG
  4236. *
  4237. * Parameters:
  4238. * containerID - {String}
  4239. * options - {Object} options for this renderer. Supported options are:
  4240. * * yOrdering - {Boolean} Whether to use y-ordering
  4241. * * zIndexing - {Boolean} Whether to use z-indexing. Will be ignored
  4242. * if yOrdering is set to true.
  4243. */
  4244. /**
  4245. * Method: updateDimensions
  4246. * To be extended by subclasses - here we set positioning related styles
  4247. * on HTML elements, subclasses have to do the same for renderer specific
  4248. * elements (e.g. viewBox, width and height of the rendererRoot)
  4249. *
  4250. * Parameters:
  4251. * zoomChanged - {Boolean} Has the zoom changed? If so, subclasses may have
  4252. * to update feature styles/dimensions.
  4253. */
  4254. updateDimensions: function(zoomChanged) {
  4255. var mapExtent = this.map.getExtent();
  4256. var renderExtent = mapExtent.scale(3);
  4257. this.setExtent(renderExtent, true);
  4258. var res = this.getResolution();
  4259. var div = this.rendererRoot.parentNode;
  4260. var layerLeft = parseFloat(div.parentNode.style.left);
  4261. var layerTop = parseFloat(div.parentNode.style.top);
  4262. div.style.left = ((renderExtent.left - mapExtent.left) / res - layerLeft) + "px";
  4263. div.style.top = ((mapExtent.top - renderExtent.top) / res - layerTop) + "px";
  4264. },
  4265. /**
  4266. * Method: resize
  4267. */
  4268. setSize: function() {
  4269. this.map.getExtent() && this.updateDimensions();
  4270. },
  4271. /**
  4272. * Method: drawFeature
  4273. * Draw the feature. The optional style argument can be used
  4274. * to override the feature's own style. This method should only
  4275. * be called from layer.drawFeature().
  4276. *
  4277. * Parameters:
  4278. * feature - {<OpenLayers.Feature.Vector>}
  4279. * style - {<Object>}
  4280. *
  4281. * Returns:
  4282. * {Boolean} true if the feature has been drawn completely, false if not,
  4283. * undefined if the feature had no geometry
  4284. */
  4285. drawFeature: function(feature, style) {
  4286. if(style == null) {
  4287. style = feature.style;
  4288. }
  4289. if (feature.geometry) {
  4290. var rendered = this.drawGeometry(feature.geometry, style, feature.id);
  4291. if(rendered !== false && style.label) {
  4292. var location = feature.geometry.getCentroid();
  4293. this.drawText(feature.id, style, location);
  4294. } else {
  4295. this.removeText(feature.id);
  4296. }
  4297. return rendered;
  4298. }
  4299. },
  4300. /**
  4301. * Method: drawText
  4302. * Function for drawing text labels.
  4303. * This method is only called by the renderer itself.
  4304. *
  4305. * Parameters:
  4306. * featureId - {String|DOMElement}
  4307. * style - {Object}
  4308. * location - {<OpenLayers.Geometry.Point>}, will be modified inline
  4309. *
  4310. * Returns:
  4311. * {DOMElement} container holding the text label (to be populated by
  4312. * subclasses)
  4313. */
  4314. drawText: function(featureId, style, location) {
  4315. var label;
  4316. if (typeof featureId !== "string") {
  4317. label = featureId;
  4318. } else {
  4319. label = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX, this.labelNodeType);
  4320. label._featureId = featureId;
  4321. }
  4322. label._style = style;
  4323. label._x = location.x;
  4324. label._y = location.y;
  4325. if(style.labelXOffset || style.labelYOffset) {
  4326. var xOffset = isNaN(style.labelXOffset) ? 0 : style.labelXOffset;
  4327. var yOffset = isNaN(style.labelYOffset) ? 0 : style.labelYOffset;
  4328. var res = this.getResolution();
  4329. location.move(xOffset*res, yOffset*res);
  4330. }
  4331. if(label.parentNode !== this.textRoot) {
  4332. this.textRoot.appendChild(label);
  4333. }
  4334. return label;
  4335. },
  4336. CLASS_NAME: "OpenLayers.Renderer.NG"
  4337. });
  4338. // Monkey-patching Layer.Vector for Renderer.NG support
  4339. (function() {
  4340. var moveTo = OpenLayers.Layer.Vector.prototype.moveTo;
  4341. OpenLayers.Layer.Vector.prototype.moveTo = function(bounds, zoomChanged, dragging) {
  4342. if (OpenLayers.Renderer.NG && this.renderer instanceof OpenLayers.Renderer.NG) {
  4343. OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
  4344. dragging || this.renderer.updateDimensions(zoomChanged);
  4345. if (!this.drawn) {
  4346. this.drawn = true;
  4347. var feature;
  4348. for(var i=0, len=this.features.length; i<len; i++) {
  4349. this.renderer.locked = (i !== (len - 1));
  4350. feature = this.features[i];
  4351. this.drawFeature(feature);
  4352. }
  4353. }
  4354. } else {
  4355. moveTo.apply(this, arguments);
  4356. }
  4357. }
  4358. var redraw = OpenLayers.Layer.Vector.prototype.redraw;
  4359. OpenLayers.Layer.Vector.prototype.redraw = function() {
  4360. if (OpenLayers.Renderer.NG && this.renderer instanceof OpenLayers.Renderer.NG) {
  4361. this.drawn = false;
  4362. }
  4363. redraw.apply(this, arguments);
  4364. }
  4365. })();
  4366. /**
  4367. * Class: OpenLayers.Renderer.SVG2
  4368. *
  4369. * Inherits from:
  4370. * - <OpenLayers.Renderer.NG>
  4371. */
  4372. OpenLayers.Renderer.SVG2 = OpenLayers.Class(OpenLayers.Renderer.NG, {
  4373. /**
  4374. * Property: xmlns
  4375. * {String}
  4376. */
  4377. xmlns: "http://www.w3.org/2000/svg",
  4378. /**
  4379. * Property: xlinkns
  4380. * {String}
  4381. */
  4382. xlinkns: "http://www.w3.org/1999/xlink",
  4383. /**
  4384. * Property: symbolMetrics
  4385. * {Object} Cache for symbol metrics according to their svg coordinate
  4386. * space. This is an object keyed by the symbol's id, and values are
  4387. * an object with size, x and y properties.
  4388. */
  4389. symbolMetrics: null,
  4390. /**
  4391. * Constant: labelNodeType
  4392. * {String} The node type for text label containers.
  4393. */
  4394. labelNodeType: "g",
  4395. /**
  4396. * Constructor: OpenLayers.Renderer.SVG2
  4397. *
  4398. * Parameters:
  4399. * containerID - {String}
  4400. */
  4401. initialize: function(containerID) {
  4402. if (!this.supported()) {
  4403. return;
  4404. }
  4405. OpenLayers.Renderer.Elements.prototype.initialize.apply(this,
  4406. arguments);
  4407. this.symbolMetrics = {};
  4408. },
  4409. /**
  4410. * APIMethod: supported
  4411. *
  4412. * Returns:
  4413. * {Boolean} Whether or not the browser supports the SVG renderer
  4414. */
  4415. supported: function() {
  4416. var svgFeature = "http://www.w3.org/TR/SVG11/feature#";
  4417. return (document.implementation &&
  4418. (document.implementation.hasFeature("org.w3c.svg", "1.0") ||
  4419. document.implementation.hasFeature(svgFeature + "SVG", "1.1") ||
  4420. document.implementation.hasFeature(svgFeature + "BasicStructure", "1.1") ));
  4421. },
  4422. /**
  4423. * Method: updateDimensions
  4424. *
  4425. * Parameters:
  4426. * zoomChanged - {Boolean}
  4427. */
  4428. updateDimensions: function(zoomChanged) {
  4429. OpenLayers.Renderer.NG.prototype.updateDimensions.apply(this, arguments);
  4430. var res = this.getResolution();
  4431. var width = this.extent.getWidth();
  4432. var height = this.extent.getHeight();
  4433. var extentString = [
  4434. this.extent.left,
  4435. -this.extent.top,
  4436. width,
  4437. height
  4438. ].join(" ");
  4439. this.rendererRoot.setAttributeNS(null, "viewBox", extentString);
  4440. this.rendererRoot.setAttributeNS(null, "width", width / res);
  4441. this.rendererRoot.setAttributeNS(null, "height", height / res);
  4442. if (zoomChanged === true) {
  4443. // update styles for the new resolution
  4444. var i, len;
  4445. var nodes = this.vectorRoot.childNodes;
  4446. for (i=0, len=nodes.length; i<len; ++i) {
  4447. this.setStyle(nodes[i]);
  4448. }
  4449. var textNodes = this.textRoot.childNodes;
  4450. var label;
  4451. for (i=0, len=textNodes.length; i<len; ++i) {
  4452. label = textNodes[i];
  4453. this.drawText(label, label._style,
  4454. new OpenLayers.Geometry.Point(label._x, label._y)
  4455. );
  4456. }
  4457. }
  4458. },
  4459. /**
  4460. * Method: getNodeType
  4461. *
  4462. * Parameters:
  4463. * geometry - {<OpenLayers.Geometry>}
  4464. * style - {Object}
  4465. *
  4466. * Returns:
  4467. * {String} The corresponding node type for the specified geometry
  4468. */
  4469. getNodeType: function(geometry, style) {
  4470. var nodeType = null;
  4471. switch (geometry.CLASS_NAME) {
  4472. case "OpenLayers.Geometry.Point":
  4473. if (style.externalGraphic) {
  4474. nodeType = "image";
  4475. } else if (this.isComplexSymbol(style.graphicName)) {
  4476. nodeType = "svg";
  4477. } else {
  4478. nodeType = "circle";
  4479. }
  4480. break;
  4481. case "OpenLayers.Geometry.Rectangle":
  4482. nodeType = "rect";
  4483. break;
  4484. case "OpenLayers.Geometry.LineString":
  4485. nodeType = "polyline";
  4486. break;
  4487. case "OpenLayers.Geometry.LinearRing":
  4488. nodeType = "polygon";
  4489. break;
  4490. case "OpenLayers.Geometry.Polygon":
  4491. case "OpenLayers.Geometry.Curve":
  4492. nodeType = "path";
  4493. break;
  4494. default:
  4495. break;
  4496. }
  4497. return nodeType;
  4498. },
  4499. /**
  4500. * Method: setStyle
  4501. * Use to set all the style attributes to a SVG node.
  4502. *
  4503. * Takes care to adjust stroke width and point radius to be
  4504. * resolution-relative
  4505. *
  4506. * Parameters:
  4507. * node - {SVGDomElement} An SVG element to decorate
  4508. * style - {Object}
  4509. * options - {Object} Currently supported options include
  4510. * 'isFilled' {Boolean} and
  4511. * 'isStroked' {Boolean}
  4512. */
  4513. setStyle: function(node, style, options) {
  4514. style = style || node._style;
  4515. options = options || node._options;
  4516. var resolution = this.getResolution();
  4517. var r = node._radius;
  4518. var widthFactor = resolution;
  4519. if (node._geometryClass == "OpenLayers.Geometry.Point" && r) {
  4520. node.style.visibility = "";
  4521. if (style.graphic === false) {
  4522. node.style.visibility = "hidden";
  4523. } else if (style.externalGraphic) {
  4524. if (style.graphicTitle) {
  4525. node.setAttributeNS(null, "title", style.graphicTitle);
  4526. //Standards-conformant SVG
  4527. // Prevent duplicate nodes. See issue https://github.com/openlayers/openlayers/issues/92
  4528. var titleNode = node.getElementsByTagName("title");
  4529. if (titleNode.length > 0) {
  4530. titleNode[0].firstChild.textContent = style.graphicTitle;
  4531. } else {
  4532. var label = this.nodeFactory(null, "title");
  4533. label.textContent = style.graphicTitle;
  4534. node.appendChild(label);
  4535. }
  4536. }
  4537. if (style.graphicWidth && style.graphicHeight) {
  4538. node.setAttributeNS(null, "preserveAspectRatio", "none");
  4539. }
  4540. var width = style.graphicWidth || style.graphicHeight;
  4541. var height = style.graphicHeight || style.graphicWidth;
  4542. width = width ? width : style.pointRadius*2;
  4543. height = height ? height : style.pointRadius*2;
  4544. width *= resolution;
  4545. height *= resolution;
  4546. var xOffset = (style.graphicXOffset != undefined) ?
  4547. style.graphicXOffset * resolution : -(0.5 * width);
  4548. var yOffset = (style.graphicYOffset != undefined) ?
  4549. style.graphicYOffset * resolution : -(0.5 * height);
  4550. var opacity = style.graphicOpacity || style.fillOpacity;
  4551. node.setAttributeNS(null, "x", node._x + xOffset);
  4552. node.setAttributeNS(null, "y", node._y + yOffset);
  4553. node.setAttributeNS(null, "width", width);
  4554. node.setAttributeNS(null, "height", height);
  4555. node.setAttributeNS(this.xlinkns, "href", style.externalGraphic);
  4556. node.setAttributeNS(null, "style", "opacity: "+opacity);
  4557. node.onclick = OpenLayers.Renderer.SVG2.preventDefault;
  4558. } else if (this.isComplexSymbol(style.graphicName)) {
  4559. // the symbol viewBox is three times as large as the symbol
  4560. var offset = style.pointRadius * 3 * resolution;
  4561. var size = offset * 2;
  4562. var src = this.importSymbol(style.graphicName);
  4563. widthFactor = this.symbolMetrics[src.id].size * 3 / size * resolution;
  4564. // remove the node from the dom before we modify it. This
  4565. // prevents various rendering issues in Safari and FF
  4566. var parent = node.parentNode;
  4567. var nextSibling = node.nextSibling;
  4568. if(parent) {
  4569. parent.removeChild(node);
  4570. }
  4571. // The more appropriate way to implement this would be use/defs,
  4572. // but due to various issues in several browsers, it is safer to
  4573. // copy the symbols instead of referencing them.
  4574. // See e.g. ticket http://trac.osgeo.org/openlayers/ticket/2985
  4575. // and this email thread
  4576. // http://osgeo-org.1803224.n2.nabble.com/Select-Control-Ctrl-click-on-Feature-with-a-graphicName-opens-new-browser-window-tc5846039.html
  4577. node.firstChild && node.removeChild(node.firstChild);
  4578. node.appendChild(src.firstChild.cloneNode(true));
  4579. node.setAttributeNS(null, "viewBox", src.getAttributeNS(null, "viewBox"));
  4580. node.setAttributeNS(null, "width", size);
  4581. node.setAttributeNS(null, "height", size);
  4582. node.setAttributeNS(null, "x", node._x - offset);
  4583. node.setAttributeNS(null, "y", node._y - offset);
  4584. // now that the node has all its new properties, insert it
  4585. // back into the dom where it was
  4586. if(nextSibling) {
  4587. parent.insertBefore(node, nextSibling);
  4588. } else if(parent) {
  4589. parent.appendChild(node);
  4590. }
  4591. } else {
  4592. node.setAttributeNS(null, "r", style.pointRadius * resolution);
  4593. }
  4594. var rotation = style.rotation;
  4595. if (rotation !== undefined || node._rotation !== undefined) {
  4596. node._rotation = rotation;
  4597. rotation |= 0;
  4598. if (node.nodeName !== "svg") {
  4599. node.setAttributeNS(null, "transform",
  4600. ["rotate(", rotation, node._x, node._y, ")"].join(" ")
  4601. );
  4602. } else {
  4603. var metrics = this.symbolMetrics[src.id];
  4604. node.firstChild.setAttributeNS(null, "transform",
  4605. ["rotate(", rotation, metrics.x, metrics.y, ")"].join(" ")
  4606. );
  4607. }
  4608. }
  4609. }
  4610. if (options.isFilled) {
  4611. node.setAttributeNS(null, "fill", style.fillColor);
  4612. node.setAttributeNS(null, "fill-opacity", style.fillOpacity);
  4613. } else {
  4614. node.setAttributeNS(null, "fill", "none");
  4615. }
  4616. if (options.isStroked) {
  4617. node.setAttributeNS(null, "stroke", style.strokeColor);
  4618. node.setAttributeNS(null, "stroke-opacity", style.strokeOpacity);
  4619. node.setAttributeNS(null, "stroke-width", style.strokeWidth * widthFactor);
  4620. node.setAttributeNS(null, "stroke-linecap", style.strokeLinecap || "round");
  4621. // Hard-coded linejoin for now, to make it look the same as in VML.
  4622. // There is no strokeLinejoin property yet for symbolizers.
  4623. node.setAttributeNS(null, "stroke-linejoin", "round");
  4624. style.strokeDashstyle && node.setAttributeNS(null,
  4625. "stroke-dasharray", this.dashStyle(style, widthFactor));
  4626. } else {
  4627. node.setAttributeNS(null, "stroke", "none");
  4628. }
  4629. if (style.pointerEvents) {
  4630. node.setAttributeNS(null, "pointer-events", style.pointerEvents);
  4631. }
  4632. if (style.cursor != null) {
  4633. node.setAttributeNS(null, "cursor", style.cursor);
  4634. }
  4635. return node;
  4636. },
  4637. /**
  4638. * Method: dashStyle
  4639. *
  4640. * Parameters:
  4641. * style - {Object}
  4642. * widthFactor - {Number}
  4643. *
  4644. * Returns:
  4645. * {String} A SVG compliant 'stroke-dasharray' value
  4646. */
  4647. dashStyle: function(style, widthFactor) {
  4648. var w = style.strokeWidth * widthFactor;
  4649. var str = style.strokeDashstyle;
  4650. switch (str) {
  4651. case 'solid':
  4652. return 'none';
  4653. case 'dot':
  4654. return [widthFactor, 4 * w].join();
  4655. case 'dash':
  4656. return [4 * w, 4 * w].join();
  4657. case 'dashdot':
  4658. return [4 * w, 4 * w, widthFactor, 4 * w].join();
  4659. case 'longdash':
  4660. return [8 * w, 4 * w].join();
  4661. case 'longdashdot':
  4662. return [8 * w, 4 * w, widthFactor, 4 * w].join();
  4663. default:
  4664. var parts = OpenLayers.String.trim(str).split(/\s+/g);
  4665. for (var i=0, ii=parts.length; i<ii; i++) {
  4666. parts[i] = parts[i] * widthFactor;
  4667. }
  4668. return parts.join();
  4669. }
  4670. },
  4671. /**
  4672. * Method: createNode
  4673. *
  4674. * Parameters:
  4675. * type - {String} Kind of node to draw
  4676. * id - {String} Id for node
  4677. *
  4678. * Returns:
  4679. * {DOMElement} A new node of the given type and id
  4680. */
  4681. createNode: function(type, id) {
  4682. var node = document.createElementNS(this.xmlns, type);
  4683. if (id) {
  4684. node.setAttributeNS(null, "id", id);
  4685. }
  4686. return node;
  4687. },
  4688. /**
  4689. * Method: nodeTypeCompare
  4690. *
  4691. * Parameters:
  4692. * node - {SVGDomElement} An SVG element
  4693. * type - {String} Kind of node
  4694. *
  4695. * Returns:
  4696. * {Boolean} Whether or not the specified node is of the specified type
  4697. */
  4698. nodeTypeCompare: function(node, type) {
  4699. return (type == node.nodeName);
  4700. },
  4701. /**
  4702. * Method: createRenderRoot
  4703. *
  4704. * Returns:
  4705. * {DOMElement} The specific render engine's root element
  4706. */
  4707. createRenderRoot: function() {
  4708. return this.nodeFactory(this.container.id + "_svgRoot", "svg");
  4709. },
  4710. /**
  4711. * Method: createRoot
  4712. *
  4713. * Parameters:
  4714. * suffix - {String} suffix to append to the id
  4715. *
  4716. * Returns:
  4717. * {DOMElement}
  4718. */
  4719. createRoot: function(suffix) {
  4720. return this.nodeFactory(this.container.id + suffix, "g");
  4721. },
  4722. /**
  4723. * Method: createDefs
  4724. *
  4725. * Returns:
  4726. * {DOMElement} The element to which we'll add the symbol definitions
  4727. */
  4728. createDefs: function() {
  4729. var defs = this.nodeFactory(this.container.id + "_defs", "defs");
  4730. this.rendererRoot.appendChild(defs);
  4731. return defs;
  4732. },
  4733. /**************************************
  4734. * *
  4735. * GEOMETRY DRAWING FUNCTIONS *
  4736. * *
  4737. **************************************/
  4738. /**
  4739. * Method: drawPoint
  4740. * This method is only called by the renderer itself.
  4741. *
  4742. * Parameters:
  4743. * node - {DOMElement}
  4744. * geometry - {<OpenLayers.Geometry>}
  4745. *
  4746. * Returns:
  4747. * {DOMElement} or false if the renderer could not draw the point
  4748. */
  4749. drawPoint: function(node, geometry) {
  4750. return this.drawCircle(node, geometry, 1);
  4751. },
  4752. /**
  4753. * Method: drawCircle
  4754. * This method is only called by the renderer itself.
  4755. *
  4756. * Parameters:
  4757. * node - {DOMElement}
  4758. * geometry - {<OpenLayers.Geometry>}
  4759. * radius - {Float}
  4760. *
  4761. * Returns:
  4762. * {DOMElement} or false if the renderer could not draw the circle
  4763. */
  4764. drawCircle: function(node, geometry, radius) {
  4765. var x = geometry.x;
  4766. var y = -geometry.y;
  4767. node.setAttributeNS(null, "cx", x);
  4768. node.setAttributeNS(null, "cy", y);
  4769. node._x = x;
  4770. node._y = y;
  4771. node._radius = radius;
  4772. return node;
  4773. },
  4774. /**
  4775. * Method: drawLineString
  4776. * This method is only called by the renderer itself.
  4777. *
  4778. * Parameters:
  4779. * node - {DOMElement}
  4780. * geometry - {<OpenLayers.Geometry>}
  4781. *
  4782. * Returns:
  4783. * {DOMElement} or null if the renderer could not draw all components of
  4784. * the linestring, or false if nothing could be drawn
  4785. */
  4786. drawLineString: function(node, geometry) {
  4787. var path = this.getComponentsString(geometry.components);
  4788. node.setAttributeNS(null, "points", path);
  4789. return node;
  4790. },
  4791. /**
  4792. * Method: drawLinearRing
  4793. * This method is only called by the renderer itself.
  4794. *
  4795. * Parameters:
  4796. * node - {DOMElement}
  4797. * geometry - {<OpenLayers.Geometry>}
  4798. *
  4799. * Returns:
  4800. * {DOMElement} or null if the renderer could not draw all components
  4801. * of the linear ring, or false if nothing could be drawn
  4802. */
  4803. drawLinearRing: function(node, geometry) {
  4804. var path = this.getComponentsString(geometry.components);
  4805. node.setAttributeNS(null, "points", path);
  4806. return node;
  4807. },
  4808. /**
  4809. * Method: drawPolygon
  4810. * This method is only called by the renderer itself.
  4811. *
  4812. * Parameters:
  4813. * node - {DOMElement}
  4814. * geometry - {<OpenLayers.Geometry>}
  4815. *
  4816. * Returns:
  4817. * {DOMElement} or null if the renderer could not draw all components
  4818. * of the polygon, or false if nothing could be drawn
  4819. */
  4820. drawPolygon: function(node, geometry) {
  4821. var d = [];
  4822. var draw = true;
  4823. var complete = true;
  4824. var linearRingResult, path;
  4825. for (var j=0, len=geometry.components.length; j<len; j++) {
  4826. d.push("M");
  4827. path = this.getComponentsString(
  4828. geometry.components[j].components, " ");
  4829. d.push(path);
  4830. }
  4831. d.push("z");
  4832. node.setAttributeNS(null, "d", d.join(" "));
  4833. node.setAttributeNS(null, "fill-rule", "evenodd");
  4834. return node;
  4835. },
  4836. /**
  4837. * Method: drawRectangle
  4838. * This method is only called by the renderer itself.
  4839. *
  4840. * Parameters:
  4841. * node - {DOMElement}
  4842. * geometry - {<OpenLayers.Geometry>}
  4843. *
  4844. * Returns:
  4845. * {DOMElement} or false if the renderer could not draw the rectangle
  4846. */
  4847. drawRectangle: function(node, geometry) {
  4848. node.setAttributeNS(null, "x", geometry.x);
  4849. node.setAttributeNS(null, "y", -geometry.y);
  4850. node.setAttributeNS(null, "width", geometry.width);
  4851. node.setAttributeNS(null, "height", geometry.height);
  4852. return node;
  4853. },
  4854. /**
  4855. * Method: drawText
  4856. * Function for drawing text labels.
  4857. * This method is only called by the renderer itself.
  4858. *
  4859. * Parameters:
  4860. * featureId - {String|DOMElement}
  4861. * style - {Object}
  4862. * location - {<OpenLayers.Geometry.Point>}, will be modified inline
  4863. *
  4864. * Returns:
  4865. * {DOMElement} container holding the text label
  4866. */
  4867. drawText: function(featureId, style, location) {
  4868. var g = OpenLayers.Renderer.NG.prototype.drawText.apply(this, arguments);
  4869. var text = g.firstChild ||
  4870. this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_text", "text");
  4871. var res = this.getResolution();
  4872. text.setAttributeNS(null, "x", location.x / res);
  4873. text.setAttributeNS(null, "y", - location.y / res);
  4874. g.setAttributeNS(null, "transform", "scale(" + res + ")");
  4875. if (style.fontColor) {
  4876. text.setAttributeNS(null, "fill", style.fontColor);
  4877. }
  4878. if (style.fontOpacity) {
  4879. text.setAttributeNS(null, "opacity", style.fontOpacity);
  4880. }
  4881. if (style.fontFamily) {
  4882. text.setAttributeNS(null, "font-family", style.fontFamily);
  4883. }
  4884. if (style.fontSize) {
  4885. text.setAttributeNS(null, "font-size", style.fontSize);
  4886. }
  4887. if (style.fontWeight) {
  4888. text.setAttributeNS(null, "font-weight", style.fontWeight);
  4889. }
  4890. if (style.fontStyle) {
  4891. text.setAttributeNS(null, "font-style", style.fontStyle);
  4892. }
  4893. if (style.labelSelect === true) {
  4894. text.setAttributeNS(null, "pointer-events", "visible");
  4895. text._featureId = featureId;
  4896. } else {
  4897. text.setAttributeNS(null, "pointer-events", "none");
  4898. }
  4899. var align = style.labelAlign || OpenLayers.Renderer.defaultSymbolizer.labelAlign;
  4900. text.setAttributeNS(null, "text-anchor",
  4901. OpenLayers.Renderer.SVG2.LABEL_ALIGN[align[0]] || "middle");
  4902. if (OpenLayers.IS_GECKO === true) {
  4903. text.setAttributeNS(null, "dominant-baseline",
  4904. OpenLayers.Renderer.SVG2.LABEL_ALIGN[align[1]] || "central");
  4905. }
  4906. var labelRows = style.label.split('\n');
  4907. var numRows = labelRows.length;
  4908. while (text.childNodes.length > numRows) {
  4909. text.removeChild(text.lastChild);
  4910. }
  4911. for (var i = 0; i < numRows; i++) {
  4912. var tspan = text.childNodes[i] ||
  4913. this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan_" + i, "tspan");
  4914. if (style.labelSelect === true) {
  4915. tspan._featureId = featureId;
  4916. }
  4917. if (OpenLayers.IS_GECKO === false) {
  4918. tspan.setAttributeNS(null, "baseline-shift",
  4919. OpenLayers.Renderer.SVG2.LABEL_VSHIFT[align[1]] || "-35%");
  4920. }
  4921. tspan.setAttribute("x", location.x / res);
  4922. if (i == 0) {
  4923. var vfactor = OpenLayers.Renderer.SVG2.LABEL_VFACTOR[align[1]];
  4924. if (vfactor == null) {
  4925. vfactor = -.5;
  4926. }
  4927. tspan.setAttribute("dy", (vfactor*(numRows-1)) + "em");
  4928. } else {
  4929. tspan.setAttribute("dy", "1em");
  4930. }
  4931. tspan.textContent = (labelRows[i] === '') ? ' ' : labelRows[i];
  4932. if (!tspan.parentNode) {
  4933. text.appendChild(tspan);
  4934. }
  4935. }
  4936. if (!text.parentNode) {
  4937. g.appendChild(text);
  4938. }
  4939. return g;
  4940. },
  4941. /**
  4942. * Method: getComponentString
  4943. *
  4944. * Parameters:
  4945. * components - {Array(<OpenLayers.Geometry.Point>)} Array of points
  4946. * separator - {String} character between coordinate pairs. Defaults to ","
  4947. *
  4948. * Returns:
  4949. * {Object} hash with properties "path" (the string created from the
  4950. * components and "complete" (false if the renderer was unable to
  4951. * draw all components)
  4952. */
  4953. getComponentsString: function(components, separator) {
  4954. var len = components.length;
  4955. var strings = new Array(len);
  4956. for (var i=0; i<len; i++) {
  4957. strings[i] = this.getShortString(components[i]);
  4958. }
  4959. return strings.join(separator || ",");
  4960. },
  4961. /**
  4962. * Method: getShortString
  4963. *
  4964. * Parameters:
  4965. * point - {<OpenLayers.Geometry.Point>}
  4966. *
  4967. * Returns:
  4968. * {String} or false if point is outside the valid range
  4969. */
  4970. getShortString: function(point) {
  4971. return point.x + "," + (-point.y);
  4972. },
  4973. /**
  4974. * Method: importSymbol
  4975. * add a new symbol definition from the rendererer's symbol hash
  4976. *
  4977. * Parameters:
  4978. * graphicName - {String} name of the symbol to import
  4979. *
  4980. * Returns:
  4981. * {DOMElement} - the imported symbol
  4982. */
  4983. importSymbol: function (graphicName) {
  4984. if (!this.defs) {
  4985. // create svg defs tag
  4986. this.defs = this.createDefs();
  4987. }
  4988. var id = this.container.id + "-" + graphicName;
  4989. // check if symbol already exists in the defs
  4990. var existing = document.getElementById(id);
  4991. if (existing != null) {
  4992. return existing;
  4993. }
  4994. var symbol = OpenLayers.Renderer.symbol[graphicName];
  4995. if (!symbol) {
  4996. throw new Error(graphicName + ' is not a valid symbol name');
  4997. }
  4998. var symbolNode = this.nodeFactory(id, "symbol");
  4999. var node = this.nodeFactory(null, "polygon");
  5000. symbolNode.appendChild(node);
  5001. var symbolExtent = new OpenLayers.Bounds(
  5002. Number.MAX_VALUE, Number.MAX_VALUE, 0, 0);
  5003. var points = [];
  5004. var x,y;
  5005. for (var i=0, len=symbol.length; i<len; i=i+2) {
  5006. x = symbol[i];
  5007. y = symbol[i+1];
  5008. symbolExtent.left = Math.min(symbolExtent.left, x);
  5009. symbolExtent.bottom = Math.min(symbolExtent.bottom, y);
  5010. symbolExtent.right = Math.max(symbolExtent.right, x);
  5011. symbolExtent.top = Math.max(symbolExtent.top, y);
  5012. points.push(x, ",", y);
  5013. }
  5014. node.setAttributeNS(null, "points", points.join(" "));
  5015. var width = symbolExtent.getWidth();
  5016. var height = symbolExtent.getHeight();
  5017. // create a viewBox three times as large as the symbol itself,
  5018. // to allow for strokeWidth being displayed correctly at the corners.
  5019. var viewBox = [symbolExtent.left - width,
  5020. symbolExtent.bottom - height, width * 3, height * 3];
  5021. symbolNode.setAttributeNS(null, "viewBox", viewBox.join(" "));
  5022. this.symbolMetrics[id] = {
  5023. size: Math.max(width, height),
  5024. x: symbolExtent.getCenterLonLat().lon,
  5025. y: symbolExtent.getCenterLonLat().lat
  5026. };
  5027. this.defs.appendChild(symbolNode);
  5028. return symbolNode;
  5029. },
  5030. /**
  5031. * Method: getFeatureIdFromEvent
  5032. *
  5033. * Parameters:
  5034. * evt - {Object} An <OpenLayers.Event> object
  5035. *
  5036. * Returns:
  5037. * {String} A feature id or undefined.
  5038. */
  5039. getFeatureIdFromEvent: function(evt) {
  5040. var featureId = OpenLayers.Renderer.Elements.prototype.getFeatureIdFromEvent.apply(this, arguments);
  5041. if(!featureId) {
  5042. var target = evt.target;
  5043. featureId = target.parentNode && target != this.rendererRoot ?
  5044. target.parentNode._featureId : undefined;
  5045. }
  5046. return featureId;
  5047. },
  5048. CLASS_NAME: "OpenLayers.Renderer.SVG2"
  5049. });
  5050. /**
  5051. * Constant: OpenLayers.Renderer.SVG2.LABEL_ALIGN
  5052. * {Object}
  5053. */
  5054. OpenLayers.Renderer.SVG2.LABEL_ALIGN = {
  5055. "l": "start",
  5056. "r": "end",
  5057. "b": "bottom",
  5058. "t": "hanging"
  5059. };
  5060. /**
  5061. * Constant: OpenLayers.Renderer.SVG2.LABEL_VSHIFT
  5062. * {Object}
  5063. */
  5064. OpenLayers.Renderer.SVG2.LABEL_VSHIFT = {
  5065. // according to
  5066. // http://www.w3.org/Graphics/SVG/Test/20061213/htmlObjectHarness/full-text-align-02-b.html
  5067. // a baseline-shift of -70% shifts the text exactly from the
  5068. // bottom to the top of the baseline, so -35% moves the text to
  5069. // the center of the baseline.
  5070. "t": "-70%",
  5071. "b": "0"
  5072. };
  5073. /**
  5074. * Constant: OpenLayers.Renderer.SVG2.LABEL_VFACTOR
  5075. * {Object}
  5076. */
  5077. OpenLayers.Renderer.SVG2.LABEL_VFACTOR = {
  5078. "t": 0,
  5079. "b": -1
  5080. };
  5081. /**
  5082. * Function: OpenLayers.Renderer.SVG2.preventDefault
  5083. * Used to prevent default events (especially opening images in a new tab on
  5084. * ctrl-click) from being executed for externalGraphic and graphicName symbols
  5085. */
  5086. OpenLayers.Renderer.SVG2.preventDefault = function(e) {
  5087. e.preventDefault && e.preventDefault();
  5088. };
  5089. /**
  5090. * Class: OpenLayers.Popup.AnchoredBubble
  5091. * This class is *deprecated*. Use {<OpenLayers.Popup.Anchored>} and
  5092. * round corners using CSS3's border-radius property.
  5093. *
  5094. * Inherits from:
  5095. * - <OpenLayers.Popup.Anchored>
  5096. */
  5097. OpenLayers.Popup.AnchoredBubble = OpenLayers.Class(OpenLayers.Popup.Anchored, {
  5098. /**
  5099. * Property: rounded
  5100. * {Boolean} Has the popup been rounded yet?
  5101. */
  5102. rounded: false,
  5103. /**
  5104. * Constructor: OpenLayers.Popup.AnchoredBubble
  5105. *
  5106. * Parameters:
  5107. * id - {String}
  5108. * lonlat - {<OpenLayers.LonLat>}
  5109. * contentSize - {<OpenLayers.Size>}
  5110. * contentHTML - {String}
  5111. * anchor - {Object} Object to which we'll anchor the popup. Must expose
  5112. * a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>)
  5113. * (Note that this is generally an <OpenLayers.Icon>).
  5114. * closeBox - {Boolean}
  5115. * closeBoxCallback - {Function} Function to be called on closeBox click.
  5116. */
  5117. initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox,
  5118. closeBoxCallback) {
  5119. this.padding = new OpenLayers.Bounds(
  5120. 0, OpenLayers.Popup.AnchoredBubble.CORNER_SIZE,
  5121. 0, OpenLayers.Popup.AnchoredBubble.CORNER_SIZE
  5122. );
  5123. OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments);
  5124. },
  5125. /**
  5126. * Method: draw
  5127. *
  5128. * Parameters:
  5129. * px - {<OpenLayers.Pixel>}
  5130. *
  5131. * Returns:
  5132. * {DOMElement} Reference to a div that contains the drawn popup.
  5133. */
  5134. draw: function(px) {
  5135. OpenLayers.Popup.Anchored.prototype.draw.apply(this, arguments);
  5136. this.setContentHTML();
  5137. //set the popup color and opacity
  5138. this.setBackgroundColor();
  5139. this.setOpacity();
  5140. return this.div;
  5141. },
  5142. /**
  5143. * Method: updateRelativePosition
  5144. * The popup has been moved to a new relative location, in which case
  5145. * we will want to re-do the rico corners.
  5146. */
  5147. updateRelativePosition: function() {
  5148. this.setRicoCorners();
  5149. },
  5150. /**
  5151. * APIMethod: setSize
  5152. *
  5153. * Parameters:
  5154. * contentSize - {<OpenLayers.Size>} the new size for the popup's
  5155. * contents div (in pixels).
  5156. */
  5157. setSize:function(contentSize) {
  5158. OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments);
  5159. this.setRicoCorners();
  5160. },
  5161. /**
  5162. * APIMethod: setBackgroundColor
  5163. *
  5164. * Parameters:
  5165. * color - {String}
  5166. */
  5167. setBackgroundColor:function(color) {
  5168. if (color != undefined) {
  5169. this.backgroundColor = color;
  5170. }
  5171. if (this.div != null) {
  5172. if (this.contentDiv != null) {
  5173. this.div.style.background = "transparent";
  5174. OpenLayers.Rico.Corner.changeColor(this.groupDiv,
  5175. this.backgroundColor);
  5176. }
  5177. }
  5178. },
  5179. /**
  5180. * APIMethod: setOpacity
  5181. *
  5182. * Parameters:
  5183. * opacity - {float}
  5184. */
  5185. setOpacity:function(opacity) {
  5186. OpenLayers.Popup.Anchored.prototype.setOpacity.call(this, opacity);
  5187. if (this.div != null) {
  5188. if (this.groupDiv != null) {
  5189. OpenLayers.Rico.Corner.changeOpacity(this.groupDiv,
  5190. this.opacity);
  5191. }
  5192. }
  5193. },
  5194. /**
  5195. * Method: setBorder
  5196. * Always sets border to 0. Bubble Popups can not have a border.
  5197. *
  5198. * Parameters:
  5199. * border - {Integer}
  5200. */
  5201. setBorder:function(border) {
  5202. this.border = 0;
  5203. },
  5204. /**
  5205. * Method: setRicoCorners
  5206. * Update RICO corners according to the popup's current relative postion.
  5207. */
  5208. setRicoCorners:function() {
  5209. var corners = this.getCornersToRound(this.relativePosition);
  5210. var options = {corners: corners,
  5211. color: this.backgroundColor,
  5212. bgColor: "transparent",
  5213. blend: false};
  5214. if (!this.rounded) {
  5215. OpenLayers.Rico.Corner.round(this.div, options);
  5216. this.rounded = true;
  5217. } else {
  5218. OpenLayers.Rico.Corner.reRound(this.groupDiv, options);
  5219. //set the popup color and opacity
  5220. this.setBackgroundColor();
  5221. this.setOpacity();
  5222. }
  5223. },
  5224. /**
  5225. * Method: getCornersToRound
  5226. *
  5227. * Returns:
  5228. * {String} The proper corners string ("tr tl bl br") for rico to round.
  5229. */
  5230. getCornersToRound:function() {
  5231. var corners = ['tl', 'tr', 'bl', 'br'];
  5232. //we want to round all the corners _except_ the opposite one.
  5233. var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition);
  5234. OpenLayers.Util.removeItem(corners, corner);
  5235. return corners.join(" ");
  5236. },
  5237. CLASS_NAME: "OpenLayers.Popup.AnchoredBubble"
  5238. });
  5239. /**
  5240. * Constant: CORNER_SIZE
  5241. * {Integer} 5. Border space for the RICO corners.
  5242. */
  5243. OpenLayers.Popup.AnchoredBubble.CORNER_SIZE = 5;