User Tools

Site Tools


source_code_serviceseditionsample_routingextension_routingstyles_cs_100211.zip

Source Code ServicesEditionSample RoutingExtension RoutingStyles CS 100211.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace RoutingStyles  
 {  
     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.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.Routing;  
 
 namespace RoutingStyles  
 {  
     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)  
         {  
             // Defines layer to render the Austin streets  
             ShapeFileFeatureLayer StreetLayer = new ShapeFileFeatureLayer(@"..\..\Data\austinstreets.shp");  
             StreetLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad3;  
             StreetLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             mapEngine.StaticLayers.Add("AustinStreets", StreetLayer);  
 
             // Define a Routing layer to render the route and stops  
             StreetLayer.Open();  
             Feature feature1 = StreetLayer.FeatureSource.GetFeatureById("7906", ReturningColumnsType.NoColumns);  
             Feature feature2 = StreetLayer.FeatureSource.GetFeatureById("5725", ReturningColumnsType.NoColumns);  
             StreetLayer.Close();  
 
             //InMemoryFeatureLayer for displaying the start and end point.  
             InMemoryFeatureLayer pointsInMemoryFeatureLayer = new InMemoryFeatureLayer();  
             //Adds column to InMemoryFeatureLayer for Type.  
             pointsInMemoryFeatureLayer.Open();  
             pointsInMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Type"));  
             pointsInMemoryFeatureLayer.Close();  
 
             //From Zoom level 01 to 15, displays as simple circles. Uses ValueStyle based on type (Start or End point).  
             ValueStyle valueStyle1 = new ValueStyle();  
             valueStyle1.ColumnName = "Type";  
             valueStyle1.ValueItems.Add(new ValueItem("Start", new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Green), 8)));  
             valueStyle1.ValueItems.Add(new ValueItem("End", new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Red), 8)));  
             pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle1);  
             pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level15;  
             //From zomm levels 16 to 18, displays with icons and label. Uses ValueStyle based on type (Start or End point).  
             pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel16.CustomStyles.Add(LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Orange, 3, GeoColor.StandardColors.Black, 6, true));  
             pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel16.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("Type", "Arial", 12, DrawingFontStyles.Bold,  
                                                                                  GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3, 11, 0));  
             ValueStyle valueStyle2 = new ValueStyle();  
             valueStyle2.ColumnName = "Type";  
             valueStyle2.ValueItems.Add(new ValueItem("Start", new PointStyle(new GeoImage(@"..\..\Data\startpoint_car.png"))));  
             valueStyle2.ValueItems.Add(new ValueItem("End", new PointStyle(new GeoImage(@"..\..\Data\endpoint_stopsign.png"))));  
             pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel16.CustomStyles.Add(valueStyle2);  
             pointsInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel16.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             Feature startFeature = new Feature(feature1.GetShape().GetCenterPoint());  
             startFeature.ColumnValues["Type"] = "Start";  
 
             Feature endFeature = new Feature(feature2.GetShape().GetCenterPoint());  
             endFeature.ColumnValues["Type"] = "End";  
 
             pointsInMemoryFeatureLayer.InternalFeatures.Add(startFeature);  
             pointsInMemoryFeatureLayer.InternalFeatures.Add(endFeature);  
 
             //Finds the route between start point and end point. The rtg file needs to be build by Routing explorer if it has not been done already.  
             RtgRoutingSource rtgRoutingSource = new RtgRoutingSource(@"..\..\Data\austinstreets.rtg");  
             RoutingEngine routingEngine = new RoutingEngine(rtgRoutingSource, StreetLayer.FeatureSource);  
             LineShape routeLineShape = routingEngine.GetRoute(feature1.GetShape().GetCenterPoint(), feature2.GetShape().GetCenterPoint()).Route;  
 
             //InMemoryFeatureLayer for displaying the route.  
             InMemoryFeatureLayer routeInMemoryFeatureLayer = new InMemoryFeatureLayer();  
             //From zoom levels 01 to 15, displays as a simple orange line style.  
             routeInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.DarkOrange, 3, true);  
             routeInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level15;  
             //From zoom levels 16 to 16, displays as thicker orange line with black outline.  
             routeInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel16.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Orange, 3, GeoColor.StandardColors.Black, 6, true);  
             routeInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel16.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             Feature routeFeature = new Feature(routeLineShape);  
             routeInMemoryFeatureLayer.InternalFeatures.Add("Route", routeFeature);  
 
             mapEngine.DynamicLayers.Add("Routes", routeInMemoryFeatureLayer);  
             mapEngine.DynamicLayers.Add("Points", pointsInMemoryFeatureLayer);  
 
             mapEngine.CurrentExtent = new RectangleShape(-97.7566, 30.3048, -97.7206, 30.2764);  
 
             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_routingextension_routingstyles_cs_100211.zip.txt · Last modified: 2015/09/08 08:02 by admin