在axGlobeControl里面画线,整个代码如下,
'添加新的图层,先把图层属性改为覆盖
Dim pG As IGraphicsLayer = New GlobeGraphicsLayer
axGlobeControl1.Globe.AddLayerType(pG, esriGlobeLayerType.esriGlobeLayerTypeUnknown) '把pG这个layer加到Globe里
Dim pGEP As IGlobeGraphicsElementProperties = New GlobeGraphicsElementProperties
pGEP.DrapeElement = True '属性改为drape
Dim pGL As IGlobeGraphicsLayer = New GlobeGraphicsLayer
pGL = pG
'为要画的线定义symbol,调用drawline
Dim pSymbol As ISimpleLineSymbol = New SimpleLineSymbol
pSymbol.Width = 2
Dim pcolor As IColor = New RgbColor
pcolor.RGB = RGB(230, 0, 0)
pSymbol.Color = pcolor
Dim pGC3D As IGraphicsContainer3D = New GlobeGraphicsLayer
pGC3D = pG '让pG获得Container
Dim nCount As Integer
For nCount = -90 To 90 Step 30
Dim pElement As IElement
'纬线
pElement = drawline(0, nCount, 0, 359.5, nCount, 0, pSymbol)
pGL.AddElement(pElement, pGEP, 0) '修改后的属性加入到画好线的element里面
pGC3D.AddElement(pElement) '把画好的图形加到layer里面
'经线
pElement = drawline(nCount, 0, 0, nCount, 359.5, 0, pSymbol)
pGL.AddElement(pElement, pGEP, 0) '修改后的属性加入到画好线的element里面
pGC3D.AddElement(pElement) '把画好的图形加到layer里面
Next nCount
axGlobeControl1.Refresh()
Public drawline(ByVal x1 As Double, ByVal y1 As Double, ByVal Z1 As Double, ByVal X2 As Double, ByVal Y2 As Double, ByVal Z2 As Double, ByVal symbol As ISimpleLineSymbol) As IElement
Dim pElement As IElement
pElement = New LineElement
Dim pLineEle As ILineElement
pLineEle = pElement
pLineEle.Symbol = symbol
Dim tmpline As IPolyline = New Polyline
'给要画的线定义起始点
Dim StartPoint As IPoint, EndPoint As IPoint
StartPoint = New Point
StartPoint.X = x1
StartPoint.Y = y1
StartPoint.Z = Z1
EndPoint = New Point
EndPoint.X = X2
EndPoint.Y = Y2
EndPoint.Z = Z2
tmpline.FromPoint = StartPoint
tmpline.ToPoint = EndPoint
pElement.Geometry = tmpline
drawline = pElement
End
整个过程关键是要把element的属性改为drape,这样画出来的线就是贴着地球表面的,而不会穿过地心,
在把图层改为Drape时,加上粘附高度设置就可以将画的线升高,而不被背景图覆盖掉。把代码修改一下,如下:
pGEP.DrapeElement = True '属性改为drape
pGEP.DrapeZOffset=1000000 '加上这一句,后面的值表示高度,单位是米