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