User Tools

Site Tools


source_code_wpfdesktopeditionsample_trackedshapestofile_cs_101126.zip

Source Code WpfDesktopEditionSample TrackedShapesToFile CS 101126.zip

App.xaml.cs

using System;  
 using System.Collections.Generic;  
 using System.Configuration;  
 using System.Data;  
 using System.Linq;  
 using System.Windows;  
 
 namespace TrackedShapesToFile  
 {  
     /// <summary>  
     /// Interaction logic for App.xaml  
     /// </summary>  
     public partial class App : Application  
     {  
     }  
 }  
 

TestWindow.xaml.cs

using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using System.IO;  
 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Data;  
 using System.Windows.Documents;  
 using System.Windows.Input;  
 using System.Windows.Media;  
 using System.Windows.Media.Imaging;  
 using System.Windows.Shapes;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace TrackedShapesToFile  
 {  
     /// <summary>  
     /// Interaction logic for TestWindow.xaml  
     /// </summary>  
     public partial class TestWindow : Window  
     {  
         public TestWindow()  
         {  
             InitializeComponent();  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             //Sets the correct map unit and the extent of the map.  
             wpfMap1.MapUnit = GeographyUnit.DecimalDegree;  
             wpfMap1.CurrentExtent = new RectangleShape(-96.8419,33.1069,-96.8254,33.0950);  
             wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243));  
 
             WorldMapKitWmsWpfOverlay worldMapKitWmsWpfOverlay = new WorldMapKitWmsWpfOverlay();  
             wpfMap1.Overlays.Add(worldMapKitWmsWpfOverlay);  
 
             //Event handler for the TrackOverlay  
             wpfMap1.TrackOverlay.TrackEnded += new EventHandler<TrackEndedTrackInteractiveOverlayEventArgs>(trackOverlay_TrackEnded);  
 
             //Loops thru the files in the Data directory to create the features from WKT. Then, we add the features to the TrackShapeLayer  
             //of the TrackOverlay.  
             string[] filePaths = Directory.GetFiles(@"../../Data", "*.txt");  
             foreach (string filePath in filePaths)  
             {  
                 StreamReader streamReader = new StreamReader(filePath);  
                 string WKT = streamReader.ReadLine();  
                 BaseShape baseShape = BaseShape.CreateShapeFromWellKnownData(WKT);  
 
                 Feature feature = new Feature(baseShape);  
                 wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Add(feature);  
             }  
 
             wpfMap1.TrackOverlay.TrackMode = TrackMode.Line;  
 
             wpfMap1.Refresh();  
         }  
 
         void trackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)  
         {  
             //When tracking the shape is finished, we create a file with the WKT of the tracked shape.  
             string WKT = e.TrackShape.GetWellKnownText();  
             WellKnownType wellKnownType = e.TrackShape.GetWellKnownType();  
 
             Guid guid = Guid.NewGuid();  
             StreamWriter streamWriter = new StreamWriter(@"../../data/" + wellKnownType.ToString() + guid.ToString());  
             streamWriter.WriteLine(WKT);  
             streamWriter.Close();  
 
         }  
 
         private void radioButtonTrackPolygon_Checked(object sender, RoutedEventArgs e)  
         {  
             if (radioButtonTrackPolygon.IsChecked == true) wpfMap1.TrackOverlay.TrackMode = TrackMode.Polygon;  
         }  
 
         private void radioButtonTrackLine_Checked(object sender, RoutedEventArgs e)  
         {  
             if (radioButtonTrackLine.IsChecked == true) wpfMap1.TrackOverlay.TrackMode = TrackMode.Line;  
         }  
 
 
         private void wpfMap1_MouseMove(object sender, MouseEventArgs e)  
         {  
             //Gets the PointShape in world coordinates from screen coordinates.  
             Point point = e.MouseDevice.GetPosition(null);  
 
             ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y);  
             PointShape pointShape = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, screenPointF, (float)wpfMap1.Width, (float)wpfMap1.Height);  
 
             textBox1.Text = "X: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.X) +  
                           "  Y: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.Y);  
         }  
     }  
 }  
 
source_code_wpfdesktopeditionsample_trackedshapestofile_cs_101126.zip.txt · Last modified: 2015/09/08 05:08 by admin