资源描述:
《OpenLayers Tutorial - Part 3 - Controls》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、OpenLayersTutorial-Part3-ControlsPostedonSunday,May022010in openlayersControlsallowinteractionwithOpenLayermaps.Panning,zooming,switchinglayers,etc,areallhandledviacontrols.Somecontrols,suchasdraggingthemaparoundtopanit,whileothers,liketheoverviewmap,dohaveavisualappearance. Therearecaseswhereyo
2、umightnotwantanycontrols-thesecasesareactuallyfairlycommon;forinstance,ifyouwantedtoshowasmallsectionofamap,mimicastaticimage,allowonlyloggedinuserstonavigatearoundthemap,etc.thenyoumightwanttohavenocontrolsonyourmap. Thistutorialisbrokendownandaimstoteachyouhowtodothefollowing: 1.AddingControls
3、 2.CustomizingControls-Passingpropertiesandcustomizingcontrolappearances 3.AddingControls/PanelsOutsideoftheMap>We'llshowhowtocreateamapwithoutcontrolsshortly,butwhatkindofstuffcanwedowithcontrols?Therearemanymoreexampleson OpenLayer.org'sExamplespage,simplysearchfor"control"togetanideaofwhatvar
4、ioustypesofcontrolsthereare.Therearelotsofsimpleones,rangingfromscalebarstofullvectorlayermanipulations. Whiletherearetoomanycontrolstocoverindepthhereinthispost,I'llbefocusingonafewdifferentcontrolsthroughoutthistutorialtoexemplifyhowflexibleOpenLayersisandgiveyouanideaofwhatcanbedone.AddingCon
5、trolsMostcontrolsthatare'visible'(e.g.thelayerswitchercontrol)canbeplacedeitherinsideoroutsideofthemap.The'invisible'controls,suchthecontrolthatallowsyoutonavigatethemapwhenyoudragthemapwithyourmouse,areeithertherearetheyaren't-sowecan'treally'place'themoutsidethemap.Placingcontrolsinsidethemapi
6、sthedefaultbehaviorandisabitsimplerthanplacingitoutside(althoughbothareeasyonceyouknowhow),sowe'llcoverthatfirst. Addingcontrolstoamapcanbedonein two differentways. 1. Whenthemapiscreated,itcanacceptanarrayofOpenLayers.Controlobjectstobepassedinwhencreatingthemapobject,andcontrolscanbeaddedtothe
7、mapafterithasbeencreated.Ifnoarrayofcontrolobjectsarepassedin,(likewe'vebeendoinginpriortutorials)OpenLayerscreatesthemapwithvariousdefaultcontrols.Thebasicformat(psuedocodefollows)is:controls:[OpenLayers.Control,OpenLayers.