Version 1.3.3: Fixed MapImageLayer.

This commit is contained in:
ClemensF 2013-05-15 15:58:07 +02:00
parent 5d6becbb50
commit 9264cf819a
12 changed files with 120 additions and 113 deletions

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -416,7 +416,7 @@ namespace MapControl
{
Loaded -= OnLoaded;
if (TileLayer == null)
if (TileLayer == null && TileLayers == null)
{
TileLayer = TileLayer.Default;
}

View file

@ -27,10 +27,12 @@ namespace MapControl
/// </summary>
public class MapImageLayer : MapPanel
{
private static readonly DependencyProperty RelativeImageSizeProperty = DependencyProperty.Register(
"RelativeImageSize", typeof(double), typeof(MapImageLayer), new PropertyMetadata(1d));
private readonly DispatcherTimer updateTimer;
private string uriFormat;
private bool latLonBoundingBox;
private bool imageIsValid;
private bool updateInProgress;
private int currentImageIndex;
@ -43,6 +45,12 @@ namespace MapControl
updateTimer.Tick += UpdateImage;
}
public double RelativeImageSize
{
get { return (double)GetValue(RelativeImageSizeProperty); }
set { SetValue(RelativeImageSizeProperty, value); }
}
public string UriFormat
{
get { return uriFormat; }
@ -78,7 +86,6 @@ namespace MapControl
{
base.OnViewportChanged();
imageIsValid = false;
updateTimer.Stop();
updateTimer.Start();
}
@ -86,6 +93,9 @@ namespace MapControl
protected virtual ImageSource GetImage(double west, double east, double south, double north, int width, int height)
{
ImageSource image = null;
if (uriFormat != null)
{
var uri = uriFormat.Replace("{X}", width.ToString()).Replace("{Y}", height.ToString());
if (latLonBoundingBox)
@ -134,28 +144,27 @@ namespace MapControl
{
Trace.TraceWarning("{0}: {1}", uri, ex.Message);
}
}
return image;
}
private void UpdateImage(object sender, EventArgs e)
{
updateTimer.Stop();
if (updateInProgress || string.IsNullOrWhiteSpace(uriFormat))
if (!updateInProgress)
{
return;
}
imageIsValid = true;
updateTimer.Stop();
updateInProgress = true;
var loc1 = ParentMap.ViewportPointToLocation(new Point(0d, 0d));
var loc2 = ParentMap.ViewportPointToLocation(new Point(ActualWidth, 0d));
var loc3 = ParentMap.ViewportPointToLocation(new Point(0d, ActualHeight));
var loc4 = ParentMap.ViewportPointToLocation(new Point(ActualWidth, ActualHeight));
var width = (int)ActualWidth;
var height = (int)ActualHeight;
var relativeSize = Math.Max(RelativeImageSize, 1d);
var width = ActualWidth * relativeSize;
var height = ActualHeight * relativeSize;
var dx = (ActualWidth - width) / 2d;
var dy = (ActualHeight - height) / 2d;
var loc1 = ParentMap.ViewportPointToLocation(new Point(dx, dy));
var loc2 = ParentMap.ViewportPointToLocation(new Point(width, dy));
var loc3 = ParentMap.ViewportPointToLocation(new Point(dx, height));
var loc4 = ParentMap.ViewportPointToLocation(new Point(width, height));
ThreadPool.QueueUserWorkItem(o =>
{
@ -163,17 +172,25 @@ namespace MapControl
var east = Math.Max(loc1.Longitude, Math.Max(loc2.Longitude, Math.Max(loc3.Longitude, loc4.Longitude)));
var south = Math.Min(loc1.Latitude, Math.Min(loc2.Latitude, Math.Min(loc3.Latitude, loc4.Latitude)));
var north = Math.Max(loc1.Latitude, Math.Max(loc2.Latitude, Math.Max(loc3.Latitude, loc4.Latitude)));
var image = GetImage(west, east, south, north, width, height);
var image = GetImage(west, east, south, north, (int)width, (int)height);
if (image != null)
{
Dispatcher.BeginInvoke((Action)(() =>
Dispatcher.BeginInvoke((Action)(() => UpdateImage(west, east, south, north, image)));
}
updateInProgress = false;
});
}
}
private void UpdateImage(double west, double east, double south, double north, ImageSource image)
{
var mapImage = (MapImage)Children[currentImageIndex];
mapImage.BeginAnimation(Image.OpacityProperty,
new DoubleAnimation
{
To = 0,
To = 0d,
Duration = Tile.AnimationDuration,
BeginTime = Tile.AnimationDuration
});
@ -188,16 +205,6 @@ namespace MapControl
mapImage.North = north;
mapImage.Source = image;
mapImage.BeginAnimation(Image.OpacityProperty, new DoubleAnimation(1d, Tile.AnimationDuration));
if (!imageIsValid)
{
UpdateImage(this, EventArgs.Empty);
}
}));
}
updateInProgress = false;
});
}
}
}

View file

@ -15,8 +15,8 @@ using System.Windows;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -19,7 +19,7 @@ namespace MapControl
internal partial class TileContainer
{
private const double maxScaledTileSize = 400d; // scaled tile size 200..400 units
private static double zoomLevelSwitchOffset = Math.Log(maxScaledTileSize / TileSource.TileSize, 2d);
private static double zoomLevelSwitchDelta = Math.Log(maxScaledTileSize / TileSource.TileSize, 2d);
internal static TimeSpan UpdateInterval = TimeSpan.FromSeconds(0.5);
@ -127,7 +127,7 @@ namespace MapControl
{
updateTimer.Stop();
var zoom = (int)Math.Floor(zoomLevel + 1d - zoomLevelSwitchOffset);
var zoom = (int)Math.Floor(zoomLevel + 1d - zoomLevelSwitchDelta);
var numTiles = 1 << zoom;
var transform = GetTileIndexMatrix(numTiles);

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("Copyright © Clemens Fischer 2012-2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.3.2")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]