From f3f4b4c0fcc01a9820e216565725986fa257c1d4 Mon Sep 17 00:00:00 2001 From: ClemensF Date: Thu, 10 Oct 2013 22:26:43 +0200 Subject: [PATCH] Version 1.4.1: Fixed MapRectangle/MapImage transform. --- .../FileDbCache/Properties/AssemblyInfo.cs | 4 +- .../ImageFileCache/Properties/AssemblyInfo.cs | 4 +- MapControl/MapControl.Silverlight.csproj | 2 + MapControl/MapControl.WPF.csproj | 4 +- MapControl/MapImage.Silverlight.WinRT.cs | 29 ++++++++++ MapControl/MapImage.WPF.cs | 28 ++++++++++ MapControl/MapImage.cs | 7 +-- MapControl/MapRectangle.Silverlight.WinRT.cs | 33 ++++++++++++ MapControl/MapRectangle.WPF.cs | 54 +++++++++++++++++++ MapControl/MapRectangle.cs | 16 +++--- MapControl/Properties/AssemblyInfo.cs | 4 +- MapControl/WinRT/MapControl.WinRT.csproj | 6 +++ MapControl/WinRT/Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- .../WpfApplication/Properties/AssemblyInfo.cs | 4 +- 18 files changed, 183 insertions(+), 32 deletions(-) create mode 100644 MapControl/MapImage.Silverlight.WinRT.cs create mode 100644 MapControl/MapImage.WPF.cs create mode 100644 MapControl/MapRectangle.Silverlight.WinRT.cs create mode 100644 MapControl/MapRectangle.WPF.cs diff --git a/Caching/FileDbCache/Properties/AssemblyInfo.cs b/Caching/FileDbCache/Properties/AssemblyInfo.cs index 75e784b7..df481000 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/Caching/ImageFileCache/Properties/AssemblyInfo.cs b/Caching/ImageFileCache/Properties/AssemblyInfo.cs index ba439a95..13ba9e2b 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/MapControl/MapControl.Silverlight.csproj b/MapControl/MapControl.Silverlight.csproj index 72dcdfb1..92b2b338 100644 --- a/MapControl/MapControl.Silverlight.csproj +++ b/MapControl/MapControl.Silverlight.csproj @@ -75,6 +75,7 @@ + @@ -84,6 +85,7 @@ + diff --git a/MapControl/MapControl.WPF.csproj b/MapControl/MapControl.WPF.csproj index 4bffa4a8..6b8397bb 100644 --- a/MapControl/MapControl.WPF.csproj +++ b/MapControl/MapControl.WPF.csproj @@ -55,10 +55,11 @@ Code + + - @@ -66,6 +67,7 @@ + diff --git a/MapControl/MapImage.Silverlight.WinRT.cs b/MapControl/MapImage.Silverlight.WinRT.cs new file mode 100644 index 00000000..6cd66b48 --- /dev/null +++ b/MapControl/MapImage.Silverlight.WinRT.cs @@ -0,0 +1,29 @@ +// XAML Map Control - http://xamlmapcontrol.codeplex.com/ +// Copyright © Clemens Fischer 2012-2013 +// Licensed under the Microsoft Public License (Ms-PL) + +#if NETFX_CORE +using Windows.UI.Xaml.Media; +#else +using System.Windows.Media; +#endif + +namespace MapControl +{ + public partial class MapImage + { + private static readonly Transform imageTransform = new MatrixTransform + { + Matrix = new Matrix(1d, 0d, 0d, -1d, 0d, 1d) + }; + + private void SourceChanged(ImageSource image) + { + Fill = new ImageBrush + { + ImageSource = image, + RelativeTransform = imageTransform + }; + } + } +} diff --git a/MapControl/MapImage.WPF.cs b/MapControl/MapImage.WPF.cs new file mode 100644 index 00000000..3c3b7e75 --- /dev/null +++ b/MapControl/MapImage.WPF.cs @@ -0,0 +1,28 @@ +// XAML Map Control - http://xamlmapcontrol.codeplex.com/ +// Copyright © Clemens Fischer 2012-2013 +// Licensed under the Microsoft Public License (Ms-PL) + +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace MapControl +{ + public partial class MapImage + { + private static readonly Transform imageTransform = new ScaleTransform(1d, -1d); + + private void SourceChanged(ImageSource image) + { + var bitmap = image as BitmapSource; + + if (bitmap != null) + { + image = new TransformedBitmap(bitmap, imageTransform); + } + + Fill = new ImageBrush { ImageSource = image }; + SetBrushTransform(); + } + } +} \ No newline at end of file diff --git a/MapControl/MapImage.cs b/MapControl/MapImage.cs index 292c83cc..77610e20 100644 --- a/MapControl/MapImage.cs +++ b/MapControl/MapImage.cs @@ -15,7 +15,7 @@ namespace MapControl /// /// Fills a rectangular area with an ImageBrush from the Source property. /// - public class MapImage : MapRectangle + public partial class MapImage : MapRectangle { public static readonly DependencyProperty SourceProperty = DependencyProperty.Register( "Source", typeof(ImageSource), typeof(MapImage), @@ -26,10 +26,5 @@ namespace MapControl get { return (ImageSource)GetValue(SourceProperty); } set { SetValue(SourceProperty, value); } } - - private void SourceChanged(ImageSource image) - { - Fill = new ImageBrush { ImageSource = image }; - } } } diff --git a/MapControl/MapRectangle.Silverlight.WinRT.cs b/MapControl/MapRectangle.Silverlight.WinRT.cs new file mode 100644 index 00000000..d4b90df3 --- /dev/null +++ b/MapControl/MapRectangle.Silverlight.WinRT.cs @@ -0,0 +1,33 @@ +// XAML Map Control - http://xamlmapcontrol.codeplex.com/ +// Copyright © Clemens Fischer 2012-2013 +// Licensed under the Microsoft Public License (Ms-PL) + +#if NETFX_CORE +using Windows.Foundation; +using Windows.UI.Xaml.Media; +#else +using System.Windows; +using System.Windows.Media; +#endif + +namespace MapControl +{ + public partial class MapRectangle + { + private void SetGeometry(Rect rect) + { + var geometry = (RectangleGeometry)Data; + + geometry.Rect = rect; + RenderTransform = ParentMap.ViewportTransform; + } + + private void ClearGeometry() + { + var geometry = (RectangleGeometry)Data; + + geometry.ClearValue(RectangleGeometry.RectProperty); + ClearValue(RenderTransformProperty); + } + } +} diff --git a/MapControl/MapRectangle.WPF.cs b/MapControl/MapRectangle.WPF.cs new file mode 100644 index 00000000..0c5c0679 --- /dev/null +++ b/MapControl/MapRectangle.WPF.cs @@ -0,0 +1,54 @@ +// XAML Map Control - http://xamlmapcontrol.codeplex.com/ +// Copyright © Clemens Fischer 2012-2013 +// Licensed under the Microsoft Public License (Ms-PL) + +using System.Windows; +using System.Windows.Media; + +namespace MapControl +{ + public partial class MapRectangle + { + static MapRectangle() + { + StrokeThicknessProperty.OverrideMetadata( + typeof(MapRectangle), new FrameworkPropertyMetadata(0d)); + } + + protected void SetBrushTransform() + { + var tileBrush = Fill as TileBrush; + + if (tileBrush != null && Data != null) + { + var geometry = (RectangleGeometry)Data; + + tileBrush.ViewportUnits = BrushMappingMode.Absolute; + tileBrush.Viewport = geometry.Rect; + tileBrush.Transform = geometry.Transform; + } + } + + private void SetGeometry(Rect rect) + { + // Instead of setting RenderTransform as done in the Silverlight and + // WinRT versions, the ViewportTransform is applied to the Transform + // properties of the Geometry and the Fill Brush. In WPF, setting the + // RenderTransform property results in incorrect hit testing. + + var geometry = (RectangleGeometry)Data; + + geometry.Rect = rect; + geometry.Transform = ParentMap.ViewportTransform; + SetBrushTransform(); + } + + private void ClearGeometry() + { + var geometry = (RectangleGeometry)Data; + + geometry.ClearValue(RectangleGeometry.RectProperty); + geometry.ClearValue(Geometry.TransformProperty); + } + } +} diff --git a/MapControl/MapRectangle.cs b/MapControl/MapRectangle.cs index d5eba46b..34241a57 100644 --- a/MapControl/MapRectangle.cs +++ b/MapControl/MapRectangle.cs @@ -16,7 +16,7 @@ namespace MapControl /// /// Fills a rectangular area defined by South, North, West and East with a Brush. /// - public class MapRectangle : MapPath + public partial class MapRectangle : MapPath { public static readonly DependencyProperty SouthProperty = DependencyProperty.Register( "South", typeof(double), typeof(MapRectangle), @@ -34,6 +34,12 @@ namespace MapControl "East", typeof(double), typeof(MapRectangle), new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateData())); + public MapRectangle() + { + Data = new RectangleGeometry(); + StrokeThickness = 0d; + } + public double South { get { return (double)GetValue(SouthProperty); } @@ -68,15 +74,11 @@ namespace MapControl var p1 = ParentMap.MapTransform.Transform(new Location(South, West)); var p2 = ParentMap.MapTransform.Transform(new Location(North, East)); - Data = new RectangleGeometry - { - Rect = new Rect(p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y), - Transform = ParentMap.ViewportTransform - }; + SetGeometry(new Rect(p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y)); } else { - ClearValue(DataProperty); + ClearGeometry(); } } } diff --git a/MapControl/Properties/AssemblyInfo.cs b/MapControl/Properties/AssemblyInfo.cs index 1acb1304..f06621dc 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/MapControl/WinRT/MapControl.WinRT.csproj b/MapControl/WinRT/MapControl.WinRT.csproj index 1aac6b9c..67d50e31 100644 --- a/MapControl/WinRT/MapControl.WinRT.csproj +++ b/MapControl/WinRT/MapControl.WinRT.csproj @@ -63,6 +63,9 @@ MapImage.cs + + MapImage.Silverlight.WinRT.cs + MapItem.Silverlight.WinRT.cs @@ -90,6 +93,9 @@ MapRectangle.cs + + MapRectangle.Silverlight.WinRT.cs + MapTransform.cs diff --git a/MapControl/WinRT/Properties/AssemblyInfo.cs b/MapControl/WinRT/Properties/AssemblyInfo.cs index 846fb712..0af50aee 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/SampleApps/SilverlightApplication.Web/Properties/AssemblyInfo.cs b/SampleApps/SilverlightApplication.Web/Properties/AssemblyInfo.cs index 9ff9dd45..25245348 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/SampleApps/SilverlightApplication/Properties/AssemblyInfo.cs b/SampleApps/SilverlightApplication/Properties/AssemblyInfo.cs index 12cadf94..03335a66 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/SampleApps/StoreApplication/Properties/AssemblyInfo.cs b/SampleApps/StoreApplication/Properties/AssemblyInfo.cs index fb5f0895..2f37e073 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/SampleApps/SurfaceApplication/Properties/AssemblyInfo.cs b/SampleApps/SurfaceApplication/Properties/AssemblyInfo.cs index 87a3d7f3..667eea6e 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/SampleApps/WpfApplication/Properties/AssemblyInfo.cs b/SampleApps/WpfApplication/Properties/AssemblyInfo.cs index f2c0a79b..e3ebb3d9 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.4.0")] -[assembly: AssemblyFileVersion("1.4.0")] +[assembly: AssemblyVersion("1.4.1")] +[assembly: AssemblyFileVersion("1.4.1")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)]