C#版整理中......
VB中建立MyCustomSymbol類,引用AFCustom對象,工程-引用-瀏覽-c:/program files/Common Files/ESRI/AFCust20.tlb--開啟
'先定義一個類別模組(MyCustomSymbol,確定引用AFCustom對象)
Implements AFCustom.ICustomMarker
Private m_filename As String
Private m_dpi As Double
Private m_picture As IPicture
Public Sub SetFileName(fn As String)
m_filename = fn
End Sub
Private Sub ICustomMarker_Draw(ByVal hDC As Long, ByVal X As Long, ByVal Y As Long)
Dim pixWidth As Double, pixHeight As Double
pixWidth = m_picture.Width * m_dpi / 2540
pixHeight = m_picture.Height * m_dpi / 2540
If Not m_picture Is Nothing Then
m_picture.Render hDC, X - pixWidth / 2, Y + pixWidth / 2, pixWidth, -pixHeight, _
0, 0, m_picture.Width, m_picture.Height, Null
End If
End Sub
Private Sub ICustomMarker_ResetDC(ByVal hDC As Long)
Set m_picture = Nothing
End Sub
Private Sub ICustomMarker_SetupDC(ByVal hDC As Long, ByVal dpi As Double, ByVal pBaseSym As Object)
m_dpi = dpi
Set m_picture = LoadPicture(m_filename)
End Sub
Private Sub Form_Load()
Dim bmpSym As New MyCustomSymbol
Dim lyr As New MapLayer
Set lyr = Map1.Layers(0)
bmpSym.SetFileName "E:/5.bmp"
'下面三行是對於點圖層中的所有點都表示成自訂符號,With語句 對圖中點擊的點使用位元影像
'Debug.Print Map1.Layers(0).shapeType
'If Map1.Layers(0).shapeType = 21 Then
' Set lyr.Symbol.Custom = bmpSym
With Map1.TrackingLayer.Symbol(0)
.Custom = bmpSym
.Size = 30
End With
'End If
End Sub
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set pt = Map1.ToMapPoint(X, Y)
Map1.TrackingLayer.AddEvent pt, 0
End Sub