From 8aed92638f2689fcefd0691fb97a2b1db9db53d2 Mon Sep 17 00:00:00 2001 From: ClemensF Date: Sat, 24 Oct 2020 11:12:47 +0200 Subject: [PATCH] Bing Maps Key from file --- SampleApps/Shared/MapLayers.cs | 2 - SampleApps/WpfApplication/MainWindow.xaml.cs | 40 ++++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/SampleApps/Shared/MapLayers.cs b/SampleApps/Shared/MapLayers.cs index 83cb98d4..e7cb9e94 100644 --- a/SampleApps/Shared/MapLayers.cs +++ b/SampleApps/Shared/MapLayers.cs @@ -163,8 +163,6 @@ namespace ViewModel // A Bing Maps API Key (http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required // for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property. - //BingMapsTileLayer.ApiKey = "..."; - if (!string.IsNullOrEmpty(BingMapsTileLayer.ApiKey)) { MapLayerNames.Add("Bing Maps Road"); diff --git a/SampleApps/WpfApplication/MainWindow.xaml.cs b/SampleApps/WpfApplication/MainWindow.xaml.cs index 291e1da8..5cbabafe 100644 --- a/SampleApps/WpfApplication/MainWindow.xaml.cs +++ b/SampleApps/WpfApplication/MainWindow.xaml.cs @@ -1,31 +1,49 @@ using System; +using System.Diagnostics; using System.Globalization; +using System.IO; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using MapControl; +using MapControl.Caching; using ViewModel; namespace WpfApplication { public partial class MainWindow : Window { + static MainWindow() + { + 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; + + BingMapsTileLayer.ApiKey = File.ReadAllText(@"..\..\..\BingMapsApiKey.txt")?.Trim(); + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message); + } + } + public MainWindow() { - ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application"); - var cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder); - TileImageLoader.Cache = cache; - //TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheFolder); - //TileImageLoader.Cache = new MapControl.Caching.SQLiteCache(TileImageLoader.DefaultCacheFolder); - //TileImageLoader.Cache = null; - InitializeComponent(); - Loaded += async (s, e) => + if (TileImageLoader.Cache is ImageFileCache cache) { - await Task.Delay(2000); - await cache.Clean(); - }; + Loaded += async (s, e) => + { + await Task.Delay(2000); + await cache.Clean(); + }; + } } private void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)