diff --git a/Caching/FileDbCache/Properties/AssemblyInfo.cs b/Caching/FileDbCache/Properties/AssemblyInfo.cs index 92046b81..c7fdc4d9 100644 --- a/Caching/FileDbCache/Properties/AssemblyInfo.cs +++ b/Caching/FileDbCache/Properties/AssemblyInfo.cs @@ -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)] diff --git a/Caching/ImageFileCache/Properties/AssemblyInfo.cs b/Caching/ImageFileCache/Properties/AssemblyInfo.cs index 96fc3d2e..730ca894 100644 --- a/Caching/ImageFileCache/Properties/AssemblyInfo.cs +++ b/Caching/ImageFileCache/Properties/AssemblyInfo.cs @@ -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)] diff --git a/MapControl/MapBase.cs b/MapControl/MapBase.cs index 9eebb9bd..5506e521 100644 --- a/MapControl/MapBase.cs +++ b/MapControl/MapBase.cs @@ -416,7 +416,7 @@ namespace MapControl { Loaded -= OnLoaded; - if (TileLayer == null) + if (TileLayer == null && TileLayers == null) { TileLayer = TileLayer.Default; } diff --git a/MapControl/MapImageLayer.cs b/MapControl/MapImageLayer.cs index d3cd7d94..55cef0c5 100644 --- a/MapControl/MapImageLayer.cs +++ b/MapControl/MapImageLayer.cs @@ -27,10 +27,12 @@ namespace MapControl /// 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,53 +93,57 @@ namespace MapControl protected virtual ImageSource GetImage(double west, double east, double south, double north, int width, int height) { ImageSource image = null; - var uri = uriFormat.Replace("{X}", width.ToString()).Replace("{Y}", height.ToString()); - if (latLonBoundingBox) + if (uriFormat != null) { - uri = uri. - Replace("{w}", west.ToString(CultureInfo.InvariantCulture)). - Replace("{s}", south.ToString(CultureInfo.InvariantCulture)). - Replace("{e}", east.ToString(CultureInfo.InvariantCulture)). - Replace("{n}", north.ToString(CultureInfo.InvariantCulture)); - } - else - { - var p1 = ParentMap.MapTransform.Transform(new Location(south, west)); - var p2 = ParentMap.MapTransform.Transform(new Location(north, east)); - var arc = TileSource.EarthRadius * Math.PI / 180d; + var uri = uriFormat.Replace("{X}", width.ToString()).Replace("{Y}", height.ToString()); - uri = uri. - Replace("{W}", (arc * p1.X).ToString(CultureInfo.InvariantCulture)). - Replace("{S}", (arc * p1.Y).ToString(CultureInfo.InvariantCulture)). - Replace("{E}", (arc * p2.X).ToString(CultureInfo.InvariantCulture)). - Replace("{N}", (arc * p2.Y).ToString(CultureInfo.InvariantCulture)); - } - - try - { - var bitmap = new BitmapImage(); - var request = (HttpWebRequest)WebRequest.Create(uri); - request.UserAgent = "XAML Map Control"; - - using (var response = (HttpWebResponse)request.GetResponse()) - using (var responseStream = response.GetResponseStream()) - using (var memoryStream = new MemoryStream()) + if (latLonBoundingBox) { - responseStream.CopyTo(memoryStream); + uri = uri. + Replace("{w}", west.ToString(CultureInfo.InvariantCulture)). + Replace("{s}", south.ToString(CultureInfo.InvariantCulture)). + Replace("{e}", east.ToString(CultureInfo.InvariantCulture)). + Replace("{n}", north.ToString(CultureInfo.InvariantCulture)); + } + else + { + var p1 = ParentMap.MapTransform.Transform(new Location(south, west)); + var p2 = ParentMap.MapTransform.Transform(new Location(north, east)); + var arc = TileSource.EarthRadius * Math.PI / 180d; - bitmap.BeginInit(); - bitmap.CacheOption = BitmapCacheOption.OnLoad; - bitmap.StreamSource = memoryStream; - bitmap.EndInit(); - bitmap.Freeze(); + uri = uri. + Replace("{W}", (arc * p1.X).ToString(CultureInfo.InvariantCulture)). + Replace("{S}", (arc * p1.Y).ToString(CultureInfo.InvariantCulture)). + Replace("{E}", (arc * p2.X).ToString(CultureInfo.InvariantCulture)). + Replace("{N}", (arc * p2.Y).ToString(CultureInfo.InvariantCulture)); } - image = bitmap; - } - catch (Exception ex) - { - Trace.TraceWarning("{0}: {1}", uri, ex.Message); + try + { + var bitmap = new BitmapImage(); + var request = (HttpWebRequest)WebRequest.Create(uri); + request.UserAgent = "XAML Map Control"; + + using (var response = (HttpWebResponse)request.GetResponse()) + using (var responseStream = response.GetResponseStream()) + using (var memoryStream = new MemoryStream()) + { + responseStream.CopyTo(memoryStream); + + bitmap.BeginInit(); + bitmap.CacheOption = BitmapCacheOption.OnLoad; + bitmap.StreamSource = memoryStream; + bitmap.EndInit(); + bitmap.Freeze(); + } + + image = bitmap; + } + catch (Exception ex) + { + Trace.TraceWarning("{0}: {1}", uri, ex.Message); + } } return image; @@ -140,64 +151,60 @@ namespace MapControl private void UpdateImage(object sender, EventArgs e) { - updateTimer.Stop(); - - if (updateInProgress || string.IsNullOrWhiteSpace(uriFormat)) + if (!updateInProgress) { - return; - } + updateTimer.Stop(); + updateInProgress = true; - imageIsValid = true; - updateInProgress = true; + 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)); - 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; - - ThreadPool.QueueUserWorkItem(o => - { - var west = Math.Min(loc1.Longitude, Math.Min(loc2.Longitude, Math.Min(loc3.Longitude, loc4.Longitude))); - 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); - - if (image != null) + ThreadPool.QueueUserWorkItem(o => { - Dispatcher.BeginInvoke((Action)(() => + var west = Math.Min(loc1.Longitude, Math.Min(loc2.Longitude, Math.Min(loc3.Longitude, loc4.Longitude))); + 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, (int)width, (int)height); + + if (image != null) { - var mapImage = (MapImage)Children[currentImageIndex]; - mapImage.BeginAnimation(Image.OpacityProperty, - new DoubleAnimation - { - To = 0, - Duration = Tile.AnimationDuration, - BeginTime = Tile.AnimationDuration - }); + Dispatcher.BeginInvoke((Action)(() => UpdateImage(west, east, south, north, image))); + } - currentImageIndex = (currentImageIndex + 1) % 2; - mapImage = (MapImage)Children[currentImageIndex]; - mapImage.Source = null; - mapImage.North = double.NaN; // avoid frequent MapRectangle.UpdateGeometry() calls - mapImage.West = west; - mapImage.East = east; - mapImage.South = south; - mapImage.North = north; - mapImage.Source = image; - mapImage.BeginAnimation(Image.OpacityProperty, new DoubleAnimation(1d, Tile.AnimationDuration)); + updateInProgress = false; + }); + } + } - if (!imageIsValid) - { - UpdateImage(this, EventArgs.Empty); - } - })); - } + 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 = 0d, + Duration = Tile.AnimationDuration, + BeginTime = Tile.AnimationDuration + }); - updateInProgress = false; - }); + currentImageIndex = (currentImageIndex + 1) % 2; + mapImage = (MapImage)Children[currentImageIndex]; + mapImage.Source = null; + mapImage.North = double.NaN; // avoid frequent MapRectangle.UpdateGeometry() calls + mapImage.West = west; + mapImage.East = east; + mapImage.South = south; + mapImage.North = north; + mapImage.Source = image; + mapImage.BeginAnimation(Image.OpacityProperty, new DoubleAnimation(1d, Tile.AnimationDuration)); } } } diff --git a/MapControl/Properties/AssemblyInfo.cs b/MapControl/Properties/AssemblyInfo.cs index 1c7eee3c..77c5242b 100644 --- a/MapControl/Properties/AssemblyInfo.cs +++ b/MapControl/Properties/AssemblyInfo.cs @@ -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)] diff --git a/MapControl/TileContainer.cs b/MapControl/TileContainer.cs index ced0995e..0f7ca1cd 100644 --- a/MapControl/TileContainer.cs +++ b/MapControl/TileContainer.cs @@ -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); diff --git a/MapControl/WinRT/Properties/AssemblyInfo.cs b/MapControl/WinRT/Properties/AssemblyInfo.cs index afdd02e5..3932bb36 100644 --- a/MapControl/WinRT/Properties/AssemblyInfo.cs +++ b/MapControl/WinRT/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/SilverlightApplication.Web/Properties/AssemblyInfo.cs b/SampleApps/SilverlightApplication.Web/Properties/AssemblyInfo.cs index 0ce64bba..217feafa 100644 --- a/SampleApps/SilverlightApplication.Web/Properties/AssemblyInfo.cs +++ b/SampleApps/SilverlightApplication.Web/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/SilverlightApplication/Properties/AssemblyInfo.cs b/SampleApps/SilverlightApplication/Properties/AssemblyInfo.cs index 874b00f2..4361ad23 100644 --- a/SampleApps/SilverlightApplication/Properties/AssemblyInfo.cs +++ b/SampleApps/SilverlightApplication/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/StoreApplication/Properties/AssemblyInfo.cs b/SampleApps/StoreApplication/Properties/AssemblyInfo.cs index cd7f1cfd..8be565ac 100644 --- a/SampleApps/StoreApplication/Properties/AssemblyInfo.cs +++ b/SampleApps/StoreApplication/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/SurfaceApplication/Properties/AssemblyInfo.cs b/SampleApps/SurfaceApplication/Properties/AssemblyInfo.cs index e140800c..557825db 100644 --- a/SampleApps/SurfaceApplication/Properties/AssemblyInfo.cs +++ b/SampleApps/SurfaceApplication/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/WpfApplication/Properties/AssemblyInfo.cs b/SampleApps/WpfApplication/Properties/AssemblyInfo.cs index 8cb44272..42b012a5 100644 --- a/SampleApps/WpfApplication/Properties/AssemblyInfo.cs +++ b/SampleApps/WpfApplication/Properties/AssemblyInfo.cs @@ -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)]