2013-05-07 18:12:25 +02:00
|
|
|
|
using System;
|
2020-10-24 11:12:47 +02:00
|
|
|
|
using System.Diagnostics;
|
2013-04-12 19:59:16 +02:00
|
|
|
|
using System.Globalization;
|
2020-10-24 11:12:47 +02:00
|
|
|
|
using System.IO;
|
2020-06-24 21:05:07 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2012-05-04 12:52:20 +02:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Input;
|
2013-05-07 18:12:25 +02:00
|
|
|
|
using MapControl;
|
2020-10-24 11:12:47 +02:00
|
|
|
|
using MapControl.Caching;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
using ViewModel;
|
2012-05-04 12:52:20 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
namespace WpfApplication
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
|
{
|
2020-10-24 11:12:47 +02:00
|
|
|
|
static MainWindow()
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2020-10-24 11:12:47 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
|
|
|
|
|
|
|
|
|
|
|
|
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
//TileImageLoader.Cache = null;
|
2014-10-19 21:50:23 +02:00
|
|
|
|
|
2020-10-24 11:12:47 +02:00
|
|
|
|
BingMapsTileLayer.ApiKey = File.ReadAllText(@"..\..\..\BingMapsApiKey.txt")?.Trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
|
{
|
2012-05-04 12:52:20 +02:00
|
|
|
|
InitializeComponent();
|
2020-06-24 21:05:07 +02:00
|
|
|
|
|
2020-10-24 11:12:47 +02:00
|
|
|
|
if (TileImageLoader.Cache is ImageFileCache cache)
|
2020-06-24 21:05:07 +02:00
|
|
|
|
{
|
2020-10-24 11:12:47 +02:00
|
|
|
|
Loaded += async (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
await Task.Delay(2000);
|
|
|
|
|
|
await cache.Clean();
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
private void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
if (e.ClickCount == 2)
|
|
|
|
|
|
{
|
2017-08-04 21:38:58 +02:00
|
|
|
|
//map.ZoomMap(e.GetPosition(map), Math.Floor(map.ZoomLevel + 1.5));
|
2017-06-25 23:05:48 +02:00
|
|
|
|
//map.ZoomToBounds(new BoundingBox(53, 7, 54, 9));
|
2020-03-28 21:53:38 +01:00
|
|
|
|
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapMouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.ClickCount == 2)
|
|
|
|
|
|
{
|
2017-10-07 17:43:28 +02:00
|
|
|
|
//map.ZoomMap(e.GetPosition(map), Math.Ceiling(map.ZoomLevel - 1.5));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapMouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
2020-03-28 21:53:38 +01:00
|
|
|
|
var location = map.ViewToLocation(e.GetPosition(map));
|
2014-07-09 21:27:28 +02:00
|
|
|
|
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
|
|
|
|
|
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
|
|
|
|
|
var latHemisphere = 'N';
|
|
|
|
|
|
var lonHemisphere = 'E';
|
|
|
|
|
|
|
|
|
|
|
|
if (latitude < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
latitude = -latitude;
|
|
|
|
|
|
latHemisphere = 'S';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (longitude < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
longitude = -longitude;
|
|
|
|
|
|
lonHemisphere = 'W';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mouseLocation.Text = string.Format(CultureInfo.InvariantCulture,
|
|
|
|
|
|
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
2017-06-25 23:05:48 +02:00
|
|
|
|
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
|
|
|
|
|
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-29 18:22:50 +01:00
|
|
|
|
private void MapMouseLeave(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
mouseLocation.Text = string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
private void MapManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.TranslationBehavior.DesiredDeceleration = 0.001;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-17 16:52:03 +01:00
|
|
|
|
private void MapItemTouchDown(object sender, TouchEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var mapItem = (MapItem)sender;
|
|
|
|
|
|
mapItem.IsSelected = !mapItem.IsSelected;
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 23:03:13 +02:00
|
|
|
|
private void SeamarksChecked(object sender, RoutedEventArgs e)
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2017-10-09 18:01:45 +02:00
|
|
|
|
map.Children.Insert(map.Children.IndexOf(mapGraticule), ((MapViewModel)DataContext).MapLayers.SeamarksLayer);
|
2014-06-11 23:03:13 +02:00
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
|
2014-06-11 23:03:13 +02:00
|
|
|
|
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2017-10-09 18:01:45 +02:00
|
|
|
|
map.Children.Remove(((MapViewModel)DataContext).MapLayers.SeamarksLayer);
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|