Apply MapObjects in C # (rendering)
Summary: MapObjects C # Rendering Special Map
Author: Yang Yutian Blue_Bat@126.Com
I used Mapx before, there is a special picture, it is very good. After a few days of trial, I tried various rendering effects in MapObjects (similar to the MapX feature map, but not the same), with the source code, if you don't understand, please ponder it yourself, haha ...
code show as below:
Using system;
Using system.drawing;
Using system.collections;
Using system.componentmodel;
Using system.windows.forms;
Using system.data;
Namespace Dbinmo
{
///
/// Form1 summary description.
/// summary>
Public class rendering example: System.Windows.Forms.form
{
Private AxmapObjects2.axmap Map;
Private system.windows.Forms.Button histogram;
Private system.windows.Forms.Button pie chart;
Private system.windows.Forms.Button point density;
Private system.windows.Forms.Button is rendered by value;
Private system.windows.Forms.Button classification rendering;
Private system.windows.Forms.Button z value rendering;
Private system.windows.Forms.Button group rendering;
Private system.windows.Forms.Button exits;
Private system.windows.Forms.Panel Operatorboard;
Private system.windows.Forms.Button deletes all rendering;
Private system.windows.Forms.Panel Panel1;
Private system.windows.Forms.Button full image;
Private system.windows.Forms.Button drag;
Private system.windows.Forms.Button reduced;
Private system.windows.Forms.Button amplified;
Private system.windows.Forms.Panel separator;
Private system.windows.Forms.Button labeling;
///
/// The required designer variable.
/// summary>
Private system.componentmodel.Container Components = NULL;
PUBLIC rendering example ()
{
//
// Windows Form Designer Support
//
InitializationComponent ();
//
// Todo: Add any constructor code after INITIALIZECOMPONENT call
//
}
///
/// 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);
THIS.MAP = New AxmapObjects2.axmap ();
THIS. Operation board = new system.windows.Forms.Panel ();
That. Template = New System.Windows.Forms.Button ();
This. Pie Chart = New System.windows.Forms.Button ();
THIS. Point density = new system.windows.Forms.Button ();
THIS. Press value rendering = new system.windows.Forms.Button ();
Classification Rendering = New System.Windows.Forms.Button ();
THIS.Z value rendering = new system.windows.forms.button ();
Group Rendering = New System.Windows.Forms.Button ();
THIS. Exit = new system.windows.Forms.Button ();
THIS. Note Rendering = New System.Windows.Forms.Button ();
Remove all rendering = new system.windows.Forms.Button ();
This.Panel1 = new system.windows.Forms.Panel ();
THIS. full picture = new system.windows.Forms.Button ();
Drag = New System.Windows.Forms.Button ();
Regeneration = new system.windows.Forms.Button ();
Zoom in zoom = new system.windows.Forms.Button ();
Separator = new system.windows.Forms.Panel ();
(System.comPonentModel.isupportInitialize) (this.map)). Begininit ();
THIS. Operation board. Suspendlayout ();
THIS.SUSPENDLAYOUT ();
//
// map
//
This.map.dock = system.windows.Forms.dockStyle.Fill;
this.map.location = new system.drawing.point (0, 0);
this.map.name = "map";
THIS.Map.ocxState = ((System.Windows.Forms.Axhost.State))))));
This.map.size = new system.drawing.size (616, 429);
THIS.MAP.TABINDEX = 0;
THIS.MAP.MOUSEDOWNEVENT = New AxmapObjects2._dmapevents_mousedowneventhandler (this.map_mousedownevent); //
// Operation board
//
THIS. Operation board. BorderStyle = system.windows.Forms.Borderstyle.fixed3d;
THIS. Operator. Controls.add (this. Delete all rendering);
THIS. Operation board. TROLS.ADD (this.Panel1);
THIS. Operation board. Trols.add (this. full map);
THIS. Operation board. Trols.add (this. Drag);
THIS. Operation board. Trols.add (this. reduction);
THIS. Operation board. Trols.add (this. Zoom);
THIS. Operator. Controls.Add (this. Split);
THIS. Operation board. Trols.add (this. Task rendering);
THIS. Operation board. Trols.add (this. Exit);
THIS. Operation board. Trols.add (this. group rendering);
THIS. Operation board .controls.add (this.z value rendering);
THIS. Operation board .controls.add (this. Classified rendering);
THIS. Operation board. Trols.add (this. Rendering by value);
THIS. Operation board. TROTROLS.ADD (this. point density);
THIS. Operation board .controls.add (this. Pie chart);
THIS. Operation board .controls.add (this. histogram);
THIS. Operator .DOCK = system.windows.forms.dockstyle.right;
THIS. Operation board .Location = new system.drawing.point (496, 0);
THIS. Operation board .Name = "Operator";
THIS. Operation board .size = new system.drawing.size (120, 429);
THIS. Operation board. TabINDEX = 1;
//
// histogram
//
That. Template .DOCK = system.windows.forms.dockstyle.top;
THIS. Template. Location = new system.drawing.point (0, 0);
THIS. Template .Name = "histogram";
That. Tempique. Size = new system.drawing.size (116, 24);
THIS. Template. TabINDEX = 0;
THIS. Template .Text = "Trenaogram";
THIS. Template. Click = New System.EventHandler (this. Temporary diagram _click);
//
// Pie
//
This. Pie. Dock = system.windows.forms.dockstyle.top;
This. Pie. Location = New System.drawing.Point (0, 24);
This. Pie .Name = "Pie Chart";
This. Pie Chart .size = new system.drawing.size (116, 24);
This. Pie chart. TabINDEX = 1;
This. Pie. TEXT = "Pie Chart";
This. Pie Chart. Click = New System.EventHandler (this. Pie Diagram _Click);
//
// point density
//
THIS. Distance .DOCK = system.windows.Forms.dockStyle.top; this. Point density .Location = new system.drawing.point (0, 48);
THIS. Point density .Name = "point density";
THIS. Point density. Size = new system.drawing.size (116, 23);
THIS. Point density. TabINDEX = 2;
THIS. Point density .Text = "point density";
THIS. Point density. Click = New System.EventHandler (this. point density _Click);
//
/ / Rendering
//
Rendering. Dock = system.windows.Forms.dockStyle.top;
THIS. Rendering. Location = New System.drawing.Point (0, 71);
THIS. Press value rendering .Name = "Rendering by value";
THIS. Rendering .Size = new system.drawing.size (116, 23);
THIS. Rendering. TabINDEX = 3;
THIS. Rendering .Text = "Rendering by Value";
Rendering. Click = New System.EventHandler (this. - Clickclick);
//
// Classification rendering
//
Classification Rendering.Dock = system.windows.forms.dockstyle.top;
THIS. Classification Rendering .Location = New System.drawing.Point (0, 94);
Classification Rendering .Name = "Classification Rendering";
Classification Rendering .Size = new system.drawing.size (116, 23);
THIS. Classification Rendering. TabINDEX = 4;
THIS. Classification Rendering .Text = "Classification Rendering";
Classification Rendering. Click = New System.EventHandler (this. Classification Rendering_Click);
//
// Z value rendering
//
THIS.Z value rendering.dock = system.windows.forms.dockstyle.top;
THIS.Z value rendering .Location = new system.drawing.point (0, 117);
THIS.Z value rendering .Name = "z value rendering";
This.z value rendered .size = new system.drawing.size (116, 23);
THIS.Z value rendering.tabindex = 5;
THIS.Z value rendering .Text = "z value rendering";
THIS.Z value rendering.Click = new system.eventhandler (this.z value rendering _click);
//
// group rendering
//
Group. Group rendering.dock = system.windows.forms.dockstyle.top;
Group. Group rendering .Location = new system.drawing.point (0, 140);
Group. Group rendering .Name = "group rendering";
Group. Group rendered .size = new system.drawing.size (116, 23);
THIS. Group rendering. TabINDEX = 6;
Group. Group rendering .Text = "Group rendered";
Group. Set. Click = New System.EventHandler (this. group rendering _click); //
// drop out
//
THIS. Exit .dock = System.Windows.Forms.dockStyle.bottom;
THIS. Exit .Location = New System.drawing.Point (0, 402);
THIS. Exit .Name = "Exit";
THIS. Exit .size = new system.drawing.size (116, 23);
THIS. Exit .tabindex = 7;
THIS. Exit .Text = "Exit";
THIS. Exit .Click = New System.EventHandler (this. Exit _Click);
//
/ / Labeling rendering
//
THIS. Target Rendering.dock = System.windows.Forms.dockStyle.top;
THIS. Label rendering .Location = new system.drawing.point (0, 163);
THIS. Note rendering .Name = "Label Rendering";
THIS. Note rendering .size = new system.drawing.size (116, 23);
THIS. Tagging. TabINDEX = 7;
THIS. Target rendering .Text = "Label Rendering";
THIS. Logging. Click = New System.EventHandler (this. Target Rendering_Click);
//
/ / Delete all rendering
//
Remove all rendering.dock = system.windows.Forms.dockStyle.top;
Remove all rendering .Location = new system.drawing.point (0, 319);
Remove all rendering .Name = "Delete all rendering";
THIS. Delete all rendering.size = new system.drawing.size (116, 23);
THIS. Delete all rendering. TabINDEX = 22;
Remove all rendering .Text = "Delete all rendering";
Remove all rendering .Click = new system.eventhandler (this. Delete all rendering _click);
//
// panel1
//
This.Panel1.dock = system.windows.Forms.dockStyle.top;
This.Panel1.Location = new system.drawing.point (0, 299);
this.Panel1.name = "panel1";
This.Panel1.size = new system.drawing.size (116, 20);
this.Panel1.tabindex = 21;
//
// full image
//
Full picture .DOCK = system.windows.forms.dockstyle.top;
THIS. Full picture. Location = new system.drawing.point (0, 276);
THIS. full map .Name = "full map";
THIS. full map .size = new system.drawing.size (116, 23);
THIS. full map. Tabindex = 20;
THIS. full map .Text = "full map";
THIS. full map. Click = new system.eventhandler (this. full picture _click); //
// Drag
//
Drag. Dock .DOCK = system.windows.forms.dockstyle.top;
Drag. Location = New System.drawing.Point (0, 253);
Drag .Name = "Drag";
THIS. Drag .size = new system.drawing.size (116, 23);
THIS. Drag. Tabindex = 19;
Drag .Text = "Drag";
Drag. Click = New System.EventHandler (this. Drag_click);
//
/ / Reduce
//
Zoom. Dock .DOCK = system.windows.forms.dockstyle.top;
THIS. Reduce .Location = New System.drawing.Point (0, 230);
Regeneration .Name = "Reduces";
Zoom. Size = new system.drawing.size (116, 23);
Zoom. Tabindex = 18;
THIS. Reduce .Text = "Reduce";
Zoom. Click = New System.EventHandler (this. Reduces _Click);
//
// Zoom
//
Zoom in .DOCK = System.Windows.Forms.dockStyle.top;
Zoom in. Location = New System.drawing.Point (0, 207);
Zoom in .Name = "Zoom";
Zoom in .size = new system.drawing.size (116, 23);
Zoom in. TabINDEX = 17;
Zoom in .Text = "Zoom";
Zoom in. Click = New System.EventHandler (this. zoom _Click);
//
// Derivator
//
Separator.dock = system.windows.forms.dockstyle.top;
Separator .Location = new system.drawing.point (0, 186);
Separator .Name = "Deliver";
Separator .size = new system.drawing.size (116, 21);
Separator. TabINDEX = 16;
//
// Rendering
//
THIS.AUTOSCALEBASESIZE = New System.drawing.size (6, 14);
THIS.CLIENTSIZE = New System.drawing.size (616, 429);
This.Controls.add (this. operating board);
This.Controls.add (this.map);
this.name = "Rendering Case";
This.Text = "Render Demand";
This.WindowsTate = system.windows.forms.formwindowsTate.maximized;
(System.comPonentModel.isupportInitialize) (this.map)). Endinit (); this. Operatorboard .ResumeLayout (false);
This.ResumeLayout (false);
}
#ndregion
///
/// The main entry point for the application.
/// summary>
[Stathread]
Static void main ()
{
Application.run (New Rendering Example ());
}
///
/// Exit system
/// summary>
Private Void Exit_Click (Object Sender, System.Eventargs E)
{
THIS.CLOSE ();
}
///
/// Chart rendering, value square diagram
/// summary>
Private void histogram _click (Object Sender, System.Eventargs E)
{
// Use the Lakers layer in the example of the histogram
//
/ / Define icons rendering variables
MapObjects2.Chartrenderer cr = new mapObjects2.ChartrendererClass ();
// Set the rendering type as a histogram
Cr.ChartType = mapObjects2.ChartTypeConstants.mobar;
// Set the number of fields displayed in the histogram to be two, that is, the histogram shows two columns
Cr.fieldcount = 2;
/ / Set the first field, please see Lakes.dbf
Cr.set_field (0, "Surf_elev");
/ / Set the column color of this histogram to red
Cr.set_color (0, (uint) mapobjects2.colorconstants.mored;
// Set the second column
Cr.set_field (1, "depth");
Cr.set_color (1, (uint) mapObjects2.colorconstants.mogreen;
MapObjects2.maplayer lyr = (mapo.layers.Item ("Lakes"));
Lyr.renderer = Cr;
// Use refresh () to refresh the old and refresh, no way. . . , Set to the full picture is good, ^ _ ^
Map.refresh ();
}
///
/// full map vision
/// summary>
Private void full picture _Click (Object Sender, System.Eventargs E)
{
Map.extent = map.fullextent;
}
///
/// Drag, only set icon
/// summary>
Private void Drag_click (Object Sender, System.EventArgs E)
{
Map.mousepointer = mapObjects2.mousepointerConstants.mopan
}
///
/// shrink, set only icon
/// summary>
Private Void reduced _Click (Object Sender, System.Eventargs E)
{
Map.MousePointer = mapObjects2.mousepointerconstants.mozoomout;
///
/// Enlarge, only icon
/// summary>
Private void zoom in _Click (Object Sender, System.EventArgs E)
{
Map.MousePointer = mapObjects2.mousepointerConstants.mozoomin
}
///
/// The mouse presses the time to process the map to zoom in, narrow, drag, etc.
/// summary>
PRIVATE VOID MAP_MOUSEDOWNEVENT (Object Sender, AxmapObjects2._dmapevents_mousedownevent e)
{
MapObjects2.Rectangle Rect;
MapObjects2.Point Pt = Map.TomAppoint (E.x, E.Y);
IF (E.Button == 2) / / Right click Cancel
{
Map.mousepointer = mapObjects2.mousepointerConstants.modefault;
}
IF (map.mousepointer == mapObjects2.mousepointerconstants.mopan) // drag
{
Map.pan ();
}
Else if (map.mousepointer == mapobjects2.mousepointerconstants.mozoomin) / / zoom
{
Rect = map.trackRectangle ();
IF (Rect == Null || (Rect.width <0.00005) || (Rect.Height <0.00005))
{
Rect = map.extent;
Rect.scalencelectrangle (0.6667);
Rect.offset (- (Rect.center.x - pt.x), - (Rect.center.y - pt.y));
}
Map.extent = Rect;
}
Else if (map.mousepointer == mapObjects2.mousepointerconstants.mozoomout) / / reduce
{
Rect = map.trackRectangle ();
IF ((NULL == Rect) || (Rect.Width <0.00005) || (Rect.Height <0.00005))
{
Rect = map.extent;
Rect.scalerectangle (1.5);
Rect.offset (- (Rect.center.x - pt.x), - (Rect.center.y - pt.y));
}
Else
{
Double Drate = Map.Extent.width / Rect.width * 10;
Rect.scalerectangle (DRATE);
}
Map.extent = Rect;
}
}
///
/// Chart rendering, use pie chart
/// summary>
Private void pie chart_click (Object Sender, System.Eventargs E)
{
/ 图 图 例 图 图
// Process is the same as the histogram
//
/ / Define icons rendering variables
MapObjects2.Chartrenderer cr = new mapObjects2.ChartrendererClass (); // Setting the rendering type as a pie chart
Cr.ChartType = mapObjects2.ChartTypeConstants.mopie;
// Set the number of fields displayed by the pie chart to two, that is, the pie chart shows two halves.
Cr.fieldcount = 2;
/ / Set the first field, please see Lakes.dbf
Cr.set_field (0, "Surf_elev");
// Set half of the color of this pie chart for red
Cr.set_color (0, (uint) mapobjects2.colorconstants.mored;
// Set the second half
Cr.set_field (1, "depth");
Cr.set_color (1, (uint) mapObjects2.colorconstants.mogreen;
// Add to the map
MapObjects2.maplayer lyr = (mapo.layers.Item ("Lakes"));
Lyr.renderer = Cr;
// Refresh
Map.refresh ();
}
///
//-point density rendering
/// summary>
Private Void Point Density_Click (Object Sender, System.Eventargs E)
{
// Point density example uses Lakes layer
//
/ / Define point density rendering variables
MapObjects2.dotndensityRectERER DDR = New mapObjects2.dotdensityRendererClass ();
// Set the rendered data field, please see Lakes.dbf
DDR.field = "depth";
// point size
DDR.DOTSIZE = 3;
// point color
DDR.DOTCOLOR = (uint) mapobjects2.colorconstants.moblue;
DDR.DOTVALUE = 1;
DDR.DRAWBACKGROUND = TRUE;
// Add to the map
MapObjects2.maplayer lyr = (mapo.layers.Item ("Lakes"));
lyr.renderer = ddr;
// Refresh
Map.refresh ();
}
///
/// Rendering
/// summary>
Private Void Press value rendering _Click (Object Sender, System.EventArgs E)
{
// Use the country layer in the example of value rendering, where the value rendering is used, and each country is displayed in different colors.
//
// String S variable, very like TstringList in Delphi, ^ _ ^
MapObjects2.strings strs = new mapObjects2.stringsclass ();
// Layer variable, reference country layer
MapObjects2.maplayer lyr = (mapObjects2.maplayer) map.layers.Item ("country");
// Recordset object, I will explain the contents of using dataset variables in MapObjects 2.2 in future articles! ! !
// How to use is almost similar to the operation of the data table in VB.
MaPObjects2.RecordSet rc = lyr.records; // This loop gets a list of abbreviated codes in all countries
While (! rc.eof)
{
strs.add (rc.fields.Item ("FIPS_CODE"). ValueAsstring;
Rc.MoveNext ();
}
/ / Define the value rendering object
MapObjects2.valuemaprenderer vmr = new mapObjects2.valuemaPrendERCLASS ();
// Add it to the layer
lyr.renderer = VMR;
/ / Set the field used by rendering, please see Country.dbf files
vmr.field = "fips_code";
// Number of rendered
VMR.Valuecount = strs.count;
/ / Default
VMr.USEDEFAULT = TRUE;
MapObjects2.Symbol Sym = VMR.DEFAULTSYMBOL;
Sym.color = (uint) mapobjects2.colorconstants.moyellow; / / The default color is yellow
// Rendering process
For (int i = 0; i { VMR.SET_VALUE ((Short) i, strs.Item ((Short) i)); } // Refresh Map.refresh (); } /// /// Classification rendering /// summary> Private Void Classification Rendering_Click (Object Sender, System.EventArgs E) { // Classified rendering examples of country layers // // Layer variable reference Cities layer MapObjects2.maplayer lyr = (MapObjects2.maplayer) ("cities"); // Define the classification rendering variable MapObjects2.classbreaksrenderer CBR = new mapObjects2.classbreaksrendererclass (); // Add to the map Lyr.renderer = CBR; // Set the symbol type as point, you can also use other types, please test your own test, the method is probably almost Cbr.symboltype = mapobjects2.symboltypeconstants.mopointsymbol; // Set the field, please see the cities.dbf file CBR.field = "population"; // statistics objects often cooperate with classification rendering, he means a CalculateStatistics method with a Recordset object // Statistical calculation of a numeric field MapObjects2.statistics stat = lyr.records.calculatestatistics ("population"); // mean - average, STDDEV - average difference Double fbv = stat.mean - (stat.stddev * 3); For (int i = 0; i <6; i ) { IF ((FBV> = stat.min) && fbv <= stat.max) { // Category number, add one Cbr.breakcount = (short) (CBR.BREAKCOUNT 1); // Set classification Cbr.Set_Break ((Short) (CBR.BREAKCOUNT - 1), FBV); FBV = stat.stddev; } // SiZESYMBOLS method The size of the head tail is used to express point feature size gradual effect Cbr.Sizesymbols (3, 8); // rampcolors method Set color from white to red gradual display Cbr.rampcolors ((uint) mapobjects2.colorconstants.mowhite, (uint) mapobjects2.colorconstants.mored; // Refresh Map.refresh (); } /// /// z value rendering /// summary> Private vid z value rendering _ Click (Object Sender, System.EventArgs E) { // I would like to do it well, but I can't find a map with Z value, haha, I recognize it, the basic statement is given below, interested // Brothers and sisters can try themselves // mapObjects2.zrenderer Zr = new mapObjects2.zrendereClass (); / / / Z value is divided into several parts? // Zr.breakcount = 2; // / / Set the boundary line of each part // Zr.SET_BREAK (0,100); // Zr.SET_BREAK (1,1000); // // Set the feature type // Zr.symboltype = mapObjects2.SymboltypeConstants.mopointsymbol; // MapObjects2.symbol SYM; // for (Short I = 0; i // { // // Get characteristics // SYM = Zr.get_symbol (i); // // Set the feature property to define a color array, set different characteristics to different colors, and the effect will be obvious // sym.color = (uint) mapObjects2.colorconstants.mored; // sym.size = 6; // sym.style = mapObjects2.markerStyleconstants.motriangleMarker; //} // / / Add to map //MapObjects2.maplayer = (MapObjects2.maplayer) map.layers.Item ("Layer Name with Z Value"); // iyr.renderer = Zr; // / Refresh // map.refresh (); } /// /// group rendering /// summary> Private void group rendering _Click (Object Sender, System.Eventargs E) { / (Group rendering is actually combined rendering, generally defining multiple rendering methods, then use the following statement to combine MaPObjects2.maplayer lyr = (mapObjects2.maplayer) map.layers.Item ("country"); // Task Rendering MapObjects2.Labelrenderer lr = new mapibjects2.labelrendrerclass (); Lr.field = "name"; Lr.get_symbol (0) .Color = (uint) mapObjects2.colorconstants.moblack Lr.get_symbol (0) .font.size = 8; / / Rendering MapObjects2.strings strs = new mapObjects2.stringsclass (); MapObjects2.Recordset rc = lyr.records; While (! rc.eof) { strs.add (rc.fields.Item ("FIPS_CODE"). ValueAsstring; Rc.MoveNext (); } MapObjects2.valuemaprenderer vmr = new mapObjects2.valuemaPrendERCLASS (); vmr.field = "fips_code"; VMR.Valuecount = strs.count; VMr.USEDEFAULT = TRUE; MapObjects2.Symbol Sym = VMR.DEFAULTSYMBOL; Sym.color = (uint) mapobjects2.colorconstants.moyellow; For (int i = 0; i { VMR.SET_VALUE ((Short) i, strs.Item ((Short) i)); } // combine the two to the layer MapObjects2.grouprenderer gr = new mapObjects2.groupRendererClass (); Gr.Add (VMR); Gr.Add (LR); lyr.renderer = gr; Map.refresh (); } /// /// Remove all rendering /// summary> Private void Deletes all rendering _Click (Object Sender, System.Eventargs E) { MapObjects2.maplayer lyr; For (int i = 0; i { Lyr = (MapObjects2.maplayer) map.layers.Item (i); lyr.renderer = new mapObjects2.labelrendererclass (); Map.refresh (); } } /// /// Tagging /// summary> Private Void Number Rendering_Click (Object Sender, System.Eventargs E) { MapObjects2.maplayer Lyr = (MapObjects2.maplayer) map.layers.Item ("cities"); MapObjects2.Labelrenderer lr = new mapibjects2.labelrendrerclass (); Lr.field = "name"; Lr.get_symbol (0) .Color = (uint) mapobjects2.colorconstants.moblack; lr.get_symbol (0) .font.size = 8; lyr.renderer = lr; Map.refresh (); } } } Yang Yuditian Blue_Bat@126.com August 11, 2004