User Tools

Site Tools


source_code_serviceseditionsample_timeline_cs_091013.zip

Source Code ServicesEditionSample TimeLine CS 091013.zip

DateBasedStyle.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace TimeLine  
 {  
     // Mark the class Serializable so that it works in SQL Server state  
     // and in every serialization context  
     [Serializable]  
     class DateBasedStyle : AreaStyle  
     {  
         private AreaStyle beforeAreaStyle;  
         private AreaStyle afterAreaStyle;  
         private string yearColumnName;  
         private int referenceYear;  
         private TextStyle textStyle = null ;  
 
         public DateBasedStyle()  
             : this(string.Empty, new AreaStyle(), new AreaStyle(), new TextStyle())  
         { }  
 
         public DateBasedStyle(string yearColumnName, AreaStyle beforeAreaStyle, AreaStyle afterAreaStyle, TextStyle textStyle)  
         {  
             this.yearColumnName = yearColumnName;  
             this.beforeAreaStyle = beforeAreaStyle;  
             this.afterAreaStyle = afterAreaStyle;  
             this.textStyle = textStyle;  
         }  
 
         public AreaStyle BeforeAreaStyle  
         {  
             get { return beforeAreaStyle; }  
             set { beforeAreaStyle = value; }  
         }  
 
         public AreaStyle AfterAreaStyle  
         {  
             get { return afterAreaStyle; }  
             set { afterAreaStyle = value; }  
         }  
 
         public TextStyle TextStyle  
         {  
             get { return textStyle; }  
             set { textStyle = value; }  
         }  
 
         public string YearColumnName  
         {  
             get { return yearColumnName; }  
             set { yearColumnName = value; }  
         }  
 
         public int ReferenceYear  
         {  
             get { return referenceYear; }  
             set { referenceYear = value; }  
         }  
 
 
         protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             foreach (Feature feature in features)  
             {  
                 // Here we are going to do the calculation to see what  
                 // the current Year it is for each feature and draw the approperate style according to  
                 //to the reference year.  
                 int currentDate = Convert.ToInt32(feature.ColumnValues[yearColumnName]);  
                 if (currentDate <= referenceYear)  
                 {  
                     beforeAreaStyle.Draw(new Collection<Feature>() { feature }, canvas, labelsInThisLayer, labelsInAllLayers);  
                     if (textStyle != null)  
                     {  
                         textStyle.Draw(new Collection<Feature>() { feature }, canvas, labelsInThisLayer, labelsInAllLayers);  
                     }  
                 }  
                 else  
                 {  
                     afterAreaStyle.Draw(new Collection<Feature>() { feature }, canvas, labelsInThisLayer, labelsInAllLayers);  
                 }  
             }  
         }  
 
         protected override Collection<string> GetRequiredColumnNamesCore()  
         {  
             Collection<string> columns = new Collection<string>();  
 
             if (!columns.Contains(yearColumnName))  
             {  
                 columns.Add(yearColumnName);  
             }  
             return columns;  
         }  
     }  
 }  
 

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace TimeLine  
 {  
     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.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace TimeLine  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private MapEngine mapEngine2 = new MapEngine();  
         private MapEngine mapEngine3 = new MapEngine();  
         private Bitmap bitmap = null;  
         private Bitmap bitmap2 = null;  
         private Bitmap bitmap3 = null;  
         ShapeFileFeatureLayer statesLayer = null;  
         ShapeFileFeatureLayer countriesLayer = null;  
         DateBasedStyle dateBasedStyle = null;  
 
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             // Sets the full extent and the background color  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-148.10,55.75,-66,21), Map.Width, Map.Height);  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
             mapEngine2.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-169.14,72.69,-130.37,51.56), Map2.Width, Map2.Height);  
             mapEngine2.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
              mapEngine3.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-161.95,23.36,-152.71,17.49), Map3.Width, Map3.Height);  
              mapEngine3.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
             // Adds the static layers to the MapEngines  
             // Adds the country background layer.  
              countriesLayer = new ShapeFileFeatureLayer(@"..\..\Data\countries02.shp", ShapeFileReadWriteMode.ReadOnly);  
              countriesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;  
              countriesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
              mapEngine.StaticLayers.Add("CountriesLayer", countriesLayer);  
              mapEngine2.StaticLayers.Add("CountriesLayer", countriesLayer);  
              mapEngine3.StaticLayers.Add("CountriesLayer", countriesLayer);  
 
             //Adds the states layer with the DateBasedStyle.  
             statesLayer = new ShapeFileFeatureLayer(@"..\..\Data\usastates.shp", ShapeFileReadWriteMode.ReadOnly);  
             dateBasedStyle = new DateBasedStyle();  
             dateBasedStyle.YearColumnName = "Year";  
             dateBasedStyle.BeforeAreaStyle =  new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightGreen));  
             dateBasedStyle.AfterAreaStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightGray));  
             dateBasedStyle.TextStyle = new TextStyle("Year", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.StandardColors.DarkGreen));  
             dateBasedStyle.ReferenceYear = trackBar1.Value;  
 
             statesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();  
             statesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(dateBasedStyle);  
             statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             mapEngine.StaticLayers.Add("StateLayer", statesLayer);  
             mapEngine2.StaticLayers.Add("StateLayer", statesLayer);  
             mapEngine3.StaticLayers.Add("StateLayer", statesLayer);  
 
             DrawImage();  
             lblYear.Text = Convert.ToString(trackBar1.Value);  
         }  
 
         private void trackBar1_ValueChanged(object sender, EventArgs e)  
         {  
             dateBasedStyle.ReferenceYear = trackBar1.Value;  
             lblYear.Text = Convert.ToString(trackBar1.Value);  
             DrawImage();  
         }  
 
         private void DrawImage()  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.CloseAllLayers();  
             Map.Image = bitmap;  
 
             if (bitmap2 != null) { bitmap2.Dispose(); }  
             bitmap2 = new Bitmap(Map2.Width, Map2.Height);  
             mapEngine2.OpenAllLayers();  
             mapEngine2.DrawStaticLayers(bitmap2, GeographyUnit.DecimalDegree);  
             mapEngine2.CloseAllLayers();  
             Map2.Image = bitmap2;  
 
             if (bitmap3 != null) { bitmap3.Dispose(); }  
             bitmap3 = new Bitmap(Map3.Width, Map3.Height);  
             mapEngine3.OpenAllLayers();  
             mapEngine3.DrawStaticLayers(bitmap3, GeographyUnit.DecimalDegree);  
             mapEngine3.CloseAllLayers();  
             Map3.Image = bitmap3;  
         }  
 
         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_timeline_cs_091013.zip.txt · Last modified: 2015/09/08 08:04 by admin