User Tools

Site Tools


source_code_serviceseditionsample_worldcoordinatewithrotation_cs_100203.zip

Source Code ServicesEditionSample WorldCoordinateWithRotation CS 100203.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace WorldCoordinateWithMapRotation  
 {  
     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 WorldCoordinateWithMapRotation  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
         private RotationProjection rotateProjection;  
 
        public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.StandardColors.LightBlue);  
 
             ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\Data\Countries02.shp");  
             worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;  
             worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             //Sets the rotation projection to the layer  
             rotateProjection = new RotationProjection();  
             worldLayer.FeatureSource.Projection = rotateProjection;  
 
 
             mapEngine.StaticLayers.Add(worldLayer);  
 
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(rotateProjection.GetUpdatedExtent(new RectangleShape(-89,69,31,-30)), Map.Width, Map.Height);  
 
 
             DrawImage();  
         }  
 
         private void btnRotateClockwise_Click(object sender, EventArgs e)  
         {  
             rotateProjection.Angle -= 20;  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(rotateProjection.GetUpdatedExtent(mapEngine.CurrentExtent), Map.Width, Map.Height);  
             DrawImage();  
         }  
 
         private void btnRotateCounterClockwise_Click(object sender, EventArgs e)  
         {  
             rotateProjection.Angle += 20;  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(rotateProjection.GetUpdatedExtent(mapEngine.CurrentExtent), Map.Width, Map.Height);  
             DrawImage();  
         }  
 
         private void Map_MouseMove(object sender, MouseEventArgs e)  
         {  
             try  
             {  
                 //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);  
 
                 //Converts to the internal projection to get the accurate world coordinate on the rotated map.  
                 Vertex vertex = rotateProjection.ConvertToInternalProjection(pointShape.X, pointShape.Y);  
 
                 //Displays world coordinates.  
                 //In Decimal Degrees  
                 statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(vertex.X, 4) + " Y:" + Math.Round(vertex.Y, 4);  
                 //In Degrees Minutes and Seconds.  
                 statusStrip1.Items["toolStripStatusLabelDMS"].Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(new PointShape(vertex));  
             }  
             catch  
             {  
             }  
         }  
 
 
         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();  
         }  
     }  
 }  
 
source_code_serviceseditionsample_worldcoordinatewithrotation_cs_100203.zip.txt · Last modified: 2015/09/08 06:08 by admin