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.Collections.ObjectModel; using System.Drawing; using System.Windows.Forms; using System.Collections.Generic; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace DraggedPointStyleWithLabel { class DragInteractiveOverlay : EditInteractiveOverlay { private PointStyle controlPointStyle; private PointStyle draggedControlPointStyle; private BaseShape referenceShape; public PointStyle ControlPointStyle { get { return controlPointStyle; } set { controlPointStyle = value; } } public PointStyle DraggedControlPointStyle { get { return draggedControlPointStyle; } set { draggedControlPointStyle = value; } } public BaseShape ReferenceShape { get { return referenceShape; } set { referenceShape = value; } } //Overrides the DrawCore function. protected override void DrawCore(GeoCanvas canvas) { //Draws the Edit Shapes as default. Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>(); EditShapesLayer.Open(); EditShapesLayer.Draw(canvas, labelsInAllLayers); canvas.Flush(); //Draws the control points. ExistingControlPointsLayer.Open(); Collection<Feature> controlPoints = ExistingControlPointsLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns); //Loops thru the control points. foreach (Feature feature in controlPoints) { //Looks at the value of "state" to draw the control point as dragged or not. if (feature.ColumnValues["state"] != "selected") { Feature[] features = new Feature[1] { feature }; controlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers); } else { Feature[] features = new Feature[1] { feature }; draggedControlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers); PointShape pointShape = feature.GetShape() as PointShape; PointShape closestPointShape = referenceShape.GetClosestPointTo(pointShape, GeographyUnit.DecimalDegree); //Draws the closest point on the reference shape and the distance to it from the dragged control point. if (closestPointShape != null) { double Dist = System.Math.Round(closestPointShape.GetDistanceTo(pointShape, GeographyUnit.DecimalDegree, DistanceUnit.Meter)); ScreenPointF ScreenPointF = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, pointShape, canvas.Width, canvas.Height); canvas.DrawTextWithScreenCoordinate(System.Convert.ToString(Dist) + " m", new GeoFont("Arial", 12, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.StandardColors.Black), ScreenPointF.X + 35, ScreenPointF.Y, DrawingLevel.LabelLevel); canvas.DrawEllipse(closestPointShape, 12, 12, new GeoSolidBrush(GeoColor.StandardColors.Purple), DrawingLevel.LevelFour); } } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace DraggedPointStyleWithLabel { 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.Windows.Forms; using System.Collections.ObjectModel; using System.IO; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; namespace DraggedPointStyleWithLabel { public partial class TestForm : Form { public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.CurrentExtent = new RectangleShape(-97.7591, 30.3126, -97.7317, 30.2964); winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay(); winformsMap1.Overlays.Add(worldMapKitDesktopOverlay); string fileName1 = @"..\..\data\polygon.txt"; StreamReader sr1 = new StreamReader(fileName1); string fileName2 = @"..\..\data\line.txt"; StreamReader sr2 = new StreamReader(fileName2); //DragtInteractiveOverlay for setting the PointStyles of the control points and dragged points. DragInteractiveOverlay dragInteractiveOverlay = new DragInteractiveOverlay(); dragInteractiveOverlay.ReferenceShape = BaseShape.CreateShapeFromWellKnownData(sr1.ReadLine()); dragInteractiveOverlay.EditShapesLayer.InternalFeatures.Add("MultiLine", new Feature(BaseShape.CreateShapeFromWellKnownData(sr2.ReadLine()))); //Sets the PointStyle for the non dragged control points. dragInteractiveOverlay.ControlPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.PaleGoldenrod), new GeoPen(GeoColor.StandardColors.Black), 8); //Sets the PointStyle for the dragged control points. dragInteractiveOverlay.DraggedControlPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Red), new GeoPen(GeoColor.StandardColors.Orange, 2), 10); // Add the point feature and specify text style. dragInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("LabelColumn", new GeoFont("Arial", 12), new GeoSolidBrush(GeoColor.SimpleColors.Black)); dragInteractiveOverlay.CanAddVertex = false; dragInteractiveOverlay.CanDrag = false; dragInteractiveOverlay.CanRemoveVertex = false; dragInteractiveOverlay.CanResize = false; dragInteractiveOverlay.CanRotate = false; dragInteractiveOverlay.CalculateAllControlPoints(); winformsMap1.EditOverlay = dragInteractiveOverlay; //InMemoryFeatureLayer for the geometry of the reference shape InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Red, GeoColor.StandardColors.Black); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Feature newFeature = new Feature(dragInteractiveOverlay.ReferenceShape ); inMemoryFeatureLayer.Open(); inMemoryFeatureLayer.EditTools.BeginTransaction(); inMemoryFeatureLayer.EditTools.Add(newFeature); inMemoryFeatureLayer.EditTools.CommitTransaction(); inMemoryFeatureLayer.Close(); LayerOverlay referenceOverlay = new LayerOverlay(); referenceOverlay.Layers.Add("Reference", inMemoryFeatureLayer); winformsMap1.Overlays.Add(referenceOverlay); 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(); } } }