📄 frminfo.vb
字号:
'---------------------------------------------------------------------
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 = "地物详细信息"
Me.ResumeLayout(False)
End Sub
#End Region
'---------------------------------------------------------------------
' 功能:确定指定位置的地物
' 参数:[in]long x 鼠标位置的X值(像素坐标)
' [in]long y 鼠标位置的Y值(像素坐标)
' 返回值: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 ' 选中地物的数目
Dim pt As MapObjects2.Point ' 鼠标的位置(地图坐标)
pt = frmMain.Map.ToMapPoint(x, y) ' 将屏幕坐标的点转换为地图坐标的点
_nIdx = -1
' 初始化控件
_comboBox1.Items.Clear() ' 清空组合框
_listBox1.Items.Clear() ' 清空列表框
ReDim _itmInfos(env.m_nLayerNum - 1) ' 根据图层数目重新设置数组大小
' 动态计算查询距离
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
' 首先,查询点地物,其次,查询线地物,最后查询面状地物
' 查询的图层只要是可见的
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
' 图层不可显示,则跳到下一个
_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() + "个地名"
_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
'---------------------------------------------------------------------
' 功能:显示地名的详细信息
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("没有详细信息")
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("临时库")
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("没有详细信息")
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)
'设置选中地物的符号
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -