增加经线和纬线
本示例内容可以参考CaseStudy目录下的文件"地图.Table"的示例二十八。
本节的任务是在地图上增加经线和纬线:

AfterLoad事件代码:
Dim
map
As
GeoMap = e.Form.Controls("Map1").GeoMap
Dim
layer
As
New
VectorLayer()
layer.Style.Stroke.Color = Color.DarkGray
layer.LabelVisibility = LabelVisibility.AutoHide
map.Layers.Add(layer)
For
Each
kr
As
VectorRecord
In
map.CreateRecordsFromKML(ProjectPath &
"WorldMap.kml")
layer.Items.Add(kr.VectorItem)
If
TypeOf
kr.VectorItem
Is
VectorPlacemark
Then
Dim
mark
As
VectorPlacemark = kr.VectorItem
'设置标记的属性:
mark.Marker.Caption = kr.Data("name")
mark.Marker.LabelPosition = LabelPosition.Center
mark.LabelStyle.ForeColor = Color.Green
mark.Lod =
New
LOD(0, 0, 2, 20)
ElseIf
TypeOf
kr.VectorItem
Is
VectorPolygon
Then
Dim
polygon
As
VectorPolygon = kr.VectorItem
'设置多边形属性:
If
kr.Data("style-fillcolor")
IsNot
Nothing
Then
'其他国家从KML取得颜色设置,如果有的话
polygon.Style.BackColor = map.GetKmlStyleColor(kr.Data("style-fillcolor"))
End
If
End
If
Next
'增加一个图层用于绘制经线和维线
layer =
New
VectorLayer()
layer.LabelVisibility = LabelVisibility.Visible
layer.Track =
False
map.Layers.Add(layer)
layer.LabelStyle.ForeColor = Color.DarkGray
layer.Style.Stroke.Color = Color.DarkGray
layer.Style.Stroke.Style = GeoDashStyle.Dash
For
lon
As
Integer
= -180
To
180
Step
30
'间隔30度绘制一条经线
layer.Items.Add(map.CreateLine({New
GeoPoint(lon, -90),
New
GeoPoint(lon, 90)}))
Dim
lbl
As
String
= Math.Abs(lon).ToString() &
"°"
If
lon > 0
Then
lbl = lbl &
"E"
ElseIf
lon < 0
Then
lbl = lbl &
"W"
End
If
Dim
pm
As
New
VectorPlacemark()
pm.Geometry =
New
GeoPoint(lon, 0)
pm.Marker =
New
Marker()
pm.Marker.Caption = lbl
pm.Marker.LabelPosition = LabelPosition.Top
layer.Items.Add(pm)
Next
For
lat
As
Integer
= -80
To
80
Step
20
'间隔20度绘制一条纬线
layer.Items.Add(map.CreateLine({New
GeoPoint( - 180, lat),
New
GeoPoint(180, lat)}))
Dim
lbl
As
String
= Math.Abs(lat).ToString() &
"°"
If
lat > 0
Then
lbl = lbl &
"N"
ElseIf
lat < 0
Then
lbl = lbl &
"S"
End
If
Dim
pm
As
New
VectorPlacemark()
pm.Geometry =
New
GeoPoint(0, lat)
pm.Marker =
New
Marker()
pm.Marker.Caption = lbl
pm.Marker.LabelPosition = LabelPosition.Right
layer.Items.Add(pm)
Next