Version 4.10.0: Updated target framework versions. Cleanup of TypeConverters, ImageLoader, MBTileSource.

This commit is contained in:
ClemensF 2018-08-08 23:31:52 +02:00
parent 63a4c1f0a7
commit 6a1653056f
36 changed files with 272 additions and 292 deletions

View file

@ -10,7 +10,10 @@ namespace MapControl
/// <summary>
/// A geographic bounding box with south and north latitude and west and east longitude values in degrees.
/// </summary>
public partial class BoundingBox
#if !WINDOWS_UWP
[System.ComponentModel.TypeConverter(typeof(BoundingBoxConverter))]
#endif
public class BoundingBox
{
private double south;
private double west;

View file

@ -0,0 +1,69 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Diagnostics;
using System.Threading.Tasks;
#if WINDOWS_UWP
using Windows.Web.Http;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
#else
using System.Net.Http;
using System.Windows.Media;
using System.Windows.Media.Imaging;
#endif
namespace MapControl
{
public static partial class ImageLoader
{
/// <summary>
/// The HttpClient instance used when image data is downloaded from a web resource.
/// </summary>
public static HttpClient HttpClient { get; set; } = new HttpClient();
public static async Task<ImageSource> LoadImageAsync(Uri uri, bool isTileImage)
{
ImageSource imageSource = null;
if (!uri.IsAbsoluteUri || uri.Scheme == "file")
{
imageSource = await LoadLocalImageAsync(uri);
}
else if (uri.Scheme == "http")
{
imageSource = await LoadHttpImageAsync(uri, isTileImage);
}
else
{
imageSource = new BitmapImage(uri);
}
return imageSource;
}
public static async Task<ImageSource> LoadHttpImageAsync(Uri uri, bool isTileImage)
{
ImageSource imageSource = null;
using (var response = await HttpClient.GetAsync(uri))
{
if (!response.IsSuccessStatusCode)
{
Debug.WriteLine("ImageLoader: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
}
else if (!isTileImage || IsTileAvailable(response.Headers))
{
using (var stream = await GetResponseStreamAsync(response.Content))
{
imageSource = await CreateImageSourceAsync(stream);
}
}
return imageSource;
}
}
}
}

View file

@ -10,7 +10,10 @@ namespace MapControl
/// <summary>
/// A geographic location with latitude and longitude values in degrees.
/// </summary>
public partial class Location : IEquatable<Location>
#if !WINDOWS_UWP
[System.ComponentModel.TypeConverter(typeof(LocationConverter))]
#endif
public class Location : IEquatable<Location>
{
private double latitude;
private double longitude;

View file

@ -11,7 +11,10 @@ namespace MapControl
/// <summary>
/// A collection of Locations with support for parsing.
/// </summary>
public partial class LocationCollection : List<Location>
#if !WINDOWS_UWP
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
#endif
public class LocationCollection : List<Location>
{
public LocationCollection()
{

View file

@ -7,6 +7,9 @@ using System.Linq;
namespace MapControl
{
/// <summary>
/// Provides helper methods for geodetic calculations on a sphere.
/// </summary>
public static class LocationEx
{
/// <summary>
@ -18,9 +21,48 @@ namespace MapControl
var lon1 = location1.Longitude * Math.PI / 180d;
var lat2 = location2.Latitude * Math.PI / 180d;
var lon2 = location2.Longitude * Math.PI / 180d;
var cosS12 = Math.Sin(lat1) * Math.Sin(lat2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1);
var sinLat1 = Math.Sin(lat1);
var cosLat1 = Math.Cos(lat1);
var sinLat2 = Math.Sin(lat2);
var cosLat2 = Math.Cos(lat2);
var cosLon12 = Math.Cos(lon2 - lon1);
var cosS12 = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosLon12;
var s12 = 0d;
return earthRadius * Math.Acos(Math.Min(Math.Max(cosS12, -1d), 1d));
if (Math.Abs(cosS12) < 0.99999999)
{
s12 = Math.Acos(Math.Min(Math.Max(cosS12, -1d), 1d));
}
else
{
var sinLon12 = Math.Sin(lon2 - lon1);
var a = cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosLon12;
var b = cosLat2 * sinLon12;
s12 = Math.Atan2(Math.Sqrt(a * a + b * b), cosS12);
}
return earthRadius * s12;
}
/// <summary>
/// see https://en.wikipedia.org/wiki/Great-circle_navigation
/// </summary>
public static Location GreatCircleLocation(this Location location, double azimuth, double distance, double earthRadius = MapProjection.Wgs84EquatorialRadius)
{
var s12 = distance / earthRadius;
var az1 = azimuth * Math.PI / 180d;
var lat1 = location.Latitude * Math.PI / 180d;
var lon1 = location.Longitude * Math.PI / 180d;
var sinS12 = Math.Sin(s12);
var cosS12 = Math.Cos(s12);
var sinAz1 = Math.Sin(az1);
var cosAz1 = Math.Cos(az1);
var sinLat1 = Math.Sin(lat1);
var cosLat1 = Math.Cos(lat1);
var lat2 = Math.Asin(sinLat1 * cosS12 + cosLat1 * sinS12 * cosAz1);
var lon2 = lon1 + Math.Atan2(sinS12 * sinAz1, (cosLat1 * cosS12 - sinLat1 * sinS12 * cosAz1));
return new Location(lat2 / Math.PI * 180d, lon2 / Math.PI * 180d);
}
public static LocationCollection CalculateMeridianLocations(this Location location, double latitude2, double resolution = 1d)

View file

@ -344,9 +344,11 @@ namespace MapControl
var maxZoomLevel = Math.Min(TileGrid.ZoomLevel, MaxZoomLevel);
var minZoomLevel = MinZoomLevel;
if (minZoomLevel < maxZoomLevel && parentMap.MapLayer != this) // load lower tiles only in a base layer
if (minZoomLevel < maxZoomLevel &&
parentMap.MapLayer != this &&
parentMap.Children.Cast<UIElement>().FirstOrDefault() != this)
{
minZoomLevel = maxZoomLevel;
minZoomLevel = maxZoomLevel; // do not load lower level tiles if this is note a "base" layer
}
for (var z = minZoomLevel; z <= maxZoomLevel; z++)

View file

@ -9,6 +9,7 @@ using System.Threading.Tasks;
#if WINDOWS_UWP
using Windows.UI.Xaml.Media;
#else
using System.ComponentModel;
using System.Windows.Media;
#endif
@ -17,7 +18,10 @@ namespace MapControl
/// <summary>
/// Provides the download Uri or ImageSource of map tiles.
/// </summary>
public partial class TileSource
#if !WINDOWS_UWP
[TypeConverter(typeof(TileSourceConverter))]
#endif
public class TileSource
{
private Func<int, int, int, string> getUri;
private string uriFormat;