GettingStartedwithMOinVBWord文件下载.docx
《GettingStartedwithMOinVBWord文件下载.docx》由会员分享,可在线阅读,更多相关《GettingStartedwithMOinVBWord文件下载.docx(34页珍藏版)》请在冰豆网上搜索。
Use,duplication,anddisclosurebytheU.S.GovernmentaresubjecttorestrictionsassetforthinFAR§
164§
52.227-14AlternateIII(g)(3)(JUN1987),FAR§
52.227-19(JUN1987),DFARS§
252.227-7015(JUN1995)[TechnicalData],and/orDFARS§
252.227-7202(JUN1995)[ComputerSoftware],asapplicable.Contractor/ManufacturerisEnvironmentalSystemsResearchInstitute,Inc.,380NewYorkStreet,Redlands,CA92373-8100USA.
ESRIisaregisteredtrademark,andMapObjects,SpatialDatabaseEngine,SDE,theESRIcorporatelogo,theMapObjectslogo,andGISbyESRIaretrademarksofEnvironmentalSystemsResearchInstitute,Inc.
Thenamesofothercompaniesandproductshereinaretrademarksorregisteredtrademarksoftheirrespectivetrademarkowners.
ContentsIntroduction5
LoadingMapObjects6
Gettinghelp6
Addingamap7
Addingpanandzoomcontrols9
Addingatoolbar11
Creatingafindtool14
Handlingresize16
Displayingmaplayersbasedonscale17
Addingaspatialquerytool18
Statisticalmapping20
Eventtracking21
WorkingwithDataConnectionobjects24
WorkingwithImageLayerobjects25
Congratulations27
GettingStarted
INTHISBOOK
∙LoadingMapObjectsintoVisualBasic
∙Addingsimpledisplaytools
∙Creatingbasicspatialquerytools
∙Displayingmaplayers
∙Trackingevents
∙WorkingwiththeDataConnectionobject
∙Addinganimagelayer
InthisintroductorydocumentyouwilluseMapObjects®
andMicrosoft®
VisualBasic®
tobuildanapplicationthatusesmaps.Alongthewayyouwilllearnhowto:
∙Displayamapwithmultiplelayers.
∙Controlpanningandzooming.
∙Createatoolbarcontrol.
∙Displaymaplayersbasedonscale.
∙Performspatialandlogicalqueries.
∙Drawsimplegraphicsonthemap.
∙Displayfeatureswiththematicrenderers.
∙Dynamicallydisplayreal-timedatawithaneventtrackinglayer.
∙Programmaticallyadddatatoamap.
NoteIfyouacceptedthedefaultswheninstallingMapObjects,thegeographicdatathatthistutorialreferstocanbefoundinC:
\ProgramFiles\ESRI\MapObjects2\Samples\Data\Usa.ThebitmapsyoucanuseareintheSamples\Bitmapsfolder.
LoadingMapObjects
StartVisualBasicandselectNewprojectfromthedialogbox.Nowright-clickonthetoolbox(theleft-hand-sidetoolbar)andchooseAdditionalControls.
Tip:
youcanalsoaddcontrolsbyselectingComponentsfromtheProjectmenu,orbypressingCTRL+T.
Find‘ESRIMapObjects2.2’inthelistofavailablecontrols,andchecktheboxbesideit.ClickOKtoclosethedialog.NoticethatanewtoolappearsintheVisualBasicToolbox.ThisnewtoolistheMapObjectsversion2.2Mapcontrol.
MapObjects
MapControl
Gettinghelp
TheMapcontrolisoneofover45objectsthatmakeupMapObjects.Tofindoutaboutthevariousobjects,clicktheObjectBrowserbuttonintheVisualBasictoolbar.
Pulldownthe“Libraries”combobox,andchooseMapObjects2.
MapObjectsobjectsandconstantsarelistedintheClassesbottomleft-handlist.
Toseethepropertiesandmethodsforanobject,clickontheobjectinthelist.ThepropertiesandmethodsofthatobjectarelistedintheMemberslisttotheright.
Toseethesignatureofamethod,clickonthemethodintheright-handlist.ThedetailswillappearinthespaceatthebottomoftheObjectBrowser.
thesimplestwaytogethelpistoselectthemapcontroland
pressF1.
TheMapObjectsonlinehelpsystemisintegratedwiththeVisualBasicObjectBrowser.
1.ClickSymbolintheClasses/Moduleslist.
2.ClickRotationintheMethods/Propertieslist.
3.Clickthehelp(questionmark)button.
Thehelpsystemprovideshelpforeveryobject,property,method,eventandconstantinMapObjects.InadditiontotheObjectBrowser,thehelpsystemisaccessibleformtheVisualBasicCodewindow.Simplytypeinthenameofanobject,property,method,eventorconstant,andpressF1.
Addingamap
TheMapcontrolistheobjectyouusetodisplaymaps.
AddtheMapcontroltotheform
1.Double-clicktheMapcontrolbuttonintheToolboxtoaddanewmaptotheform.
2.Resizethemaptofilltheform.
Selectthedatatodisplayonthemap
YoucanspecifythedatathatisdisplayedinthemapbysettingpropertiesintheMapcontrol’spropertysheet.
1.Right-clickthemouseonthemaptodisplaythecontextmenu.
2.ChoosePropertiestodisplaythepropertysheet.
3.ClicktheAddbuttonandlocatethefoldercontainingtheStatessampledata.IfyouselectedthedefaultswhenyouinstalledMapObjects,thiswillbeinc:
\ProgramFiles\ESRI\MapObjects2\Samples\Data.
4.ClicktheStates.shpfileandthenclickOpen.
5.AddthefileUSHigh.shpinthesamemanner.
Setpropertiesforthelayers
1.ClicktheStateslayerintheLayerslistandthenclickProperties.
2.ClicktheColorbuttontoselectacolorfortheStateslayer.
3.ClickOKtoclosethedialog.
4.SelectacolorfortheUSHighlayerinthesamemanner.
5.ClickOKtoclosethepropertysheet.
Savetheproject
1.ClicktheFilemenuandthenclickSaveProject.
2.Browsetoasuitablefolder,thenintheFileNameboxtypeStarterMap.frm.
3.ClickSave.
4.InthesecondSavedialog,typeStarterMap.vbpintheFileNamebox.
5.ClickSave.
Run
Testyourapplication
1.ClicktheRunbuttonintheVisualBasictoolbar.
Stop
2.Tostoprunningyourapplicationandreturntodesignmode,clicktheStopbuttonintheVisualBasictoolbar.
Addingpanandzoomcontrols
Atthispointyourapplicationcandisplaythemapatitsfullextent.Inthissectionyouwilladdsomesimplepanandzoomcontrolsthatyourapplicationwillactivateinresponsetomouseclicksinsidethemap.YouwillwritesomecodethattheapplicationwillexecuteinresponsetotheMouseDowneventonthemap.
RespondtotheMouseDownevent
1.Double-clickthemaptodisplaytheVisualBasicCodewindow.
2.AddcodetoMap1’sMouseDownprocedure.
PrivateSubMap1_MouseDown(ButtonAsInteger,_ShiftAsInteger,xAsSingle,yAsSingle)
SetMap1.Extent=Map1.TrackRectangle
EndSub
Testyourchange
2.Clickthemapwiththeleftmousebuttonanddragoutarectangle.
3.Releasethemousebuttonandnoticethatthemapisredrawnatthelocationyouspecified.
TrackRectangleisamethodthatappliestoamap.Ittracksthemovementofthemousewhiletheuserpressesthemousebutton,rubber-bandingarectangleatthesametime.Whentheuserreleasesthemousebutton,theTrackRectanglemethodreturnsaRectangleobjectthattheapplicationassignsintotheExtentpropertyofthemap,causingthemaptoberedrawnwithanewmapextent.
4.ClickthestopbuttoninVisualBasictoreturntodesignmode.
Addpanning
1.Double-clickthemaptodisplaytheVisualBasicCodewindowagain.
2.ChangethecodefortheMouseDownevent.
PrivateSubMap1_MouseDown(ButtonAsInteger,_ShiftAsInteger,xAsSingle,yAsSingle)
IfButton=vbLeftButtonThen
ElseifButton=vbRightButtonthen
Map1.Pan
EndIf
IftheButtonparameterisequaltovbLeftButtonwhentheMouseDowneventoccu