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 ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace CustomTrackPolygon { public class CustomTrackInteractiveOverlay : TrackInteractiveOverlay { const int minVertexNum = 2; public CustomTrackInteractiveOverlay() : base() { this.TrackMode = TrackMode.Polygon; } protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments) { System.Diagnostics.Debug.WriteLine(this.Vertices.Count); if (interactionArguments.MouseButton != MapMouseButton.Right) { return base.MouseDownCore(interactionArguments); } else { if (this.Vertices.Count >= 5) { RemoveLastVertexAdded(); MouseDownCount = MouseDownCount - 1; } return new InteractiveResult(); } } private void RemoveLastVertexAdded() { if (this.Vertices.Count > minVertexNum) { this.Lock.EnterWriteLock(); try { Vertex lastVertex = this.Vertices[this.Vertices.Count|- 3]; this.Vertices.Remove(lastVertex); } finally { this.Lock.ExitWriteLock(); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace CustomTrackPolygon { 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.Windows.Forms; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace CustomTrackPolygon { public partial class TestForm : Form { public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { label1.Text = "Left click to track polygon. Right click to remove last vertex."; winformsMap1.TrackOverlay = new CustomTrackInteractiveOverlay(); winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.CurrentExtent = new RectangleShape(-95.2957, 38.9791, -95.2397, 38.9452); winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay(); winformsMap1.Overlays.Add(worldMapKitDesktopOverlay); winformsMap1.Refresh(); } 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(); } } }