多个矢量层
本节内容可以参考CaseStudy目录下的文件"地图.Table"的示例四。
Map可以有多个矢量层,不同的矢量层显示不同的内容。
本节的内容是:
1、增加三个矢量层,一个显示城市,一个显示北京航线,一个显示上海航线。
2、增加两个个CheckBox,用于选择显示北京航线还是上海航线,或者两个都显示:

示例:
1、将Map控件的"地图来源"属性设置为"Custom"
2、将Map控件的GetMapTile事件代码设置为:
Dim
style
As
Integer
= 8
'地图类型,可选值为6到10,其中6为卫星图
Dim
size
As
Integer
= 1
Dim
scale
As
Integer
= 1
Dim
server
As
Integer
= Rand.Next(1, 5)
'随机使用1到4号服务器
Dim
scl
As
Integer
= 2
'设置为2可以隐藏地图的文字标注,且分辨率更好
Dim
Language
As
String
=
"zh_cn"
'中文地图,如果需要英文可设置为"en",我
测试只有style为8的时候才支持英文
Dim
url
As
String
If
style = 7
OrElse
style = 8
Then
url =
"https://webrd0{0}.is.autonavi.com/appmaptile?lang={1}&size={2}&scale={3}&style={4}&x={5}&y={6}&z={7}&scl={8}"
Else
url =
"https://webst0{0}.is.autonavi.com/appmaptile?lang={1}&size={2}&scale={3}&style={4}&x={5}&y={6}&z={7}&scl={8}"
End
If
e.URI = CExp(url, server, Language, Size, scale, style, e.X, e.Y, e.Z, scl)
3、将窗口的AfterLoad事件代码设置为:
Dim
map
As
GeoMap = e.Form.Controls("Map1").GeoMap
'定义各城市的经纬度
Dim
cities
As
New
Dictionary(Of
String,
GeoPoint)
cities.Add("北京",
New
GeoPoint(116.4053, 39.905))
cities.Add("上海",
New
GeoPoint(121.4726, 31.2317))
cities.Add("广州",
New
GeoPoint(113.2806, 23.1252))
cities.Add("成都",
New
GeoPoint(104.0657, 30.6595))
cities.Add("哈尔滨",
New
GeoPoint(126.6425, 45.757))
'逐个绘制城市
Dim
layer
As
New
VectorLayer()
'定义一个矢量层,专门用于显示城市
layer.LabelVisibility = LabelVisibility.Visible
'标题可见
layer.Style.Stroke.Color = Color.Red
'标记边框为红色
layer.LabelStyle.ForeColor = Color.Green
'标题为绿色
map.Layers.Add(layer)
'将矢量层增加代map控件中
For
Each
city
As
String
In
cities.Keys
Dim
mark
As
New
VectorPlacemark()
'增加一个标记
mark.Marker.Caption = city
'设置标题
mark.Geometry = cities(city)
'设置标记位置为对应城市的经纬度
If
city =
"北京"
Then
'如果是北京
mark.Marker.Size =
New
SizeF(16, 16)
'指定
标记大小
mark.Marker.Shape = MarkerShape.Star
'标记为五角星
Else
mark.Marker.Size =
New
SizeF(10, 10)
'其他城市的
标记要小一些
mark.Marker.Shape = MarkerShape.Circle
'且
标记为圆形
End
If
mark.Marker.LabelPosition = LabelPosition.Right
'标题显示在
标记右边
mark.Style.BackColor = Color.Red
'标记的填充颜色为红色
layer.Items.Add(mark)
'将
标记添加到矢量层中
Next
'绘制北京和各城市之间的连接线条
layer =
New
VectorLayer()
'定义一个矢量层,用于
显示北京和其他城市之间的连线
map.Layers.Add(layer)
'将矢量层增加代map控件中
For
Each
city
As
String
In
cities.Keys
If
city <>
"北京"
Then
Dim
points()
As
GeoPoint = {cities("北京"),
cities(city)}
'线条至少需要用两个经纬度点,起点为北京的经纬度
Dim
line
As
VectorPolyline = map.CreateLine(points)
'创建线条
line.Style.Stroke.Color = Color.Blue
'线条颜色
line.Style.Stroke.Style = GeoDashStyle.Dash
'线型
layer.Items.Add(line)
End
If
Next
'绘制上海和各城市之间的链接线条
layer =
New
VectorLayer()
'定义一个矢量层,用于上海和其他城市之间的连线
layer.Visible =
False
'这个矢量层默认隐藏
map.Layers.Add(layer)
'将矢量层增加代map控件中
For
Each
city
As
String
In
cities.Keys
If
city <>
"上海"
Then
Dim
points()
As
GeoPoint = {cities("上海"),
cities(city)}
Dim
line
As
VectorPolyline = map.CreateLine(points)
line.Style.Stroke.Color = Color.BlueViolet
line.Style.Stroke.Style = GeoDashStyle.Dash
layer.Items.Add(line)
End
If
Next
4、两个CheckBox的代码分别设置为:
Dim
map
As
GeoMap = e.Form.Controls("Map1").GeoMap
map.Layers(1).Visible = e.Sender.Checked
和:
Dim
map
As
GeoMap = e.Form.Controls("Map1").GeoMap
map.Layers(2).Visible = e.Sender.Checked