绘制图层
天下维客,你可以修改的网络知识库
Layers 集合的 AddUserDraw Layer 方法使开发人员在地图上绘制图层。当需要绘制图层时,它与激活的 DrawUserLayer 事件结合在一起使用。该方法返回新创建的 Layer 对象。用户可以绘制任意数量的图层。
如何工作
首先,添加用户绘制图层到图层集合:
Dim lyr as Layer
Set lyr = Map1.Layers.AddUserDrawLayer("My Layer", 1)
然后,设置 DrawUser Layer 事件中的代码以绘制图层。当应用程序使用 Layers 集合的 AddUserDrawLayer 方法创建了 UserDraw 图层,在窗口需要更新时,应用程序就会激活该事件。 下面是完整的示例。
' API DEFS should be declared in a separate module
Declare Function MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Declare Function LineTo Lib "gdi32" Alias "LineTo" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function SetMapMode Lib "gdi32" Alias "SetMapMode" (ByVal hdc As Long, ByVal nMapMode As Long) As Long
Type POINTAPI
x As Long
y As Long
End Type
Public Const MM_TWIPS = 6
' this sets the UserDraw Layer to “My Layer”
Dim lyr as Layer
Set lyr = Map1.Layers.AddUserDrawLayer("My Layer", 1)
' this example draws a line between the corners of Wyoming
Private Sub Map1_DrawUserLayer(ByVal Layer As Object, ByVal hDC As
stdole.OLE_HANDLE, ByVal hAttributeDC As stdole.OLE_HANDLE, ByVal RectFull As Object, ByVal RectInvalid As Object)
Dim pt As POINTAPI
SetMapMode hDC, MM_TWIPS
dim PX as single
dim PY as single
Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
X1 = -111.0542
Y1 = 45.0009
X2 = -104.0528
Y2 = 41.0018
if map1.ClipLine(X1,Y1,X2,Y2) then
mp1.ConvertCoord X, PY, X1,Y1, miMapToScreen
MoveToEx hDC, PX, -PY, pt ' win api call
map1.ConvertCoord PX, PY, X2,Y2, miMapToScreen LineTo hDC, PX, -PY ' win api call end if
End Sub


