Replaced BingMaps by MapTiler

This commit is contained in:
ClemensFischer 2024-12-06 22:42:56 +01:00
parent 35df7e0155
commit 82466bbab7
6 changed files with 60 additions and 85 deletions

View file

@ -1,76 +0,0 @@
using System;
using System.IO;
using MapControl;
using MapControl.UiTools;
#if WPF
using System.Windows.Media;
#elif WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml.Media;
#elif UWP
using Windows.UI;
using Windows.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Media;
#endif
namespace SampleApplication
{
#if UWP
public partial class MainPage
#else
public partial class MainWindow
#endif
{
partial void AddBingMapsLayers()
{
#if UWP
var bingMapsApiKeyPath = "BingMapsApiKey.txt";
#else
var bingMapsApiKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "BingMapsApiKey.txt");
#endif
if (File.Exists(bingMapsApiKeyPath))
{
BingMapsTileLayer.ApiKey = File.ReadAllText(bingMapsApiKeyPath)?.Trim();
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)
}
});
}
}
}
}

View file

@ -0,0 +1,50 @@
using System;
using System.IO;
using MapControl;
using MapControl.UiTools;
#if WPF
using System.Windows.Media;
#elif WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml.Media;
#elif UWP
using Windows.UI;
using Windows.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Media;
#endif
namespace SampleApplication
{
#if UWP
public partial class MainPage
#else
public partial class MainWindow
#endif
{
partial void AddMapTilerLayers()
{
#if UWP
var mapTilerApiKeyPath = "BingMapsApiKey.txt";
#else
var mapTilerApiKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "MapTilerApiKey.txt");
#endif
if (File.Exists(mapTilerApiKeyPath))
{
string apiKey = File.ReadAllText(mapTilerApiKeyPath)?.Trim();
mapLayersMenuButton.MapLayers.Add(new MapLayerItem
{
Text = "MapTiler Satellite",
Layer = new MapTileLayer
{
TileSource = new TileSource { UriTemplate = "https://api.maptiler.com/maps/satellite/{z}/{x}/{y}.jpg?key=" + apiKey },
SourceName = "MapTiler Satellite",
Description = "© [MapTiler](https://www.maptiler.com/)"
}
});
}
}
}
}

View file

@ -25,11 +25,11 @@ namespace SampleApplication
{
InitializeComponent();
AddBingMapsLayers();
AddMapTilerLayers();
AddTestLayers();
}
partial void AddBingMapsLayers();
partial void AddMapTilerLayers();
partial void AddTestLayers();
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)

View file

@ -48,12 +48,12 @@
<EnableGatekeeperAnalysis>false</EnableGatekeeperAnalysis>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\BingMapsLayers.cs">
<Link>BingMapsLayers.cs</Link>
</Compile>
<Compile Include="..\Shared\HyperlinkText.cs">
<Link>HyperlinkText.cs</Link>
</Compile>
<Compile Include="..\Shared\MapTilerLayers.cs">
<Link>MapTilerLayers.cs</Link>
</Compile>
<Compile Include="..\Shared\MapViewModel.cs">
<Link>MapViewModel.cs</Link>
</Compile>

View file

@ -26,11 +26,11 @@ namespace SampleApplication
Title = "XAML Map Control - WinUI Sample Application";
AddBingMapsLayers();
AddMapTilerLayers();
AddTestLayers();
}
partial void AddBingMapsLayers();
partial void AddMapTilerLayers();
partial void AddTestLayers();
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)

View file

@ -6,6 +6,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace SampleApplication
{
@ -29,11 +30,11 @@ namespace SampleApplication
{
InitializeComponent();
AddBingMapsLayers();
AddMapTilerLayers();
AddTestLayers();
}
partial void AddBingMapsLayers();
partial void AddMapTilerLayers();
partial void AddTestLayers();
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)