先定义连接Dim dConn As New MapObjects2.DataConnection
'以下添加Shp图层
dConn.Database = "D:Program FilesESRIMapObjects2SamplesDataWorld"
If Not dConn.Connect Then
Exit Sub
End If
Dim layer As New MapObjects2.MapLayer
layer.GeoDataset = dConn.FindGeoDataset("country")
Map1.Layers.Add layer
'以下向Map1中添加SDE图层
With dConn
'在服务器名称前面要加上SDE版本标志
.Server = "SDE92:GISServer"
'这里是用Port设置Database
.Database = "instance=port:5150"
'设置用户名和密码
.User = "User"
.Password = "Password"
End With
If Not dConn.Connect Then Exit Sub
Dim layer As New MapObjects2.MapLayer
'要注意FindGeoDataset的参数格式为:数据库名.SDE层名.SHAPE.图层类型
layer.GeoDataset = dConn.FindGeoDataset("GISServer.country.SHAPE.Polygons")
Map1.Layers.Add layer
'以下添加Coverage图层
'注意在Coverage前面加上[arc]
dConn.Database = "[arc]D:Program FilesESRIMapObjects2SamplesDataUSA Coverages"
If dConn.Connect Then
Dim layer As New MapObjects2.MapLayer
'注意下面FindGeoDataset的参数有后缀,表示加入的是什么对象,Pat是指多边形或点,aat表示Arc等等
Set layer.GeoDataset = dConn.FindGeoDataset("landuse.pat")
Map1.Layers.Add layer
Else
MsgBox "连接失败"
End If
'以下添加CAD图层
'注意在CAD文件前加上[CADLine]或者[CADPoint]等等
dConn.Database = "[CADline]d:CAD"
If dConn.Connect Then
Dim layer As New MapObjects2.MapLayer
Set layer.GeoDataset = dConn.FindGeoDataset("River.DWG")
Map1.Layers.Add layer
Else
MsgBox "连接失败"
End If
'以下添加图像层
Dim ImgLayer As New MapObjects2.ImageLayer
ImgLayer.File = "c:sunset.jpg"
Map1.Layers.Add layer
下面访问图层:
Dim layer As mapobject2.MapLayer
'通过索引号访问
Set layer = Map1.Layers.Item(0)
'通过图层名访问
Set layer = Map1.Layers.Item("Country")
'访问SDE图层要用数据库名.SDE层名.SHAPE.图层类型
Set layer = Map1.Layers.Item("数据库名.SDE层名.SHAPE.图层类型")
删除图层:
'删除所有图层
Map1.Layers.Clear
'删除0图层
Map1.Layers.Remove 0
责任编辑:小草