www.pudn.com > 12136.rar > Form06.frm


VERSION 5.00 
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx" 
Begin VB.Form Form06  
   Caption         =   "墨西哥地图" 
   ClientHeight    =   4665 
   ClientLeft      =   60 
   ClientTop       =   345 
   ClientWidth     =   6765 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   4665 
   ScaleWidth      =   6765 
   StartUpPosition =   3  '窗口缺省 
   Begin MapObjects2.Map Map1  
      Height          =   4575 
      Left            =   0 
      TabIndex        =   0 
      Top             =   0 
      Width           =   6735 
      _Version        =   131072 
      _ExtentX        =   11880 
      _ExtentY        =   8070 
      _StockProps     =   225 
      BackColor       =   16777215 
      BorderStyle     =   1 
      Contents        =   "Form06.frx":0000 
   End 
End 
Attribute VB_Name = "Form06" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
'Xuewei,2003/6/13 
'添加特征示例; 
 
Option Explicit 
 
Private Sub DrawLayer() 
  Dim Layer As MapLayer 
  Dim dc As New DataConnection 
    
  On Error GoTo Err1 
  dc.Database = App.Path + "\..\" + "Mexico" 
  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("CITIES1") 
  Layer.Symbol.Color = moRed 
  Map1.Layers.Add Layer 
  Exit Sub 
   
Err1: 
  If dc.ConnectError = 0 Then 
    MsgBox "没找到图层", vbInformation, "MO示例" 
  Else 
    MsgBox ConnectErrorMsg(dc.ConnectError), vbInformation, "MO示例" 
  End If 
  End 
End Sub 
 
Private Sub Form_Load() 
  DrawLayer   '加载墨西哥地图的States和Cities1图层; 
End Sub 
 
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 
  Dim P1 As MapObjects2.Point 
  Dim Ans As Variant 
  Dim Recs As MapObjects2.Recordset 
  Dim Layer As MapObjects2.MapLayer 
   
  Set Layer = Map1.Layers("CITIES1") 
  Set Recs = Layer.Records 
  Set P1 = Map1.ToMapPoint(X, Y) 
   
  Ans = MsgBox("要添加这个特征?", vbYesNo, "MO示例") 
  If Ans = vbYes Then 
    If Recs.Updatable Then 
      With Layer.Records 
        .AddNew 
        .Fields("Shape").Value = P1    '添加特征; 
        .Fields("Name").Value = "新城市" 
        .Fields("CITIES_").Value = "1" 
        .Update 
        .StopEditing 
      End With 
      Map1.Refresh 
    Else 
      MsgBox "图层文件不能编辑" 
    End If 
  End If 
End Sub