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<TrackEndedTrackInteractiveOverlayEventArgs>(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;
}
/// <summary>
/// Cancels the current lasso operation
/// </summary>
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();
}
}
}