using System; using System.Windows.Forms; using System.Collections.ObjectModel; using System.IO; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; using System.Collections.Generic; namespace DraggedPointStyle { public partial class TestForm : Form { TrackInteractiveOverlay featureOverlay = null; EditInteractiveOverlay selectedFeatureOverlay = null; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.Meter; // create a overlay with a selectable line feature featureOverlay = new TrackInteractiveOverlay(); List LineSegmentPoints = new List(); LineSegmentPoints.Add(new Vertex(150, 150)); LineSegmentPoints.Add(new Vertex(300, 900)); Feature f = new Feature(new LineShape(LineSegmentPoints)); featureOverlay.TrackShapeLayer.InternalFeatures.Add(f); winformsMap1.Overlays.Add(featureOverlay); // create a overlay in which a selected feature can be editted selectedFeatureOverlay = new MyEditOverlay(); winformsMap1.EditOverlay = selectedFeatureOverlay; winformsMap1.MapClick += new EventHandler(winformsMap1_MapClick); winformsMap1.CurrentExtent = new RectangleShape(0,1000, 1000, 0); winformsMap1.Refresh(); } void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e) { // deselect all selected features foreach (Feature selectedFeature in selectedFeatureOverlay.EditShapesLayer.InternalFeatures) { featureOverlay.TrackShapeLayer.InternalFeatures.Add(selectedFeature); } selectedFeatureOverlay.EditShapesLayer.InternalFeatures.Clear(); // collect clicked on features int screenBuffer = 15; ScreenPointF clickedPointF = new ScreenPointF(e.ScreenX, e.ScreenY); ScreenPointF bufferPointF = new ScreenPointF(clickedPointF.X + screenBuffer, clickedPointF.Y); double distanceBuffer = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(winformsMap1.CurrentExtent, clickedPointF, bufferPointF, winformsMap1.Width, winformsMap1.Height, winformsMap1.MapUnit, DistanceUnit.Meter); Collection columnNames = new Collection(); Collection toBeSelectedFeatures = featureOverlay.TrackShapeLayer.FeatureSource.GetFeaturesNearestTo(new PointShape(e.WorldX, e.WorldY), winformsMap1.MapUnit, 1, columnNames, distanceBuffer, DistanceUnit.Meter); // if the user clicked on a feature, move it to be editable if (toBeSelectedFeatures.Count > 0) { foreach (Feature toBeSelectedFeature in toBeSelectedFeatures) { selectedFeatureOverlay.EditShapesLayer.InternalFeatures.Add(toBeSelectedFeature); } featureOverlay.TrackShapeLayer.InternalFeatures.Clear(); } selectedFeatureOverlay.CalculateAllControlPoints(); winformsMap1.Refresh(selectedFeatureOverlay); winformsMap1.Refresh(featureOverlay); } } class MyEditOverlay : EditInteractiveOverlay { // protected override void DrawCore(GeoCanvas canvas) { // Collection labelsInAllLayers = new Collection(); // EditShapesLayer.Open(); // EditShapesLayer.Draw(canvas, labelsInAllLayers); // DragControlPointsLayer.Open(); // DragControlPointsLayer.Draw(canvas, labelsInAllLayers); // canvas.Flush(); //} } }