====== Source Code DesktopEditionSample SweepAngle CS 100506.zip ====== ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace SweepAngleDesktop { 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.Windows.Forms; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace SweepAngleDesktop { public partial class TestForm : Form { float sweepAngle = 1; Collection pointShapes = new Collection(); public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { //In Desktop version, you have to set the MapUnit as a property of the map control. winformsMap1.MapUnit = GeographyUnit.DecimalDegree; //Services Edition: mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-95.2834,38.9834,-95.2058,38.9401), Map.Width, Map.Height); winformsMap1.CurrentExtent = new RectangleShape(-95.2834, 38.9834, -95.2058, 38.9401); //Services Edition: mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay(); //Services Edition: mapEngine.StaticLayers.Add(worldMapKitLayer); winformsMap1.Overlays.Add(worldMapKitDesktopOverlay); //----Identical code in all the versions--------------------------------------------------- //Displays the polygon for sweep angle. InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHueFamilyLinearGradientAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Yellow, 5, GeoColor.FromArgb(150,GeoColor.StandardColors.Blue), GeoColor.FromArgb(150,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)); //------------------------------------------------------------------------------------------- //Services Edition: //mapEngine.DynamicLayers.Add("Sweep Angle", inMemoryFeatureLayer); //mapEngine.DynamicLayers.Add("Points", pointsInMemoryFeatureLayer); LayerOverlay dynamicLayerOverlay = new LayerOverlay(); dynamicLayerOverlay.Layers.Add("Sweep Angle",inMemoryFeatureLayer); dynamicLayerOverlay.Layers.Add("Points", pointsInMemoryFeatureLayer); winformsMap1.Overlays.Add("Dynamic Overlay", dynamicLayerOverlay); timer1.Interval = 10; timer1.Start(); winformsMap1.Refresh(); } private void timer1_Tick(object sender, EventArgs e) { if (sweepAngle == 360) sweepAngle = 1; //Updates the sweep angle polygon //Services Edition: InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["Sweep|Angle"]; //Services Edition: InMemoryFeatureLayer pointsInMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers["Points"]; LayerOverlay dynamicLayerOverlay = (LayerOverlay)winformsMap1.Overlays["Dynamic|Overlay"]; InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicLayerOverlay.Layers["Sweep|Angle"]; InMemoryFeatureLayer pointsInMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicLayerOverlay.Layers["Points"]; 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. 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; //Services Edition: DrawImage(); winformsMap1.Refresh(dynamicLayerOverlay); } //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 vertices = new Collection(); 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 winformsMap1_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(winformsMap1.CurrentExtent, new ScreenPointF(e.X, e.Y), winformsMap1.Width, winformsMap1.Height); //Displays world coordinates. statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } }