Application of MapObjects2.2 in C # (Basic Map Features)
Keywords: mapobjects 2.2 C #
Only enlarged, narrow, roaming, full diagram, distance, area and other functions.
/ *
* Yang Yuditian 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
{
///
/// Handling instance
/// summary>
Public Class frmmain: System.Windows.Forms.form
{
Private axMapObjects2.axmap mapmain
Private system.windows.Forms.mainMenu mainmentu1;
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 miaarea;
///
/// The required designer variable.
/// summary>
Private system.componentmodel.Container Components = NULL;
Public frmmain ()
{
//
// Windows Form Designer Support
//
InitializationComponent ();
}
///
/// Clean all the resources being used.
/// summary>
Protected Override Void Dispose (Bool Disposing)
{
IF (Disposing)
{
IF (Components! = NULL)
{
Components.dispose ();
}
}
Base.dispose (Disposing);
}
#Region Windows Form Designer Generated Code
///
/// Designer supports the required method - do not use the code editor to modify
/// This method is content.
/// summary>
Private vidinitiRizeComponent ()
{
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 ();
THISELECTBYPOINT = new system.windows.Forms.MenuItem ();
THIS.MIDISTANCE = New System.windows.Forms.MenuItem ();
This.miaarea = 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) ("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.MIZOOMOMOUT,
THIS.MIPAN,
this.mifullview,
this.MiselectrbyPoint,
this.miDistance,
THIS.MIAREA});
//
// mizoomin
//
this.mizoomin.index = 0;
This.Mizoomin.Text = "Zoom";
THIS.MIZOOMIN.CLICK = New System.EventHandler (this.Mizoomin_Click);
//
// mizoomout
//
this.Mizoomout.index = 1;
This.Mizoomout.text = "Reduce";
This.Mizoomout.click = new system.eventhandler (this.mizoomout_click);
//
//Mipan
//
THIS.MIPAN.INDEX = 2;
THIS.MIPAN.TEXT = "Roam";
THIS.MIPAN.CLICK = New System.EventHandler (this.Mipan_Click);
//
// mifullview
//
THIS.MIFULLVIEW.INDEX = 3;
THIS.MIFULLVIEW.TEXT = "full map"; this.mifullview.click = new system.eventhandler (this.mifullview_click);
//
// MiselectrByPoint
//
THIS.MISElectrByPoint.index = 4;
this.MiselectrbyPoint.text = "Click";
This.MiselectrbyPoint.Click = New System.EventHandler (this.miselectrbyPoint_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.miaarea.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);
}
#ndregion
///
/// The main entry point for the application.
/// summary>
[Stathread]
Static void main ()
{
Application.run (new frmmain ());
}
///
/// full image
/// summary>
Private Void MifullView_Click (Object Sender, System.Eventargs E)
{
THIS.CUROPERATE = 4;
MapMain.extent = MapMain.fullextent;
MapMain.mousepointer = mapObjects2.mousepointerConstants.modefault;
}
///
/// roaming
/// summary>
Private void Mipan_Click (Object Sender, System.EventArgs E)
{
THIS.CUROPERATE = 3;
MapMain.mousepointer = mapObjects2.mousepointerConstants.mopan
}
///
/// summary>
Private void Mizoomout_Click (Object Sender, System.EventArgs E)
{
THIS.CUROPERATE = 2;
MapMain.mousepointer = mapObjects2.mousepointerConstants.mozoomout;
}
///
/// Zoom
/// summary>
Private vid mizoomin_click (Object Sender, System.Eventargs E)
{
this.curoperate = 1;
MapMain.mousepointer = mapObjects2.mousepointerConstants.mozoomin
}
///
/// Zoom in reduction
/// 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 click on cancellation
Switch (this.curoperate)
{
Case 1: // Zoom
{
Rect = MapMain.trackRectangle ();
IF (Rect == Null || (Rect.width <0.00005) || (Rect.Height <0.00005))
{
RECT = MapMain.extent;
Rect.scalencelectrangle (0.6667);
Rect.offset (- (Rect.center.x - pt.x), - (Rect.center.y - pt.y));
}
MapMain.extent = Rect;
Break;
}
Case 2: // Reduce
{
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: // Roam
{
MapMain.pan ();
Break;
}
Case 5: // click
{
Break;
}
Case 6: // Distance
{
MapObjects2.Points PTS;
PTS = (MapObjects2.Points) MapMain.trackline (). Parts.Item (0);
Double ddistance = 0;
For (INT i = 0; 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; } } } /// // / click /// summary> Private Void MiselectrByPoint_Click (Object Sender, System.Eventargs E) { THIS.CUROPERATE = 5; MapMain.MousePointer = mapObjects2.mousepointerConstants.moarrowquest; } /// /// Distance /// summary> Private void midistance_click (Object Sender, System.Eventargs E) { THIS.CUROPERATE = 6; MapMain.mousepointer = mapObjects2.mousepointerconstants.mocross; } /// /// area /// summary> Private void Miarea_Click (Object Sender, System.EventArgs E) { THIS.CUROPERATE = 7; MapMain.mousepointer = mapObjects2.mousepointerconstants.mocross; } } }