Version 1.4.1: Fixed MapRectangle/MapImage transform.

This commit is contained in:
ClemensF 2013-10-10 22:26:43 +02:00
parent 14cc7bcea2
commit f3f4b4c0fc
18 changed files with 183 additions and 32 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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -75,6 +75,7 @@
<Compile Include="MapGraticule.cs" />
<Compile Include="MapGraticule.Silverlight.WinRT.cs" />
<Compile Include="MapImage.cs" />
<Compile Include="MapImage.Silverlight.WinRT.cs" />
<Compile Include="MapItem.Silverlight.WinRT.cs" />
<Compile Include="MapItemsControl.Silverlight.WinRT.cs" />
<Compile Include="MapPanel.cs" />
@ -84,6 +85,7 @@
<Compile Include="MapPolyline.cs" />
<Compile Include="MapPolyline.Silverlight.WinRT.cs" />
<Compile Include="MapPath.Silverlight.WinRT.cs" />
<Compile Include="MapRectangle.Silverlight.WinRT.cs" />
<Compile Include="MapTransform.cs" />
<Compile Include="MatrixEx.cs" />
<Compile Include="MercatorTransform.cs" />

View file

@ -55,10 +55,11 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="MapBase.WPF.cs" />
<Compile Include="MapImage.cs" />
<Compile Include="MapImage.WPF.cs" />
<Compile Include="MapImageLayer.cs" />
<Compile Include="MapItem.WPF.cs" />
<Compile Include="MapItemsControl.WPF.cs" />
<Compile Include="MapImage.cs" />
<Compile Include="MapPanel.cs" />
<Compile Include="MapPanel.WPF.cs" />
<Compile Include="MapPolyline.cs" />
@ -66,6 +67,7 @@
<Compile Include="MapRectangle.cs" />
<Compile Include="MapPath.cs" />
<Compile Include="MapPath.WPF.cs" />
<Compile Include="MapRectangle.WPF.cs" />
<Compile Include="MapTransform.cs" />
<Compile Include="MercatorTransform.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -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
};
}
}
}

View file

@ -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();
}
}
}

View file

@ -15,7 +15,7 @@ namespace MapControl
/// <summary>
/// Fills a rectangular area with an ImageBrush from the Source property.
/// </summary>
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 };
}
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -16,7 +16,7 @@ namespace MapControl
/// <summary>
/// Fills a rectangular area defined by South, North, West and East with a Brush.
/// </summary>
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();
}
}
}

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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -63,6 +63,9 @@
<Compile Include="..\MapImage.cs">
<Link>MapImage.cs</Link>
</Compile>
<Compile Include="..\MapImage.Silverlight.WinRT.cs">
<Link>MapImage.Silverlight.WinRT.cs</Link>
</Compile>
<Compile Include="..\MapItem.Silverlight.WinRT.cs">
<Link>MapItem.Silverlight.WinRT.cs</Link>
</Compile>
@ -90,6 +93,9 @@
<Compile Include="..\MapRectangle.cs">
<Link>MapRectangle.cs</Link>
</Compile>
<Compile Include="..\MapRectangle.Silverlight.WinRT.cs">
<Link>MapRectangle.Silverlight.WinRT.cs</Link>
</Compile>
<Compile Include="..\MapTransform.cs">
<Link>MapTransform.cs</Link>
</Compile>

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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[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.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]