C#+mo implement some rendering functions _c# tutorial
Last Update:2017-01-18
Source: Internet
Author: User
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Namespace Dbinmo
{
<summary>
Summary description of the Form1.
</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 are 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 exit;
Private System.Windows.Forms.Panel Operation board;
Private System.Windows.Forms.Button Delete all rendering;
Private System.Windows.Forms.Panel Panel1;
Private System.Windows.Forms.Button full picture;
Private System.Windows.Forms.Button drag;
Private System.Windows.Forms.Button shrink;
Private System.Windows.Forms.Button amplification;
Private System.Windows.Forms.Panel separator;
private System.Windows.Forms.Button annotation rendering;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;
Public Render Example ()
{
//
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 (Rendering sample));
This.map = new Axmapobjects2.axmap ();
this. Operator board = new System.Windows.Forms.Panel ();
this. Histogram = new System.Windows.Forms.Button ();
this. Pie chart = new System.Windows.Forms.Button ();
this. Dot density = new System.Windows.Forms.Button ();
this. Render by value = new System.Windows.Forms.Button ();
this. Classification rendering = new System.Windows.Forms.Button ();
This. Z-Value rendering = new System.Windows.Forms.Button ();
this. Group rendering = new System.Windows.Forms.Button ();
this. Exit = new System.Windows.Forms.Button ();
this. Callout rendering = new System.Windows.Forms.Button ();
This. Deletes all render = new System.Windows.Forms.Button ();
This.panel1 = new System.Windows.Forms.Panel ();
this. Whole picture = new System.Windows.Forms.Button ();
this. Drag = new System.Windows.Forms.Button ();
this. Narrows = new System.Windows.Forms.Button ();
this. Enlarge = new System.Windows.Forms.Button ();
this. 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) (resources. GetObject ("map.") OcxState "));
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 board. Controls.Add (this. Remove all rendering);
this. Operation board. Controls.Add (THIS.PANEL1);
this. Operation board. Controls.Add (this. whole picture);
this. Operator board. Controls.Add (this. drag);
this. Operation board. Controls.Add (this. shrink);
this. Operation board. Controls.Add (this. enlarge);
this. Operator board. Controls.Add (this. separator);
this. Operator board. Controls.Add (this. callout rendering);
this. Operator board. Controls.Add (this. exit);
this. Operation board. Controls.Add (this. Group rendering);
this. Operation board. Controls.Add (this. Z-value rendering);
this. Operation board. Controls.Add (this. classification rendering);
this. Operation board. Controls.Add (this. by value rendering);
this. Operator board. Controls.Add (this. Point density);
this. Operation board. Controls.Add (this. pie chart);
this. Operator board. Controls.Add (this. straight square diagram);
this. Operator board. Dock = System.Windows.Forms.DockStyle.Right;
this. Operation board. Location = new System.Drawing.Point (496, 0);
this. Operator board. Name = "Operation Board";
this. Operator board. Size = new System.Drawing.Size (120, 429);
this. Operation board. TabIndex = 1;
//
Histogram
//
this. Histogram. Dock = System.Windows.Forms.DockStyle.Top;
this. Histogram. Location = new System.Drawing.Point (0, 0);
this. Histogram. Name = "histogram";
this. Histogram. Size = new System.Drawing.Size (116, 24);
this. Histogram. TabIndex = 0;
this. Histogram. Text = "histogram";
this. Histogram. Click + + new System.EventHandler (this. histogram _click);
//
Pie chart
//
this. Pie chart. Dock = System.Windows.Forms.DockStyle.Top;
this. Pie chart. Location = new System.Drawing.Point (0, 24);
this. Pie chart. Name = pie chart;
this. Pie chart. Size = new System.Drawing.Size (116, 24);
this. Pie chart. TabIndex = 1;
this. Pie chart. Text = pie chart;
this. Pie chart. Click + + new System.EventHandler (this. pie chart _click);
//
Point density
//
this. Point density. Dock = System.Windows.Forms.DockStyle.Top;
this. Dot density. Location = new System.Drawing.Point (0, 48);
this. Dot density. Name = "point density";
this. Point density. Size = new System.Drawing.Size (116, 23);
this. Dot density. TabIndex = 2;
this. Dot density. Text = "point density";
this. Dot density. Click + + new System.EventHandler (this. Point density _click);
//
Render by value
//
this. Render by value. Dock = System.Windows.Forms.DockStyle.Top;
this. Render by value. Location = new System.Drawing.Point (0, 71);
this. Render by value. Name = "Render by value";
this. Render by value. Size = new System.Drawing.Size (116, 23);
this. Render by value. TabIndex = 3;
this. Render by value. Text = "Render by value";
this. Render by value. Click + + new System.EventHandler (this. Render _click by value);
//
Classification rendering
//
this. Classification rendering. Dock = System.Windows.Forms.DockStyle.Top;
this. Classification rendering. Location = new System.Drawing.Point (0, 94);
this. Classification rendering. Name = "Classification rendering";
this. Classification rendering. Size = new System.Drawing.Size (116, 23);
this. Classification rendering. TabIndex = 4;
this. Classification rendering. Text = "Classification rendering";
this. 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 rendering. 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
//
this. Group rendering. Dock = System.Windows.Forms.DockStyle.Top;
this. Group rendering. Location = new System.Drawing.Point (0, 140);
this. Group render. Name = "group Render";
this. Group rendering. Size = new System.Drawing.Size (116, 23);
this. Group rendering. TabIndex = 6;
this. Group rendering. Text = "group Rendering";
this. Group rendering. Click + + new System.EventHandler (this. Group renders _click);
//
Exit
//
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);
//
Callout Rendering
//
this. Callout renders. Dock = System.Windows.Forms.DockStyle.Top;
this. Callout rendering. Location = new System.Drawing.Point (0, 163);
this. Callout rendering. Name = "annotation rendering";
this. Callout rendering. Size = new System.Drawing.Size (116, 23);
this. Callout rendering. TabIndex = 7;
this. Callout renders. Text = "callout Rendering";
this. Callout rendering. Click + + new System.EventHandler (this. Callout renders _click);
//
Remove all rendering
//
this. Deletes all rendering. Dock = System.Windows.Forms.DockStyle.Top;
this. Deletes all rendering. Location = new System.Drawing.Point (0, 319);
This. Deletes all render. Name = "Delete all render";
this. Deletes all rendering. Size = new System.Drawing.Size (116, 23);
this. Deletes all rendering. TabIndex = 22;
This. Deletes all render. Text = "Delete all render";
this. Deletes all rendering. Click + + new System.EventHandler (this. Delete all render _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 picture
//
this. Full map. Dock = System.Windows.Forms.DockStyle.Top;
this. Full map. Location = new System.Drawing.Point (0, 276);
this. The whole picture. Name = "full picture";
this. Full map. Size = new System.Drawing.Size (116, 23);
this. Full map. TabIndex = 20;
this. Full picture. Text = "full picture";
this. The full picture. Click + + new System.EventHandler (this. Full picture _click);
//
Drag
//
this. drag. Dock = System.Windows.Forms.DockStyle.Top;
this. drag. Location = new System.Drawing.Point (0, 253);
this. drag. Name = "drag";
this. drag. Size = new System.Drawing.Size (116, 23);
this. drag. TabIndex = 19;
this. drag. Text = "drag";
this. Drag. Click + + new System.EventHandler (this. drag _click);
//
Narrow
//
this. Narrowing. Dock = System.Windows.Forms.DockStyle.Top;
this. Narrowing. Location = new System.Drawing.Point (0, 230);
this. Shrink. Name = "shrink";
this. Shrink. Size = new System.Drawing.Size (116, 23);
this. Shrink. TabIndex = 18;
this. Reduce. Text = "shrink";
this. Zoom out. Click + + new System.EventHandler (this. Shrink _click);
//
Amplification
//
this. Enlarge. Dock = System.Windows.Forms.DockStyle.Top;
this. Enlarge. Location = new System.Drawing.Point (0, 207);
this. Enlarge. Name = "Enlarge";
this. Enlarge. Size = new System.Drawing.Size (116, 23);
this. enlarge. TabIndex = 17;
this. Enlarge. Text = "Enlarge";
this. Zoom in. Click + + new System.EventHandler (this. enlarge _click);
//
Separator
//
this. Separator. Dock = System.Windows.Forms.DockStyle.Top;
this. Separator. Location = new System.Drawing.Point (0, 186);
this. Separator. Name = "Separator";
this. Separator. Size = new System.Drawing.Size (116, 21);
this. Separator. TabIndex = 16;
//
Rendering examples
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (616, 429);
This. Controls.Add (this. Operation board);
This. Controls.Add (THIS.MAP);
This. Name = "render Example";
This. Text = "render Example";
This. WindowState = System.Windows.Forms.FormWindowState.Maximized;
((System.ComponentModel.ISupportInitialize) (This.map)). EndInit ();
this. Operation board. ResumeLayout (FALSE);
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New rendering example ());
}
<summary>
Exit system
</summary>
private void Exit _click (object sender, System.EventArgs e)
{
This. Close ();
}
<summary>
Graph rendering, Value square chart
</summary>
private void histogram _click (object sender, System.EventArgs e)
{
The histogram example uses Lakers layers
//
Define Icon Rendering variables
Mapobjects2.chartrenderer cr = new Mapobjects2.chartrendererclass ();
Set render type to histogram
Cr. ChartType = MapObjects2.ChartTypeConstants.moBar;
Set the histogram to display the number of fields two, is the histogram display two columns
Cr. FieldCount = 2;
To set the first field, 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 a second pillar
Cr.set_field (1, "DEPTH");
Cr.set_color (1, (UINT) MapObjects2.ColorConstants.moGreen);
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) (map. Layers.item ("Lakes"));
Lyr. Renderer = CR;
Refresh by using refresh () The old is also refreshing bad, is no way ... It's a good idea to set the whole picture, ^_^
Map. Refresh ();
}
<summary>
Full picture view
</summary>
private void Full map _click (object sender, System.EventArgs e)
{
Map. Extent = map. Fullextent;
}
<summary>
Drag, set icon only
</summary>
private void drag _click (object sender, System.EventArgs e)
{
Map. MousePointer = MapObjects2.MousePointerConstants.moPan;
}
<summary>
Zoom out, just set the icon
</summary>
private void narrowing _click (object sender, System.EventArgs e)
{
Map. MousePointer = MapObjects2.MousePointerConstants.moZoomOut;
}
<summary>
Zoom in, just set the icon
</summary>
private void magnification _click (object sender, System.EventArgs e)
{
Map. MousePointer = MapObjects2.MousePointerConstants.moZoomIn;
}
<summary>
The mouse presses the time, handles the map to enlarge, reduces, drags and so on.
</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)/enlarge
{
Rect = map. Trackrectangle ();
if (rect = = null| | (Rect. Width < 0.00005) | | (Rect. Height < 0.00005))
{
Rect = map. Extent;
Rect. Scalerectangle (0.6667);
Rect. Offset (-(RECT). Center.x-pt. X),-(rect. Center.y-pt. Y));
}
Map. Extent = rect;
}
else if (map. MousePointer = = MapObjects2.MousePointerConstants.moZoomOut)/Shrink
{
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;
}
}
<summary>
Graph rendering, using pie charts
</summary>
private void Pie chart _click (object sender, System.EventArgs e)
{
Use Lakers layer in the example of pie chart
The procedure is the same as the histogram
//
Define Icon Rendering variables
Mapobjects2.chartrenderer cr = new Mapobjects2.chartrendererclass ();
To set a render type as a pie chart
Cr. ChartType = MapObjects2.ChartTypeConstants.moPie;
Set the pie chart to display a number of two fields, which is a pie chart showing two halves
Cr. FieldCount = 2;
To set the first field, see LAKES.DBF
Cr.set_field (0, "Surf_elev");
Set half the color of this pie chart to red
Cr.set_color (0, (UINT) MapObjects2.ColorConstants.moRed);
Set second half
Cr.set_field (1, "DEPTH");
Cr.set_color (1, (UINT) MapObjects2.ColorConstants.moGreen);
Add to map
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) (map. Layers.item ("Lakes"));
Lyr. Renderer = CR;
Refresh
Map. Refresh ();
}
<summary>
Dot Density rendering
</summary>
private void point density _click (object sender, System.EventArgs e)
{
Use lakes layer in the example of dot density
//
Define point density rendering variables
Mapobjects2.dotdensityrenderer DDR = new Mapobjects2.dotdensityrendererclass ();
To set the rendered data field, see LAKES.DBF
Ddr. Field = "DEPTH";
Point size
Ddr. Dotsize = 3;
Dot Color
Ddr. Dotcolor = (UINT) MapObjects2.ColorConstants.moBlue;
Ddr. Dotvalue = 1;
Ddr. Drawbackground = true;
Add to map
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) (map. Layers.item ("Lakes"));
Lyr. Renderer = DDR;
Refresh
Map. Refresh ();
}
<summary>
Render by value
</summary>
private void renders _click by value (object sender, System.EventArgs e)
{
The country layer is used in the example of value rendering, where each country is displayed in a different color using a value rendering
//
The string s variable, much like the Tstringlist in Delphi, ^_^
Mapobjects2.strings STRs = new Mapobjects2.stringsclass ();
Layer variables, referencing country layers
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) map. Layers.item ("Country");
Recordset object, which I will explain in future articles about using dataset variables in MapObjects2.2!!!
The usage method is roughly similar to the operation of the data table in VB.
Mapobjects2.recordset rc = Lyr. Records;
This loop gets the abbreviation code list for all countries
while (!RC. EOF)
{
STRs. ADD (RC. Fields.item ("Fips_code"). valueasstring);
Rc. MoveNext ();
}
Define object-by-value rendering
Mapobjects2.valuemaprenderer VMR = new Mapobjects2.valuemaprendererclass ();
Add it to a layer
Lyr. Renderer = VMR;
To set the fields used for rendering, see COUNTRY.DBF file
Vmr. Field = "Fips_code";
Number of renders
Vmr. Valuecount = STRs. Count;
Default value
Vmr. Usedefault = true;
Mapobjects2.symbol sym = VMR. Defaultsymbol;
Sym. color = (UINT) mapobjects2.colorconstants.moyellow;//default color is yellow
Rendering process
for (int I=0;I<VMR. valuecount;i++)
{
Vmr.set_value (short) i,strs. Item ((short) i));
}
Refresh
Map. Refresh ();
}
<summary>
Classification rendering
</summary>
private void Category render _click (object sender, System.EventArgs e)
{
Examples of category rendering using country layers
//
Layer Variable Reference Cities layer
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) (map. Layers.item ("Cities"));
Define a category render variable
Mapobjects2.classbreaksrenderer CBR = new Mapobjects2.classbreaksrendererclass ();
Add to map
Lyr. Renderer = CBR;
To set the symbol type to point or other type, try it yourself, probably all the same.
Cbr. Symboltype = MapObjects2.SymbolTypeConstants.moPointSymbol;
To set a field, see CITIES.DBF file
Cbr. Field = "POPULATION";
Statistics objects are often used in conjunction with category rendering, he says, using a Calculatestatistics method of a Recordset object
Statistical calculation of a numeric field
Mapobjects2.statistics stat = Lyr. Records.calculatestatistics ("POPULATION");
mean--mean, stddev--mean variance
Double FBV = Stat. Mean-(Stat. StdDev * 3);
for (int i=0;i<6;i++)
{
if (FBV >= Stat. Min) &&FBV <= Stat. MAX)
{
The number of categories, in turn, add a
Cbr. Breakcount = (short) (CBR. Breakcount + 1);
Set up Categories
Cbr.set_break (short) (CBR. BreakCount-1), FBV);
}
FBV + = Stat. StdDev;
}
Sizesymbols method to set the size of the tail to show the point feature size progressive effect
Cbr. Sizesymbols (3,8);
Rampcolors method sets the progressive display of colors from white to red
Cbr. Rampcolors ((UINT) MapObjects2.ColorConstants.moWhite, (UINT) MapObjects2.ColorConstants.moRed);
Refresh
Map. Refresh ();
}
<summary>
Z-Value Rendering
</summary>
private void Z-Value rendering _click (object sender, System.EventArgs e)
{
Originally wanted to do a good job, but I can not find a map with z value, haha, recognized it, the following gives the basic statement, interested in
Brothers and sisters, they can try it on their own.
Mapobjects2.zrenderer ZR = new Mapobjects2.zrendererclass ();
What is the z value divided into several parts?
Zr. Breakcount = 2;
Set the boundaries of each section
Zr.set_break (0,100);
Zr.set_break (1,1000);
Set feature types
Zr. Symboltype = MapObjects2.SymbolTypeConstants.moPointSymbol;
Mapobjects2.symbol sym;
for (short I=0;I<ZR. breakcount;i++)
// {
Get features
Sym = Zr.get_symbol (i);
Setting a feature property, defining an array of colors, and setting different colors differently will make the effect more obvious.
Sym. Color = (UINT) MapObjects2.ColorConstants.moRed;
Sym. Size = 6;
Sym. Style = MapObjects2.MarkerStyleConstants.moTriangleMarker;
// }
Add to map
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) map. Layers.item ("Layer name with Z value");
Lyr. Renderer = ZR;
Refresh
Map. Refresh ();
}
<summary>
Group rendering
</summary>
private void group render _click (object sender, System.EventArgs e)
{
Group rendering is actually a combination of rendering, generally define multiple rendering methods, and then use the following statements to combine
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) map. Layers.item ("Country");
Callout Rendering
Mapobjects2.labelrenderer lr = new Mapobjects2.labelrendererclass ();
Lr. Field = "NAME";
Lr.get_symbol (0). Color = (UINT) MapObjects2.ColorConstants.moBlack;
Lr.get_symbol (0). Font.Size = 8;
Render by value
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.valuemaprendererclass ();
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. valuecount;i++)
{
Vmr.set_value (short) i,strs. Item ((short) i));
}
Combine the two to add to the layer
Mapobjects2.grouprenderer gr = new Mapobjects2.grouprendererclass ();
Gr. ADD (VMR);
Gr. ADD (LR);
Lyr. Renderer = gr;
Map. Refresh ();
}
<summary>
Remove all rendering
</summary>
private void Deletes all render _click (object sender, System.EventArgs e)
{
Mapobjects2.maplayer Lyr;
for (int i=0;i<map. layers.count;i++)
{
LYR = (mapobjects2.maplayer) map. Layers.item (i);
Lyr. Renderer = new Mapobjects2.labelrendererclass ();
Map. Refresh ();
}
}
<summary>
Callout Rendering
</summary>
private void Callout Render _click (object sender, System.EventArgs e)
{
Mapobjects2.maplayer Lyr = (mapobjects2.maplayer) map. Layers.item ("Cities");
Mapobjects2.labelrenderer lr = new Mapobjects2.labelrendererclass ();
Lr. Field = "NAME";
Lr.get_symbol (0). Color = (UINT) MapObjects2.ColorConstants.moBlack;
Lr.get_symbol (0). Font.Size = 8;
Lyr. Renderer = LR;
Map. Refresh ();
}
}
}