User Tools

Site Tools


source_code_serviceseditionsample_rotateicon_cs_091031.zip

Source Code ServicesEditionSample RotateIcon CS 091031.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace RotateIcon  
 {  
     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 RotateIcon  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
         private Timer timer;  
         private int index;  
         private GeoImage planeGeoImageNorth = new GeoImage(@"..\..\data\jet_north.png");  
         private GeoImage planeGeoImageSouth = new GeoImage(@"..\..\data\jet_south.png");  
         private bool WestToEast = true;  
 
        public TestForm()  
         {  
             InitializeComponent();  
             timer = new Timer();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             //Sets timer properties  
             timer.Interval = 1500;  
             timer.Tick += new EventHandler(timer_Tick);  
 
             // Sets the extent and the background color  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-122,77,61,6), Map.Width, Map.Height);  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
             //Displays the World Map Kit as a background.  
             ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer();  
             mapEngine.StaticLayers.Add(worldMapKitLayer);  
 
             //Adds the inMemoryFeatureLayer for plane icon.  
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap;  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.ContestedBorder2;  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             PointShape planeShape = new PointShape(-95.2806, 38.9554);  
             PointShape destinationPoint = new PointShape(36.04, 48.49);  
             //Great circle is the shortest path between two points on the surface. http://en.wikipedia.org/wiki/Great_circle  
             MultilineShape pathMultiLineShape = planeShape.GreatCircle(destinationPoint);  
 
             inMemoryFeatureLayer.InternalFeatures.Add("Plane", new Feature(planeShape));  
             inMemoryFeatureLayer.InternalFeatures.Add("Path", new Feature(pathMultiLineShape));  
 
             mapEngine.DynamicLayers.Add("Air",inMemoryFeatureLayer);  
 
             DrawImage();  
 
             timer.Start();  
         }  
 
         void timer_Tick(object sender, EventArgs e)  
         {  
             StartingPoint startingPoint;  
             float angleOffset;  
 
             InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["Air"];  
             PointShape pointShape = inMemoryFeatureLayer.InternalFeatures[0].GetShape() as PointShape;  
             LineShape pathLineShape = ((MultilineShape)inMemoryFeatureLayer.InternalFeatures[1].GetShape()).Lines[0];  
 
             //We have to use two different images for representing the plane because the images are side views.  
             //What we are doing for planes, can do done for ground vehicle. It is the same principle.  
             //Depending on the vehicle orientation of the side view image (pointing North, South, East or West), you will have to adjust the angleOffset.  
             //Also, depending on what direction the vehicle, you will have to switch image.  
             //If using a top down view, only one image can be used.  
             if (WestToEast == true)  
             {  
                 inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = planeGeoImageNorth;  
                 startingPoint = StartingPoint.FirstPoint;  
                 angleOffset = 360;  
             }  
             else  
             {  
                 inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = planeGeoImageSouth;  
                 startingPoint = StartingPoint.LastPoint;  
                 angleOffset = 180;  
              }  
 
             index += 5;  
             if (index <= 100)  
             {  
                 LineShape lineShape = (LineShape)pathLineShape.GetLineOnALine(startingPoint, index);  
                 PointShape newPointShape = new PointShape(lineShape.Vertices[lineShape.Vertices.Count|- 1]);  
 
                 double angle = GetAngleFromTwoVertices(lineShape.Vertices[lineShape.Vertices.Count|- 2],  
                                      lineShape.Vertices[lineShape.Vertices.Count|- 1]);  
                 inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.RotationAngle = angleOffset - (float)angle;  
 
                 pointShape.X = newPointShape.X;  
                 pointShape.Y = newPointShape.Y;  
                 pointShape.Id = "Plane";  
 
                 inMemoryFeatureLayer.Open();  
                 inMemoryFeatureLayer.EditTools.BeginTransaction();  
                 inMemoryFeatureLayer.EditTools.Update(pointShape);  
                 inMemoryFeatureLayer.EditTools.CommitTransaction();  
                 inMemoryFeatureLayer.Close();  
             }  
             else  
             {  
                 index = 0;  
                 if (WestToEast == true) WestToEast = false;  
                 else WestToEast = true;  
             }  
             DrawImage();  
         }  
 
         private void EfficientlyMoveAPlaneImage_ParentChanged(object sender, EventArgs e)  
         {  
             timer.Stop();  
         }  
 
         //We assume that the angle is based on a third point that is on top of b on the same x axis.  
         private double GetAngleFromTwoVertices(Vertex b, Vertex c)  
         {  
             double alpha = 0;  
             double tangentAlpha = (c.Y - b.Y) / (c.X - b.X);  
             double Peta = Math.Atan(tangentAlpha);  
 
             if (c.X > b.X)  
             {  
                 alpha = 90 - (Peta * (180 / Math.PI));  
             }  
             else if (c.X < b.X)  
             {  
                 alpha = 270 - (Peta * (180 / Math.PI));  
             }  
             else  
             {  
                 if ( c.Y > b.Y) alpha = 0;  
                 if (c.Y < b.Y)  alpha = 180;  
             }  
             return alpha;  
         }  
 
 
        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 DrawImageDynamicLayers()  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             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_rotateicon_cs_091031.zip.txt · Last modified: 2015/09/08 08:01 by admin