User Tools

Site Tools


source_code_serviceseditionsample_textstyleformultiline_cs_100831.zip

Source Code ServicesEditionSample TextStyleForMultiLine CS 100831.zip

MultiLabelTextStyle.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace TextStyleForMultiLine  
 {  
     class MultiLabelTextStyle : TextStyle  
     {  
         public MultiLabelTextStyle(string textColumnName, GeoFont textFont, GeoSolidBrush textSolidBrush)  
         : base(textColumnName, textFont, textSolidBrush)  
         { }  
 
         protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             Collection<Feature> featuresForDrawing = new Collection<Feature>();  
             foreach (Feature feature in features)  
             {  
                 if (feature.GetWellKnownType() == WellKnownType.Multiline)  
                 {  
                     MultilineShape multiline = (MultilineShape)(feature.GetShape());  
 
                     foreach (LineShape line in multiline.Lines)  
                     {  
                         Feature newFeature = new Feature(line);  
                         CopyColumnValues(newFeature, feature);  
                         featuresForDrawing.Add(newFeature);  
                     }  
                 }  
                 else  
                 {  
                     featuresForDrawing.Add(feature);  
                 }  
             }  
 
             base.DrawCore(featuresForDrawing, canvas, labelsInThisLayer, labelsInAllLayers);  
         }  
 
         private static void CopyColumnValues(Feature targetFeature, Feature sourceFeature)  
         {  
             targetFeature.ColumnValues.Clear();  
             foreach (KeyValuePair<string, string> item in sourceFeature.ColumnValues)  
             {  
                 targetFeature.ColumnValues.Add(item.Key, item.Value);  
             }  
         }  
 
     }  
 }  
 

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace TextStyleForMultiLine  
 {  
     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.ObjectModel;  
 using System.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace TextStyleForMultiLine  
 {  
     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(-96.8563,33.0969,-96.8377,33.0863), 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);  
 
             MultilineShape multiLineShape = new MultilineShape();  
             LineShape lineShape1 = new LineShape();  
             lineShape1.Vertices.Add(new Vertex(-96.8536, 33.0873));  
             lineShape1.Vertices.Add(new Vertex(-96.8473, 33.0873));  
             LineShape lineShape2 = new LineShape();  
             lineShape2.Vertices.Add(new Vertex(-96.8416, 33.0899));  
             lineShape2.Vertices.Add(new Vertex(-96.8393, 33.0899));  
             LineShape lineShape3 = new LineShape();  
             lineShape3.Vertices.Add(new Vertex(-96.8403, 33.0941));  
             lineShape3.Vertices.Add(new Vertex(-96.8417, 33.0969));  
             multiLineShape.Lines.Add(lineShape1);  
             multiLineShape.Lines.Add(lineShape2);  
             multiLineShape.Lines.Add(lineShape3);  
 
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.Open();  
             inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Name"));  
             inMemoryFeatureLayer.Close();  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.Red), 10, true);  
             //inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Name", "Arial", 12, DrawingFontStyles.Bold, GeoColor.StandardColors.Black);  
 
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new MultiLabelTextStyle("Name", new GeoFont("Arial", 12, DrawingFontStyles.Bold),  
                                                                                                     new GeoSolidBrush(GeoColor.StandardColors.Black));  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.TextLineSegmentRatio = 2;  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             Feature feature = new Feature(multiLineShape);  
             feature.ColumnValues.Add("Name", "In Reparation");  
 
             inMemoryFeatureLayer.InternalFeatures.Add(feature);  
 
             mapEngine.DynamicLayers.Add(inMemoryFeatureLayer);  
 
             DrawImage();  
         }  
 
 
         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_textstyleformultiline_cs_100831.zip.txt · Last modified: 2015/09/08 08:03 by admin