?? frminfo.vb
字號(hào):
'---------------------------------------------------------------------
Public Class ItemInfo
Public szName As String
Public szType As String
Public szSubType As String
Public szTable As String
Public szFieldName As String
Public rst As MapObjects2.Recordset
Public layer As MapObjects2.MapLayer
End Class
'---------------------------------------------------------------------
Public Class frmInfo
Inherits System.Windows.Forms.Form
Private frmMain As MainForm
Private _itmInfos As ItemInfo()
Private _nIdx As Integer
#Region " Windows Form Designer generated code "
Public Sub New(ByVal frmMainTemp As MainForm)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
frmMain = frmMainTemp
FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents _label_layer As System.Windows.Forms.Label
Friend WithEvents _listBox1 As System.Windows.Forms.ListBox
Friend WithEvents _label1 As System.Windows.Forms.Label
Friend WithEvents _comboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me._label_layer = New System.Windows.Forms.Label()
Me._listBox1 = New System.Windows.Forms.ListBox()
Me._label1 = New System.Windows.Forms.Label()
Me._comboBox1 = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'_label_layer
'
Me._label_layer.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left)
Me._label_layer.Location = New System.Drawing.Point(8, 254)
Me._label_layer.Name = "_label_layer"
Me._label_layer.Size = New System.Drawing.Size(168, 24)
Me._label_layer.TabIndex = 13
Me._label_layer.Text = "圖層名:"
'
'_listBox1
'
Me._listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me._listBox1.ItemHeight = 12
Me._listBox1.Location = New System.Drawing.Point(8, 62)
Me._listBox1.Name = "_listBox1"
Me._listBox1.SelectionMode = System.Windows.Forms.SelectionMode.None
Me._listBox1.Size = New System.Drawing.Size(168, 184)
Me._listBox1.TabIndex = 12
'
'_label1
'
Me._label1.Location = New System.Drawing.Point(15, 14)
Me._label1.Name = "_label1"
Me._label1.Size = New System.Drawing.Size(160, 16)
Me._label1.TabIndex = 11
'
'_comboBox1
'
Me._comboBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me._comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me._comboBox1.Location = New System.Drawing.Point(12, 30)
Me._comboBox1.Name = "_comboBox1"
Me._comboBox1.Size = New System.Drawing.Size(164, 20)
Me._comboBox1.TabIndex = 10
'
'frmInfo
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(184, 293)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me._label_layer, Me._listBox1, Me._label1, Me._comboBox1})
Me.Name = "frmInfo"
Me.Text = "地物詳細(xì)信息"
Me.ResumeLayout(False)
End Sub
#End Region
'---------------------------------------------------------------------
' 功能:確定指定位置的地物
' 參數(shù):[in]long x 鼠標(biāo)位置的X值(像素坐標(biāo))
' [in]long y 鼠標(biāo)位置的Y值(像素坐標(biāo))
' 返回值:void
Public Sub Identify(ByVal x As Integer, ByVal y As Integer)
Dim env As CEnvironment = frmMain._environment
env.ClearSelRsts()
Dim nFeatCount As Integer = 0 ' 選中地物的數(shù)目
Dim pt As MapObjects2.Point ' 鼠標(biāo)的位置(地圖坐標(biāo))
pt = frmMain.Map.ToMapPoint(x, y) ' 將屏幕坐標(biāo)的點(diǎn)轉(zhuǎn)換為地圖坐標(biāo)的點(diǎn)
_nIdx = -1
' 初始化控件
_comboBox1.Items.Clear() ' 清空組合框
_listBox1.Items.Clear() ' 清空列表框
ReDim _itmInfos(env.m_nLayerNum - 1) ' 根據(jù)圖層數(shù)目重新設(shè)置數(shù)組大小
' 動(dòng)態(tài)計(jì)算查詢距離
Dim dScale As Double = env.CalcScale(frmMain.Map) ' 地圖比例尺
If dScale > 8000 Then
dScale = dScale / 10000
dScale = dScale / 5000
Else
dScale = dScale / 10000
dScale = dScale / 2500
End If
' 首先,查詢點(diǎn)地物,其次,查詢線地物,最后查詢面狀地物
' 查詢的圖層只要是可見的
Dim aShapeType(2) As MapObjects2.ShapeTypeConstants
aShapeType(0) = MapObjects2.ShapeTypeConstants.moShapeTypePoint
aShapeType(1) = MapObjects2.ShapeTypeConstants.moShapeTypeLine
aShapeType(2) = MapObjects2.ShapeTypeConstants.moShapeTypePolygon
Dim i, j As Integer
For j = 0 To 2
For i = 0 To env.m_nLayerNum - 1
_itmInfos(i) = New ItemInfo()
If env.m_layerInfos(i).layer.shapeType <> aShapeType(j) Then
GoTo InnerRepetition
End If
_itmInfos(i).szName = ""
' 圖層可見并且可選擇,才能夠identify
If env.m_layerInfos(i).layer.Visible = True And env.m_layerInfos(i).bCanSelected = True Then
_itmInfos(i).rst = env.m_layerInfos(i).layer.SearchByDistance(pt, dScale, "")
Else
' 圖層不可顯示,則跳到下一個(gè)
_itmInfos(i).rst = Nothing
GoTo InnerRepetition
End If
_itmInfos(i).szTable = env.m_layerInfos(i).szTableName
_itmInfos(i).layer = env.m_layerInfos(i).layer
_itmInfos(i).szType = env.m_layerInfos(i).szType
_itmInfos(i).szSubType = env.m_layerInfos(i).szSubType
_itmInfos(i).szFieldName = env.m_layerInfos(i).szFieldName
If Not _itmInfos(i).rst Is Nothing Then
If _itmInfos(i).rst.EOF = False Then
If Not _itmInfos(i).rst.Fields._Item("名稱").Value Is System.DBNull.Value Then
_itmInfos(i).szName = _itmInfos(i).rst.Fields._Item("名稱").Value.ToString()
Else
_itmInfos(i).rst = Nothing
GoTo InnerRepetition
End If
If _itmInfos(i).szName <> "" Then
_comboBox1.Items.Add(_itmInfos(i).szName)
nFeatCount = nFeatCount + 1
End If
End If
End If
InnerRepetition:
Next
Next
If nFeatCount > 0 Then
_label1.Text = "總共找到" + nFeatCount.ToString() + "個(gè)地名"
_comboBox1.SelectedIndex = 0
_nIdx = 0
LoadListBox(GetIndex(_comboBox1.Items(0).ToString()))
Else
_label1.Text = "沒有找到任何地名"
_label_layer.Text = "類型:沒有"
env.m_selectedSymbol = Nothing
env.m_selectedFeature = Nothing
End If
End Sub
'---------------------------------------------------------------------
' 功能:顯示地名的詳細(xì)信息
Private Sub LoadListBox(ByVal nIndex As Integer)
If _itmInfos(nIndex).szName = "" Then
Return
End If
_listBox1.Items.Clear()
_label_layer.Text = "類型:" + _itmInfos(nIndex).szSubType
If _itmInfos(nIndex).szTable = "" Then
_listBox1.Items.Add("沒有詳細(xì)信息")
GoTo FLASH
Else
Dim strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + frmMain._environment.m_szDBName + ";Persist Security Info=False"
Dim myConnection As New System.Data.OleDb.OleDbConnection(strConnectionString)
myConnection.Open()
Dim DataSet As New System.Data.DataSet("臨時(shí)庫")
Dim myDataAdapter As System.Data.OleDb.OleDbDataAdapter
Dim szSQL As String
szSQL = "Select * From [" + _itmInfos(nIndex).szTable + "] Where " + _itmInfos(nIndex).szFieldName + " ='" + _itmInfos(nIndex).szName + "'"
myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(szSQL, myConnection)
Try
myDataAdapter.Fill(DataSet, "地名")
Catch
GoTo FLASH
End Try
Dim indexTbl As System.Data.DataTable = DataSet.Tables("地名")
Dim rowsType As System.Data.DataRow() = indexTbl.Select()
If rowsType.Length = 0 Then
_listBox1.Items.Add("沒有詳細(xì)信息")
GoTo FLASH
End If
Dim i As Integer
For i = 0 To indexTbl.Columns.Count - 1
Dim szValue As String = indexTbl.Columns(i).ColumnName + ":" + rowsType(0)(i).ToString()
_listBox1.Items.Add(szValue)
Next
End If
FLASH:
frmMain.Map.FlashShape(_itmInfos(nIndex).rst.Fields.Item("Shape").Value, 4)
'設(shè)置選中地物的符號(hào)
If frmMain._environment.m_layerInfos(nIndex).nCharacterIndex >= 0 And frmMain._environment.m_layerInfos(nIndex).layer.shapeType = MapObjects2.ShapeTypeConstants.moShapeTypePoint Then
frmMain._environment.m_selectedSymbol = New MapObjects2.Symbol()
frmMain._environment.m_selectedSymbol.SymbolType = MapObjects2.SymbolTypeConstants.moPointSymbol
frmMain._environment.m_selectedSymbol.Font.Name = frmMain._environment.m_layerInfos(nIndex).szFontName
frmMain._environment.m_selectedSymbol.Style = 4
frmMain._environment.m_selectedSymbol.Size = frmMain._environment.m_layerInfos(nIndex).layer.Symbol.Size
frmMain._environment.m_selectedSymbol.CharacterIndex = frmMain._environment.m_layerInfos(nIndex).nCharacterIndex
frmMain._environment.m_selectedSymbol.Color = System.Convert.ToUInt32(MapObjects2.ColorConstants.moRed)
frmMain._environment.m_selectedSymbolSize = frmMain._environment.m_layerInfos(nIndex).nSymSize
Else
If frmMain._environment.m_layerInfos(nIndex).layer.shapeType = MapObjects2.ShapeTypeConstants.moShapeTypePoint Then
frmMain._environment.m_selectedSymbol = New MapObjects2.Symbol()
frmMain._environment.m_selectedSymbol.SymbolType = frmMain._environment.m_layerInfos(nIndex).layer.Symbol.SymbolType
frmMain._environment.m_selectedSymbol.Style = frmMain._environment.m_layerInfos(nIndex).layer.Symbol.Style
frmMain._environment.m_selectedSymbol.Size = frmMain._environment.m_layerInfos(nIndex).layer.Symbol.Size
frmMain._environment.m_selectedSymbol.Color = System.Convert.ToUInt32(MapObjects2.ColorConstants.moRed)
frmMain._environment.m_selectedSymbolSize = frmMain._environment.m_layerInfos(nIndex).nSymSize
Else
frmMain._environment.m_selectedSymbol = Nothing
End If
End If
frmMain._environment.m_selectedFeature = _itmInfos(nIndex).rst.Fields.Item("Shape").Value
frmMain.Map.Extent = frmMain.Map.Extent
End Sub
'---------------------------------------------------------------------
Private Function GetIndex(ByVal szName As String) As Integer
Dim nIndex As Integer = -1
Dim i As Integer
For i = 0 To frmMain._environment.m_nLayerNum - 1
If _itmInfos(i).szName = szName Then
nIndex = i
Return nIndex
End If
Next
Return nIndex
End Function
'---------------------------------------------------------------------
Private Sub frmInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
_label_layer.Text = "圖層名:沒有"
End Sub
'---------------------------------------------------------------------
Private Sub _comboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles _comboBox1.SelectionChangeCommitted
If _nIdx <> _comboBox1.SelectedIndex Then
_nIdx = _comboBox1.SelectedIndex
Else
frmMain.Map.FlashShape(_itmInfos(GetIndex(_comboBox1.Items(_nIdx).ToString())).rst.Fields.Item("Shape").Value, 4)
Return
End If
LoadListBox(GetIndex(_comboBox1.Items(_nIdx).ToString()))
End Sub
'---------------------------------------------------------------------
End Class
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -