ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace SweepAngle { 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()); } } }
using System; using System.Collections.ObjectModel; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace SweepAngle { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; float sweepAngle = 1; Collection<PointShape> pointShapes = new Collection<PointShape>(); public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Set the extent and the background color mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-95.2834,38.9834,-95.2058,38.9401), 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); //Displays the polygon for sweep angle. InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHueFamilyLinearGradientAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Yellow, 5, GeoColor.StandardColors.Blue, GeoColor.StandardColors.Red, 45); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Yellow, 10); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; InMemoryFeatureLayer pointsInMemoryFeatureLayer = new InMemoryFeatureLayer(); pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Yellow, 10); pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Collection of PointShapes to do the spatial query based on the sweep angle PolygonShape. pointShapes.Add(new PointShape(-95.2297, 38.9704)); pointShapes.Add(new PointShape(-95.2452, 38.9696)); pointShapes.Add(new PointShape(-95.2597, 38.9676)); pointShapes.Add(new PointShape(-95.2565, 38.9581)); pointShapes.Add(new PointShape(-95.2455, 38.947)); pointShapes.Add(new PointShape(-95.2352, 38.9531)); mapEngine.DynamicLayers.Add("Sweep Angle", inMemoryFeatureLayer); mapEngine.DynamicLayers.Add("Points", pointsInMemoryFeatureLayer); timer1.Interval = 10; timer1.Start(); DrawImage(); } private void timer1_Tick(object sender, EventArgs e) { if (sweepAngle == 360) sweepAngle = 1; //Updates the sweep angle polygon InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["Sweep|Angle"]; inMemoryFeatureLayer.Open(); inMemoryFeatureLayer.EditTools.BeginTransaction(); inMemoryFeatureLayer.InternalFeatures.Clear(); PolygonShape polygonShape = CreatePie(new PointShape(-95.2462, 38.9609), 0F, sweepAngle, 0.0001F, 0.02F); inMemoryFeatureLayer.EditTools.Add(new Feature(polygonShape)); inMemoryFeatureLayer.EditTools.CommitTransaction(); inMemoryFeatureLayer.Close(); //Updates the points based on spatial query. InMemoryFeatureLayer pointsInMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["Points"]; pointsInMemoryFeatureLayer.Open(); pointsInMemoryFeatureLayer.EditTools.BeginTransaction(); pointsInMemoryFeatureLayer.InternalFeatures.Clear(); foreach (PointShape pointShape in pointShapes) { if (polygonShape.Contains(pointShape)) { pointsInMemoryFeatureLayer.EditTools.Add(new Feature(pointShape)); } } pointsInMemoryFeatureLayer.EditTools.CommitTransaction(); pointsInMemoryFeatureLayer.Close(); sweepAngle = sweepAngle + 1; DrawImage(); } //Creates the Pie based on a start angle and a sweep angle. private PolygonShape CreatePie(PointShape origin, float startAngle, float sweepAngle, float innerRadius, float outerRadius) { double minAngle = Math.Min(startAngle, sweepAngle); double maxAngle = Math.Max(startAngle, sweepAngle); int quaterPointCount = 96; RingShape innerCircle = new EllipseShape(origin, innerRadius).ToPolygon(quaterPointCount).OuterRing; RingShape outerCircle = new EllipseShape(origin, outerRadius).ToPolygon(quaterPointCount).OuterRing; int innerStartIndex = (int)(startAngle * quaterPointCount * 4 / 360.0); int innerEndIndex = (int)(sweepAngle * quaterPointCount * 4 / 360.0); int outerStartIndex = innerStartIndex; int outerEndIndex = innerEndIndex; Collection<Vertex> vertices = new Collection<Vertex>(); for (int i = outerEndIndex; i >= outerStartIndex; i--) { vertices.Add(outerCircle.Vertices[i]); } for (int i = innerStartIndex; i <= innerEndIndex; i++) { vertices.Add(innerCircle.Vertices[i]); } vertices.Add(outerCircle.Vertices[outerEndIndex]); RingShape resultRing = new RingShape(vertices); PolygonShape resultPolygon = new PolygonShape(resultRing); return resultPolygon; } 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(); } 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); } } }