VB+ArcGis Engine 开发零基础GIS程序框架教程
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VB+ArcGis Engine开发零基础GIS程序框架教程
第一步配置环境和设计界面
环境:ArcGisEngine 9.1 + Microsoft Visual Basic 6.0
使用Engine控件:ESRI ToolbarControl, ESRITOCControl 、ESRILicenseControl、ESRIMapControl。
(按Ctrl+T调出部件面板,选中以下控件)
再从[工程]-[引用]添加一下引用:
界面布局(右侧大的MapcControl命名为MapControl1,为显示地图主界面。左下角的MapcControl命名为MapControl2,作为地图鹰眼。在工具栏里添加如图的几个按钮即可。其它再添加一个CommonDialog1和状态栏):
在ESRI ToccControl和 ESRIToolbarControl属性里绑定控件EsriMapControl (buddy选择MapControl1)。
这样基本界面就布置好了。
第二步加载地图
代码为:
'打开地图文档
On Error Resume Next
Dim sFileName As String
With CommonDialog1
.DialogTitle = "Open Map Document"
.Filter = "Map Documents (*.mxd;*.pmf)|*.mxd;*.pmf"
.ShowOpen
If .FileName = "" Then Exit Sub
sFileName = .FileName
End With
If MapControl1.CheckMxFile(sFileName) Then
MapControl1.LoadMxFile sFileName
MapControl1.Extent = MapControl1.FullExtent
Else
MsgBox sFileName & " is not a valid ArcMap document"
Exit Sub
End If
StatusBar1.Panels(3).Text = sFileName ‘状态栏显示文件路径
第三步让鹰眼地图跟MapControl1的地图互动
1.先在声明里定义几个变量:
'地图鹰眼
Private m_pEnvelope As IEnvelope ' The envelope drawn on the MapControl Private m_pFillSymbol As ISimpleFillSymbol' The symbol used to draw the Private WithEvents m_pTransformEvents AsdisplayTransformation
2.定义如下函数:
Private Sub CreateOverviewSymbol() '设置鹰眼图中的红线框
'Get the IRgbColor interface.
DimpColor As IRgbColor
SetpColor = New RgbColor
'Set the color properties.
pColor.RGB = RGB(255, 0, 0)
'Get the ILine symbol interface.
Dim pOutline As ILineSymbol
SetpOutline = New SimpleLineSymbol
'Set the line symbol properties.
pOutline.Width = 1.5
pOutline.Color = pColor
'Get the IFillSymbol interface.
Setm_pFillSymbol = New SimpleFillSymbol
'Set the fill symbol properties.
m_pFillSymbol.Outline = pOutline
m_pFillSymbol.Style = esriSFSHollow
End Sub
Private Sub MapControl2_OnAfterDraw(ByValdisplay As Variant, ByVal viewDrawPhase As Long)
Ifm_pEnvelope Is Nothing Then Exit Sub
'If the foreground phase has drawn
DimpViewDrawPhase As esriViewDrawPhase
pViewDrawPhase = viewDrawPhase
IfpViewDrawPhase = esriViewForeground Then
'Draw the shape on the MapControl.
MapControl2.DrawShape m_pEnvelope, m_pFillSymbol
EndIf
End Sub
Private Sub m_pTransformEvents_VisibleBoundsUpdated(ByValsender As esriDisplay.IDisplayTransformation, ByVal sizeChanged As Boolean)
'Set the extent to the new visible extent.
Setm_pEnvelope = sender.VisibleBounds
'Refresh the MapControl's foreground phase.
MapControl2.RefreshesriViewForeground
End Sub
3.在Form_Load 事件中调用CreateOverviewSymbol:
Private Sub Form_Load()
Call CreateOverviewSymbol
End Sub
4.在MapControl1的OnMapReplaced中加入以下代码:
Private Sub MapControl1_OnMapReplaced(ByValnewMap As Variant)
'当主地图显示控件的地图改变时,鹰眼中的地图也跟随改变
'Get the IActiveView of the focus map in the PageLayoutControl. DimpActiveView As IActiveView
SetpActiveView = MapControl1.ActiveView.FocusMap
'Trap the ITransformEvents of the PageLayoutControl's focus map. Setm_pTransformEvents =
pActiveView.ScreenDisplay.displayTransformation
'Get the extent of the focus map.
Setm_pEnvelope = pActiveView.Extent
'Load the same preauthored map document into the MapControl. MapControl2.LoadMxFile MapControl1.DocumentFilename
'Set the extent of the MapControl to the full extent of the data. MapControl2.Extent = MapControl2.FullExtent
End Sub
5.当点击鹰眼中的某个地方时,主窗口的地图跟随着改变:
Private Sub MapControl2_OnMouseDown(ByValbutton As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long, ByValmapX As Double, ByVal mapY As Double)
Dim pPt As IPoint
Set pPt = New Point
pPt.PutCoords mapX, mapY
'改变主控件的视图范围
MapControl1.CenterAt pPt
End Sub
这样地图鹰眼就做好了。