Version 1.1.5: Added support for file:// URIs to access map tile sets in local files.

This commit is contained in:
ClemensF 2013-01-17 18:48:38 +01:00
parent 8e85aa8e17
commit fab8530770
66 changed files with 245 additions and 187 deletions

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.UI.Xaml;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows.Media;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
namespace MapControl

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
namespace MapControl

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
namespace MapControl

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,12 +1,14 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
#endif
@ -25,6 +27,11 @@ namespace MapControl
}
}
private UIElementCollection InternalChildren
{
get { return Children; }
}
/// <summary>
/// Helper method to work around missing property value inheritance in Silverlight and WinRT.
/// Adds Loaded and Unloaded handlers to the specified FrameworkElement, which set and clear

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
@ -51,7 +51,7 @@ namespace MapControl
protected override Size MeasureOverride(Size availableSize)
{
foreach (UIElement element in Children)
foreach (UIElement element in InternalChildren)
{
element.Measure(availableSize);
}
@ -63,7 +63,7 @@ namespace MapControl
{
var parentMap = GetParentMap(this);
foreach (UIElement element in Children)
foreach (UIElement element in InternalChildren)
{
var rect = new Rect(0d, 0d, element.DesiredSize.Width, element.DesiredSize.Height);
var location = GetLocation(element);
@ -96,7 +96,7 @@ namespace MapControl
{
var parentMap = GetParentMap(this);
foreach (UIElement element in Children)
foreach (UIElement element in InternalChildren)
{
var location = GetLocation(element);

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.UI.Xaml;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
@ -19,7 +19,7 @@ namespace MapControl
{
public override double MaxLatitude
{
get { return 85.0511; }
get { return 85.0511287798066; }
}
public override double RelativeScale(Location location)

View file

@ -13,9 +13,9 @@ using System.Windows;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
@ -28,7 +28,7 @@ namespace MapControl
public void SetImageSource(ImageSource image, bool animateOpacity)
{
if (Image.Source == null)
if (image != null && Image.Source == null)
{
if (animateOpacity)
{
@ -51,6 +51,7 @@ namespace MapControl
}
Image.Source = image;
HasImage = true;
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
@ -20,7 +20,7 @@ namespace MapControl
public void SetImageSource(ImageSource image, bool animateOpacity)
{
if (Brush.ImageSource == null)
if (image != null && Brush.ImageSource == null)
{
if (animateOpacity)
{
@ -43,6 +43,7 @@ namespace MapControl
}
Brush.ImageSource = image;
HasImage = true;
}
private void BitmapDownloadCompleted(object sender, EventArgs e)

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
@ -24,7 +24,7 @@ namespace MapControl
Y = y;
}
public Uri Uri { get; set; }
public bool HasImage { get; private set; }
public int XIndex
{

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows.Media;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
@ -26,10 +26,11 @@ namespace MapControl
internal void BeginGetTiles(IEnumerable<Tile> tiles)
{
foreach (var tile in tiles.Where(t => t.ImageSource == null && t.Uri == null))
foreach (var tile in tiles.Where(t => !t.HasImage))
{
tile.Uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
tile.SetImageSource(new BitmapImage(tile.Uri), true);
var uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
tile.SetImageSource(new BitmapImage(uri), true);
}
}

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
@ -73,7 +73,7 @@ namespace MapControl
internal void BeginGetTiles(IEnumerable<Tile> tiles)
{
ThreadPool.QueueUserWorkItem(BeginGetTilesAsync, new List<Tile>(tiles.Where(t => t.ImageSource == null && t.Uri == null)));
ThreadPool.QueueUserWorkItem(BeginGetTilesAsync, new List<Tile>(tiles.Where(t => !t.HasImage)));
}
internal void CancelGetTiles()
@ -82,131 +82,174 @@ namespace MapControl
while (pendingTiles.TryDequeue(out tile)) ; // no Clear method
}
private string GetCacheKey(Tile tile)
{
return string.Format("{0}/{1}/{2}/{3}", tileLayer.SourceName, tile.ZoomLevel, tile.XIndex, tile.Y);
}
private void BeginGetTilesAsync(object newTilesList)
{
var newTiles = (List<Tile>)newTilesList;
var imageTileSource = tileLayer.TileSource as ImageTileSource;
if (imageTileSource != null)
if (imageTileSource != null && !imageTileSource.CanLoadAsync)
{
if (imageTileSource.CanLoadAsync)
foreach (var tile in newTiles)
{
foreach (var tile in newTiles)
{
tileLayer.Dispatcher.BeginInvoke(
(Action<Tile, ImageSource>)((t, i) => t.SetImageSource(i, true)),
DispatcherPriority.Background, tile,
imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel));
}
}
else
{
foreach (var tile in newTiles)
{
tileLayer.Dispatcher.BeginInvoke(
(Action<Tile, ImageTileSource>)((t, i) => t.SetImageSource(i.LoadImage(t.XIndex, t.Y, t.ZoomLevel), true)),
DispatcherPriority.Background, tile, imageTileSource);
}
tileLayer.Dispatcher.BeginInvoke(
(Action<Tile, ImageTileSource>)((t, ts) => t.SetImageSource(ts.LoadImage(t.XIndex, t.Y, t.ZoomLevel), true)),
DispatcherPriority.Background, tile, imageTileSource);
}
}
else
{
if (Cache != null && !string.IsNullOrWhiteSpace(tileLayer.SourceName))
if (imageTileSource == null && Cache != null &&
!tileLayer.TileSource.UriFormat.StartsWith("file://") &&
!string.IsNullOrWhiteSpace(tileLayer.SourceName))
{
var outdatedTiles = new List<Tile>(newTiles.Count);
foreach (var tile in newTiles)
{
var key = CacheKey(tile);
var key = GetCacheKey(tile);
var buffer = Cache.Get(key) as byte[];
var image = CreateImage(buffer);
if (buffer == null)
if (image != null)
{
tileLayer.Dispatcher.BeginInvoke(
(Action<Tile, ImageSource>)((t, i) => t.SetImageSource(i, true)),
DispatcherPriority.Background, tile, image);
var creationTime = BitConverter.ToInt64(buffer, 0);
if (DateTime.FromBinary(creationTime) + CacheUpdateAge < DateTime.UtcNow)
{
// update outdated cache
outdatedTiles.Add(tile);
}
}
else
{
pendingTiles.Enqueue(tile);
}
else if (!CreateTileImage(tile, buffer))
{
// got corrupted buffer from cache
Cache.Remove(key);
pendingTiles.Enqueue(tile);
}
else if (IsCacheOutdated(buffer))
{
// update cached image
outdatedTiles.Add(tile);
}
}
foreach (var tile in outdatedTiles)
{
pendingTiles.Enqueue(tile);
}
newTiles = outdatedTiles; // enqueue outdated tiles at last
}
else
foreach (var tile in newTiles)
{
foreach (var tile in newTiles)
{
pendingTiles.Enqueue(tile);
}
pendingTiles.Enqueue(tile);
}
while (downloadThreadCount < Math.Min(pendingTiles.Count, tileLayer.MaxParallelDownloads))
{
Interlocked.Increment(ref downloadThreadCount);
ThreadPool.QueueUserWorkItem(DownloadTiles);
ThreadPool.QueueUserWorkItem(LoadTiles);
}
}
}
private void DownloadTiles(object o)
private void LoadTiles(object o)
{
Tile tile;
while (pendingTiles.TryDequeue(out tile))
{
tile.Uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
var buffer = DownloadImage(tile.Uri);
byte[] buffer = null;
ImageSource image = null;
var imageTileSource = tileLayer.TileSource as ImageTileSource;
if (buffer != null && CreateTileImage(tile, buffer) && Cache != null)
if (imageTileSource != null)
{
Cache.Set(CacheKey(tile), buffer, new CacheItemPolicy { SlidingExpiration = CacheExpiration });
try
{
image = imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel);
}
catch (Exception ex)
{
Trace.TraceWarning("Loading tile image failed: {0}", ex.Message);
}
}
else
{
var uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
if (uri.Scheme != "http")
{
image = CreateImage(uri);
}
else
{
buffer = DownloadImage(uri);
image = CreateImage(buffer);
}
}
if (image != null)
{
tileLayer.Dispatcher.BeginInvoke(
(Action<Tile, ImageSource>)((t, i) => t.SetImageSource(i, true)),
DispatcherPriority.Background, tile, image);
if (buffer != null && Cache != null)
{
Cache.Set(GetCacheKey(tile), buffer, new CacheItemPolicy { SlidingExpiration = CacheExpiration });
}
}
}
Interlocked.Decrement(ref downloadThreadCount);
}
private string CacheKey(Tile tile)
{
return string.Format("{0}/{1}/{2}/{3}", tileLayer.SourceName, tile.ZoomLevel, tile.XIndex, tile.Y);
}
private bool CreateTileImage(Tile tile, byte[] buffer)
private ImageSource CreateImage(Uri uri)
{
var image = new BitmapImage();
try
{
using (var stream = new MemoryStream(buffer, 8, buffer.Length - 8, false))
{
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = stream;
image.EndInit();
image.Freeze();
}
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = uri;
image.EndInit();
image.Freeze();
}
catch (Exception ex)
{
Trace.TraceWarning("Creating tile image failed: {0}", ex.Message);
return false;
image = null;
}
tileLayer.Dispatcher.BeginInvoke(
(Action<Tile, ImageSource>)((t, i) => t.SetImageSource(i, true)),
DispatcherPriority.Background, tile, image);
return image;
}
return true;
private ImageSource CreateImage(byte[] buffer)
{
BitmapImage image = null;
if (buffer != null && buffer.Length > 8)
{
try
{
using (var stream = new MemoryStream(buffer, 8, buffer.Length - 8, false))
{
image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = stream;
image.EndInit();
image.Freeze();
}
}
catch (Exception ex)
{
Trace.TraceWarning("Creating tile image failed: {0}", ex.Message);
image = null;
}
}
return image;
}
private static byte[] DownloadImage(Uri uri)
@ -216,7 +259,7 @@ namespace MapControl
try
{
var request = (HttpWebRequest)WebRequest.Create(uri);
request.UserAgent = typeof(TileImageLoader).ToString();
request.UserAgent = "XAML Map Control";
using (var response = (HttpWebResponse)request.GetResponse())
using (var responseStream = response.GetResponseStream())
@ -257,12 +300,5 @@ namespace MapControl
return buffer;
}
private static bool IsCacheOutdated(byte[] buffer)
{
var creationTime = BitConverter.ToInt64(buffer, 0);
return DateTime.FromBinary(creationTime) + CacheUpdateAge < DateTime.UtcNow;
}
}
}

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.ObjectModel;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
@ -92,35 +92,44 @@ namespace MapControl
private Uri GetOpenStreetMapUri(int x, int y, int zoomLevel)
{
hostIndex = (hostIndex + 1) % 3;
lock (getUri) // protect hostIndex
{
hostIndex = (hostIndex + 1) % 3;
return new Uri(UriFormat.
Replace("{c}", "abc".Substring(hostIndex, 1)).
Replace("{x}", x.ToString()).
Replace("{y}", y.ToString()).
Replace("{z}", zoomLevel.ToString()));
return new Uri(UriFormat.
Replace("{c}", "abc".Substring(hostIndex, 1)).
Replace("{x}", x.ToString()).
Replace("{y}", y.ToString()).
Replace("{z}", zoomLevel.ToString()));
}
}
private Uri GetGoogleMapsUri(int x, int y, int zoomLevel)
{
hostIndex = (hostIndex + 1) % 4;
lock (getUri) // protect hostIndex
{
hostIndex = (hostIndex + 1) % 4;
return new Uri(UriFormat.
Replace("{i}", hostIndex.ToString()).
Replace("{x}", x.ToString()).
Replace("{y}", y.ToString()).
Replace("{z}", zoomLevel.ToString()));
return new Uri(UriFormat.
Replace("{i}", hostIndex.ToString()).
Replace("{x}", x.ToString()).
Replace("{y}", y.ToString()).
Replace("{z}", zoomLevel.ToString()));
}
}
private Uri GetMapQuestUri(int x, int y, int zoomLevel)
{
hostIndex = (hostIndex % 4) + 1;
lock (getUri) // protect hostIndex
{
hostIndex = (hostIndex % 4) + 1;
return new Uri(UriFormat.
Replace("{n}", hostIndex.ToString()).
Replace("{x}", x.ToString()).
Replace("{y}", y.ToString()).
Replace("{z}", zoomLevel.ToString()));
return new Uri(UriFormat.
Replace("{n}", hostIndex.ToString()).
Replace("{x}", x.ToString()).
Replace("{y}", y.ToString()).
Replace("{z}", zoomLevel.ToString()));
}
}
private Uri GetQuadKeyUri(int x, int y, int zoomLevel)

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;

View file

@ -1,5 +1,5 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Copyright © 2013 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.Foundation;

View file

@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]

View file

@ -7,10 +7,10 @@ using System.Windows;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

View file

@ -33,10 +33,13 @@
TileSource="http://ecn.t{i}.tiles.virtualearth.net/tiles/h{q}.jpeg?g=0&amp;stl=h" MaxZoomLevel="20" HasDarkBackground="True"/>-->
<!-- The TileLayer below uses an ImageTileSource, which bypasses caching of map tile images -->
<!--<map:TileLayer SourceName="OSM Uncached" Description="© {y} OpenStreetMap Contributors, CC-BY-SA">
<map:ImageTileSource UriFormat="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>
</map:TileLayer>-->
<!-- The TileLayer below demonstrates how to access local tile image files (from ImageFileCache here) -->
<!--<map:TileLayer SourceName="OSM Local Files" Description="© {y} OpenStreetMap Contributors, CC-BY-SA"
TileSource="file://C:/ProgramData/MapControl/TileCache/OpenStreetMap/{z}/{x}/{y}.png"/>-->
</map:TileLayerCollection>
<CollectionViewSource x:Key="TileLayersView" Source="{StaticResource TileLayers}"/>
<local:LocationToVisibilityConverter x:Key="LocationToVisibilityConverter"/>

View file

@ -7,10 +7,10 @@ using System.Windows;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]