Application of MapObjects2.2 in C # (dynamic loading map)
Last Update:2017-02-28
Source: Internet
Author: User
object| Dynamic | Load MapObjects2.2 application in C # (dynamic load map)
Keywords: mapobjects 2.2 C #
This article realizes the dynamic loading map function, the nonsense is little said, the function realization sees the code.
Load Process Code:
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Namespace Loadmap
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Private Axmapobjects2.axmap AxMap1;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;
Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
//
TODO: Add any constructor code after the InitializeComponent call
//
}
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (Form1));
This.axmap1 = new Axmapobjects2.axmap ();
((System.ComponentModel.ISupportInitialize) (THIS.AXMAP1)). BeginInit ();
This. SuspendLayout ();
//
AxMap1
//
This.axMap1.Dock = System.Windows.Forms.DockStyle.Fill;
This.axMap1.Location = new System.Drawing.Point (0, 0);
This.axMap1.Name = "AxMap1";
This.axMap1.OcxState = ((System.Windows.Forms.AxHost.State) (resources. GetObject ("Axmap1.ocxstate"));
This.axMap1.Size = new System.Drawing.Size (600, 357);
This.axMap1.TabIndex = 0;
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (600, 357);
This. Controls.Add (THIS.AXMAP1);
This. Name = "Form1";
This. Text = "Form1";
This. Load + = new System.EventHandler (this. Form1_Load);
((System.ComponentModel.ISupportInitialize) (THIS.AXMAP1)). EndInit ();
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());
}
private void Form1_Load (object sender, System.EventArgs e)
{
Defining Data connections
Mapobjects2.dataconnection dc = new Mapobjects2.dataconnectionclass ();
Defining layers
Mapobjects2.maplayer layer = new Mapobjects2.maplayerclass ();
My map file is in the "g:\\loadmap\\bin\\debug\\" directory, please replace it with your own map directory
dc. Database = "g:\\loadmap\\bin\\debug\\";
Exit if connection is unsuccessful
if (!DC. Connect ())
{
MessageBox.Show ("No layer data file found under specified folder");
Application.exit ();
}
else//connection is successful, load the map.
{
/*
* Map loading sequence is generally surface, line, point, first loaded at the bottom of the map
*/
Load layer states,
Layer. Geodataset = DC. Findgeodataset ("States");
AXMAP1.LAYERS.ADD (layer);
Load Layer rivers,
Layer. Geodataset = DC. Findgeodataset ("Rivers");
AXMAP1.LAYERS.ADD (layer);
Load other layers ...
}
Must be refreshed before it can be displayed
Axmap1.refresh ();
}
}
}