User Tools

Site Tools


source_code_desktopeditionsample_ruleroverlay_cs_100730.zip

Source Code DesktopEditionSample RulerOverlay CS 100730.zip

Program.cs

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

RulerTrackInteractiveOverlay.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 namespace RulerOverlay  
 {  
 
     class RulerTrackInteractiveOverlay : TrackInteractiveOverlay  
     {  
         private const string currentFeatureKey = "CurrentFeature";  
         private LineShape rulerLineShape;  
        private int mouseDown;  
 
         public RulerTrackInteractiveOverlay()  
             : base()  
         {  
             TrackShapeLayer.Open();  
             TrackShapeLayer.Columns.Add(new FeatureSourceColumn("length"));  
             //Sets the appearance of the ruler  
             TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.DarkRed), 4,false);  
             TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("length", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
             TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.TextLineSegmentRatio = 100;  
             TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.YOffsetInPixel = 10;  
             TrackShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
 
         protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)  
         {  
             //Sets the first and last point of the line where the user clicks.  
             InteractiveResult interactiveResult = new InteractiveResult();  
             interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;  
             interactiveResult.ProcessOtherOverlaysMode  = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;  
 
             rulerLineShape = new LineShape(new Collection<Vertex>() { new Vertex(interactionArguments.WorldX, interactionArguments.WorldY), new Vertex(interactionArguments.WorldX, interactionArguments.WorldY) });  
 
             TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, new Feature(rulerLineShape));  
 
             mouseDown++;  
             return interactiveResult;  
         }  
 
         protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)  
         {  
             //Updates the line with the last point to where the mouse pointer is being dragged.  
             InteractiveResult interactiveResult = new InteractiveResult();  
 
             if (mouseDown > 0)  
             {  
                 Lock.EnterWriteLock();  
                 rulerLineShape.Vertices[rulerLineShape.Vertices.Count|- 1] = new Vertex(interactionArguments.WorldX, interactionArguments.WorldY);  
                 Lock.ExitWriteLock();  
 
                 interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;  
                 interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;  
             }  
 
             return interactiveResult;  
         }  
 
         protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)  
         {  
             //Removes the line of the ruler at finishing dragging (at mouse up event).  
             InteractiveResult interactiveResult = new InteractiveResult();  
 
             interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;  
             interactiveResult.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;  
 
             if (mouseDown == 1)  
             {  
                 mouseDown = 0;  
                 Lock.EnterWriteLock();  
                 TrackShapeLayer.InternalFeatures.Remove(currentFeatureKey);  
                 Lock.ExitWriteLock();  
             }  
             return interactiveResult;  
         }  
 
         protected override void DrawCore(GeoCanvas canvas)  
         {  
             //Draws the line and update the distance text of the ruler.  
             Collection<SimpleCandidate> labelingInAllLayers = new Collection<SimpleCandidate>();  
 
             try  
             {  
                 if (rulerLineShape != null)  
                 {  
                     Feature feature = new Feature(rulerLineShape);  
                     double length = rulerLineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Feet);  
                     feature.ColumnValues.Add("length", ((int)length).ToString() + " feet");  
 
                     Lock.EnterWriteLock();  
                     {  
                         if (TrackShapeLayer.InternalFeatures.Contains(currentFeatureKey))  
                         {  
                             TrackShapeLayer.InternalFeatures[currentFeatureKey] = feature;  
                         }  
                         else  
                         {  
                             TrackShapeLayer.InternalFeatures.Add(currentFeatureKey, feature);  
                         }  
                     }  
                     Lock.ExitWriteLock();  
                 }  
 
                 TrackShapeLayer.Open();  
                 TrackShapeLayer.Draw(canvas, labelingInAllLayers);  
                 canvas.Flush();  
             }  
             finally  
             {  
                 TrackShapeLayer.Close();  
             }  
         }  
     }  
 }  
 

TestForm.cs

 using System;  
 using System.Windows.Forms;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 
 namespace  RulerOverlay  
 {  
     public partial class TestForm : Form  
     {  
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             winformsMap1.MapUnit = GeographyUnit.DecimalDegree;  
             winformsMap1.CurrentExtent = new RectangleShape(-96.8756,33.0875,-96.8629,33.0789);  
             winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));  
 
             //Displays the World Map Kit as a background.  
             WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();  
             winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);  
 
             RulerTrackInteractiveOverlay rulerTrackInteractiveOverlay = new RulerTrackInteractiveOverlay();  
             winformsMap1.TrackOverlay = rulerTrackInteractiveOverlay;  
             winformsMap1.TrackOverlay.TrackMode = TrackMode.Line;  
 
             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();  
         }  
 
     }  
 }  
 
source_code_desktopeditionsample_ruleroverlay_cs_100730.zip.txt · Last modified: 2015/09/08 07:44 by admin