Property Get 字体字段() As String
字体字段 = m_Fld_Zt
End Property
Property Let 字体字段(str As String)
m_Fld_Zt = str
End Property
Property Get 字型字段() As String
字型字段 = m_Fld_Zx
End Property
Property Let 字型字段(str As String)
m_Fld_Zx = str
End Property
Property Get 颜色字段() As String
颜色字段 = m_Fld_Color
End Property
Property Let 颜色字段(str As String)
m_Fld_Color = str
End Property
Property Get 间距字段() As String
间距字段 = m_Fld_Jj
End Property
Property Let 间距字段(str As String)
m_Fld_Jj = str
End Property
Property Get 角度字段() As String
角度字段 = m_Fld_Jd
End Property
Property Let 角度字段(str As String)
m_Fld_Jd = str
End Property
Property Get 字宽字段() As String
字宽字段 = m_Fld_Zk
End Property
Property Let 字宽字段(str As String)
m_Fld_Zk = str
End Property
Property Get 字高字段() As String
字高字段 = m_Fld_Zg
End Property
Property Let 字高字段(str As String)
m_Fld_Zg = str
End Property
Property Get 地图控件()
Set 地图控件 = m_map
End Property
Property Set 地图控件(地图控件 As MapObjects2.map)
Set m_map = 地图控件
m_hWnd = m_map.hwnd
m_hDC = GetDC(m_hWnd)
SetROP2 m_hDC, R2_NOTXORPEN
End Property
Private Sub Class_Initialize()
m_sym.Style = moCircleMarker
m_sym.size = 2
m_sym.color = vbRed
End Sub
Private Sub Class_Terminate()
ReleaseDC m_hWnd, m_hDC
End Sub
Private Sub ICustomRenderer_Draw(ByVal pMapLayer As Object, ByVal hDC As Long)
Dim tmpRect As rect
If m_map Is Nothing Or m_Fld_Wznr = "" Then
Exit Sub
End If
Dim tfont As LOGFONT
Dim pRecs As MapObjects2.Recordset
Set pRecs = pMapLayer.Records
SetBkMode hDC, 1 '0透明输出,1非
If pRecs(m_Fld_Wznr) Is Nothing Then Exit Sub
pRecs.MoveFirst
Set TRectCol = New Collection
Screen.MousePointer = vbHourglass
Do While Not pRecs.EOF
DrawTxt pMapLayer, pRecs, hDC
pRecs.MoveNext
Loop
Screen.MousePointer = vbDefault
End Sub
Private Function GetGldValue(trd As MapObjects2.Recordset, tfldstr As String) As String '获取字体值
If tfldstr = "" Then Exit Function
Dim tfld As MapObjects2.Field
Set tfld = trd.Fields(tfldstr)
If tfld Is Nothing Then Exit Function
GetGldValue = tfld.Value
End Function
Sub DrawTxt(lyr As MapObjects2.maplayer, trd As MapObjects2.Recordset, hDC As Long) '画文字
Dim tzx As String
Dim trt As New MapObjects2.Rectangle
Dim w As Long, H As Long
Dim tshp As MapObjects2.Point
Dim X As Single, Y As Single
Dim lz As size
Dim i As Long
Dim TempByteArray() As Byte
Dim ByteArrayLimit As Long
Dim color As Long
Dim tzt As String '字体
Dim tzg As String '字高
Dim tzk As String '字宽
Dim tjd As String '角度
Dim tjj As String '间距
Dim tsize As Double
Dim oldfont As Long
Dim newfont As Long
Dim tfont As LOGFONT
Dim tcolor As String
Dim tmpRect As rect
Dim oldcolor As Long
Dim twznr As String
Set tshp = trd.Fields("shape").Value
Set tshp = Projected(m_map, tshp, lyr)
m_map.FromMapPoint tshp, X, Y
X = m_map.Parent.ScaleX(X, m_map.Parent.ScaleMode, 3)
Y = m_map.Parent.ScaleX(Y, m_map.Parent.ScaleMode, 3)
Set m_oldrt = Nothing
tsize = GMapextentHeight / m_map.extent.Height
On Error Resume Next
twznr = GetGldValue(trd, m_Fld_Wznr)
tzg = GetGldValue(trd, m_Fld_Zg)
tzk = GetGldValue(trd, m_Fld_Zk)
tjd = GetGldValue(trd, m_Fld_Jd)
tzt = GetGldValue(trd, m_Fld_Zt)
tjj = GetGldValue(trd, m_Fld_Jj)
tzx = GetGldValue(trd, m_Fld_Zx)
tcolor = GetGldValue(trd, m_Fld_Color)
If tjd = "" Then tjd = 0
If tjj = "" Then tjj = 0
If tzg = "" Then tzg = 1
If tzk = "" Then tzk = tzg
If tzt = "" Then tzg = "宋体"
If tcolor = "" Then tcolor = 0
With tfont
.lfHeight = tzg * tsize
.lfWidth = tzk * tsize
If .lfHeight < 1 Then .lfHeight = 1
If .lfWidth < 1 Then .lfWidth = 1
If tzx = "左斜" Then
.lfItalic = True
Else
.lfItalic = False
End If
.lfUnderline = False
.lfEscapement = tjd
.lfOutPrecision = OUT_DEFAULT_PRECIS
.lfClipPrecision = OUT_DEFAULT_PRECIS
.lfQuality = DEFAULT_QUALITY
.lfPitchAndFamily = DEFAULT_PITCH Or FF_DONTCARE
.lfCharSet = DEFAULT_CHARSET
TempByteArray = StrConv(tzt & Chr$(0), vbFromUnicode)
ByteArrayLimit = UBound(TempByteArray)
For i = 0 To ByteArrayLimit
.lfFaceName(i) = TempByteArray(i)
Next i
End With
oldcolor = SetTextColor(hDC, tcolor)
newfont = CreateFontIndirect(tfont)
oldfont = SelectObject(hDC, newfont)
SetTextCharacterExtra hDC, tjj * tsize
GetTextExtentPoint32 hDC, twznr, ReturnByte(twznr), lz
With tmpRect
.left = X - lz.cx / 2
.Right = X + lz.cx / 2
.bottom = Y + lz.cy / 2
.top = Y - lz.cy / 2
End With
DrawText hDC, twznr, ReturnByte(twznr), tmpRect, DT_NOCLIP Or DT_CENTER
With trt
.left = X - lz.cx / 2
.Right = X + lz.cx / 2
.bottom = Y - lz.cy / 2
.top = Y + lz.cy / 2
w = m_map.Parent.ScaleX(m_map.Width, vbTwips, vbPixels)
H = m_map.Parent.ScaleY(m_map.Height, vbTwips, vbPixels)
If .left < w And .Right > 0 And .top > 0 And .bottom < H Then
TRectCol.Add PixelsRectToMap(trt)
End If
End With
DeleteObject newfont
End Sub
Private Sub ICustomRenderer_DrawBackground(result As Long)
result = 0
End Sub
Private Function ReturnByte(string1 As String) As Long '获得文字长度
Dim i As Long, t As Long
Dim strByte As Long
string1 = string1
For i = 1 To Len(string1)
t = Asc(Mid$(string1, i, 1))
If t >= 0 Then
strByte = strByte + 1
Else
strByte = strByte + 2
End If
Next
ReturnByte = strByte
End Function
Private Function MapRectToPixels(R As Object) As MapObjects2.Rectangle '地图坐标----->像素坐标
Dim p As New Point
Dim xc As Single, yc As Single
Set MapRectToPixels = New MapObjects2.Rectangle
p.X = R.left
p.Y = R.top
m_map.FromMapPoint p, xc, yc
With MapRectToPixels
' convert to pixels
.left = m_map.Parent.ScaleX(xc, vbTwips, vbPixels)
.bottom = m_map.Parent.ScaleY(yc, vbTwips, vbPixels)
p.X = R.Right
p.Y = R.bottom
m_map.FromMapPoint p, xc, yc
' convert to pixels
.Right = m_map.Parent.ScaleX(xc, vbTwips, vbPixels)
.top = m_map.Parent.ScaleY(yc, vbTwips, vbPixels)
End With
End Function
Function PixelsRectToMap(tPiec As Object) As MapObjects2.Rectangle '像素坐标----->地图坐标
Dim xc As Single, yc As Single
Set PixelsRectToMap = New MapObjects2.Rectangle
Dim p As MapObjects2.Point
With tPiec
xc = m_map.Parent.ScaleX(.left, vbPixels, vbTwips)
yc = m_map.Parent.ScaleY(.bottom, vbPixels, vbTwips)
Set p = m_map.ToMapPoint(xc, yc)
PixelsRectToMap.left = p.X
PixelsRectToMap.top = p.Y
xc = m_map.Parent.ScaleX(.Right, vbPixels, vbTwips)
yc = m_map.Parent.ScaleY(.top, vbPixels, vbTwips)
Set p = m_map.ToMapPoint(xc, yc)
PixelsRectToMap.Right = p.X
PixelsRectToMap.bottom = p.Y
End With
End Function
Public Function draw(trt As MapObjects2.Rectangle) As Boolean '画选择文字
Dim tmpRt As MapObjects2.Rectangle
Dim newpen As Long, oldpen As Long
Dim peninfo As LOGBRUSH
peninfo.lbStyle = 0
peninfo.lbHatch = 4
peninfo.lbColor = vbRed
newpen = ExtCreatePen(66048, 1, peninfo, 0, ByVal 0&)
oldpen = SelectObject(m_hDC, newpen)
If Not m_oldrt Is Nothing Then
With m_oldrt
GdiRectangle m_hDC, .left, .bottom, .Right, .top
End With
End If
If Not trt Is Nothing Then
Set tmpRt = MapRectToPixels(trt)
With tmpRt
GdiRectangle m_hDC, .left, .bottom, .Right, .top
End With
End If
Set m_oldrt = tmpRt
DeleteObject newpen
End Function