2024-05-24 15:28:28 +02:00
|
|
|
|
using Avalonia.Controls;
|
2024-05-28 18:56:28 +02:00
|
|
|
|
using Avalonia.Data.Converters;
|
2024-05-24 15:28:28 +02:00
|
|
|
|
using Avalonia.Input;
|
|
|
|
|
|
using Avalonia.Media;
|
|
|
|
|
|
using MapControl;
|
|
|
|
|
|
using MapControl.UiTools;
|
|
|
|
|
|
using System;
|
2024-05-28 18:56:28 +02:00
|
|
|
|
using System.Globalization;
|
2024-05-24 15:28:28 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
2024-05-27 11:10:10 +02:00
|
|
|
|
namespace SampleApplication
|
2024-05-24 15:28:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
|
{
|
|
|
|
|
|
static MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
//TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder);
|
|
|
|
|
|
|
|
|
|
|
|
var bingMapsApiKeyPath = Path.Combine(
|
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(bingMapsApiKeyPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyPath)?.Trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey))
|
|
|
|
|
|
{
|
|
|
|
|
|
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = "Bing Maps Road",
|
|
|
|
|
|
Layer = new BingMapsTileLayer
|
|
|
|
|
|
{
|
|
|
|
|
|
Mode = BingMapsTileLayer.MapMode.Road,
|
|
|
|
|
|
SourceName = "Bing Maps Road",
|
|
|
|
|
|
Description = "© [Microsoft](http://www.bing.com/maps/)"
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = "Bing Maps Aerial",
|
|
|
|
|
|
Layer = new BingMapsTileLayer
|
|
|
|
|
|
{
|
|
|
|
|
|
Mode = BingMapsTileLayer.MapMode.Aerial,
|
|
|
|
|
|
SourceName = "Bing Maps Aerial",
|
|
|
|
|
|
Description = "© [Microsoft](http://www.bing.com/maps/)",
|
|
|
|
|
|
MapForeground = Brushes.White,
|
|
|
|
|
|
MapBackground = Brushes.Black
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = "Bing Maps Aerial with Labels",
|
|
|
|
|
|
Layer = new BingMapsTileLayer
|
|
|
|
|
|
{
|
|
|
|
|
|
Mode = BingMapsTileLayer.MapMode.AerialWithLabels,
|
|
|
|
|
|
SourceName = "Bing Maps Hybrid",
|
|
|
|
|
|
Description = "© [Microsoft](http://www.bing.com/maps/)",
|
|
|
|
|
|
MapForeground = Brushes.White,
|
|
|
|
|
|
MapBackground = Brushes.Black
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnMapDoubleTapped(object sender, TappedEventArgs e)
|
|
|
|
|
|
{
|
2024-05-28 18:56:28 +02:00
|
|
|
|
if (e.Source == map)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ResetHeadingButtonClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.TargetHeading = 0d;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MapHeadingToVisibilityConverter : IValueConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (double)value != 0d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotSupportedException();
|
2024-05-24 15:28:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|