Application of MAPX Control in C # (1)
Keywords: Mapx, C #, Net, ActiveX control
/ *
* In this code, we applied the MAPX control to combine the oldest map.
* Map browsing feature: zoom in, shrink, drag, full image, measurement distance, measurement area.
*
* Yang Yutian yangyutian@hotmail.com
* / using system;
Using system.drawing;
Using system.collections;
Using system.componentmodel;
Using system.windows.forms;
Using system.data;
Namespace WA
{
Public Class frmmain: System.Windows.Forms.form
{
Private axmapxlib.axmap mapMain;
Private Double Mapzoom;
PRIVATE DOUBLE CENTERX;
PRIVATE DOUBLE CENTERY;
Private system.windows.Forms.statusbar sbmain;
Private system.windows.Forms.mainMenu mainmenu;
Private system.windows.Forms.MenuItem MIMAP;
Private system.windows.Forms.MenuItem Mimaptoolzoomin
Private system.windows.Forms.MenuItem mimaptoolzoomout;
Private system.windows.Forms.MenuItem mimaptoolpan
Private system.windows.Forms.MenuItem mimaptoolrestore;
Private system.windows.Forms.MenuItem mimaptooldistance;
Private system.windows.Forms.MenuItem mimaptoolarea;
Private system.windows.Forms.MenuItem mimaptool;
Private system.componentmodel.Container Components = NULL;
Public frmmain ()
{
InitializationComponent ();
}
Protected Override Void Dispose (Bool Disposing)
{
//slightly
}
#Region Windows Form Designer Generated Code
Private vidinitiRizeComponent ()
{
//slightly
}
#ndregion
[Stathread]
Static void main ()
{
Application.run (New Form1 ());
}
Private void mapmain_polytoolused (Object sender, axmapxlib.cmapxevents_polytoolusedEvent E)
{
IF (e.toolnum == 99) // Measure distance
{
Mapxlib.points PTS = (MapxLib.Points) E.POINTS;
Mapxlib.Point PT1, PT2;
Double D = 0.0;
/ / Calculate the order of two points, accumulated to get the total distance
For (INT i = 1; i { Pt1 = PTS.Item (i); PT2 = PTS.Item (i 1); D = MapMain.distance (pt1.x, pt1.y, pt2.x, pt2.y);} SBMain.Text = "Distance:" D.toString (); } Else IF (e.toolnum == 98) // area { Mapxlib.points PTS = (MapxLib.Points) E.POINTS; // is lazy but it is correct Mapxlib.featurefactory DD = MapMain.FeatureFactory; Mapxlib.Style Style = MapMain.defaultStyle; SBMain.Text = "Area:" DD.createRegion (PTS, Style) .Are.toString (); } } Private Void Mimaptoolzoomin_Click (Object Sender, System.Eventargs E) { //enlarge MapMain.currentTool = Mapxlib.ToolConstants.Mizoomintool; } Private Void Mimaptoolzoomout_Click (Object Sender, System.EventArgs E) { / / Reduce MapMain.currentTool = Mapxlib.ToolConstants.MizoomoutTool; } Private Void Mimaptoolpan_Click (Object Sender, System.EventArgs E) { //drag MapMain.currentTool = MapxLib.ToolConstants.Mipantool; } Private Void MimaptoolRestore_Click (Object Sender, System.EventArgs E) { / / Zoom to the initial size (full map) MapMain.Zoomto (this.mapzoom, this.centerx, this.centery); } Private void MimaptoolDistance_Click (Object Sender, System.Eventargs E) { // Measure distance MapMain.currentTool = (MapxLib.ToolConstants) 99; } Private Void Mimaptoolarea_Click (Object Sender, System.EventArgs E) { // Measuring area MapMain.currentTool = (MapxLib.ToolConstants) 98; } Private void frmmain_load (Object Sender, System.EventArgs E) { // Record the proportion of maps in the map THIS.MAPZOOM = MapMain.zoom; this.centerx = MapMain.centerx; THIS.CENTERY = MapMain.Centery; // Create a tool for measuring distance mapMain.CreateCustomTool (99, (short) MapXLib.ToolTypeConstants.miToolTypePoly, MapXLib.CursorConstants.miCrossCursor, MapXLib.CursorConstants.miCrossCursor, MapXLib.CursorConstants.miCrossCursor, false); // Create a tool for measurement area mapMain.CreateCustomTool (98, (short) MapXLib.ToolTypeConstants.miToolTypePolygon, MapXLib.CursorConstants.miCrossCursor, MapXLib.CursorConstants.miCrossCursor, MapXLib.CursorConstants.miCrossCursor, false);} } }