Version 1.3.5. Fixed rendering issue with MapPath (formerly MapShape) and re-arranging of MapPanel child elements when Location is set initially.

This commit is contained in:
ClemensF 2013-05-25 08:53:50 +02:00
parent e2ef560e36
commit abfdd89efb
22 changed files with 168 additions and 163 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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -80,11 +80,11 @@
<Compile Include="MapItemsControl.Silverlight.WinRT.cs" />
<Compile Include="MapPanel.cs" />
<Compile Include="MapPanel.Silverlight.WinRT.cs" />
<Compile Include="MapPath.cs" />
<Compile Include="MapRectangle.cs" />
<Compile Include="MapShape.cs" />
<Compile Include="MapPolyline.cs" />
<Compile Include="MapPolyline.Silverlight.WinRT.cs" />
<Compile Include="MapShape.Silverlight.WinRT.cs" />
<Compile Include="MapPath.Silverlight.WinRT.cs" />
<Compile Include="MapTransform.cs" />
<Compile Include="MatrixEx.cs" />
<Compile Include="MercatorTransform.cs" />

View file

@ -65,8 +65,8 @@
<Compile Include="MapPolyline.cs" />
<Compile Include="MapPolyline.WPF.cs" />
<Compile Include="MapRectangle.cs" />
<Compile Include="MapShape.cs" />
<Compile Include="MapShape.WPF.cs" />
<Compile Include="MapPath.cs" />
<Compile Include="MapPath.WPF.cs" />
<Compile Include="MapTransform.cs" />
<Compile Include="MercatorTransform.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -203,7 +203,7 @@ namespace MapControl
currentImageIndex = (currentImageIndex + 1) % 2;
mapImage = (MapImage)Children[currentImageIndex];
mapImage.Source = null;
mapImage.North = double.NaN; // avoid frequent MapRectangle.UpdateGeometry() calls
mapImage.North = double.NaN; // avoid frequent MapRectangle.UpdateData() calls
mapImage.West = west;
mapImage.East = east;
mapImage.South = south;

View file

@ -2,7 +2,6 @@
// Copyright © Clemens Fischer 2012-2013
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if NETFX_CORE
using Windows.Foundation;
using Windows.UI.Xaml;
@ -98,28 +97,14 @@ namespace MapControl
{
foreach (UIElement element in InternalChildren)
{
var rect = new Rect(0d, 0d, element.DesiredSize.Width, element.DesiredSize.Height);
var location = GetLocation(element);
if (element is FrameworkElement)
{
if (location != null)
{
AlignElementWithLocation((FrameworkElement)element, ref rect);
}
else
{
AlignElementWithoutLocation((FrameworkElement)element, finalSize, ref rect);
}
}
element.Arrange(rect);
ArrangeElement(element, finalSize, location != null);
if (location != null)
{
SetViewportPosition(element, parentMap, location);
}
}
return finalSize;
@ -143,8 +128,14 @@ namespace MapControl
{
var mapElement = element as IMapElement;
var parentMap = mapElement != null ? mapElement.ParentMap : GetParentMap(element);
var location = e.NewValue as Location;
SetViewportPosition(element, parentMap, (Location)e.NewValue);
if ((location != null) != (e.OldValue != null))
{
ArrangeElement(element, null, location != null);
}
SetViewportPosition(element, parentMap, location);
}
}
@ -193,74 +184,90 @@ namespace MapControl
translateTransform.Y = viewportPosition.Y;
}
private static void AlignElementWithLocation(FrameworkElement element, ref Rect arrangeRect)
private static void ArrangeElement(UIElement element, Size? panelSize, bool hasLocation)
{
switch (element.HorizontalAlignment)
var rect = new Rect(0d, 0d, element.DesiredSize.Width, element.DesiredSize.Height);
var frameworkElement = element as FrameworkElement;
if (frameworkElement != null)
{
case HorizontalAlignment.Center:
arrangeRect.X = -arrangeRect.Width / 2d;
break;
if (hasLocation)
{
switch (frameworkElement.HorizontalAlignment)
{
case HorizontalAlignment.Center:
rect.X = -rect.Width / 2d;
break;
case HorizontalAlignment.Right:
arrangeRect.X = -arrangeRect.Width;
break;
case HorizontalAlignment.Right:
rect.X = -rect.Width;
break;
default:
break;
default:
break;
}
switch (frameworkElement.VerticalAlignment)
{
case VerticalAlignment.Center:
rect.Y = -rect.Height / 2d;
break;
case VerticalAlignment.Bottom:
rect.Y = -rect.Height;
break;
default:
break;
}
}
else
{
if (!panelSize.HasValue)
{
var panel = frameworkElement.Parent as Panel;
panelSize = panel != null ? panel.RenderSize : Size.Empty;
}
switch (frameworkElement.HorizontalAlignment)
{
case HorizontalAlignment.Center:
rect.X = (panelSize.Value.Width - rect.Width) / 2d;
break;
case HorizontalAlignment.Right:
rect.X = panelSize.Value.Width - rect.Width;
break;
case HorizontalAlignment.Stretch:
rect.Width = panelSize.Value.Width;
break;
default:
break;
}
switch (frameworkElement.VerticalAlignment)
{
case VerticalAlignment.Center:
rect.Y = (panelSize.Value.Height - rect.Height) / 2d;
break;
case VerticalAlignment.Bottom:
rect.Y = panelSize.Value.Height - rect.Height;
break;
case VerticalAlignment.Stretch:
rect.Height = panelSize.Value.Height;
break;
default:
break;
}
}
}
switch (element.VerticalAlignment)
{
case VerticalAlignment.Center:
arrangeRect.Y = -arrangeRect.Height / 2d;
break;
case VerticalAlignment.Bottom:
arrangeRect.Y = -arrangeRect.Height;
break;
default:
break;
}
}
private static void AlignElementWithoutLocation(FrameworkElement element, Size panelSize, ref Rect arrangeRect)
{
switch (element.HorizontalAlignment)
{
case HorizontalAlignment.Center:
arrangeRect.X = (panelSize.Width - arrangeRect.Width) / 2d;
break;
case HorizontalAlignment.Right:
arrangeRect.X = panelSize.Width - arrangeRect.Width;
break;
case HorizontalAlignment.Stretch:
arrangeRect.Width = panelSize.Width;
break;
default:
break;
}
switch (element.VerticalAlignment)
{
case VerticalAlignment.Center:
arrangeRect.Y = (panelSize.Height - arrangeRect.Height) / 2d;
break;
case VerticalAlignment.Bottom:
arrangeRect.Y = panelSize.Height - arrangeRect.Height;
break;
case VerticalAlignment.Stretch:
arrangeRect.Height = panelSize.Height;
break;
default:
break;
}
element.Arrange(rect);
}
}
}

View file

@ -3,20 +3,17 @@
// Licensed under the Microsoft Public License (Ms-PL)
#if NETFX_CORE
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
#else
using System.Windows.Media;
using System.Windows.Shapes;
#endif
namespace MapControl
{
public partial class MapShape : Path
public partial class MapPath : Path
{
public MapShape(Geometry geometry)
public MapPath()
{
Data = Geometry = geometry;
MapPanel.AddParentMapHandlers(this);
}
}

28
MapControl/MapPath.WPF.cs Normal file
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.Shapes;
namespace MapControl
{
public partial class MapPath : Shape
{
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
"Data", typeof(Geometry), typeof(MapPath),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
public Geometry Data
{
get { return (Geometry)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
protected override Geometry DefiningGeometry
{
get { return Data; }
}
}
}

View file

@ -4,11 +4,8 @@
#if NETFX_CORE
using Windows.Foundation;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
@ -16,7 +13,7 @@ namespace MapControl
/// <summary>
/// Base class for map shapes.
/// </summary>
public partial class MapShape : IMapElement
public partial class MapPath : IMapElement
{
private MapBase parentMap;
@ -26,20 +23,18 @@ namespace MapControl
set
{
parentMap = value;
UpdateGeometry();
UpdateData();
}
}
protected readonly Geometry Geometry;
protected virtual void UpdateGeometry()
protected virtual void UpdateData()
{
}
protected override Size MeasureOverride(Size constraint)
{
// Shape.MeasureOverride in WPF and WinRT sometimes return a Size with zero
// width or height, whereas Shape.MeasureOverride in Silverlight occasionally
// base.MeasureOverride in WPF and WinRT sometimes return a Size with zero
// width or height, whereas base.MeasureOverride in Silverlight occasionally
// throws an ArgumentException, as it tries to create a Size from a negative
// width or height, apparently resulting from a transformed Geometry.
// In either case it seems to be sufficient to simply return a non-zero size.

View file

@ -15,13 +15,13 @@ namespace MapControl
public partial class MapPolyline
{
public MapPolyline()
: base(new PathGeometry())
{
Data = new PathGeometry();
}
protected override void UpdateGeometry()
protected override void UpdateData()
{
var geometry = (PathGeometry)Geometry;
var geometry = (PathGeometry)Data;
var locations = Locations;
Location first;

View file

@ -10,13 +10,13 @@ namespace MapControl
public partial class MapPolyline
{
public MapPolyline()
: base(new StreamGeometry())
{
Data = new StreamGeometry();
}
protected override void UpdateGeometry()
protected override void UpdateData()
{
var geometry = (StreamGeometry)Geometry;
var geometry = (StreamGeometry)Data;
var locations = Locations;
Location first;

View file

@ -14,7 +14,7 @@ using System.Windows;
namespace MapControl
{
public partial class MapPolyline : MapShape
public partial class MapPolyline : MapPath
{
#if NETFX_CORE
// For WinRT, the Locations dependency property type is declared as object
@ -29,7 +29,7 @@ namespace MapControl
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
"IsClosed", typeof(bool), typeof(MapPolyline),
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateGeometry()));
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateData()));
/// <summary>
/// Gets or sets the locations that define the polyline points.
@ -51,7 +51,7 @@ namespace MapControl
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateGeometry();
UpdateData();
}
private static void LocationsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
@ -70,7 +70,7 @@ namespace MapControl
newCollection.CollectionChanged += mapPolyline.LocationCollectionChanged;
}
mapPolyline.UpdateGeometry();
mapPolyline.UpdateData();
}
}
}

View file

@ -16,27 +16,27 @@ namespace MapControl
/// <summary>
/// Fills a rectangular area defined by South, North, West and East with a Brush.
/// </summary>
public class MapRectangle : MapShape
public class MapRectangle : MapPath
{
public static readonly DependencyProperty SouthProperty = DependencyProperty.Register(
"South", typeof(double), typeof(MapRectangle),
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateGeometry()));
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateData()));
public static readonly DependencyProperty NorthProperty = DependencyProperty.Register(
"North", typeof(double), typeof(MapRectangle),
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateGeometry()));
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateData()));
public static readonly DependencyProperty WestProperty = DependencyProperty.Register(
"West", typeof(double), typeof(MapRectangle),
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateGeometry()));
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateData()));
public static readonly DependencyProperty EastProperty = DependencyProperty.Register(
"East", typeof(double), typeof(MapRectangle),
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateGeometry()));
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateData()));
public MapRectangle()
: base(new RectangleGeometry())
{
Data = new RectangleGeometry();
}
public double South
@ -63,9 +63,9 @@ namespace MapControl
set { SetValue(EastProperty, value); }
}
protected override void UpdateGeometry()
protected override void UpdateData()
{
var geometry = (RectangleGeometry)Geometry;
var geometry = (RectangleGeometry)Data;
if (ParentMap != null &&
!double.IsNaN(South) && !double.IsNaN(North) &&

View file

@ -1,22 +0,0 @@
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © Clemens Fischer 2012-2013
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows.Media;
using System.Windows.Shapes;
namespace MapControl
{
public partial class MapShape : Shape
{
public MapShape(Geometry geometry)
{
Geometry = geometry;
}
protected override Geometry DefiningGeometry
{
get { return Geometry; }
}
}
}

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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -78,6 +78,12 @@
<Compile Include="..\MapPanel.Silverlight.WinRT.cs">
<Link>MapPanel.Silverlight.WinRT.cs</Link>
</Compile>
<Compile Include="..\MapPath.cs">
<Link>MapPath.cs</Link>
</Compile>
<Compile Include="..\MapPath.Silverlight.WinRT.cs">
<Link>MapPath.Silverlight.WinRT.cs</Link>
</Compile>
<Compile Include="..\MapPolyline.cs">
<Link>MapPolyline.cs</Link>
</Compile>
@ -87,12 +93,6 @@
<Compile Include="..\MapRectangle.cs">
<Link>MapRectangle.cs</Link>
</Compile>
<Compile Include="..\MapShape.cs">
<Link>MapShape.cs</Link>
</Compile>
<Compile Include="..\MapShape.Silverlight.WinRT.cs">
<Link>MapShape.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.3.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[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.4")]
[assembly: AssemblyFileVersion("1.3.4")]
[assembly: AssemblyVersion("1.3.5")]
[assembly: AssemblyFileVersion("1.3.5")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]