User Tools

Site Tools


source_code_desktopeditionsample_selectvertices_cs_101104.zip

Source Code DesktopEditionSample SelectVertices CS 101104.zip

Program.cs

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

SelectVerticesEditInteractiveOverlay.cs

using System;  
 using System.Collections.ObjectModel;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 namespace SelectVertices  
 {  
     class SelectVerticesEditInteractiveOverlay : EditInteractiveOverlay  
     {  
         private PointStyle controlPointStyle;  
         private PointStyle selectedControlPointStyle;  
 
         public SelectVerticesEditInteractiveOverlay()  
             : base()  
         {  
             //We add the column "IsSelected" to ExistingControlPointsLayer that will be used to keep track if the control point has been dragged.  
             //Notice that the column "State" already exists. It is used for keeping tracked if the control point is being dragged.  
             this.ExistingControlPointsLayer.Open();  
             this.ExistingControlPointsLayer.Columns.Add(new FeatureSourceColumn("IsSelected"));  
             this.ExistingControlPointsLayer.Close();  
         }  
 
         //Style for drawing a control point not selected  
         public PointStyle ControlPointStyle  
         {  
             get { return controlPointStyle; }  
             set { controlPointStyle = value; }  
         }  
 
         //Style for drawing a control point when selected (being dragged or after having being dragged)  
         public PointStyle SelectedControlPointStyle  
         {  
             get { return selectedControlPointStyle; }  
             set { selectedControlPointStyle = value; }  
         }  
 
         //Sets the column value for "IsSelected" to "true" if control point selected.  
         protected override void OnControlPointSelected(ControlPointSelectedEditInteractiveOverlayEventArgs e)  
         {  
             base.OnControlPointSelected(e);  
 
             foreach (Feature feature in this.ExistingControlPointsLayer.InternalFeatures)  
             {  
                 if (feature.ColumnValues["State"] == "selected")  
                 {  
                     feature.ColumnValues["IsSelected"] = "true";  
                 }  
             }  
         }  
 
         //At the Mouse Up event, the features of ExistingControlPointsLayer will be cleared and new one will  
         //be generated for better performance. So it is necessary to reupdate the column values of "IsSelected" to the new  
         //ExistingControlPointsLayer.  
         protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)  
         {  
             Collection<int> draggedPointsIndex = new Collection<int>();  
 
             //Before the actual MouseUp event, we get the indexes of the features with value "true" of column "IsSelected".  
             this.ExistingControlPointsLayer.Open();  
             Collection<Feature> draggedPoints = this.ExistingControlPointsLayer.QueryTools.GetAllFeatures(new string[] { "IsSelected" });  
             this.ExistingControlPointsLayer.Close();  
 
             for (int index = 0; index < draggedPoints.Count; index++)  
             {  
                 if (draggedPoints[index].ColumnValues["IsSelected"] == "true")  
                 {  
                     draggedPointsIndex.Add(index);  
                 }  
             }  
 
             //The MouseUp is called clearing ExistingControlPointsLayer. (We do that for better performance)  
             InteractiveResult interactiveResult = base.MouseUpCore(interactionArguments);  
 
             //Now, we need to reset the column values of "IsSelected" for the relevant features.  
             foreach (int index in draggedPointsIndex)  
             {  
                 this.ExistingControlPointsLayer.InternalFeatures[index].ColumnValues["IsSelected"] = "true";  
             }  
             this.ExistingControlPointsLayer.Close();  
 
             return interactiveResult;  
         }  
 
         //Overrides the DrawCore function.  
         protected override void DrawCore(GeoCanvas canvas)  
         {  
             //Draws the Edit Shapes as default.  
             Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>();  
             EditShapesLayer.Open();  
             EditShapesLayer.Draw(canvas, labelsInAllLayers);  
             canvas.Flush();  
 
             //Gets the control points and draw its features according to the value of "IsSelected" column.  
             this.ExistingControlPointsLayer.Open();  
             Collection<Feature> ExistingControlPoints = this.ExistingControlPointsLayer.QueryTools.GetAllFeatures(new string[1] { "IsSelected" });  
             ExistingControlPointsLayer.Close();  
 
             //Loops thru the control points features and check for the value of "IsSelected" collumn.  
             foreach (Feature feature in ExistingControlPoints)  
             {  
                 if (feature.ColumnValues.ContainsKey("IsSelected") && feature.ColumnValues["IsSelected"] == "true")  
                 {  
                     Feature[] features = new Feature[1] { feature };  
                     selectedControlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers);  
                 }  
                 else  
                 {  
                     Feature[] features = new Feature[1] { feature };  
                     controlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers);  
                 }  
             }  
         }  
     }  
 }  
 

TestForm.cs

using System;  
 using System.Windows.Forms;  
 using System.Collections.ObjectModel;  
 using System.IO;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 
 namespace  SelectVertices  
 {  
     public partial class TestForm : Form  
     {  
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             winformsMap1.MapUnit = GeographyUnit.DecimalDegree;  
             winformsMap1.CurrentExtent = new RectangleShape(-97.755, 30.319, -97.7266, 30.3018);  
             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);  
 
             string fileName1 = @"..\..\data\polygon.txt";  
             StreamReader sr1 = new StreamReader(fileName1);  
 
             string fileName2 = @"..\..\data\line.txt";  
             StreamReader sr2 = new StreamReader(fileName2);  
 
             //DragtInteractiveOverlay for setting the PointStyles of the control points and dragged points.  
             SelectVerticesEditInteractiveOverlay selectVerticesEditInteractiveOverlay = new SelectVerticesEditInteractiveOverlay();  
             selectVerticesEditInteractiveOverlay.EditShapesLayer.InternalFeatures.Add("Polygon", new Feature(BaseShape.CreateShapeFromWellKnownData(sr1.ReadLine())));  
 
             //Sets the PointStyle for the non dragged control points.  
             selectVerticesEditInteractiveOverlay.ControlPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.PaleGoldenrod), new GeoPen(GeoColor.StandardColors.Black), 8);  
             //Sets the PointStyle for the dragged control points.  
             selectVerticesEditInteractiveOverlay.SelectedControlPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Green), new GeoPen(GeoColor.StandardColors.DarkGreen, 2), 10);  
             //LineShape snapping feature.  
             LineShape snappingLineShape = (LineShape)BaseShape.CreateShapeFromWellKnownData(sr2.ReadLine());  
 
 
             selectVerticesEditInteractiveOverlay.CanAddVertex = false;  
             selectVerticesEditInteractiveOverlay.CanDrag = false;  
             selectVerticesEditInteractiveOverlay.CanRemoveVertex = false;  
             selectVerticesEditInteractiveOverlay.CanResize = false;  
             selectVerticesEditInteractiveOverlay.CanRotate = false;  
             selectVerticesEditInteractiveOverlay.CalculateAllControlPoints();  
 
             winformsMap1.EditOverlay = selectVerticesEditInteractiveOverlay;  
 
             //Regular InMemoryFeatureLayer for displaying line snapping feature.  
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 4, true);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             inMemoryFeatureLayer.InternalFeatures.Add(new Feature(snappingLineShape));  
 
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add(inMemoryFeatureLayer);  
             winformsMap1.Overlays.Add(layerOverlay);  
 
             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_selectvertices_cs_101104.zip.txt · Last modified: 2015/09/08 04:15 by admin