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.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace PresetVertexToTrackedPolygon { //Custom TrackInteractiveOverlay to add preset vertices to polygon while tracking class PresetVertexTrackInteractiveOverlay : TrackInteractiveOverlay { private Collection<PointShape> presetPointShapes = new Collection<PointShape>(); private Collection<int> addVertexIndexes = new Collection<int>(); private PointShape newAddedVertex = null; public Collection<PointShape> PresetPointShapes { get { return presetPointShapes; } set { presetPointShapes = value; } } public Collection<int> AddVertexIndexes { get { return addVertexIndexes; } set { addVertexIndexes = value; } } public PointShape NewAddedVertex { get { return newAddedVertex; } set { newAddedVertex = value; } } protected override void OnTrackEnded(TrackEndedTrackInteractiveOverlayEventArgs e) { addVertexIndexes = new Collection<int>(); presetPointShapes = new Collection<PointShape>(); base.OnTrackEnded(e); } protected override BaseShape GetTrackingShapeCore() { BaseShape baseShape = base.GetTrackingShapeCore(); if (baseShape is PolygonShape) { PolygonShape polygon = (PolygonShape)baseShape; if (polygon != null) { if (newAddedVertex != null) { AddVertexIndexes.Add(Vertices.Count - 2); PresetPointShapes.Add(new PointShape(newAddedVertex.X, newAddedVertex.Y)); newAddedVertex = null; } int index = 0; foreach (int addVertexIndex in AddVertexIndexes) { PointShape presetPointShape = presetPointShapes[index]; index++; if (presetPointShape != null) { Vertices[addVertexIndex] = new Vertex(presetPointShape); } } } } return baseShape; } protected override InteractiveResult MouseClickCore(InteractionArguments interactionArguments) { if (interactionArguments.MouseButton == MapMouseButton.Left) { return base.MouseClickCore(interactionArguments); } else { return new InteractiveResult(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace PresetVertexToTrackedPolygon { 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 ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace PresetVertexToTrackedPolygon { public partial class TestForm : Form { PresetVertexTrackInteractiveOverlay presetVertexTrackInteractiveOverlay = new PresetVertexTrackInteractiveOverlay(); public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.CurrentExtent = new RectangleShape(-96.8405,33.109,-96.812,33.092); 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); //Sets the TrackOverlay to PresetVertexTrackInteractiveOverlay. winformsMap1.TrackOverlay = presetVertexTrackInteractiveOverlay; winformsMap1.TrackOverlay.TrackMode = TrackMode.Polygon; winformsMap1.Refresh(); } private void button1_Click(object sender, EventArgs e) { presetVertexTrackInteractiveOverlay.NewAddedVertex = new PointShape(Convert.ToDouble(txtX.Text), Convert.ToDouble(txtY.Text)); } 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(); } } }