User Tools

Site Tools


source_code_serviceseditionsample_removelineshape_cs_100425.zip

Source Code ServicesEditionSample RemoveLineShape CS 100425.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace RemoveLineFromMultiLine  
 {  
     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.Collections.Generic;  
 using System.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 
 namespace RemoveLineFromMultiLine  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
 
        public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             // Set the extent and the background color  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-95.3123,38.9718,-95.2837,38.9549), Map.Width, Map.Height);  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
             //Displays the World Map Kit as a background.  
             ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer();  
             mapEngine.StaticLayers.Add(worldMapKitLayer);  
 
             //InMemoryFeatureLayer to display features for MultilineShape and PointShape.  
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(150,GeoColor.StandardColors.Red), 8, false);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Green, 15);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Text", "Arial", 12, DrawingFontStyles.Bold, GeoColor.StandardColors.Black);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             //Creates the MultiLineShape.  
             MultilineShape multiLineShape = new MultilineShape();  
             LineShape lineShape1 = new LineShape();  
             lineShape1.Vertices.Add(new Vertex(-95.3002, 38.9625));  
             lineShape1.Vertices.Add(new Vertex(-95.2988, 38.9621));  
 
             LineShape lineShape2 = new LineShape();  
             lineShape2.Vertices.Add(new Vertex(-95.2988,38.9621));  
             lineShape2.Vertices.Add(new Vertex(-95.2961,38.962));  
 
             LineShape lineShape3 = new LineShape();  
             lineShape3.Vertices.Add(new Vertex(-95.2961,38.962));  
             lineShape3.Vertices.Add(new Vertex(-95.2945,38.9622));  
 
             LineShape lineShape4 = new LineShape();  
             lineShape4.Vertices.Add(new Vertex(-95.2945,38.9622));  
             lineShape4.Vertices.Add(new Vertex(-95.2885,38.9622));  
 
             multiLineShape.Lines.Add(lineShape1);  
             multiLineShape.Lines.Add(lineShape2);  
             multiLineShape.Lines.Add(lineShape3);  
             multiLineShape.Lines.Add(lineShape4);  
 
             double Longitude = -95.2953;  
             double Latitude =  38.9621;  
 
             //Addss the features with the columns.  
             inMemoryFeatureLayer.Open();  
             inMemoryFeatureLayer.EditTools.BeginTransaction();  
             inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Text"));  
             Feature multilineFeature = new Feature(multiLineShape);  
             multilineFeature.ColumnValues.Add("Text", "Multiline");  
             inMemoryFeatureLayer.InternalFeatures.Add("Multiline",multilineFeature);  
             Feature pointFeature = new Feature(new PointShape(Longitude,Latitude));  
             pointFeature.ColumnValues.Add("Text", "Point");  
             inMemoryFeatureLayer.InternalFeatures.Add("Point", pointFeature);  
             inMemoryFeatureLayer.EditTools.CommitTransaction();  
             inMemoryFeatureLayer.Close();  
 
             mapEngine.DynamicLayers.Add("MultilineLayer",inMemoryFeatureLayer);  
 
             DrawImage();  
         }  
 
         private void button1_Click(object sender, EventArgs e)  
         {  
             InMemoryFeatureLayer inmemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers[0];  
             PointShape pointShape = (PointShape)inmemoryFeatureLayer.InternalFeatures[1].GetShape();  
 
             RemoveLinesFromMultilineShapeLine("MultilineLayer", "Multiline", pointShape.X, pointShape.Y);  
 
             DrawImage();  
         }  
 
         //Removes a LineShape of the MultilineShape based on a Point.  
         public void RemoveLinesFromMultilineShapeLine(string inMemoryFeatureLayerKey, string multilineKey, double Longitude, double Latitude)  
         {  
             InMemoryFeatureLayer lineLayer = null;  
 
             if (mapEngine.DynamicLayers.Contains(inMemoryFeatureLayerKey))  
             {  
                 if (mapEngine.DynamicLayers[inMemoryFeatureLayerKey] is InMemoryFeatureLayer)  
                 {  
                     lineLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers[inMemoryFeatureLayerKey];  
 
                     if (lineLayer.InternalFeatures.Contains(multilineKey))  
                     {  
                         MultilineShape existingMultiLineShape = (MultilineShape)lineLayer.InternalFeatures[multilineKey].GetShape();  
                         int index = 0;  
                         EllipseShape ellipseShape = new EllipseShape(new PointShape(Longitude, Latitude), 5, GeographyUnit.DecimalDegree, DistanceUnit.Meter);  
 
                         foreach (LineShape lineShape in existingMultiLineShape.Lines)  
                         {  
                             //If the LineShape crosses the ellipseShape then we remove that LineShape.  
                             if (lineShape.Crosses(ellipseShape))  
                             {  
                                 existingMultiLineShape.Lines.RemoveAt(index);  
                                 break;  
                             }  
                             index = index + 1;  
                         }  
 
                         Dictionary<string,string> columnValues= lineLayer.InternalFeatures[multilineKey].ColumnValues;  
                         lineLayer.InternalFeatures[multilineKey] = new Feature(existingMultiLineShape, columnValues);  
                     }  
                 }  
             }  
         }  
 
         private void DrawImage()  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.CloseAllLayers();  
 
             Map.Image = bitmap;  
         }  
 
         private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)  
         {  
             switch (e.Button.Tag.ToString())  
             {  
                 case "Zoom In":  
                     mapEngine.CurrentExtent.ScaleDown(50);  
                     break;  
                 case "Zoom Out":  
                     mapEngine.CurrentExtent.ScaleUp(50);  
                     break;  
                 case "Full Extent":  
                     mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height);  
                     break;  
                 case "Pan Left":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20);  
                     break;  
                 case "Pan Right":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20);  
                     break;  
                 case "Pan Up":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20);  
                     break;  
                 case "Pan Down":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20);  
                     break;  
                 default:  
                     break;  
             }  
             DrawImage();  
         }  
 
         private void btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
 
         private void Map_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(mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), Map.Width, Map.Height);  
 
             //Displays world coordinates.  
             statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4);  
         }  
 
 
     }  
 }  
 
source_code_serviceseditionsample_removelineshape_cs_100425.zip.txt · Last modified: 2015/09/08 05:35 by admin