Version 4.9.0: Reworked MapPanel child arrangement.

This commit is contained in:
ClemensF 2018-04-30 23:13:50 +02:00
parent 0a7d0fccd2
commit 56d376c4d0
24 changed files with 326 additions and 322 deletions

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -62,12 +62,12 @@ namespace MapControl
public static readonly DependencyProperty InlinesSourceProperty = DependencyProperty.RegisterAttached(
"InlinesSource", typeof(string), typeof(HyperlinkText), new PropertyMetadata(null, InlinesSourcePropertyChanged));
public static string GetInlinesSource(UIElement element)
public static string GetInlinesSource(DependencyObject element)
{
return (string)element.GetValue(InlinesSourceProperty);
}
public static void SetInlinesSource(UIElement element, string value)
public static void SetInlinesSource(DependencyObject element, string value)
{
element.SetValue(InlinesSourceProperty, value);
}

View file

@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
#if WINDOWS_UWP
using Windows.Foundation;
@ -295,7 +296,7 @@ namespace MapControl
boundingBox.West += offset;
boundingBox.East += offset;
foreach (UIElement element in Children)
foreach (var element in Children.OfType<FrameworkElement>())
{
var bbox = GetBoundingBox(element);
@ -309,7 +310,7 @@ namespace MapControl
private void ClearImages()
{
foreach (UIElement element in Children)
foreach (var element in Children.OfType<FrameworkElement>())
{
element.ClearValue(BoundingBoxProperty);
element.ClearValue(Image.SourceProperty);

View file

@ -24,6 +24,16 @@ namespace MapControl
{
Loaded += (s, e) =>
{
#if WINDOWS_UWP
if (Foreground == null)
{
SetBinding(ForegroundProperty, new Binding
{
Source = this,
Path = new PropertyPath("ParentMap.Foreground")
});
}
#endif
if (Stroke == null)
{
SetBinding(StrokeProperty, new Binding

View file

@ -3,6 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Linq;
#if WINDOWS_UWP
using Windows.Foundation;
using Windows.UI.Xaml;
@ -18,7 +19,6 @@ namespace MapControl
{
/// <summary>
/// Optional interface to hold the value of the MapPanel.ParentMap attached property.
/// May be used to get notified when the property value changes.
/// </summary>
public interface IMapElement
{
@ -28,8 +28,6 @@ namespace MapControl
/// <summary>
/// Arranges child elements on a Map at positions specified by the attached property Location,
/// or in rectangles specified by the attached property BoundingBox.
/// An element's viewport position is assigned as TranslateTransform to its RenderTransform property,
/// either directly or as last child of a TransformGroup.
/// </summary>
public partial class MapPanel : Panel, IMapElement
{
@ -46,37 +44,57 @@ namespace MapControl
InitMapElement(this);
}
public static Location GetLocation(UIElement element)
public static Location GetLocation(FrameworkElement element)
{
return (Location)element.GetValue(LocationProperty);
}
public static void SetLocation(UIElement element, Location value)
public static void SetLocation(FrameworkElement element, Location value)
{
element.SetValue(LocationProperty, value);
}
public static BoundingBox GetBoundingBox(UIElement element)
public static BoundingBox GetBoundingBox(FrameworkElement element)
{
return (BoundingBox)element.GetValue(BoundingBoxProperty);
}
public static void SetBoundingBox(UIElement element, BoundingBox value)
public static void SetBoundingBox(FrameworkElement element, BoundingBox value)
{
element.SetValue(BoundingBoxProperty, value);
}
public static Point? GetViewportPosition(FrameworkElement element)
{
return (Point?)element.GetValue(ViewportPositionProperty);
}
public MapBase ParentMap
{
get { return parentMap; }
set { SetParentMap(value); }
set
{
if (parentMap != null && parentMap != this)
{
parentMap.ViewportChanged -= OnViewportChanged;
}
parentMap = value;
if (parentMap != null && parentMap != this)
{
parentMap.ViewportChanged += OnViewportChanged;
OnViewportChanged(new ViewportChangedEventArgs());
}
}
}
protected override Size MeasureOverride(Size availableSize)
{
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
foreach (UIElement element in Children)
foreach (var element in Children.OfType<FrameworkElement>())
{
element.Measure(availableSize);
}
@ -86,62 +104,34 @@ namespace MapControl
protected override Size ArrangeOverride(Size finalSize)
{
foreach (UIElement element in Children)
foreach (var element in Children.OfType<FrameworkElement>())
{
BoundingBox boundingBox;
Location location;
BoundingBox boundingBox;
Point? viewportPosition = null;
if ((boundingBox = GetBoundingBox(element)) != null)
if ((location = GetLocation(element)) != null)
{
ArrangeElementWithBoundingBox(element);
SetBoundingBoxRect(element, parentMap, boundingBox);
viewportPosition = ArrangeElementWithLocation(element, parentMap, location);
}
else if ((location = GetLocation(element)) != null)
else if ((boundingBox = GetBoundingBox(element)) != null)
{
ArrangeElementWithLocation(element);
SetViewportPosition(element, parentMap, location);
ArrangeElementWithBoundingBox(element, parentMap, boundingBox);
}
else
{
ArrangeElement(element, finalSize);
}
SetViewportPosition(element, viewportPosition);
}
return finalSize;
}
protected virtual void SetParentMap(MapBase map)
{
if (parentMap != null && parentMap != this)
{
parentMap.ViewportChanged -= OnViewportChanged;
}
parentMap = map;
if (parentMap != null && parentMap != this)
{
parentMap.ViewportChanged += OnViewportChanged;
OnViewportChanged(new ViewportChangedEventArgs());
}
}
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
foreach (UIElement element in Children)
{
BoundingBox boundingBox;
Location location;
if ((boundingBox = GetBoundingBox(element)) != null)
{
SetBoundingBoxRect(element, parentMap, boundingBox);
}
else if ((location = GetLocation(element)) != null)
{
SetViewportPosition(element, parentMap, location);
}
}
InvalidateArrange();
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
@ -161,245 +151,201 @@ namespace MapControl
private static void LocationPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var element = (UIElement)obj;
var map = GetParentMap(element);
var element = (FrameworkElement)obj;
var parentMap = GetParentMap(element);
var location = (Location)e.NewValue;
Point? viewportPosition = null;
if (location == null)
if (location != null)
{
ArrangeElement(element, map?.RenderSize ?? new Size());
viewportPosition = ArrangeElementWithLocation(element, parentMap, location);
}
else if (e.OldValue == null)
else
{
ArrangeElementWithLocation(element); // arrange once when Location was null before
ArrangeElement(element, parentMap?.RenderSize ?? new Size());
}
SetViewportPosition(element, map, location);
SetViewportPosition(element, viewportPosition);
}
private static void BoundingBoxPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var element = (FrameworkElement)obj;
var map = GetParentMap(element);
var parentMap = GetParentMap(element);
var boundingBox = (BoundingBox)e.NewValue;
if (boundingBox == null)
if (boundingBox != null)
{
ArrangeElement(element, map?.RenderSize ?? new Size());
ArrangeElementWithBoundingBox(element, parentMap, boundingBox);
}
else if (e.OldValue == null)
else
{
ArrangeElementWithBoundingBox(element); // arrange once when BoundingBox was null before
ArrangeElement(element, parentMap?.RenderSize ?? new Size());
}
SetBoundingBoxRect(element, map, boundingBox);
SetViewportPosition(element, null);
}
private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location)
private static void ArrangeElement(FrameworkElement element, Size parentSize)
{
var viewportPosition = new Point();
var rect = new Rect(new Point(), element.DesiredSize);
if (parentMap != null && location != null)
switch (element.HorizontalAlignment)
{
viewportPosition = parentMap.MapProjection.LocationToViewportPoint(location);
case HorizontalAlignment.Center:
rect.X = (parentSize.Width - rect.Width) / 2d;
break;
case HorizontalAlignment.Right:
rect.X = parentSize.Width - rect.Width;
break;
case HorizontalAlignment.Stretch:
rect.Width = parentSize.Width;
break;
default:
break;
}
switch (element.VerticalAlignment)
{
case VerticalAlignment.Center:
rect.Y = (parentSize.Height - rect.Height) / 2d;
break;
case VerticalAlignment.Bottom:
rect.Y = parentSize.Height - rect.Height;
break;
case VerticalAlignment.Stretch:
rect.Height = parentSize.Height;
break;
default:
break;
}
if (element.UseLayoutRounding)
{
rect.X = Math.Round(rect.X);
rect.Y = Math.Round(rect.Y);
}
element.Arrange(rect);
}
private static Point ArrangeElementWithLocation(FrameworkElement element, MapBase parentMap, Location location)
{
var pos = new Point();
var rect = new Rect(pos, element.DesiredSize);
if (parentMap != null)
{
pos = parentMap.MapProjection.LocationToViewportPoint(location);
if (parentMap.MapProjection.IsContinuous &&
(viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height))
(pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
{
viewportPosition = parentMap.MapProjection.LocationToViewportPoint(new Location(
pos = parentMap.MapProjection.LocationToViewportPoint(new Location(
location.Latitude,
Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude)));
}
if ((bool)element.GetValue(UseLayoutRoundingProperty))
{
viewportPosition.X = Math.Round(viewportPosition.X);
viewportPosition.Y = Math.Round(viewportPosition.Y);
}
rect.X = pos.X;
rect.Y = pos.Y;
}
var translateTransform = element.RenderTransform as TranslateTransform;
if (translateTransform == null)
switch (element.HorizontalAlignment)
{
var transformGroup = element.RenderTransform as TransformGroup;
case HorizontalAlignment.Center:
rect.X -= rect.Width / 2d;
break;
if (transformGroup == null)
{
translateTransform = new TranslateTransform();
element.RenderTransform = translateTransform;
}
else
{
if (transformGroup.Children.Count > 0)
{
translateTransform = transformGroup.Children[transformGroup.Children.Count - 1] as TranslateTransform;
}
case HorizontalAlignment.Right:
rect.X -= rect.Width;
break;
if (translateTransform == null)
{
translateTransform = new TranslateTransform();
transformGroup.Children.Add(translateTransform);
}
}
default:
break;
}
translateTransform.X = viewportPosition.X;
translateTransform.Y = viewportPosition.Y;
switch (element.VerticalAlignment)
{
case VerticalAlignment.Center:
rect.Y -= rect.Height / 2d;
break;
case VerticalAlignment.Bottom:
rect.Y -= rect.Height;
break;
default:
break;
}
if (element.UseLayoutRounding)
{
rect.X = Math.Round(rect.X);
rect.Y = Math.Round(rect.Y);
}
element.Arrange(rect);
return pos;
}
private static void SetBoundingBoxRect(UIElement element, MapBase parentMap, BoundingBox boundingBox)
private static void ArrangeElementWithBoundingBox(FrameworkElement element, MapBase parentMap, BoundingBox boundingBox)
{
var rect = new Rect();
var rotation = 0d;
var viewportPosition = new Point();
if (parentMap != null && boundingBox != null)
if (parentMap != null)
{
var projection = parentMap.MapProjection;
var rect = projection.BoundingBoxToRect(boundingBox);
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
rect = projection.BoundingBoxToRect(boundingBox);
rotation = parentMap.Heading;
viewportPosition = projection.ViewportTransform.Transform(center);
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var pos = projection.ViewportTransform.Transform(center);
if (parentMap.MapProjection.IsContinuous &&
(viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height))
(pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
{
var location = projection.PointToLocation(center);
location.Longitude = Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude);
viewportPosition = projection.LocationToViewportPoint(location);
pos = projection.LocationToViewportPoint(location);
}
var width = rect.Width * projection.ViewportScale;
var height = rect.Height * projection.ViewportScale;
rect.Width *= projection.ViewportScale;
rect.Height *= projection.ViewportScale;
rect.X = pos.X - rect.Width / 2d;
rect.Y = pos.Y - rect.Height / 2d;
if (element is FrameworkElement)
if (element.UseLayoutRounding)
{
((FrameworkElement)element).Width = width;
((FrameworkElement)element).Height = height;
}
else
{
element.Arrange(new Rect(-width / 2d, -height / 2d, width, height)); // ???
rect.X = Math.Round(rect.X);
rect.Y = Math.Round(rect.Y);
}
rotation = parentMap.Heading;
}
var transformGroup = element.RenderTransform as TransformGroup;
RotateTransform rotateTransform;
TranslateTransform translateTransform;
element.Width = rect.Width;
element.Height = rect.Height;
element.Arrange(rect);
if (transformGroup == null ||
transformGroup.Children.Count != 2 ||
(rotateTransform = transformGroup.Children[0] as RotateTransform) == null ||
(translateTransform = transformGroup.Children[1] as TranslateTransform) == null)
var rotateTransform = element.RenderTransform as RotateTransform;
if (rotateTransform == null)
{
transformGroup = new TransformGroup();
rotateTransform = new RotateTransform();
translateTransform = new TranslateTransform();
transformGroup.Children.Add(rotateTransform);
transformGroup.Children.Add(translateTransform);
element.RenderTransform = transformGroup;
element.RenderTransform = rotateTransform;
element.RenderTransformOrigin = new Point(0.5, 0.5);
}
rotateTransform.Angle = rotation;
translateTransform.X = viewportPosition.X;
translateTransform.Y = viewportPosition.Y;
}
private static void ArrangeElementWithBoundingBox(UIElement element)
{
var size = element.DesiredSize;
element.Arrange(new Rect(-size.Width / 2d, -size.Height / 2d, size.Width, size.Height));
}
private static void ArrangeElementWithLocation(UIElement element)
{
var rect = new Rect(new Point(), element.DesiredSize);
if (element is FrameworkElement)
{
switch (((FrameworkElement)element).HorizontalAlignment)
{
case HorizontalAlignment.Center:
rect.X = -rect.Width / 2d;
break;
case HorizontalAlignment.Right:
rect.X = -rect.Width;
break;
default:
break;
}
switch (((FrameworkElement)element).VerticalAlignment)
{
case VerticalAlignment.Center:
rect.Y = -rect.Height / 2d;
break;
case VerticalAlignment.Bottom:
rect.Y = -rect.Height;
break;
default:
break;
}
}
element.Arrange(rect);
}
private static void ArrangeElement(UIElement element, Size parentSize)
{
var rect = new Rect(new Point(), element.DesiredSize);
if (element is FrameworkElement)
{
switch (((FrameworkElement)element).HorizontalAlignment)
{
case HorizontalAlignment.Center:
rect.X = (parentSize.Width - rect.Width) / 2d;
break;
case HorizontalAlignment.Right:
rect.X = parentSize.Width - rect.Width;
break;
case HorizontalAlignment.Stretch:
rect.Width = parentSize.Width;
break;
default:
break;
}
switch (((FrameworkElement)element).VerticalAlignment)
{
case VerticalAlignment.Center:
rect.Y = (parentSize.Height - rect.Height) / 2d;
break;
case VerticalAlignment.Bottom:
rect.Y = parentSize.Height - rect.Height;
break;
case VerticalAlignment.Stretch:
rect.Height = parentSize.Height;
break;
default:
break;
}
}
element.Arrange(rect);
}
}
}

View file

@ -26,7 +26,7 @@ namespace MapControl
public class MapScale : MapOverlay
{
public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register(
nameof(Padding), typeof(Thickness), typeof(MapScale), null);
nameof(Padding), typeof(Thickness), typeof(MapScale), new PropertyMetadata(new Thickness(4)));
private TextBlock label = new TextBlock();
private Polyline line = new Polyline();
@ -34,11 +34,11 @@ namespace MapControl
public MapScale()
{
IsHitTestVisible = false;
#if WINDOWS_UWP
MinWidth = 100d;
Padding = new Thickness(4d);
HorizontalAlignment = HorizontalAlignment.Left;
VerticalAlignment = VerticalAlignment.Bottom;
#else
SetCurrentValue(MinWidthProperty, 100d);
#endif
label.HorizontalAlignment = HorizontalAlignment.Left;
label.VerticalAlignment = VerticalAlignment.Top;
label.TextAlignment = TextAlignment.Center;
@ -49,16 +49,12 @@ namespace MapControl
Path = new PropertyPath("Foreground")
});
line.SetBinding(Shape.StrokeProperty, new Binding
{
Source = this,
Path = new PropertyPath("Stroke")
});
line.SetBinding(Shape.StrokeThicknessProperty, new Binding
{
Source = this,

View file

@ -220,9 +220,9 @@ namespace MapControl
{
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
foreach (UIElement element in Children)
foreach (var tile in Tiles)
{
element.Measure(availableSize);
tile.Image.Measure(availableSize);
}
return new Size();

View file

@ -35,18 +35,7 @@ namespace MapControl
Data = new PathGeometry()
};
path.SetBinding(Shape.StrokeProperty, new Binding
{
Source = this,
Path = new PropertyPath("Stroke")
});
path.SetBinding(Shape.StrokeThicknessProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeThickness")
});
SetStrokeBindings(path);
Children.Add(path);
}

View file

@ -6,6 +6,7 @@ using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace MapControl
{
@ -56,18 +57,61 @@ namespace MapControl
public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyProperty.Register(
nameof(StrokeMiterLimit), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d));
protected override void SetParentMap(MapBase parentMap)
public void SetStrokeBindings(Shape shape)
{
if (parentMap != null && Foreground == null)
shape.SetBinding(Shape.StrokeProperty, new Binding
{
SetBinding(ForegroundProperty, new Binding
{
Source = parentMap,
Path = new PropertyPath("Foreground")
});
}
Source = this,
Path = new PropertyPath("Stroke")
});
base.SetParentMap(parentMap);
shape.SetBinding(Shape.StrokeThicknessProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeThickness")
});
shape.SetBinding(Shape.StrokeDashArrayProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeDashArray")
});
shape.SetBinding(Shape.StrokeDashOffsetProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeDashOffset")
});
shape.SetBinding(Shape.StrokeDashCapProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeDashCap")
});
shape.SetBinding(Shape.StrokeStartLineCapProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeStartLineCap")
});
shape.SetBinding(Shape.StrokeEndLineCapProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeEndLineCap")
});
shape.SetBinding(Shape.StrokeLineJoinProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeLineJoin")
});
shape.SetBinding(Shape.StrokeMiterLimitProperty, new Binding
{
Source = this,
Path = new PropertyPath("StrokeMiterLimit")
});
}
}
}

View file

@ -12,6 +12,9 @@ namespace MapControl
public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached(
"ParentMap", typeof(MapBase), typeof(MapPanel), new PropertyMetadata(null, ParentMapPropertyChanged));
private static readonly DependencyProperty ViewportPositionProperty = DependencyProperty.RegisterAttached(
"ViewportPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata(null));
public static void InitMapElement(FrameworkElement element)
{
if (element is MapBase)
@ -28,7 +31,7 @@ namespace MapControl
}
}
public static MapBase GetParentMap(UIElement element)
public static MapBase GetParentMap(FrameworkElement element)
{
var parentMap = (MapBase)element.GetValue(ParentMapProperty);
@ -40,14 +43,19 @@ namespace MapControl
return parentMap;
}
private static MapBase FindParentMap(UIElement element)
private static MapBase FindParentMap(FrameworkElement element)
{
var parent = VisualTreeHelper.GetParent(element) as UIElement;
var parent = VisualTreeHelper.GetParent(element) as FrameworkElement;
return parent == null ? null
: ((parent as MapBase)
?? (MapBase)element.GetValue(ParentMapProperty)
?? FindParentMap(parent));
}
private static void SetViewportPosition(FrameworkElement element, Point? viewportPosition)
{
element.SetValue(ViewportPositionProperty, viewportPosition);
}
}
}

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -66,17 +66,7 @@ namespace MapControl
var latLabels = new List<Label>((int)((boundingBox.North - latLabelStart) / lineDistance) + 1);
var lonLabels = new List<Label>((int)((boundingBox.East - lonLabelStart) / lineDistance) + 1);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
var pen = new Pen
{
Brush = Stroke,
Thickness = StrokeThickness,
LineJoin = StrokeLineJoin,
MiterLimit = StrokeMiterLimit,
StartLineCap = StrokeStartLineCap,
EndLineCap = StrokeEndLineCap,
DashCap = StrokeDashCap,
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset)
};
var pen = CreatePen();
for (var lat = latLabelStart; lat <= boundingBox.North; lat += lineDistance)
{

View file

@ -4,6 +4,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MapControl
@ -11,42 +12,52 @@ namespace MapControl
public partial class MapOverlay
{
public static readonly DependencyProperty FontSizeProperty = Control.FontSizeProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty FontFamilyProperty = Control.FontFamilyProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty FontStyleProperty = Control.FontStyleProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty FontStretchProperty = Control.FontStretchProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty FontWeightProperty = Control.FontWeightProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty ForegroundProperty = Control.ForegroundProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty StrokeProperty = Shape.StrokeProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeProperty = Shape.StrokeProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeThicknessProperty = Shape.StrokeThicknessProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeThicknessProperty = Shape.StrokeThicknessProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeDashArrayProperty = Shape.StrokeDashArrayProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeDashArrayProperty = Shape.StrokeDashArrayProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeDashOffsetProperty = Shape.StrokeDashOffsetProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeDashOffsetProperty = Shape.StrokeDashOffsetProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeDashCapProperty = Shape.StrokeDashCapProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeDashCapProperty = Shape.StrokeDashCapProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(PenLineCap.Flat, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeStartLineCapProperty = Shape.StrokeStartLineCapProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeStartLineCapProperty = Shape.StrokeStartLineCapProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(PenLineCap.Flat, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeEndLineCapProperty = Shape.StrokeEndLineCapProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeEndLineCapProperty = Shape.StrokeEndLineCapProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(PenLineCap.Flat, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeLineJoinProperty = Shape.StrokeLineJoinProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeLineJoinProperty = Shape.StrokeLineJoinProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(PenLineJoin.Miter, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StrokeMiterLimitProperty = Shape.StrokeMiterLimitProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeMiterLimitProperty = Shape.StrokeMiterLimitProperty.AddOwner(typeof(MapOverlay),
new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsRender));
public Pen CreatePen()
{
return new Pen
{
Brush = Stroke,
Thickness = StrokeThickness,
LineJoin = StrokeLineJoin,
MiterLimit = StrokeMiterLimit,
StartLineCap = StrokeStartLineCap,
EndLineCap = StrokeEndLineCap,
DashCap = StrokeDashCap,
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset)
};
}
}
}

View file

@ -12,9 +12,13 @@ namespace MapControl
"ParentMap", typeof(MapBase), typeof(MapPanel), new FrameworkPropertyMetadata(
null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
private static readonly DependencyPropertyKey ViewportPositionPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
"ViewportPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata());
public static MapBase GetParentMap(UIElement element)
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
public static readonly DependencyProperty ViewportPositionProperty = ViewportPositionPropertyKey.DependencyProperty;
public static MapBase GetParentMap(FrameworkElement element)
{
return (MapBase)element.GetValue(ParentMapProperty);
}
@ -26,5 +30,10 @@ namespace MapControl
element.SetValue(ParentMapPropertyKey, element);
}
}
private static void SetViewportPosition(FrameworkElement element, Point? viewportPosition)
{
element.SetValue(ViewportPositionPropertyKey, viewportPosition);
}
}
}

View file

@ -14,7 +14,7 @@ namespace MapControl
{
public abstract partial class MapShape : Shape, IWeakEventListener
{
protected Geometry Data { get; }
public Geometry Data { get; }
protected override Geometry DefiningGeometry
{

View file

@ -8,8 +8,8 @@ using System.Windows;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

View file

@ -115,7 +115,7 @@
</Image>
<map:MapGraticule x:Name="mapGraticule" Opacity="0.6"/>
<map:MapScale/>
<map:MapScale HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
<!-- use ItemTemplate or ItemContainerStyle alternatively -->
<map:MapItemsControl ItemsSource="{Binding Polylines}"

View file

@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("4.7.0")]
[assembly: AssemblyFileVersion("4.7.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: ComVisible(false)]

View file

@ -2,7 +2,6 @@
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using MapControl;
namespace WpfApplication
@ -13,13 +12,14 @@ namespace WpfApplication
{
var visibility = Visibility.Hidden;
if (values.Length == 2 && values[0] is Map && values[1] is Transform)
if (values.Length == 2 && values[0] is MapBase && values[1] is Point?)
{
var parentMap = (Map)values[0];
var transform = ((Transform)values[1]).Value;
var parentMap = (MapBase)values[0];
var position = (Point?)values[1];
if (transform.OffsetX >= 0d && transform.OffsetX <= parentMap.ActualWidth &&
transform.OffsetY >= 0d && transform.OffsetY <= parentMap.ActualHeight)
if (position.HasValue &&
position.Value.X >= 0d && position.Value.X <= parentMap.ActualWidth &&
position.Value.Y >= 0d && position.Value.Y <= parentMap.ActualHeight)
{
visibility = Visibility.Visible;
}

View file

@ -88,7 +88,7 @@
<Setter.Value>
<MultiBinding Converter="{StaticResource LocationToVisibilityConverter}">
<Binding Path="(map:MapPanel.ParentMap)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="RenderTransform" RelativeSource="{RelativeSource Self}"/>
<Binding Path="(map:MapPanel.ViewportPosition)" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Setter.Value>
</Setter>
@ -139,7 +139,7 @@
map:MapPanel.BoundingBox="53.54031,8.08594,53.74871,8.43750"/>
<map:MapGraticule x:Name="mapGraticule" Opacity="0.6"/>
<map:MapScale/>
<map:MapScale HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
<!-- use ItemTemplate or ItemContainerStyle alternatively -->
<map:MapItemsControl ItemsSource="{Binding Polylines}"
@ -171,7 +171,7 @@
<map:Pushpin.Visibility>
<MultiBinding Converter="{StaticResource LocationToVisibilityConverter}">
<Binding Path="(map:MapPanel.ParentMap)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="RenderTransform" RelativeSource="{RelativeSource Self}"/>
<Binding Path="(map:MapPanel.ViewportPosition)" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</map:Pushpin.Visibility>
</map:Pushpin>

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.7.0")]
[assembly: AssemblyFileVersion("4.7.0")]
[assembly: AssemblyVersion("4.9.0")]
[assembly: AssemblyFileVersion("4.9.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]