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.Configuration; using System.Data; using System.Linq; using System.Windows; namespace SaveLoadState { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { } }
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 SaveLoadState { /// <summary> /// Interaction logic for TestWindow.xaml /// </summary> public partial class TestWindow : Window { //private byte[] savedStates; 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(-128,51,-65,19); wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243)); WorldMapKitWmsWpfOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsWpfOverlay(); wpfMap1.Overlays.Add(worldMapKitDesktopOverlay); //SimpleMarkerOverlay for points. SimpleMarkerOverlay simpleMarkerOverlay = new SimpleMarkerOverlay(); simpleMarkerOverlay.DragMode = MarkerDragMode.Drag; wpfMap1.Overlays.Add("SimpleMarkerOverlay", simpleMarkerOverlay); wpfMap1.Refresh(); btnSave.IsEnabled = false; } private void btnLoad_Click(object sender, RoutedEventArgs e) { //Loads the SimpleMakerOverlay from file SimpleMarkerOverlay simpleMarkerOverlay = (SimpleMarkerOverlay)wpfMap1.Overlays["SimpleMarkerOverlay"]; //Gets the byte array from file to load the SimpleMarkerOverlay Byte[] savedStates = ByteArrayFromFile(@"..\..\data\points.dat"); simpleMarkerOverlay.LoadState(savedStates); simpleMarkerOverlay.Refresh(); btnSave.IsEnabled = true; } private void btnSave_Click(object sender, RoutedEventArgs e) { SimpleMarkerOverlay simpleMarkerOverlay = (SimpleMarkerOverlay)wpfMap1.Overlays["SimpleMarkerOverlay"]; //Gets the byte array of SimpleMarkerOverlay to save to file. Byte[] savedStates = simpleMarkerOverlay.SaveState(); ByteArrayToFile(@"..\..\data\points.dat", savedStates); } public void ByteArrayToFile(string fileName, byte[] byteArray) { FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write); fileStream.Write(byteArray, 0, byteArray.Length); fileStream.Close(); } public byte[] ByteArrayFromFile(string fileName) { byte[] byteArray = null; FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader binaryReader = new BinaryReader(fileStream); long numBytes = new FileInfo(fileName).Length; byteArray = binaryReader.ReadBytes((int)numBytes); return byteArray; } 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); } } }