====== Source Code ServicesEditionSample TimeBasedPointStyle CS 090728.zip ====== ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace TimeBasedPointStyle { static class Program { /// /// The main entry point for the application. /// [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 TimeBasedPointStyle { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; private ShapeFileFeatureLayer worldLayer = null; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Set the full extent and the background color mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); // Add the static layers to the MapEngine worldLayer = new ShapeFileFeatureLayer(@"..\..\Data\Countries02.shp", ShapeFileReadWriteMode.ReadOnly); worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1; worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.StaticLayers.Add("WorldLayer", worldLayer); ShapeFileFeatureLayer worldCapitalsLayer = new ShapeFileFeatureLayer(@"..\..\Data\WorldCapitals.shp", ShapeFileReadWriteMode.ReadOnly); worldCapitalsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; TimeBasedPointStyle timeBasedPointStyle = new TimeBasedPointStyle(); timeBasedPointStyle.TimeZoneColumnName = "TimeZone"; timeBasedPointStyle.DaytimePointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Yellow, 8); timeBasedPointStyle.NighttimePointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Gray, 8); worldCapitalsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear(); worldCapitalsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(timeBasedPointStyle); mapEngine.StaticLayers.Add("WorldCapitals", worldCapitalsLayer); DrawImage(); } 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(); } } } ====TimeBasedPointStyle.cs==== using System; using System.Collections.Generic; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; namespace TimeBasedPointStyle { // Mark the class Serializable so that it workes in SQL Server state // and in every serialization context [Serializable] class TimeBasedPointStyle : Style { private PointStyle daytimePointStyle; private PointStyle nighttimePointStyle; private string timeZoneColumnName; public TimeBasedPointStyle() : this(string.Empty, new PointStyle(), new PointStyle()) { } public TimeBasedPointStyle(string timeZoneColumnName, PointStyle daytimePointStyle, PointStyle nighttimePointStyle) { this.timeZoneColumnName = timeZoneColumnName; this.daytimePointStyle = daytimePointStyle; this.nighttimePointStyle = nighttimePointStyle; } public PointStyle DaytimePointStyle { get { return daytimePointStyle; } set { daytimePointStyle = value; } } public PointStyle NighttimePointStyle { get { return nighttimePointStyle; } set { nighttimePointStyle = value; } } public string TimeZoneColumnName { get { return timeZoneColumnName; } set { timeZoneColumnName = value; } } protected override void DrawCore(IEnumerable features, GeoCanvas canvas, Collection labelsInThisLayer, Collection labelsInAllLayers) { foreach (Feature feature in features) { // Here we are going to do the calculation to see what // time it is for each feature and draw the approperate style float offsetToGmt = Convert.ToSingle(feature.ColumnValues[timeZoneColumnName]); DateTime localTime = DateTime.UtcNow.AddHours(offsetToGmt); if (localTime.Hour >= 7 && localTime.Hour <= 19) { // Daytime daytimePointStyle.Draw(new Collection() { feature }, canvas, labelsInThisLayer, labelsInAllLayers); } else { //Nighttime nighttimePointStyle.Draw(new Collection() { feature }, canvas, labelsInThisLayer, labelsInAllLayers); } } } protected override Collection GetRequiredColumnNamesCore() { Collection columns = new Collection(); // Grab any columns that the daytime style may need. Collection daytimeColumns = daytimePointStyle.GetRequiredColumnNames(); foreach (string column in daytimeColumns) { if (!columns.Contains(column)) { columns.Add(column); } } // Grab any columns that the nighttime style may need. Collection nighttimeColumns = nighttimePointStyle.GetRequiredColumnNames(); foreach (string column in nighttimeColumns) { if (!columns.Contains(column)) { columns.Add(column); } } // Make sure we add the timezone column if (!columns.Contains(timeZoneColumnName)) { columns.Add(timeZoneColumnName); } return columns; } } }