Version 2.7.2: Improved TileImageLoader.WinRT.

This commit is contained in:
ClemensF 2016-01-14 17:56:25 +01:00
parent ed271719f8
commit 3717081f18
22 changed files with 143 additions and 141 deletions

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -39,9 +39,10 @@ namespace MapControl
public bool Equals(Location location)
{
return location != null
return ReferenceEquals(this, location)
|| (location != null
&& location.latitude == latitude
&& location.longitude == longitude;
&& location.longitude == longitude);
}
public override bool Equals(object obj)

View file

@ -2,8 +2,6 @@
// © 2015 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
@ -17,8 +15,6 @@ namespace MapControl
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
"MouseWheelZoomDelta", typeof(double), typeof(Map), new PropertyMetadata(1d));
private Point? mousePosition;
public Map()
{
ManipulationMode = ManipulationModes.Scale |
@ -26,11 +22,6 @@ namespace MapControl
ManipulationDelta += OnManipulationDelta;
PointerWheelChanged += OnPointerWheelChanged;
PointerPressed += OnPointerPressed;
PointerReleased += OnPointerReleased;
PointerCanceled += OnPointerReleased;
PointerCaptureLost += OnPointerReleased;
PointerMoved += OnPointerMoved;
}
/// <summary>
@ -49,40 +40,9 @@ namespace MapControl
ZoomMap(point.Position, TargetZoomLevel + zoomChange);
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
CapturePointer(e.Pointer))
{
mousePosition = e.GetCurrentPoint(this).Position;
}
}
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
mousePosition = null;
ReleasePointerCapture(e.Pointer);
}
}
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
if (mousePosition.HasValue)
{
var position = e.GetCurrentPoint(this).Position;
TranslateMap(new Point(position.X - mousePosition.Value.X, position.Y - mousePosition.Value.Y));
mousePosition = position;
}
}
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (e.PointerDeviceType == PointerDeviceType.Touch)
{
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
}
}

View file

@ -323,10 +323,8 @@ namespace MapControl
/// </summary>
public void SetTransformOrigin(Point origin)
{
ViewportOrigin = new Point(
Math.Min(Math.Max(origin.X, 0d), RenderSize.Width),
Math.Min(Math.Max(origin.Y, 0d), RenderSize.Height));
transformOrigin = ViewportPointToLocation(ViewportOrigin);
transformOrigin = ViewportPointToLocation(origin);
ViewportOrigin = origin;
}
/// <summary>
@ -388,11 +386,8 @@ namespace MapControl
/// </summary>
public void ZoomMap(Point origin, double zoomLevel)
{
if (zoomLevel >= MinZoomLevel && zoomLevel <= MaxZoomLevel)
{
SetTransformOrigin(origin);
TargetZoomLevel = zoomLevel;
}
SetTransformOrigin(origin);
TargetZoomLevel = Math.Min(Math.Max(zoomLevel, MinZoomLevel), MaxZoomLevel);
}
/// <summary>

View file

@ -14,8 +14,8 @@ using System.Windows;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -25,12 +25,13 @@ namespace MapControl
public bool Equals(TileGrid tileGrid)
{
return tileGrid != null
return ReferenceEquals(this, tileGrid)
|| (tileGrid != null
&& tileGrid.ZoomLevel == ZoomLevel
&& tileGrid.XMin == XMin
&& tileGrid.YMin == YMin
&& tileGrid.XMax == XMax
&& tileGrid.YMax == YMax;
&& tileGrid.YMax == YMax);
}
public override bool Equals(object obj)

View file

@ -9,6 +9,7 @@ using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MapControl.Caching;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Core;
@ -77,47 +78,54 @@ namespace MapControl
{
var tileSource = tileLayer.TileSource;
var imageTileSource = tileSource as ImageTileSource;
var sourceName = tileLayer.SourceName;
var useCache = Cache != null && !string.IsNullOrEmpty(sourceName);
foreach (var tile in tiles)
if (imageTileSource != null)
{
try
foreach (var tile in tiles)
{
if (imageTileSource != null)
try
{
tile.SetImage(imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel));
}
else
catch (Exception ex)
{
var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
if (uri == null)
{
tile.SetImage(null);
}
else if (!useCache)
{
tile.SetImage(new BitmapImage(uri));
}
else
{
pendingTiles.Enqueue(new PendingTile(tile, uri));
}
Debug.WriteLine(ex.Message);
}
}
catch (Exception ex)
}
else
{
foreach (var tile in tiles)
{
Debug.WriteLine(ex.Message);
}
Uri uri = null;
var newTaskCount = Math.Min(pendingTiles.Count, tileLayer.MaxParallelDownloads) - taskCount;
try
{
uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
while (newTaskCount-- > 0)
{
Interlocked.Increment(ref taskCount);
if (uri == null)
{
tile.SetImage(null);
}
else
{
pendingTiles.Enqueue(new PendingTile(tile, uri));
Task.Run(async () => await LoadPendingTiles(tileSource, sourceName));
var newTaskCount = Math.Min(pendingTiles.Count, tileLayer.MaxParallelDownloads) - taskCount;
var sourceName = tileLayer.SourceName;
while (newTaskCount-- > 0)
{
Interlocked.Increment(ref taskCount);
Task.Run(async () => await LoadPendingTiles(tileSource, sourceName));
}
}
}
}
}
@ -132,37 +140,48 @@ namespace MapControl
private async Task LoadPendingTiles(TileSource tileSource, string sourceName)
{
PendingTile pendingTile;
var cache = Cache;
while (pendingTiles.TryDequeue(out pendingTile))
if (cache == null || sourceName == null)
{
var tile = pendingTile.Tile;
var uri = pendingTile.Uri;
var image = pendingTile.Image;
var extension = Path.GetExtension(uri.LocalPath);
if (string.IsNullOrEmpty(extension) || extension == ".jpeg")
while (pendingTiles.TryDequeue(out pendingTile))
{
extension = ".jpg";
await DownloadImage(pendingTile.Tile, pendingTile.Image, pendingTile.Uri, null);
}
var cacheKey = string.Format(@"{0}\{1}\{2}\{3}{4}", sourceName, tile.ZoomLevel, tile.XIndex, tile.Y, extension);
var cacheItem = await Cache.GetAsync(cacheKey);
var loaded = false;
if (cacheItem == null || cacheItem.Expiration <= DateTime.UtcNow)
}
else
{
while (pendingTiles.TryDequeue(out pendingTile))
{
loaded = await DownloadImage(tile, image, uri, cacheKey);
}
var tile = pendingTile.Tile;
var image = pendingTile.Image;
var uri = pendingTile.Uri;
var extension = Path.GetExtension(uri.LocalPath);
if (!loaded && cacheItem != null && cacheItem.Buffer != null)
{
using (var stream = new InMemoryRandomAccessStream())
if (string.IsNullOrEmpty(extension) || extension == ".jpeg")
{
await stream.WriteAsync(cacheItem.Buffer);
await stream.FlushAsync();
stream.Seek(0);
extension = ".jpg";
}
await LoadImageFromStream(tile, image, stream);
var cacheKey = string.Format(@"{0}\{1}\{2}\{3}{4}", sourceName, tile.ZoomLevel, tile.XIndex, tile.Y, extension);
var cacheItem = await cache.GetAsync(cacheKey);
var loaded = false;
if (cacheItem == null || cacheItem.Expiration <= DateTime.UtcNow)
{
loaded = await DownloadImage(tile, image, uri, cacheKey);
}
if (!loaded && cacheItem != null && cacheItem.Buffer != null)
{
using (var stream = new InMemoryRandomAccessStream())
{
await stream.WriteAsync(cacheItem.Buffer);
await stream.FlushAsync();
stream.Seek(0);
await LoadImageFromStream(tile, image, stream);
}
}
}
}
@ -206,8 +225,9 @@ namespace MapControl
stream.Seek(0);
var loaded = await LoadImageFromStream(tile, image, stream);
IImageCache cache;
if (loaded && cacheKey != null)
if (loaded && cacheKey != null && (cache = Cache) != null)
{
var buffer = new Windows.Storage.Streams.Buffer((uint)stream.Size);
@ -226,7 +246,7 @@ namespace MapControl
}
}
await Cache.SetAsync(cacheKey, buffer, DateTime.UtcNow.Add(expiration));
await cache.SetAsync(cacheKey, buffer, DateTime.UtcNow.Add(expiration));
}
return loaded;

View file

@ -37,7 +37,8 @@ namespace MapControl
{
SourceName = "OpenStreetMap",
Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)",
TileSource = new TileSource { UriFormat = "http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png" }
TileSource = new TileSource { UriFormat = "http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png" },
MaxZoomLevel = 19
};
}
}
@ -75,6 +76,9 @@ namespace MapControl
public static readonly DependencyProperty UpdateWhileViewportChangingProperty = DependencyProperty.Register(
"UpdateWhileViewportChanging", typeof(bool), typeof(TileLayer), new PropertyMetadata(true));
public static readonly DependencyProperty LoadTilesDescendingProperty = DependencyProperty.Register(
"LoadTilesDescending", typeof(bool), typeof(TileLayer), new PropertyMetadata(false));
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(
"Foreground", typeof(Brush), typeof(TileLayer), new PropertyMetadata(null));
@ -198,6 +202,16 @@ namespace MapControl
set { SetValue(UpdateWhileViewportChangingProperty, value); }
}
/// <summary>
/// Controls the order of zoom levels in which map tiles are loaded.
/// The default is value is false, i.e. tiles are loaded in ascending order.
/// </summary>
public bool LoadTilesDescending
{
get { return (bool)GetValue(LoadTilesDescendingProperty); }
set { SetValue(LoadTilesDescendingProperty, value); }
}
/// <summary>
/// Optional foreground brush. Sets MapBase.Foreground, if not null.
/// </summary>
@ -313,7 +327,14 @@ namespace MapControl
Children.Add(tile.Image);
}
TileImageLoader.BeginLoadTiles(this, Tiles.Where(t => t.Pending).OrderByDescending(t => t.ZoomLevel));
var pendingTiles = Tiles.Where(t => t.Pending);
if (LoadTilesDescending)
{
pendingTiles = pendingTiles.OrderByDescending(t => t.ZoomLevel); // higher zoom levels first
}
TileImageLoader.BeginLoadTiles(this, pendingTiles);
}
}

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="XamlMapControl.PhoneApp" Publisher="CN=Clemens" Version="2.5.0.0" />
<Identity Name="XamlMapControl.PhoneApp" Publisher="CN=Clemens" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="a28a99bb-a24b-4713-a6ea-3015d8aa2d72" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>XAML Map Control Phone Application</DisplayName>

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -4,10 +4,11 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<StartPageUrl>SilverlightApplicationTestPage.aspx</StartPageUrl>
<StartAction>SpecificPage</StartAction>
<StartPageUrl>
</StartPageUrl>
<StartAction>CurrentPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>True</SilverlightDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram>
@ -18,7 +19,7 @@
</StartCmdLineArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<EnableENC>False</EnableENC>
<EnableENC>True</EnableENC>
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
<ProjectOutputReferences>
<Ref Project="{CBA8C535-CCA3-4F60-8D3E-0E25791CBD21}" Folder="ClientBin">SilverlightApplication.xap</Ref>

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: ComVisible(false)]

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="XamlMapControl.UniversalApp" Publisher="CN=Clemens" Version="2.5.0.0" />
<Identity Name="XamlMapControl.UniversalApp" Publisher="CN=Clemens" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="6781ec09-e195-49eb-9a20-b25a8dc39b2a" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>UniversalApp</DisplayName>

View file

@ -1,14 +1,14 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Windows Universal Sample Application")]
[assembly: AssemblyDescription("XAML Map Control Windows Universal Sample Application")]
[assembly: AssemblyTitle("Universal Windows Sample Application")]
[assembly: AssemblyDescription("XAML Map Control Universal Windows Sample Application")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: ComVisible(false)]

View file

@ -4,4 +4,7 @@
<DeviceId>30F105C9-681E-420b-A277-7C086EAD8A4E</DeviceId>
<UseEmulator>true</UseEmulator>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<AuthenticationMode>Windows</AuthenticationMode>
</PropertyGroup>
</Project>

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]
[assembly: AssemblyVersion("2.7.2")]
[assembly: AssemblyFileVersion("2.7.2")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]