form02.frm

来自「一个关于基于MO编程的参考资料希望对大家的交流和学习有帮助」· FRM 代码 · 共 137 行

FRM
137
字号
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form02 
   Caption         =   "墨西哥地图"
   ClientHeight    =   5460
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6765
   LinkTopic       =   "Form1"
   ScaleHeight     =   5460
   ScaleWidth      =   6765
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   4920
      TabIndex        =   2
      Top             =   4680
      Width           =   1050
   End
   Begin VB.ListBox List1 
      Height          =   780
      Left            =   720
      TabIndex        =   1
      Top             =   4560
      Width           =   3495
   End
   Begin MapObjects2.Map Map1 
      Height          =   4455
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   6735
      _Version        =   131072
      _ExtentX        =   11880
      _ExtentY        =   7858
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form02.frx":0000
   End
End
Attribute VB_Name = "Form02"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xuewei,2003/5/27
'使用前,先把中间的一个,如cities图层的prj文件去掉;
'单击Command1,把cities图层的CoordinateSystem属性再设置上;

Option Explicit
Dim mapPCS As New MapObjects2.ProjCoordSys
Dim mapGCS As New MapObjects2.GeoCoordSys

Private Sub Command1_Click()
  Dim layer As MapLayer
  
  '给图层设置坐标系;
  Set layer = Map1.Layers("cities")
  If Map1.Layers(0).CoordinateSystem.IsProjected Then
    mapPCS.Type = Map1.Layers(0).CoordinateSystem.Type
    layer.CoordinateSystem = mapPCS
  ElseIf Not Map1.Layers(0).CoordinateSystem.IsProjected Then
    mapGCS.Type = Map1.Layers(0).CoordinateSystem.Type
    layer.CoordinateSystem = mapGCS
  End If
  
  '重新显示屏幕;
  List1.Clear
  addList
  DrawLayer
End Sub

Private Sub addList()
  Dim curLayer As MapObjects2.MapLayer
  For Each curLayer In Map1.Layers
    If Not curLayer.CoordinateSystem Is Nothing Then
      List1.AddItem curLayer.Name & ": " & curLayer.CoordinateSystem.Name
      Map1.Layers(curLayer.Name).Visible = True
    Else
      List1.AddItem curLayer.Name & ":坐标系没有设置!"
      Map1.Layers(curLayer.Name).Visible = False
    End If
  Next curLayer
  List1.AddItem "Map控件: " & Map1.CoordinateSystem.Name
End Sub

Private Sub Form_Load()
  '加载墨西哥地图的State、Cities和Rivers等3个图层;
  DrawLayer
  Command1.Caption = "改变"
  
  '给Map1设置坐标系;
  If Map1.CoordinateSystem Is Nothing Then
    If Map1.Layers(0).CoordinateSystem.IsProjected Then
      Dim mapPCS As New MapObjects2.ProjCoordSys
      mapPCS.Type = Map1.Layers(0).CoordinateSystem.Type
      Map1.CoordinateSystem = mapPCS
    ElseIf Not Map1.Layers(0).CoordinateSystem.IsProjected Then
      Dim mapGCS As New MapObjects2.GeoCoordSys
      mapGCS.Type = "4326"
      Map1.CoordinateSystem = mapGCS
    End If
  End If
  
  '向List1中写坐标系信息;
  addList
End Sub

Private Sub DrawLayer()
  Dim DC As New DataConnection
  Dim layer As MapLayer
  DC.Database = App.Path + "\..\" + "Mexico"
  If Not DC.Connect Then
    MsgBox "在指定的文件夹下没找到图层数据文件!"
    End
  End If
  
  Set layer = New MapLayer
  Set layer.GeoDataset = DC.FindGeoDataset("states")
  layer.Symbol.Color = moLimeGreen
  Map1.Layers.Add layer
  
  Set layer = New MapLayer
  Set layer.GeoDataset = DC.FindGeoDataset("cities")
  layer.Symbol.Color = moLimeGreen
  Map1.Layers.Add layer
  
  Set layer = New MapLayer
  Set layer.GeoDataset = DC.FindGeoDataset("rivers")
  layer.Symbol.Color = moBlue
  Map1.Layers.Add layer
End Sub


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?