·ÖÀà

  • Èí¼þÌìµØ

  • MapObjects2.2 ÔÚC#ÖеÄÓ¦ÓÃ(¶¯Ì¬¼ÓÔØµØÍ¼)¡¬

    ¡¡¡¡using System;                                                    

    ¡¡¡¡using System.Drawing;                                    

    ¡¡¡¡using System.Collections;                            

    ¡¡¡¡using System.ComponentModel;                      

    ¡¡¡¡using System.Windows.Forms;                        

    ¡¡¡¡using System.Data;                                          

    ¡¡¡¡namespace LoadMap                                            

    ¡¡¡¡{                                                                            

    ¡¡¡¡¡¡¡¡ /// <summary>


    ¡¡¡¡¡¡¡¡ /// Form1 µÄժҪ˵Ã÷¡£                                        

    ¡¡¡¡¡¡¡¡ /// </summary>


    ¡¡¡¡¡¡¡¡ public class Fo
    rm1 : System.Windows.Forms.F
    orm

    ¡¡¡¡¡¡¡¡ {                                                                      


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡private Ax
    MapObjects2.AxMap axMap1;

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// <summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡ /// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£                                          

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// </summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡private Sy
    stem.ComponentModel.Containe
    r components = null;

    ¡¡¡¡¡¡¡¡¡¡¡¡ public Form1()                                        

    ¡¡¡¡¡¡¡¡¡¡¡¡ {                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                            

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡// Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ                    

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                            

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡InitializeComponent();                    

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                            

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡// TODO: ÔÚ Initia
    lizeComponent µ÷ÓúóÌí¼ÓÈκι¹Ô캯Êý´úÂë

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                            

    ¡¡¡¡¡¡¡¡¡¡¡¡ }                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// <summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡ /// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£                                    

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// </summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡protected override voi
    d Dispose( bool disposing )

    ¡¡¡¡¡¡¡¡¡¡¡¡ {                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡if( disposing )                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡{                                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ if (components != null)           

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ {                                                        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡components.Dispose();            

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡?}                                                        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡}                                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡base.Dispose( disposing );            

    ¡¡¡¡¡¡¡¡¡¡¡¡ }                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ #region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë              

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// <summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡ /// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼­Æ÷Ð޸Ġ           

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// ´Ë·½·¨µÄÄÚÈÝ¡£                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// </summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡private void InitializeComponent()

    ¡¡¡¡¡¡¡¡¡¡¡¡ {                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡System
    ystem.Resources.Resource
    .Resources.ResourceManager r
    Manager(typeof(Form1));
    esources = new S


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.axMap1 = new
    AxMapObjects2.AxMap();

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡?(Syst
    xMap1)).BeginInit();
    em.ComponentModel.ISupportIn

    itialize)(this.a


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.SuspendLayout();                      

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                           

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡// axMap1                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                           

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.a
    xMap1.Dock = System.Windows.
    Forms.DockStyle.Fill;

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.a
    xMap1.Location = new System.
    Drawing.Point(0, 0);

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.axMap1.Name = "axMap1";        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.axMap1.OcxSta
    rms.AxHost.State)(resources.GetObjec
    te = ((System.Windows.Fo
    t("axMap1.OcxState")));

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.axMap1.Size =
    new System.Drawing.Size(600, 357);

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.axMap1.TabIndex = 0;              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                           

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡// Form1                                                

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//                                                           

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.A
    utoScaleBaseSize = new Syste
    m.Drawing.Size(6, 14);

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.C
    lientSize = new System.Drawi
    ng.Size(600, 357);

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.Controls.Add(this.axMap1);  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.Name = "Form1";                        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.Text = "Form1";                        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.Load += new S
    ystem.EventHandler(this.Form1_Load);

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡((Syst
    xMap1)).EndInit();
    em.ComponentModel.ISupportIn

    itialize)(this.a


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this.ResumeLayout(false);              

    ¡¡¡¡¡¡¡¡¡¡¡¡ }                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡#endregion                                                

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// <summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡ /// Ó¦ÓóÌÐòµÄÖ÷Èë¿Úµã¡£                                        

    ¡¡¡¡¡¡¡¡¡¡¡¡ /// </summary>


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡[STAThread]                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡ static void Main()                               

    ¡¡¡¡¡¡¡¡¡¡¡¡ {                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Application.Run(new Form1());      

    ¡¡¡¡¡¡¡¡¡¡¡¡ }                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡ private v
    oid Form1_Load(object sender
    , System.EventArgs e)

    ¡¡¡¡¡¡¡¡¡¡¡¡ {                                                                  

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//¶¨ÒåÊý¾ÝÁ¬½Ó                                                

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MapObjects2.DataCo
    ects2.DataConnectionClass();
    nnection dc = new MapObj


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//¶¨Òåͼ²ã                                                    

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MapObj
    ects2.MapLayer layer = new M
    apObjects2.MapLayerClass();

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//ÎҵĵØÍ¼Îļþ¶¼´æ
    Ϊ×Ô¼ºµÄµØÍ¼Ä¿Â¼
    ÔÚÁË"G:\LoadMap\bin\Debug\"Ŀ¼Ï£¬ÇëÌæ»»


    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dc.Dat
    abase = "G:\LoadMap\bin\D
    ebug\";

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//Á¬½Ó²»³É¹¦¾ÍÍ˳ö                                            

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡if(!dc.Connect())                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡{                                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ M
    essageBox.Show("ÔÚÖ¸¶¨µÄÎļþ
    ¼ÐÏÂûÕÒµ½Í¼²ãÊý¾ÝÎļþ");

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ Application.Exit();                    

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡}                                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡else//Á¬½Ó³É¹¦Á˾ͼÓÔØµØÍ¼                                

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡{                                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ /*                                                      

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡* µØÍ¼¼ÓÔØË³ÐòÒ»°ãÊÇÃæ¡¢Ïß¡¢µã£¬ÏȼÓÔØµÄÔÚµØÍ¼µÄ×îÏ    

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡*/                                                      

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ //¼ÓÔØÍ¼²ãStates£¬                                

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ layer.GeoData
    set = dc.FindGeoDataset("States");

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ axMap1.Layers.Add(layer);        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ //¼ÓÔØÍ¼²ãRivers£¬                                

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ l
    ayer.GeoDataset = dc.FindGeo
    Dataset("Rivers");

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ axMap1.Layers.Add(layer);        

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ //¼ÓÔØÆäËüͼ²ã...                                    

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡}                                                              

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//±ØÐë½øÐÐˢкó²ÅÄÜÏÔʾ                                      

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡axMap1.Refresh();                              

    ¡¡¡¡¡¡¡¡¡¡¡¡ }                                                                  

    ¡¡¡¡¡¡¡¡ }                                                                      

    ¡¡¡¡}                                                                            



    ÉÏÒ»Ò³ ÏÂÒ»Ò³




    map