2021-12-05 17:16:14 +01:00
|
|
|
|
using MapControl;
|
|
|
|
|
|
using System;
|
2023-01-06 16:01:03 +01:00
|
|
|
|
using System.Diagnostics;
|
2013-04-12 19:59:16 +02:00
|
|
|
|
using System.Globalization;
|
2023-01-06 16:01:03 +01:00
|
|
|
|
using System.Linq;
|
2012-05-04 12:52:20 +02:00
|
|
|
|
using System.Windows;
|
2024-05-31 10:40:29 +02:00
|
|
|
|
using System.Windows.Controls;
|
2012-05-04 12:52:20 +02:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
2021-10-28 20:26:51 +02:00
|
|
|
|
namespace SampleApplication
|
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
|
|
|
|
{
|
2024-02-11 15:28:36 +01:00
|
|
|
|
//TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
//TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
//TileImageLoader.Cache = new MapControl.Caching.SQLiteCache(TileImageLoader.DefaultCacheFolder);
|
2024-02-10 20:50:09 +01:00
|
|
|
|
//TileImageLoader.Cache = new RedisCache(Options.Create(new RedisCacheOptions
|
|
|
|
|
|
//{
|
2024-08-24 23:12:35 +02:00
|
|
|
|
// Configuration = "yoga:6379",
|
2024-02-10 20:50:09 +01:00
|
|
|
|
// InstanceName = "MapTileCache/"
|
|
|
|
|
|
//}));
|
2020-10-24 11:12:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
|
{
|
2012-05-04 12:52:20 +02:00
|
|
|
|
InitializeComponent();
|
2020-06-24 21:05:07 +02:00
|
|
|
|
|
2024-06-30 16:21:36 +02:00
|
|
|
|
AddBingMapsLayers();
|
2022-11-28 17:34:06 +01:00
|
|
|
|
AddTestLayers();
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-30 16:21:36 +02:00
|
|
|
|
partial void AddBingMapsLayers();
|
2022-11-28 17:34:06 +01:00
|
|
|
|
partial void AddTestLayers();
|
2022-01-13 20:12:49 +01:00
|
|
|
|
|
2024-05-31 10:40:29 +02:00
|
|
|
|
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine("SelectedItems: " + string.Join(", ", ((MapItemsControl)sender).SelectedItems.OfType<PointItem>().Select(item => item.Name)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-06 17:54:46 +01:00
|
|
|
|
private void ResetHeadingButtonClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TargetHeading = 0d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 16:01:03 +01:00
|
|
|
|
private async void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
2022-12-02 23:15:09 +01:00
|
|
|
|
{
|
2024-08-25 18:09:20 +02:00
|
|
|
|
if (e.ClickCount == 2 && e.Source == map)
|
2022-12-02 23:15:09 +01:00
|
|
|
|
{
|
2022-12-03 20:57:34 +01:00
|
|
|
|
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
2022-12-02 23:15:09 +01:00
|
|
|
|
}
|
2023-01-06 16:01:03 +01:00
|
|
|
|
else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) &&
|
|
|
|
|
|
map.MapLayer is WmsImageLayer wmsLayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(e.GetPosition(map)));
|
|
|
|
|
|
}
|
2022-12-02 23:15:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 16:01:03 +01:00
|
|
|
|
private void MapMouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2023-01-06 16:01:03 +01:00
|
|
|
|
var location = map.ViewToLocation(e.GetPosition(map));
|
|
|
|
|
|
|
2024-07-15 00:02:30 +02:00
|
|
|
|
if (location != null && map.CaptureMouse())
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2024-08-24 23:12:35 +02:00
|
|
|
|
map.Cursor = Cursors.Cross;
|
2023-01-06 16:01:03 +01:00
|
|
|
|
measurementLine.Visibility = Visibility.Visible;
|
|
|
|
|
|
measurementLine.Locations = new LocationCollection(location);
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 16:01:03 +01:00
|
|
|
|
private void MapMouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
2024-07-15 00:02:30 +02:00
|
|
|
|
map.ReleaseMouseCapture();
|
2024-08-24 23:12:35 +02:00
|
|
|
|
map.Cursor = null;
|
2023-01-06 16:01:03 +01:00
|
|
|
|
measurementLine.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
measurementLine.Locations = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-03-04 22:28:18 +01:00
|
|
|
|
if (location != null)
|
2014-07-09 21:27:28 +02:00
|
|
|
|
{
|
2023-01-06 16:01:03 +01:00
|
|
|
|
mouseLocation.Visibility = Visibility.Visible;
|
|
|
|
|
|
mouseLocation.Text = GetLatLonText(location);
|
2022-03-04 22:28:18 +01:00
|
|
|
|
|
2023-01-06 16:01:03 +01:00
|
|
|
|
var start = measurementLine.Locations?.FirstOrDefault();
|
2014-07-09 21:27:28 +02:00
|
|
|
|
|
2023-01-06 16:01:03 +01:00
|
|
|
|
if (start != null)
|
2022-03-04 22:28:18 +01:00
|
|
|
|
{
|
2023-01-06 16:01:03 +01:00
|
|
|
|
measurementLine.Locations = LocationCollection.OrthodromeLocations(start, location);
|
|
|
|
|
|
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
|
2022-03-04 22:28:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2014-07-09 21:27:28 +02:00
|
|
|
|
{
|
2023-01-05 15:37:43 +01:00
|
|
|
|
mouseLocation.Visibility = Visibility.Collapsed;
|
2024-07-12 18:42:18 +02:00
|
|
|
|
mouseLocation.Text = "";
|
2014-07-09 21:27:28 +02:00
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-29 18:22:50 +01:00
|
|
|
|
private void MapMouseLeave(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
2023-01-05 15:37:43 +01:00
|
|
|
|
mouseLocation.Visibility = Visibility.Collapsed;
|
2024-07-12 18:42:18 +02:00
|
|
|
|
mouseLocation.Text = "";
|
2014-10-29 18:22:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-01-06 16:01:03 +01:00
|
|
|
|
|
|
|
|
|
|
private static string GetLatLonText(Location location)
|
|
|
|
|
|
{
|
|
|
|
|
|
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';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return string.Format(CultureInfo.InvariantCulture,
|
|
|
|
|
|
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
|
|
|
|
|
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
|
|
|
|
|
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-24 23:12:35 +02:00
|
|
|
|
private static string GetDistanceText(double distance)
|
2023-01-06 16:01:03 +01:00
|
|
|
|
{
|
|
|
|
|
|
var unit = "m";
|
|
|
|
|
|
|
|
|
|
|
|
if (distance >= 1000d)
|
|
|
|
|
|
{
|
|
|
|
|
|
distance /= 1000d;
|
|
|
|
|
|
unit = "km";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var distanceFormat = distance >= 100d ? "F0" : "F1";
|
|
|
|
|
|
|
|
|
|
|
|
return string.Format(CultureInfo.InvariantCulture, "\n {0:" + distanceFormat + "} {1}", distance, unit);
|
|
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|