2024-05-24 15:28:28 +02:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
using Avalonia.Input;
|
|
|
|
|
|
using MapControl;
|
2024-07-15 00:02:30 +02:00
|
|
|
|
using System;
|
2024-05-31 10:40:29 +02:00
|
|
|
|
using System.Diagnostics;
|
2024-07-15 00:02:30 +02:00
|
|
|
|
using System.Globalization;
|
2024-05-31 10:40:29 +02:00
|
|
|
|
using System.Linq;
|
2024-05-24 15:28:28 +02:00
|
|
|
|
|
2024-05-27 11:10:10 +02:00
|
|
|
|
namespace SampleApplication
|
2024-05-24 15:28:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
|
{
|
2025-02-22 16:07:21 +01:00
|
|
|
|
public MainWindow()
|
2024-05-24 15:28:28 +02:00
|
|
|
|
{
|
2025-03-22 17:08:43 +01:00
|
|
|
|
TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
Closed += (s, e) => (TileImageLoader.Cache as IDisposable)?.Dispose();
|
2024-05-24 15:28:28 +02:00
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
2024-05-29 17:19:03 +02:00
|
|
|
|
AddTestLayers();
|
2024-05-28 18:56:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 17:19:03 +02:00
|
|
|
|
partial void AddTestLayers();
|
2024-05-28 18:56:28 +02:00
|
|
|
|
|
2024-05-31 22:45:50 +02:00
|
|
|
|
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)
|
2024-05-31 10:40:29 +02:00
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine("SelectedItems: " + string.Join(", ", ((MapItemsControl)sender).SelectedItems.OfType<PointItem>().Select(item => item.Name)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-15 00:02:30 +02:00
|
|
|
|
private void ResetHeadingButtonClick(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TargetHeading = 0d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-31 09:17:44 +02:00
|
|
|
|
private void MapDoubleTapped(object sender, TappedEventArgs e)
|
2024-05-28 18:56:28 +02:00
|
|
|
|
{
|
2024-08-25 18:02:23 +02:00
|
|
|
|
if (e.Source == map)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
|
|
|
|
|
}
|
2024-05-28 18:56:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-15 00:02:30 +02:00
|
|
|
|
private void MapPointerPressed(object sender, PointerPressedEventArgs e)
|
2024-05-28 18:56:28 +02:00
|
|
|
|
{
|
2024-07-15 00:02:30 +02:00
|
|
|
|
if (e.Pointer.Type == PointerType.Mouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
var point = e.GetCurrentPoint(map);
|
|
|
|
|
|
|
2024-08-25 18:02:23 +02:00
|
|
|
|
if (point.Properties.IsRightButtonPressed)
|
2024-07-15 00:02:30 +02:00
|
|
|
|
{
|
|
|
|
|
|
e.Pointer.Capture(map);
|
|
|
|
|
|
var location = map.ViewToLocation(point.Position);
|
|
|
|
|
|
|
|
|
|
|
|
if (location != null)
|
|
|
|
|
|
{
|
2024-08-24 23:12:35 +02:00
|
|
|
|
map.Cursor = new Cursor(StandardCursorType.Cross);
|
2024-07-15 00:02:30 +02:00
|
|
|
|
measurementLine.IsVisible = true;
|
|
|
|
|
|
measurementLine.Locations = new LocationCollection(location);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapPointerReleased(object sender, PointerReleasedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Pointer.Captured == map)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Pointer.Capture(null);
|
2024-08-25 18:02:23 +02:00
|
|
|
|
map.Cursor = null;
|
2024-07-15 00:02:30 +02:00
|
|
|
|
measurementLine.IsVisible = false;
|
|
|
|
|
|
measurementLine.Locations = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapPointerMoved(object sender, PointerEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var location = map.ViewToLocation(e.GetPosition(map));
|
|
|
|
|
|
|
|
|
|
|
|
if (location != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mouseLocation.IsVisible = true;
|
|
|
|
|
|
mouseLocation.Text = GetLatLonText(location);
|
|
|
|
|
|
|
|
|
|
|
|
var start = measurementLine.Locations?.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
if (start != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
measurementLine.Locations = LocationCollection.OrthodromeLocations(start, location);
|
|
|
|
|
|
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mouseLocation.IsVisible = false;
|
|
|
|
|
|
mouseLocation.Text = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapPointerExited(object sender, PointerEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
mouseLocation.IsVisible = false;
|
|
|
|
|
|
mouseLocation.Text = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string GetLatLonText(MapControl.Location location)
|
|
|
|
|
|
{
|
|
|
|
|
|
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
|
|
|
|
|
var longitude = (int)Math.Round(MapControl.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)
|
2024-07-15 00:02:30 +02: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);
|
2024-05-24 15:28:28 +02:00
|
|
|
|
}
|
2025-03-22 17:08:43 +01:00
|
|
|
|
|
|
|
|
|
|
private void MapItemsControl_PointerPressed(object sender, Avalonia.Input.PointerPressedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine("PointerPressed");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapItemsControl_PointerReleased(object sender, Avalonia.Input.PointerReleasedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine("PointerReleased");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MapItemsControl_Tapped(object sender, Avalonia.Input.TappedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine("Tapped");
|
|
|
|
|
|
}
|
2024-05-24 15:28:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|