计算机地图制图上机实习报告二(3)
时间:2025-04-06
时间:2025-04-06
Set layer = New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("Rivers") yers.Add layer
Map1.Refresh
以对话框形式加shp图层
导入CommonDialog 组件,这一组件在对象库Microsoft Common Dialog Control 6.0 中。添加Map控件,Conmon Dialog 控件,并将其名称改为cDlg1,添加一个按钮。
在Form上增加一个标注“增加图层”的按钮,并增加Visual Basic的CommonDialog控件,以便确定Shape文件的路径和文件名。双击增加图层按钮就可以编程了,增加以下的VB语句。 Private Sub Commandl_Click() ‘打开对话框的方式添加图层
CommonDialog1.CancelError = True
CommonDialog1.DialogTitle = "选择地图文件" Dim oConnect As New DataConnection Dim oDataset As GeoDataset Dim sName As String
Dim oLayer As MapObjects2.MapLayer
CommonDialog1.Filter = "ESRI Shapefiles (*.shp)|*.shp" CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) = 0 Then Exit Sub oConnect.Database = CurDir
If Not oConnect.Connect Then Exit Sub
sName = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4) Set oDataset = oConnect.FindGeoDataset(sName) If oDataset Is Nothing Then Exit Sub Set oLayer = New MapLayer oLayer.GeoDataset = oDataset yers.Add oLayer yers.Add oLayer legend1.setMapSource Map1 legend1.LoadLegend True Map1.Refresh
End Sub
下一篇:建筑预算计算规则一