using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace CSHowDoISamples { public partial class TrackAndEditShapes : UserControl { List points = new List(); public TrackAndEditShapes() { InitializeComponent(); } private void WpfMap_Loaded(object sender, RoutedEventArgs e) { wpfMap1.MapUnit = GeographyUnit.DecimalDegree; wpfMap1.CurrentExtent = new RectangleShape(-133.2515625, 89.2484375, 126.9046875, -88.290625); WorldMapKitWmsWpfOverlay worldMapKitOverlay = new WorldMapKitWmsWpfOverlay(); wpfMap1.Overlays.Add(worldMapKitOverlay); wpfMap1.TrackOverlay.TrackEnded += new System.EventHandler(TrackOverlay_TrackEnded); wpfMap1.Refresh(); } private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e) { if (wpfMap1.TrackOverlay.TrackMode == TrackMode.Point) { PointShape point = e.TrackShape as PointShape; if (point != null) { points.Add(point); if (points.Count == 2) { Feature lastPointFeature = wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures .Where(feature => feature.GetWellKnownText() == points[0].GetWellKnownText()) .FirstOrDefault(); wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Remove(lastPointFeature); points.RemoveAt(0); wpfMap1.TrackOverlay.Refresh(); } } } } private void button_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button != null) { switch (button.Name) { case "btnTrackNormal": wpfMap1.TrackOverlay.TrackMode = TrackMode.None; break; case "btnTrackPoint": wpfMap1.TrackOverlay.TrackMode = TrackMode.Point; points.Clear(); break; case "btnTrackLine": wpfMap1.TrackOverlay.TrackMode = TrackMode.Line; break; case "btnTrackRectangle": wpfMap1.TrackOverlay.TrackMode = TrackMode.Rectangle; break; case "btnTrackSquare": wpfMap1.TrackOverlay.TrackMode = TrackMode.Square; break; case "btnTrackPolygon": wpfMap1.TrackOverlay.TrackMode = TrackMode.Polygon; break; case "btnTrackCircle": wpfMap1.TrackOverlay.TrackMode = TrackMode.Circle; break; case "btnTrackEllipse": wpfMap1.TrackOverlay.TrackMode = TrackMode.Ellipse; break; case "btnTrackEdit": wpfMap1.TrackOverlay.TrackMode = TrackMode.None; foreach (Feature feature in wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures) { wpfMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature); } wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear(); wpfMap1.EditOverlay.CalculateAllControlPoints(); wpfMap1.Refresh(new Overlay[] { wpfMap1.EditOverlay, wpfMap1.TrackOverlay }); break; case "btnTrackDelete": // should use TrackMode.EditShape select a shape, and then call DeleteTrackShape(); int lastIndex = wpfMap1.EditOverlay.EditShapesLayer.InternalFeatures.Count - 1; if (lastIndex >= 0) { wpfMap1.EditOverlay.EditShapesLayer.InternalFeatures.RemoveAt(lastIndex); wpfMap1.EditOverlay.CalculateAllControlPoints(); } wpfMap1.Refresh(wpfMap1.EditOverlay); break; default: wpfMap1.TrackOverlay.TrackMode = TrackMode.None; break; } } } } }