User Tools

Site Tools


source_code_serviceseditionsample_drawapieshape_cs_100204.zip

Source Code ServicesEditionSample DrawAPieShape CS 100204.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace DrawAPieShape  
 {  
     static class Program  
     {  
         /// <summary>  
         /// The main entry point for the application.  
         /// </summary>  
         [STAThread]  
         static void Main()  
         {  
             Application.EnableVisualStyles();  
             Application.SetCompatibleTextRenderingDefault(false);  
             Application.Run(new TestForm());  
         }  
     }  
 }  
 

TestForm.cs

 using System;  
 using System.Collections.ObjectModel;  
 using System.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace DrawAPieShape  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
 
        public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             // Set the extent and the background color  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-126.51,50.92,-66.08,22.48), Map.Width, Map.Height);  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
             mapEngine.SnapToZoomLevel(GeographyUnit.DecimalDegree, Map.Width, Map.Height, new ZoomLevelSet());  
 
             //Displays the World Map Kit as a background.  
             ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer();  
             mapEngine.StaticLayers.Add(worldMapKitLayer);  
 
             //  
             EllipseShape ellipseShape = new EllipseShape(new PointShape(-95.1304, 39.0181), 40, 25);  
             InMemoryFeatureLayer ellipseLayer = new InMemoryFeatureLayer();  
             ellipseLayer.InternalFeatures.Add("Ellipse", new Feature(ellipseShape));  
             ellipseLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.StandardColors.Transparent;  
             ellipseLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Blue);  
             ellipseLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             InMemoryFeatureLayer pieLayer = new InMemoryFeatureLayer();  
             pieLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             pieLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, GeoColor.StandardColors.Red));  
 
             mapEngine.DynamicLayers.Add("ellipseFeatureLayer", ellipseLayer);  
             mapEngine.DynamicLayers.Add("pieFeatureLayer", pieLayer);  
 
 
 
             comboBox1.SelectedIndex = 0;  
             comboBox2.SelectedIndex = 1;  
 
             DrawImage();  
         }  
 
         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  
         {  
             InMemoryFeatureLayer ellipseLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["ellipseFeatureLayer"];  
             Feature ellipseFeature = ellipseLayer.InternalFeatures[0];  
             RingShape ellipseRingShape = ((PolygonShape)ellipseFeature.GetShape()).OuterRing;  
 
             double startPositionAngle = 0.0;  
             if (!string.IsNullOrEmpty(comboBox1.Text))  
             {  
                 startPositionAngle = Convert.ToDouble(comboBox1.Text);  
             }  
             double angle = 30;  
             if (!string.IsNullOrEmpty(comboBox2.Text))  
             {  
                 angle = Convert.ToDouble(comboBox2.Text);  
             }  
 
             RingShape pieRingShape = GetRingShape(ellipseRingShape, startPositionAngle, angle);  
 
             InMemoryFeatureLayer pieLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["pieFeatureLayer"];  
             pieLayer.InternalFeatures.Clear();  
             pieLayer.InternalFeatures.Add(new Feature(pieRingShape));  
 
             DrawImage();  
         }  
 
         private RingShape GetRingShape(RingShape ellipseRingShape, double angle)  
         {  
             return GetRingShape(ellipseRingShape, 0, angle);  
         }  
 
 
         private RingShape GetRingShape(RingShape ellipseRingShape, double startPositionAngle, double angle)  
         {  
             PointShape centerPointShape = ellipseRingShape.GetCenterPoint();  
             RingShape pieRingShape = new RingShape();  
             int startCount = (int)(ellipseRingShape.Vertices.Count * startPositionAngle / 360);  
             int endCount = (int)(ellipseRingShape.Vertices.Count * (startPositionAngle + angle) / 360);  
             int ellipseRingShapeVertexCount = ellipseRingShape.Vertices.Count;  
 
             //If it is a circle, just ignore the center point.  
             if (angle != 360) { pieRingShape.Vertices.Add(new Vertex(centerPointShape.X, centerPointShape.Y)); }  
             //Add the point needed from the ellipse ring shape to the target shape.  
             for (int i = startCount; i < endCount; i++)  
             {  
                 pieRingShape.Vertices.Add(ellipseRingShape.Vertices[i|% ellipseRingShapeVertexCount]);  
             }  
             //If it is a circle, just ignore the center point.  
             if (angle != 360) { pieRingShape.Vertices.Add(new Vertex(centerPointShape.X, centerPointShape.Y)); }  
 
             return pieRingShape;  
         }  
 
 
 
         private void DrawImage()  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.CloseAllLayers();  
 
             Map.Image = bitmap;  
         }  
 
         private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)  
         {  
             switch (e.Button.Tag.ToString())  
             {  
                 case "Zoom In":  
                     mapEngine.CurrentExtent.ScaleDown(50);  
                     break;  
                 case "Zoom Out":  
                     mapEngine.CurrentExtent.ScaleUp(50);  
                     break;  
                 case "Full Extent":  
                     mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height);  
                     break;  
                 case "Pan Left":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20);  
                     break;  
                 case "Pan Right":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20);  
                     break;  
                 case "Pan Up":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20);  
                     break;  
                 case "Pan Down":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20);  
                     break;  
                 default:  
                     break;  
             }  
             DrawImage();  
         }  
 
         private void btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
 
         private void Map_MouseMove(object sender, MouseEventArgs e)  
         {  
             //Displays the X and Y in screen coordinates.  
             statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y;  
 
             //Gets the PointShape in world coordinates from screen coordinates.  
             PointShape pointShape = ExtentHelper.ToWorldCoordinate(mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), Map.Width, Map.Height);  
 
             //Displays world coordinates.  
             statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4);  
         }  
 
 
     }  
 }  
 
source_code_serviceseditionsample_drawapieshape_cs_100204.zip.txt · Last modified: 2015/09/08 05:27 by admin