123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media.Imaging;
- using Google.Maps;
- using Google.Maps.StaticMaps;
- using InABox.Wpf;
- namespace PRSDesktop.Forms
- {
- /// <summary>
- /// Interaction logic for MapForm.xaml
- /// </summary>
- public partial class MapForm : ThemableWindow
- {
- String GOOGLE_KEY = "AIzaSyChZhoJCzeaOm8q2QMm2KJOgc26aCeopjQ";
- StaticMapRequest request = new StaticMapRequest();
- StaticMapService service = new StaticMapService();
- public BitmapImage ToImage(byte[] array)
- {
- using (var ms = new System.IO.MemoryStream(array))
- {
- var image = new BitmapImage();
- image.BeginInit();
- image.CacheOption = BitmapCacheOption.OnLoad; // here
- image.StreamSource = ms;
- image.EndInit();
- return image;
- }
- }
- public MapForm(double latitude, double longitude, DateTime timestamp)
- {
- InitializeComponent();
- GoogleSigned.AssignAllServices(new GoogleSigned(GOOGLE_KEY));
- request = new StaticMapRequest();
- String sLoc = String.Format("{0},{1}", latitude, longitude);
- Location location = new Location(sLoc);
- request.Center = location;
- request.Markers.Add(location);
- request.Scale = 2;
- request.Size = new MapSize(640, 640); // Convert.ToInt32(ActualWidth)-20, Convert.ToInt32(ActualHeight)-20);
- request.Zoom = 15;
- service = new StaticMapService();
- var imageSource = new BitmapImage();
- imageSource.BeginInit();
- imageSource.StreamSource = service.GetStream(request);
- imageSource.CacheOption = BitmapCacheOption.OnLoad;
- imageSource.EndInit();
- staticmap.Source = imageSource;
- TimeStamp.Content = String.Format("Last Updated {0:dd MMM yyy hh:mm:ss tt}", timestamp);
- }
- private void staticmap_MouseUp(object sender, MouseButtonEventArgs e)
- {
- Close();
- }
- }
- }
|