Skip to content

Commit

Permalink
Version 4.10.0: Updated target framework versions. Cleanup of TypeCon…
Browse files Browse the repository at this point in the history
…verters, ImageLoader, MBTileSource.
  • Loading branch information
ClemensFischer committed Aug 8, 2018
1 parent 63a4c1f commit 6a16530
Show file tree
Hide file tree
Showing 36 changed files with 266 additions and 286 deletions.
2 changes: 1 addition & 1 deletion FileDbCache/UWP/FileDbCache.UWP.csproj
Expand Up @@ -46,7 +46,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.1.5</Version>
<Version>6.1.7</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions FileDbCache/UWP/Properties/AssemblyInfo.cs
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyVersion("4.10.0")]
[assembly: AssemblyFileVersion("4.10.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
2 changes: 1 addition & 1 deletion FileDbCache/WPF/FileDbCache.WPF.csproj
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapControl.Caching</RootNamespace>
<AssemblyName>FileDbCache.WPF</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions FileDbCache/WPF/Properties/AssemblyInfo.cs
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyVersion("4.10.0")]
[assembly: AssemblyFileVersion("4.10.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
4 changes: 4 additions & 0 deletions MBTiles/Shared/MBTileLayer.cs
@@ -1,3 +1,7 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)

#if WINDOWS_UWP
using Windows.UI.Xaml;
#else
Expand Down
12 changes: 6 additions & 6 deletions MBTiles/UWP/MBTileSource.UWP.cs
@@ -1,12 +1,15 @@
using System;
// 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.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Microsoft.Data.Sqlite;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

namespace MapControl
{
Expand Down Expand Up @@ -53,10 +56,7 @@ public override async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLev
await stream.WriteAsync(buffer.AsBuffer());
stream.Seek(0);

var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream);

imageSource = bitmapImage;
imageSource = await ImageLoader.CreateImageSourceAsync(stream);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion MBTiles/UWP/MBTiles.UWP.csproj
Expand Up @@ -52,7 +52,7 @@
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.1.5</Version>
<Version>6.1.7</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions MBTiles/UWP/Properties/AssemblyInfo.cs
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyVersion("4.10.0")]
[assembly: AssemblyFileVersion("4.10.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
18 changes: 9 additions & 9 deletions MBTiles/WPF/MBTileSource.WPF.cs
@@ -1,11 +1,14 @@
using System;
// 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.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Data.SQLite;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MapControl
{
Expand Down Expand Up @@ -47,13 +50,10 @@ public override async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLev

if (buffer != null)
{
imageSource = await Task.Run(() =>
using (var stream = new MemoryStream(buffer))
{
using (var stream = new MemoryStream(buffer))
{
return BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
});
imageSource = await ImageLoader.CreateImageSourceAsync(stream);
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions MBTiles/WPF/MBTiles.WPF.csproj
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapControl</RootNamespace>
<AssemblyName>MBTiles.WPF</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
Expand Down Expand Up @@ -38,8 +38,8 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.107.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Data.SQLite.Core.1.0.107.0\lib\net45\System.Data.SQLite.dll</HintPath>
<Reference Include="System.Data.SQLite, Version=1.0.108.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Data.SQLite.Core.1.0.108.0\lib\net46\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
Expand All @@ -61,11 +61,11 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\System.Data.SQLite.Core.1.0.107.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\..\packages\System.Data.SQLite.Core.1.0.107.0\build\net45\System.Data.SQLite.Core.targets')" />
<Import Project="..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\System.Data.SQLite.Core.1.0.107.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\System.Data.SQLite.Core.1.0.107.0\build\net45\System.Data.SQLite.Core.targets'))" />
<Error Condition="!Exists('..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets'))" />
</Target>
</Project>
4 changes: 2 additions & 2 deletions MBTiles/WPF/Properties/AssemblyInfo.cs
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyVersion("4.10.0")]
[assembly: AssemblyFileVersion("4.10.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
2 changes: 1 addition & 1 deletion MBTiles/WPF/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Data.SQLite.Core" version="1.0.107.0" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.108.0" targetFramework="net47" />
</packages>
5 changes: 4 additions & 1 deletion MapControl/Shared/BoundingBox.cs
Expand Up @@ -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;
Expand Down
69 changes: 69 additions & 0 deletions MapControl/Shared/ImageLoader.cs
@@ -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;
}
}
}
}
5 changes: 4 additions & 1 deletion MapControl/Shared/Location.cs
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion MapControl/Shared/LocationCollection.cs
Expand Up @@ -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()
{
Expand Down
46 changes: 44 additions & 2 deletions MapControl/Shared/LocationEx.cs
Expand Up @@ -7,6 +7,9 @@

namespace MapControl
{
/// <summary>
/// Provides helper methods for geodetic calculations on a sphere.
/// </summary>
public static class LocationEx
{
/// <summary>
Expand All @@ -18,9 +21,48 @@ public static double GreatCircleDistance(this Location location1, Location locat
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;

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 earthRadius * Math.Acos(Math.Min(Math.Max(cosS12, -1d), 1d));
return new Location(lat2 / Math.PI * 180d, lon2 / Math.PI * 180d);
}

public static LocationCollection CalculateMeridianLocations(this Location location, double latitude2, double resolution = 1d)
Expand Down
6 changes: 4 additions & 2 deletions MapControl/Shared/MapTileLayer.cs
Expand Up @@ -344,9 +344,11 @@ private void UpdateTiles()
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++)
Expand Down
6 changes: 5 additions & 1 deletion MapControl/Shared/TileSource.cs
Expand Up @@ -9,6 +9,7 @@
#if WINDOWS_UWP
using Windows.UI.Xaml.Media;
#else
using System.ComponentModel;
using System.Windows.Media;
#endif

Expand All @@ -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;
Expand Down

0 comments on commit 6a16530

Please sign in to comment.