一共有三种:
1.用位图当SYMBOL
2.自定义线型
3.自定义填充类型
1.
Point symbol example using a Bitmap
Here is an example of some code for a custom point symbol server, using a Bitmap to render each Point feature:
Option Explicit
'Indicate that this class will implement ICustomMarker
'Remember that you must first browse for the type library
Implements AFCustom.ICustomMarker
'Internal data members
Private m_filename As String
Private m_dpi Asdo
uble
Private m_picture As IPicture
'External method which allows users to specify the
'image path and name to be rendered.
Public Sub SetFileName(fn As String)
m_filename = fn
End Sub
'The draw method. This method is called for each symbol.
Private Sub ICustomMarker_Draw(ByVal hDC As Long, ByVal x As Long, ByVal y As Long)
Dim pixWidth Asdo
uble, pixHeight Asdo
uble
'Convert the picture width (normally in HI_METRIC) to pixels
'using the previously stored dpi member.
pixWidth = m_picture.Width * m_dpi / 2540
pixHeight = m_picture.Height * m_dpi / 2540
'Always check for a valid interface before using it.
If Not m_picture Is Nothing then
'Render the picture, centered on the given point.
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
'This method is called once per refresh, at the completion of rendering.
Private Sub ICustomMarker_ResetDC(ByVal hDC As Long)
'Set the picture object to nothing, free all resources.
Set m_picture = Nothing
End Sub
'This method is called once per refresh, prior to rendering.
Private Sub ICustomMarker_SetupDC(ByVal hDC As Long, ByVal dpi Asdo
uble, ByVal pBaseSym As Object)
'Store thedo
ts per inch.
m_dpi = dpi
'Try to load the specified picture.
Set m_picture = LoadPicture(m_filename)
End Sub
To use this custom symbol in a Visual Basic project, you may write code like this:
Private Sub Form_Load()
Dim bmpSym As New MyCustomSymbol.CustomBitmapMarker
'Use the SetFileName property to set the location of the
'image to use as the symbol
bmpSym.SetFileName "C:/MyImages/MyMapSymbol.gif"
Set Map1.Layers(0).Symbol.Custom = bmpSym
End Sub
2.
Line symbol example
Here is an example of some code for a custom line symbol server:
Option Explicit
Implements AFCustom.ICustomLine
Dim g_hOldPen As Long
Dim g_hPen As Long
Private Declare Function Polyline Lib "gdi32" (ByVal hDC As Long, lppt As Long, ByVal cCount As Long) As Long
Private Declare Function PolyPolyline Lib "gdi32" (ByVal hDC As Long, lppt As Long, lpdwPolyPoints As Long, ByVal cCount As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Public Sub ICustomLine_Draw(ByVal hDC As Long, points As Long, partCounts As Long, ByVal numParts As Long)
PolyPolyline hDC, points, partCounts, numParts
End Sub
Public Sub ICustomLine_ResetDC(ByVal hDC As Long)
' clean up pen
If Not g_hPen = 0 then
SelectObject hDC, g_hOldPen
DeleteObject g_hPen
End If
End Sub
Public Sub ICustomLine_SetupDC(ByVal hDC As Long, ByVal dpi Asdo
uble, ByVal pBaseSym As Object)
' Set pen attributes to match base symbol
g_hPen = CreatePen(pBaseSym.Style, pBaseSym.Size, pBaseSym.Color)
g_hOldPen = SelectObject(hDC, g_hPen)
End Sub
3.
Fill symbol example
Here is an example of some code for a custom fill symbol server:
Option Explicit
Implements AFCustom.IcustomFill
Dim g_hOldPen As Long
Dim g_hPen As Long
Dim g_hOldBrush As Long
Dim g_hBrush As Long
Private Declare Function PolyPolygon Lib "gdi32" (ByVal hDC As Long, lppt As Long, lpdwPolyPoints As Long, ByVal cCount As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Public Sub ICustomFill_Draw(ByVal hDC As Long, points As Long, partCounts As Long, ByVal numParts As Long)
PolyPolygon hDC, points, partCounts, numParts
End Sub
Public Sub ICustomFill_ResetDC(ByVal hDC As Long)
' clean up pen
If Not g_hPen = 0 then
SelectObject hDC, g_hOldPen
DeleteObject g_hPen
End If
If Not g_hBrush = 0 then
SelectObject hDC, g_hOldBrush
DeleteObject g_hBrush
End If
End Sub
Public Sub ICustomFill_SetupDC(ByVal hDC As Long, ByVal dpi Asdo
uble, ByVal pBaseSym As Object)
' Set pen attributes to match base symbol
g_hPen = CreatePen(pBaseSym.Style, pBaseSym.Size, pBaseSym.OutlineColor)
g_hOldPen = SelectObject(hDC, g_hPen)
g_hBrush = CreateSolidBrush(pBaseSym.Color)
g_hOldBrush = SelectObject(hDC, g_hBrush)
End Sub