using MapControl; using MapControl.UiTools; using System; using System.Globalization; using System.IO; using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; namespace SampleApplication { public sealed partial class MainPage : Page { static MainPage() { ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application"); TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new MapControl.Caching.SQLiteCache(TileImageLoader.DefaultCacheFolder); var bingMapsApiKeyPath = "BingMapsApiKey.txt"; if (File.Exists(bingMapsApiKeyPath)) { BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyPath)?.Trim(); } } public MainPage() { 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 = new SolidColorBrush(Colors.White), MapBackground = new SolidColorBrush(Colors.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 = new SolidColorBrush(Colors.White), MapBackground = new SolidColorBrush(Colors.Black) } }); } AddChartServerLayer(); } partial void AddChartServerLayer(); private void ResetHeadingButtonClick(object sender, RoutedEventArgs e) { map.TargetHeading = 0d; } private void MapPointerMoved(object sender, PointerRoutedEventArgs e) { var location = map.ViewToLocation(e.GetCurrentPoint(map).Position); 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'; } mouseLocation.Text = 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); mouseLocation.Visibility = Visibility.Visible; } private void MapPointerExited(object sender, PointerRoutedEventArgs e) { mouseLocation.Visibility = Visibility.Collapsed; mouseLocation.Text = string.Empty; } } }