User Tools

Site Tools


source_code_desktopeditionsample_customtrackline_cs_100210.zip

Source Code DesktopEditionSample CustomTrackLine CS 100210.zip

CustomTrackInteractiveOverlay.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
namespace CustomTrackLine
{
    class CustomTrackInteractiveOverlay : TrackInteractiveOverlay
    {
        public CustomTrackInteractiveOverlay()
            : base()
        {
            this.TrackMode = TrackMode.Line;
        }
        protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
        {
            if (interactionArguments.MouseButton != MapMouseButton.Right)
                return base.MouseDownCore(interactionArguments);
            else
                RemoveLastVertexAdded();
                return new InteractiveResult();
        }
        private void RemoveLastVertexAdded()
        {
            int minVertex = 2;
            if (this.Vertices.Count > minVertex)
            {
                this.Lock.EnterWriteLock();
                try
                {
                    Vertex lastVertex = this.Vertices[this.Vertices.Count|- 2];
                    this.Vertices.Remove(lastVertex);
                }
                finally
                {
                    this.Lock.ExitWriteLock();
                }
            }
       }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace CustomTrackLine
{
    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());
        }
    }
}

TestForm.cs

using System;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
 
namespace  CustomTrackLine
{
    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
        }
        private void TestForm_Load(object sender, EventArgs e)
        {
            label1.Text = "Left click to track line. Right click to remove last vertex.";
 
            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 button1_Click(object sender, EventArgs e)
        {
            CustomTrackInteractiveOverlay customTrackInteractiveOverlay = new CustomTrackInteractiveOverlay();
            winformsMap1.TrackOverlay = customTrackInteractiveOverlay;
        }
        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();
        }
    }
}
source_code_desktopeditionsample_customtrackline_cs_100210.zip.txt · Last modified: 2015/09/09 03:31 by admin