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.Collections.ObjectModel; using System.Linq; using System.Text; using ThinkGeo.MapSuite.Core; namespace StartEndLineStyle { class CustomStartEndLineStyle : LineStyle { private PointStyle startPointStyle; private PointStyle endPointStyle; private LineStyle lineStyle; public CustomStartEndLineStyle() : this(new PointStyle(PointSymbolType.Square, new GeoSolidBrush(GeoColor.StandardColors.Green), 12), new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Red), 12), new LineStyle(new GeoPen(GeoColor.FromArgb(150,GeoColor.StandardColors.BlueViolet),6))) { } public CustomStartEndLineStyle(PointStyle StartPointStyle, PointStyle EndPointStyle, LineStyle LineStyle) { this.startPointStyle = StartPointStyle; this.endPointStyle = EndPointStyle; this.lineStyle = LineStyle; } protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers) { Collection<BaseShape> startPointShapes = new Collection<BaseShape>(); Collection<BaseShape> endPointShapes = new Collection<BaseShape>(); Collection<BaseShape> multiLineShapes = new Collection<BaseShape>(); //Loops thru the features to display the first and end point of each LineShape of the MultilineShape. foreach (Feature feature in features) { MultilineShape multilineShape = (MultilineShape)feature.GetShape(); multiLineShapes.Add(multilineShape); for (int i = 0; i <= multilineShape.Lines.Count - 1; i++) { LineShape lineShape = multilineShape.Lines[i]; startPointShapes.Add(new PointShape(lineShape.Vertices[0])); endPointShapes.Add(new PointShape(lineShape.Vertices[lineShape.Vertices.Count|- 1])); } } lineStyle.Draw(multiLineShapes, canvas, labelsInThisLayer, labelsInAllLayers); startPointStyle.Draw(startPointShapes, canvas, labelsInThisLayer, labelsInAllLayers); endPointStyle.Draw(endPointShapes, canvas, labelsInThisLayer, labelsInAllLayers); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace StartEndLineStyle { 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.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace StartEndLineStyle { 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(-97.7347,30.2883,-97.7274,30.2841), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.StandardColors.LightGoldenrodYellow); //Displays the Austin street shapefile. ShapeFileFeatureLayer layer1 = new ShapeFileFeatureLayer(@"../../data/Austinstreets.shp"); layer1.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad2; layer1.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.LocalRoad2("NAME"); layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Gets the feature to display with the CustomStartEndLineStyle. layer1.Open(); Feature feature = layer1.FeatureSource.GetFeatureById("7838", ReturningColumnsType.AllColumns); layer1.Close(); InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); //Adds the CustomStartEndLineStyle to the CustomStyles of the InMemoryFeatureLayer. inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new CustomStartEndLineStyle()); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; inMemoryFeatureLayer.InternalFeatures.Add(feature); mapEngine.StaticLayers.Add(layer1); 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); } } }