ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace SmoothTransparentRoute { 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()); } } }
using System; using System.Collections.ObjectModel; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; using ThinkGeo.MapSuite.Routing; namespace SmoothTransparentRoute { public partial class TestForm : Form { private static RoutingEngine routingEngine; private static RoutingSource RoutingSourceForFastest; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.CurrentExtent = new RectangleShape(-97.7563, 30.2989, -97.6998, 30.2651); winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)); ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(@"..\..\data\Austinstreets.shp"); RoutingSourceForFastest = new RtgRoutingSource(@"..\..\data\AustinStreetsForFastest.rtg"); routingEngine = new RoutingEngine(RoutingSourceForFastest, featureSource); RenderMap(); FindPath(); winformsMap1.Refresh(); } private void FindPath() { RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.Routes.Clear(); LineShape routeLine = new LineShape(); LineShape route = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint).Route; //Logic for merging the collection of LineShape of two vertices into one LineShape with the multiple vertices. routeLine.Vertices.Add(route.Vertices[0]); for (int i = 0; i < route.Vertices.Count - 1; i++) { LineShape routeSegment = new LineShape(new Collection<Vertex> { route.Vertices[i], route.Vertices[i|+ 1] }); MergeSegments(routeLine, routeSegment); } routingLayer.Routes.Add(routeLine); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); } private void MergeSegments(LineShape destinationLine, LineShape sourceLine) { if (destinationLine.Vertices[destinationLine.Vertices.Count|- 1] == sourceLine.Vertices[0]) { for (int i = 1; i < sourceLine.Vertices.Count; i++) { destinationLine.Vertices.Add(sourceLine.Vertices[i]); } } else { for (int i = sourceLine.Vertices.Count - 2; i >= 0; i--) { destinationLine.Vertices.Add(sourceLine.Vertices[i]); } } } private void RenderMap() { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#e6e5d1")); WorldMapKitWmsDesktopOverlay worldMapKitsOverlay = new WorldMapKitWmsDesktopOverlay(); winformsMap1.Overlays.Add(worldMapKitsOverlay); ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(@"..\..\data\Austinstreets.shp"); featureSource.Open(); RoutingLayer routingLayer = new RoutingLayer(); routingLayer.RouteStyle.OuterPen.Color = new GeoColor(120, GeoColor.SimpleColors.Blue); routingLayer.StartPoint = new PointShape(-97.7322, 30.2951); routingLayer.EndPoint = new PointShape(-97.7246, 30.2674); LayerOverlay routingOverlay = new LayerOverlay(); routingOverlay.Layers.Add("RoutingLayer", routingLayer); winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay); InMemoryFeatureLayer routingExtentLayer = new InMemoryFeatureLayer(); routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Green)); routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; routingExtentLayer.InternalFeatures.Add(new Feature(new RectangleShape(-97.815409, 30.369949, -97.657999, 30.217922))); routingOverlay.Layers.Add("RoutingExtentLayer", routingExtentLayer); 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(); } } }