XAML-Map-Control/SampleApps/WinUiApp/MainWindow.xaml.cs

75 lines
2.2 KiB
C#
Raw Normal View History

2021-07-01 22:07:46 +02:00
using MapControl;
using MapControl.Caching;
using Microsoft.UI.Xaml;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using ViewModel;
namespace WinUiApp
{
public sealed partial class MainWindow : Window
{
private readonly MapViewModel viewModel = new();
static MainWindow()
{
try
{
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
2021-07-02 21:18:39 +02:00
var bingMapsApiKeyFile = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
2021-07-01 22:07:46 +02:00
2021-07-02 21:18:39 +02:00
BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyFile)?.Trim();
2021-07-04 15:45:18 +02:00
//TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
2021-07-02 21:18:39 +02:00
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);
2021-07-01 22:07:46 +02:00
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public MainWindow()
{
InitializeComponent();
Title = "XAML Map Control - WinUI Sample Application";
root.DataContext = viewModel;
2021-07-07 19:30:05 +02:00
if (TileImageLoader.Cache is ImageFileCache)
2021-07-01 22:07:46 +02:00
{
2021-07-07 19:30:05 +02:00
Activated += WindowActivated;
2021-07-01 22:07:46 +02:00
}
}
2021-07-07 19:30:05 +02:00
private async void WindowActivated(object sender, WindowActivatedEventArgs e)
{
Activated -= WindowActivated;
await Task.Delay(2000);
await ((ImageFileCache)TileImageLoader.Cache).Clean();
}
2021-07-01 22:07:46 +02:00
private void SeamarksChecked(object sender, RoutedEventArgs e)
{
map.Children.Insert(map.Children.IndexOf(graticule), viewModel.MapLayers.SeamarksLayer);
}
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
{
map.Children.Remove(viewModel.MapLayers.SeamarksLayer);
}
2021-07-07 19:30:05 +02:00
private void MapViewportChanged(object sender, ViewportChangedEventArgs e)
{
GC.Collect();
}
2021-07-01 22:07:46 +02:00
}
}