?? mapx+vb.txt
字號:
一,查找圖元
mapx查找地圖上的圖元有多種方法
a, FindObj.Search
這種方法在用的時候有局限性:數據集必須要有索引,查找的字段類型不能是10進制類型(可能還有其它的類型,忘了),否則在圖上找不到。
Set FindObj = fMainForm.Map1.Layers(LayerCombo.Text).Find
Set FindObj.FindDataset = fMainForm.Map1.DataSets(LayerCombo.Text & " dataset")
Set FindObj.FindField = FindObj.FindDataset.Fields(FieldCombo.Text)
Set FoundFeature = FindObj.Search(FindText.Text)
If FoundFeature.FindRC Mod 10 = 1 Or FoundFeature.FindRC Mod 10 = 2 Then
fMainForm.Map1.Layers(LayerCombo.Text).Selection.Add FoundFeature
fMainForm.Map1.AutoRedraw = False
fMainForm.Map1.CenterX = FoundFeature.CenterX
fMainForm.Map1.CenterY = FoundFeature.CenterY
End If
b,SQL語句方法
Dim ftrs As MapXLib.Features
Dim lyr As Layer
Dim i As Integer
Set lyr = fMainForm.Map1.Layers(RoadlyrName)
Dim strs As String
strs = Trim("路線編碼 = " + Chr(34) + ComRoadID.List(ComRoadID.ListIndex) + Chr(34))‘在值前面加雙引號如:ID="001", 觀測點名稱 like "%天平莊"
Set ftrs = lyr.Search(strs)
lyr.Selection.ClearSelection
lyr.Selection.Add ftrs
If ftrs.Count > 0 Then
fMainForm.Map1.CenterX = ftrs.Item(1).CenterX
fMainForm.Map1.CenterY = ftrs.Item(1).CenterY
End If
二,顯示鼠標當前的經緯度
Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim MX As Double, MY As Double
Map1.ConvertCoord x, y, MX, MY, 1
Text1.Item(1).Caption = "當前位置"
Text1.Item(2).Caption = "東經 " & Format(MX, "###0.0000") + ",北緯 " + Format(MY, "###0.0000")
Text1.Item(3).Caption = " 當前圖層"
Text1.Item(4).Caption = Map1.Layers(1).Name
End Sub
14自動滾屏
Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If mnuMoveCenter.Checked = True Then
If x > Map1.MapScreenWidth - 10 Then
Map1.CenterX = Map1.CenterX + 0.05
Map1.Refresh
Else
If x < 10 Then
Map1.CenterX = Map1.CenterX - 0.05
Map1.Refresh
Else
If y > Map1.MapScreenHeight - 10 Then
Map1.CenterY = Map1.CenterY - 0.05
Map1.Refresh
Else
If y < 10 Then
Map1.CenterY = Map1.CenterY + 0.05
Map1.Refresh
End If
End If
End If
End If
End If
End Sub
15測距和測面積
Private Sub Form_Load()
Map1.CreateCustomTool PolyRulerToolID, miToolTypePoly, miSizeAllCursor
Map1.CreateCustomTool PolyAreaToolID, miToolTypePolygon, miSelectRegionMinusCursor
End Sub
Private Sub Map1_PolyToolUsed(ByVal ToolNum As Integer, ByVal flags As Long, ByVal Points As Object, ByVal bShift As Boolean, ByVal bCtrl As Boolean, EnableDefault As Boolean)
If ToolNum = PolyRulerToolID Then
Dim i As Integer
Dim DistanceSoFar As Double
Map1.MapUnit = RulerUnit
DistanceSoFar = 0#
If Points.Count > 1 Then
For i = 2 To Points.Count
DistanceSoFar = DistanceSoFar + Map1.Distance(Points.Item(i).x, Points.Item(i).y, Points.Item(i - 1).x, Points.Item(i - 1).y)
Next
End If
If flags = miPolyToolEnd Then
'First, clear the status bar
Text1.Item(4).Caption = ""
MsgBox "距離: " & DistanceSoFar & " " & RulerUnitString
Else
Text1.Item(3).Caption = "距離"
Text1.Item(4).Caption = DistanceSoFar & " " & RulerUnitString
End If
End If
If ToolNum = PolyAreaToolID Then
'面積
Map1.AreaUnit = miUnitSquareKilometer
On Error Resume Next
Dim apolygoN As New MapXLib.Feature
Dim ax As Double
If (Points.Count > 2) Then
Set apolygoN = New Feature
Set apolygoN = Map1.FeatureFactory.CreateRegion(Points)
ax = apolygoN.Area
MsgBox "面積: " & ax
End If
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -