====== Source Code DesktopEditionSample TrackOverlayWithEsc CS 090811.zip ====== ====CustomTrackInteractiveOverlay.cs==== using ThinkGeo.MapSuite.DesktopEdition; namespace TrackOverlayWithEscNew { /// /// This class is used to handle dismissing the trackshape. It also has a property to determine if you are in a trackshape operation. The Interactive click interval is changed because the is a discrepency between when the user clicks and the point is registerd when the vlaue is left at the default 500. /// public class CustomTrackInteractiveOverlay : TrackInteractiveOverlay { private bool isTracking = false; public CustomTrackInteractiveOverlay():base() { } public bool IsTracking { get { return isTracking; } } public new void EndTracking() { base.EndTracking(); } protected override void OnTrackStarted(TrackStartedTrackInteractiveOverlayEventArgs e) { InteractiveClickInterval = 400; isTracking = true; base.OnTrackStarted(e); } protected override void OnTrackEnded(TrackEndedTrackInteractiveOverlayEventArgs e) { InteractiveClickInterval = 1; isTracking = false; base.OnTrackEnded(e); } } } ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace TrackOverlayWithEscNew { 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 TrackOverlayWithEscNew { public partial class TestForm : Form { public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.TrackOverlay = new CustomTrackInteractiveOverlay(); winformsMap1.TrackOverlay.TrackEnded += new EventHandler(TrackOverlay_TrackEnded); winformsMap1.KeyDown += new KeyEventHandler(winformsMap1_KeyDown); winformsMap1.TrackOverlay.TrackMode = TrackMode.Polygon; //setting the interactiveclick interval here ensures the first point is set in the proper location. After the trackshape is started, the value is set to 400 in the customtrackoverlay. InteractiveOverlay.InteractiveClickInterval = 1; //winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.CurrentExtent = new RectangleShape(-125, 47, -67, 25); 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(); } void winformsMap1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Escape: //cancels the current lasso operation TrackOverlayCancelled(); break; } } void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e) { //setting the interactiveclick interval here ensures the first point is set in the proper location. After the trackshape is started, the value is set to 400 in the customtrackoverlay. InteractiveOverlay.InteractiveClickInterval = 1; } /// /// Cancels the current lasso operation /// private void TrackOverlayCancelled() { ClearTrackingLayer(); if (winformsMap1.TrackOverlay.TrackMode == TrackMode.Polygon || winformsMap1.TrackOverlay.TrackMode == TrackMode.Line) { //we are using a custom overlay to handle this ((CustomTrackInteractiveOverlay)winformsMap1.TrackOverlay).EndTracking(); winformsMap1.TrackOverlay.MouseDoubleClick(new InteractionArguments()); } else { winformsMap1.TrackOverlay.MouseUp(new InteractionArguments()); } winformsMap1.Refresh(); } private void ClearTrackingLayer() { winformsMap1.TrackOverlay.Lock.EnterWriteLock(); try { int count = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count; if (count > 0) { winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear(); } } finally { winformsMap1.TrackOverlay.Lock.ExitWriteLock(); } } 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(); } } }