mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Removed default User-Agent header.
Using a library's default User-Agent violates OpenStreetMap's tile usage policy: https://operations.osmfoundation.org/policies/tiles/
This commit is contained in:
parent
8124d5714a
commit
66a51906ef
10 changed files with 67 additions and 30 deletions
|
|
@ -10,16 +10,43 @@ using System.Windows.Input;
|
|||
|
||||
namespace SampleApplication
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class HttpHandler : DelegatingHandler
|
||||
{
|
||||
public HttpHandler()
|
||||
#if NET
|
||||
: base(new SocketsHttpHandler())
|
||||
#else
|
||||
: base(new HttpClientHandler())
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
Debug.WriteLine(request.RequestUri);
|
||||
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
var httpClient = new HttpClient(new HttpHandler()) { Timeout = TimeSpan.FromSeconds(10) };
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Avalonia Sample Application");
|
||||
ImageLoader.HttpClient = httpClient;
|
||||
|
||||
var loggerFactory = LoggerFactory.Create(builder => builder.AddDebug().SetMinimumLevel(LogLevel.Information));
|
||||
ImageLoader.LoggerFactory = loggerFactory;
|
||||
|
||||
//var tileCache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder, loggerFactory);
|
||||
//TileImageLoader.Cache = tileCache;
|
||||
//Closed += (s, e) => tileCache.Dispose();
|
||||
var tileCache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder, loggerFactory);
|
||||
TileImageLoader.Cache = tileCache;
|
||||
Closed += (s, e) => tileCache.Dispose();
|
||||
|
||||
InitializeComponent();
|
||||
AddTestLayers();
|
||||
|
|
@ -43,6 +70,10 @@ namespace SampleApplication
|
|||
{
|
||||
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
||||
}
|
||||
else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
{
|
||||
map.ProjectionCenter = map.ViewToLocation(e.GetPosition(map));
|
||||
}
|
||||
else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) &&
|
||||
map.MapLayer is WmsImageLayer wmsLayer)
|
||||
{
|
||||
|
|
@ -83,7 +114,7 @@ namespace SampleApplication
|
|||
|
||||
if (start != null)
|
||||
{
|
||||
measurementLine.Locations = LocationCollection.OrthodromeLocations(start, location);
|
||||
measurementLine.Locations = LocationCollection.GeodesicLocations(start, location);
|
||||
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue