mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Minor code improvements
This commit is contained in:
parent
6b25260536
commit
472658a6d9
19 changed files with 301 additions and 175 deletions
|
|
@ -1,4 +1,8 @@
|
|||
using System;
|
||||
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
|
||||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using System;
|
||||
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
|
||||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using System;
|
||||
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
|
||||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@
|
|||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
using System;
|
||||
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
|
||||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using System.Collections;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -11,7 +12,6 @@ using System.Net;
|
|||
using System.Runtime.Caching;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
|
||||
|
|
@ -48,19 +48,52 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// The time interval after which cached images expire. The default value is 30 days.
|
||||
/// When an image is not retrieved from the cache during this interval it is considered
|
||||
/// as expired and will be removed from the cache. If an image is retrieved from the cache
|
||||
/// and the CacheUpdateAge time interval has expired, the image is downloaded again and
|
||||
/// rewritten to the cache with new expiration time.
|
||||
/// as expired and will be removed from the cache. If an image is retrieved from the
|
||||
/// cache and the CacheUpdateAge time interval has expired, the image is downloaded
|
||||
/// again and rewritten to the cache with a new expiration time.
|
||||
/// </summary>
|
||||
public static TimeSpan CacheExpiration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time interval after which a cached image is updated and rewritten to the cache.
|
||||
/// The default value is one day. This time interval should be shorter than the value of
|
||||
/// the CacheExpiration property.
|
||||
/// The default value is one day. This time interval should be shorter than the value
|
||||
/// of the CacheExpiration property.
|
||||
/// </summary>
|
||||
public static TimeSpan CacheUpdateAge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the ObjectCache-derived type T and sets the static Cache
|
||||
/// property to this instance. Class T must (like System.Runtime.Caching.MemoryCache)
|
||||
/// provide a constructor with two parameters, first a string that gets the name of
|
||||
/// the cache instance, second a NameValueCollection that gets the config parameter.
|
||||
/// If config is null, a new NameValueCollection is created. If config does not already
|
||||
/// contain an entry with key "directory", a new entry is added with this key and a
|
||||
/// value that specifies the path to an application data directory where the cache
|
||||
/// implementation may store persistent cache data files.
|
||||
/// </summary>
|
||||
public static void CreateCache<T>(NameValueCollection config = null) where T : ObjectCache
|
||||
{
|
||||
if (config == null)
|
||||
{
|
||||
config = new NameValueCollection(1);
|
||||
}
|
||||
|
||||
if (config["directory"] == null)
|
||||
{
|
||||
config["directory"] = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Cache = (ObjectCache)Activator.CreateInstance(typeof(T), "TileCache", config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.TraceWarning("Could not create instance of type {0} with String and NameValueCollection constructor parameters: {1}", typeof(T), ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
static TileImageLoader()
|
||||
{
|
||||
Cache = MemoryCache.Default;
|
||||
|
|
@ -77,7 +110,7 @@ namespace MapControl
|
|||
};
|
||||
}
|
||||
|
||||
public TileImageLoader(TileLayer tileLayer)
|
||||
internal TileImageLoader(TileLayer tileLayer)
|
||||
{
|
||||
this.tileLayer = tileLayer;
|
||||
}
|
||||
|
|
@ -128,7 +161,7 @@ namespace MapControl
|
|||
}
|
||||
else if (!CreateTileImage(tile, cachedImage.ImageBuffer))
|
||||
{
|
||||
// got garbage from cache
|
||||
// got corrupted buffer from cache
|
||||
Cache.Remove(key);
|
||||
pendingTiles.Enqueue(tile);
|
||||
}
|
||||
|
|
@ -215,28 +248,28 @@ namespace MapControl
|
|||
|
||||
TraceInformation("{0} - Completed", tile.Uri);
|
||||
}
|
||||
catch (WebException exc)
|
||||
catch (WebException ex)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if (exc.Status == WebExceptionStatus.ProtocolError)
|
||||
if (ex.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
TraceInformation("{0} - {1}", tile.Uri, ((HttpWebResponse)exc.Response).StatusCode);
|
||||
TraceInformation("{0} - {1}", tile.Uri, ((HttpWebResponse)ex.Response).StatusCode);
|
||||
}
|
||||
else if (exc.Status == WebExceptionStatus.RequestCanceled) // by HttpWebRequest.Abort in CancelDownloadTiles
|
||||
else if (ex.Status == WebExceptionStatus.RequestCanceled) // by HttpWebRequest.Abort in CancelDownloadTiles
|
||||
{
|
||||
TraceInformation("{0} - {1}", tile.Uri, exc.Status);
|
||||
TraceInformation("{0} - {1}", tile.Uri, ex.Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceWarning("{0} - {1}", tile.Uri, exc.Status);
|
||||
TraceWarning("{0} - {1}", tile.Uri, ex.Status);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
catch (Exception ex)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
TraceWarning("{0} - {1}", tile.Uri, exc.Message);
|
||||
TraceWarning("{0} - {1}", tile.Uri, ex.Message);
|
||||
}
|
||||
|
||||
if (request != null)
|
||||
|
|
@ -267,9 +300,9 @@ namespace MapControl
|
|||
|
||||
Dispatcher.BeginInvoke((Action)(() => tile.Image = bitmap));
|
||||
}
|
||||
catch (Exception exc)
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceWarning("Creating tile image failed: {0}", exc.Message);
|
||||
TraceWarning("Creating tile image failed: {0}", ex.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
// Copyright © 2012 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue