User Tools

Site Tools


source_code_serviceseditionsample_rotatedimagestyle_cs_090728.zip

Source Code ServicesEditionSample RotatedImageStyle CS 090728.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace RotatedImageStyle  
 {  
     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());  
         }  
     }  
 }  
 

RotatedImageStyle.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Linq;  
 using System.Text;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace RotatedImageStyle  
 {  
     class RotatedImageStyle : Style  
     {  
         private GeoImage geoImage;  
         private string angleColumnName;  
 
     public RotatedImageStyle()  
         : this(new GeoImage(), string.Empty)  
     { }  
 
     public RotatedImageStyle(GeoImage geoImage, string angleColumnName)  
     {  
         this.geoImage = geoImage;  
         this.angleColumnName = angleColumnName;  
     }  
 
     public GeoImage GeoImage  
     {  
         get { return geoImage; }  
         set { GeoImage = value; }  
     }  
 
     public string AngleColumnName  
     {  
         get { return angleColumnName; }  
         set { AngleColumnName = value; }  
     }  
 
     protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
     {  
         foreach (Feature feature in features)  
             {  
                 float angleData = Convert.ToSingle(feature.ColumnValues[angleColumnName]);  
                 PointShape pointShape = (PointShape)feature.GetShape();  
                 canvas.DrawWorldImageWithoutScaling(geoImage, pointShape.X, pointShape.Y, DrawingLevel.LevelFour, 0, 0, 360 - angleData); //angleData);  
             }  
     }  
 
     protected override Collection<string> GetRequiredColumnNamesCore()  
     {  
         Collection<string> columns = new Collection<string>();  
         if (!columns.Contains(angleColumnName))  
         {  
             columns.Add(angleColumnName);  
         }  
         return columns;  
     }  
     }  
 }  
 

TestForm.cs

 using System;  
 using System.Drawing;  
 using System.IO;  
 using System.Windows.Forms;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace RotatedImageStyle  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
         private int count1 = 0;  
         private int count2 = 0;  
         private Collection<PointShape> pointShapes1;  
         private Collection<PointShape> pointShapes2;  
 
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));  
 
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.Open();  
             inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Angle"));  
             inMemoryFeatureLayer.Close();  
 
             pointShapes1 = ReadTextFile(@"..\..\Data\GPSreadings1.txt");  
             pointShapes2 = ReadTextFile(@"..\..\Data\GPSreadings2.txt");  
 
             Feature newFeature1 = new Feature(pointShapes1[count1]);  
             newFeature1.ColumnValues["Angle"] = System.Convert.ToString(pointShapes1[count1].Z);  
             inMemoryFeatureLayer.InternalFeatures.Add("Vehicle1", newFeature1);  
 
             Feature newFeature2 = new Feature(pointShapes2[count2]);  
             newFeature2.ColumnValues["Angle"] = System.Convert.ToString(pointShapes2[count2].Z);  
             inMemoryFeatureLayer.InternalFeatures.Add("Vehicle2", newFeature2);  
 
             RotatedImageStyle rotatedImageStyle = new RotatedImageStyle(new GeoImage(@"..\..\Data\vehicle2.png"), "Angle");  
 
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(rotatedImageStyle);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             mapEngine.DynamicLayers.Add(inMemoryFeatureLayer);  
             mapEngine.CurrentExtent = new RectangleShape(-66.8581, 10.4995, -66.8456, 10.4915);  
 
             timer1.Start();  
 
             DrawImage();  
         }  
 
         private Collection<PointShape> ReadTextFile(string textFile)  
         {  
             Collection<PointShape> pointShapes = new Collection<PointShape>();  
             StreamReader SR = File.OpenText(textFile);  
             string S;  
             S = SR.ReadLine();  
             while (S != null)  
             {  
                 double X = System.Convert.ToDouble(S.Substring(0, 8));  
                 double Y = System.Convert.ToDouble(S.Substring(9, 7));  
                 double Angle = System.Convert.ToDouble(S.Substring(17, 3));  
                 PointShape pointShape = new PointShape(X, Y, Angle);  
                 pointShapes.Add(pointShape);  
                 S = SR.ReadLine();  
 
             }  
             SR.Close();  
             return pointShapes;  
         }  
 
        private void timer1_Tick(object sender, EventArgs e)  
         {  
             if (count1 == pointShapes1.Count) count1 = 0;  
             if (count2 == pointShapes2.Count) count2 = 0;  
 
             try  
             {  
                 InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers[0];  
 
                 Feature feature = inMemoryFeatureLayer.InternalFeatures["Vehicle1"];  
                 feature.ColumnValues["Angle"] = System.Convert.ToString(pointShapes1[count1].Z);  
                 PointShape pointShape1 = feature.GetShape() as PointShape;  
                 pointShape1.X = pointShapes1[count1].X;  
                 pointShape1.Y = pointShapes1[count1].Y;  
                 pointShape1.Id = "Vehicle1";  
 
                 Feature feature2 = inMemoryFeatureLayer.InternalFeatures["Vehicle2"];  
                 feature2.ColumnValues["Angle"] = System.Convert.ToString(pointShapes2[count2].Z);  
                 PointShape pointShape2 = feature2.GetShape() as PointShape;  
                 pointShape2.X = pointShapes2[count2].X;  
                 pointShape2.Y = pointShapes2[count2].Y;  
                 pointShape2.Id = "Vehicle2";  
 
                 inMemoryFeatureLayer.Open();  
                 inMemoryFeatureLayer.EditTools.BeginTransaction();  
 
                 inMemoryFeatureLayer.EditTools.Update(pointShape1);  
                 inMemoryFeatureLayer.EditTools.Update(pointShape2);  
                 inMemoryFeatureLayer.EditTools.CommitTransaction();  
                 inMemoryFeatureLayer.Close();  
 
             }  
             finally  
             {  
                 count1 = count1 + 1;  
                 count2 = count2 + 1;  
             }  
             DrawImage();  
         }  
 
        private void DrawImage()  
         {  
             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(-66.8581, 10.4995, -66.8456, 10.4915), 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_rotatedimagestyle_cs_090728.zip.txt · Last modified: 2015/09/08 05:39 by admin