The application of MapObjects2.2 in C # (basic map function)
Last Update:2017-02-28
Source: Internet
Author: User
Application of Object MapObjects2.2 in C # (basic map function)
Keywords: mapobjects 2.2 C #
Only realized the map enlargement, the reduction, the roaming, the whole graph, the distance, the area and so on function.
/*
* Yang Yutin blue_bat@126.com
* July 27, 2004
*/
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Namespace Artemis.IVS.Test
{
<summary>
Working with instances
</summary>
public class FrmMain:System.Windows.Forms.Form
{
Private Axmapobjects2.axmap Mapmain;
Private System.Windows.Forms.MainMenu mainMenu1;
Private System.Windows.Forms.MenuItem mizoomin;
Private System.Windows.Forms.MenuItem mizoomout;
Private System.Windows.Forms.MenuItem Mipan;
Private System.Windows.Forms.MenuItem Mifullview;
private int curoperate = 0;
Private System.Windows.Forms.MenuItem Miselectbypoint;
Private System.Windows.Forms.MenuItem midistance;
Private System.Windows.Forms.MenuItem Miarea;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;
Public Frmmain ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
}
<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 (Frmmain));
This.mapmain = new Axmapobjects2.axmap ();
this.mainmenu1 = new System.Windows.Forms.MainMenu ();
This.mizoomin = new System.Windows.Forms.MenuItem ();
This.mizoomout = new System.Windows.Forms.MenuItem ();
This.mipan = new System.Windows.Forms.MenuItem ();
This.mifullview = new System.Windows.Forms.MenuItem ();
This.miselectbypoint = new System.Windows.Forms.MenuItem ();
This.midistance = new System.Windows.Forms.MenuItem ();
This.miarea = new System.Windows.Forms.MenuItem ();
((System.ComponentModel.ISupportInitialize) (This.mapmain)). BeginInit ();
This. SuspendLayout ();
//
Mapmain
//
This.mapMain.Dock = System.Windows.Forms.DockStyle.Fill;
This.mapMain.Location = new System.Drawing.Point (0, 0);
This.mapMain.Name = "Mapmain";
This.mapMain.OcxState = ((System.Windows.Forms.AxHost.State) (resources. GetObject ("Mapmain.ocxstate"));
This.mapMain.Size = new System.Drawing.Size (592, 401);
This.mapMain.TabIndex = 0;
This.mapMain.MouseDownEvent + = new Axmapobjects2._dmapevents_mousedowneventhandler (this.mapmain_mousedownevent);
//
MainMenu1
//
This.mainMenu1.MenuItems.AddRange (new system.windows.forms.menuitem[] {
This.mizoomin,
This.mizoomout,
This.mipan,
This.mifullview,
This.miselectbypoint,
This.midistance,
This.miarea});
//
Mizoomin
//
This.miZoomIn.Index = 0;
This.miZoomIn.Text = "Enlarge";
This.miZoomIn.Click + = new System.EventHandler (This.mizoomin_click);
//
Mizoomout
//
This.miZoomOut.Index = 1;
This.miZoomOut.Text = "shrink";
This.miZoomOut.Click + = new System.EventHandler (This.mizoomout_click);
//
Mipan
//
This.miPan.Index = 2;
This.miPan.Text = "roaming";
This.miPan.Click + = new System.EventHandler (This.mipan_click);
//
Mifullview
//
This.miFullView.Index = 3;
This.miFullView.Text = "whole picture";
This.miFullView.Click + = new System.EventHandler (This.mifullview_click);
//
Miselectbypoint
//
This.miSelectByPoint.Index = 4;
This.miSelectByPoint.Text = "point selection";
This.miSelectByPoint.Click + = new System.EventHandler (This.miselectbypoint_click);
//
Midistance
//
This.miDistance.Index = 5;
This.miDistance.Text = "Distance";
This.miDistance.Click + = new System.EventHandler (This.midistance_click);
//
Miarea
//
This.miArea.Index = 6;
This.miArea.Text = "area";
This.miArea.Click + = new System.EventHandler (This.miarea_click);
//
Frmmain
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (592, 401);
This. Controls.Add (This.mapmain);
This. Menu = this.mainmenu1;
This. Name = "Frmmain";
This. Text = "Artemis.IVS.Test";
This. Load + = new System.EventHandler (this. Frmmain_load);
((System.ComponentModel.ISupportInitialize) (This.mapmain)). EndInit ();
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Frmmain ());
}
<summary>
Full picture
</summary>
private void Mifullview_click (object sender, System.EventArgs e)
{
This. Curoperate = 4;
Mapmain.extent = mapmain.fullextent;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moDefault;
}
<summary>
Roaming
</summary>
private void Mipan_click (object sender, System.EventArgs e)
{
This. Curoperate = 3;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moPan;
}
<summary>
Narrow
</summary>
private void Mizoomout_click (object sender, System.EventArgs e)
{
This. Curoperate = 2;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moZoomOut;
}
<summary>
Amplification
</summary>
private void Mizoomin_click (object sender, System.EventArgs e)
{
This. Curoperate = 1;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moZoomIn;
}
<summary>
The process of zooming in, narrowing, etc.
</summary>
private void Mapmain_mousedownevent (object sender, Axmapobjects2._dmapevents_mousedownevent e)
{
Mapobjects2.rectangle rect;
Mapobjects2.point pt = mapmain.tomappoint (E.X,E.Y);
if (E.button = 2) this. Curoperate = 0;//Right button click Cancel
Switch (this. Curoperate)
{
Case 1://Amplification
{
Rect = Mapmain.trackrectangle ();
if (rect = = null| | (Rect. Width < 0.00005) | | (Rect. Height < 0.00005))
{
rect = mapmain.extent;
Rect. Scalerectangle (0.6667);
Rect. Offset (-(RECT). Center.x-pt. X),-(rect. Center.y-pt. Y));
}
Mapmain.extent = rect;
Break
}
Case 2://Shrink
{
Rect = Mapmain.trackrectangle ();
if (null = rect) | | (Rect. Width < 0.00005) | | (Rect. Height < 0.00005))
{
rect = mapmain.extent;
Rect. Scalerectangle (1.5);
Rect. Offset (-(RECT). Center.x-pt. X),-(rect. Center.y-pt. Y));
}
Else
{
Double drate = Mapmain.extent.width/rect. Width * 10;
Rect. Scalerectangle (drate);
}
Mapmain.extent = rect;
Break
}
Case 3://Roaming
{
Mapmain.pan ();
Break
}
Case 5://Point Selection
{
Break
}
Case 6://Distance
{
Mapobjects2.points pts;
pts = (mapobjects2.points) mapmain.trackline (). Parts.item (0);
Double ddistance = 0;
for (int i=0;i<pts. count-1;i++)
{
Ddistance + = Math.sqrt (pts. Item (i). X*pts. Item (i). X + pts. Item (i). Y*pts. Item (i). Y);
}
This. Text = Mapmain.tomapdistance ((float) ddistance). ToString ();
Break
}
Case 7://Area
{
Mapobjects2.polygon ply = Mapmain.trackpolygon ();
Double Darea = ply. area;
This. Text = Mapmain.tomapdistance ((float) darea). ToString ();
Break
}
default://Arrow
{
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moDefault;
Break
}
}
}
<summary>
Point selection
</summary>
private void Miselectbypoint_click (object sender, System.EventArgs e)
{
This. Curoperate = 5;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moArrowQuestion;
}
<summary>
Distance
</summary>
private void Midistance_click (object sender, System.EventArgs e)
{
This. Curoperate = 6;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moCross;
}
<summary>
Area
</summary>
private void Miarea_click (object sender, System.EventArgs e)
{
This. Curoperate = 7;
Mapmain.mousepointer = MapObjects2.MousePointerConstants.moCross;
}
}
}