mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 4.1.0
This commit is contained in:
parent
0be26af38c
commit
ef6d1ed959
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
141
MapControl/Shared/MapScale.cs
Normal file
141
MapControl/Shared/MapScale.cs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a map scale overlay.
|
||||
/// </summary>
|
||||
public class MapScale : MapOverlay
|
||||
{
|
||||
public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register(
|
||||
nameof(Padding), typeof(Thickness), typeof(MapScale), null);
|
||||
|
||||
private TextBlock label = new TextBlock();
|
||||
private Polyline line = new Polyline();
|
||||
|
||||
public MapScale()
|
||||
{
|
||||
IsHitTestVisible = false;
|
||||
MinWidth = 100d;
|
||||
Padding = new Thickness(4d);
|
||||
HorizontalAlignment = HorizontalAlignment.Left;
|
||||
VerticalAlignment = VerticalAlignment.Bottom;
|
||||
|
||||
label.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
label.VerticalAlignment = VerticalAlignment.Top;
|
||||
label.TextAlignment = TextAlignment.Center;
|
||||
|
||||
label.SetBinding(TextBlock.ForegroundProperty,
|
||||
GetBindingExpression(ForegroundProperty)?.ParentBinding ??
|
||||
new Binding
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("Foreground")
|
||||
});
|
||||
|
||||
line.SetBinding(Shape.StrokeProperty,
|
||||
GetBindingExpression(StrokeProperty)?.ParentBinding ??
|
||||
new Binding
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("Stroke")
|
||||
});
|
||||
|
||||
line.SetBinding(Shape.StrokeThicknessProperty,
|
||||
GetBindingExpression(StrokeThicknessProperty)?.ParentBinding ??
|
||||
new Binding
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("StrokeThickness")
|
||||
});
|
||||
|
||||
Children.Add(line);
|
||||
Children.Add(label);
|
||||
}
|
||||
|
||||
public Thickness Padding
|
||||
{
|
||||
get { return (Thickness)GetValue(PaddingProperty); }
|
||||
set { SetValue(PaddingProperty, value); }
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
var size = new Size();
|
||||
|
||||
if (ParentMap != null && ParentMap.ScaleTransform.ScaleX > 0d)
|
||||
{
|
||||
var length = MinWidth / ParentMap.ScaleTransform.ScaleX;
|
||||
var magnitude = Math.Pow(10d, Math.Floor(Math.Log10(length)));
|
||||
|
||||
if (length / magnitude < 2d)
|
||||
{
|
||||
length = 2d * magnitude;
|
||||
}
|
||||
else if (length / magnitude < 5d)
|
||||
{
|
||||
length = 5d * magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 10d * magnitude;
|
||||
}
|
||||
|
||||
size.Width = length * ParentMap.ScaleTransform.ScaleX + StrokeThickness + Padding.Left + Padding.Right;
|
||||
size.Height = 1.25 * FontSize + StrokeThickness + Padding.Top + Padding.Bottom;
|
||||
|
||||
var x1 = Padding.Left + StrokeThickness / 2d;
|
||||
var x2 = size.Width - Padding.Right - StrokeThickness / 2d;
|
||||
var y1 = size.Height / 2d;
|
||||
var y2 = size.Height - Padding.Bottom - StrokeThickness / 2d;
|
||||
var points = new PointCollection();
|
||||
points.Add(new Point(x1, y1));
|
||||
points.Add(new Point(x1, y2));
|
||||
points.Add(new Point(x2, y2));
|
||||
points.Add(new Point(x2, y1));
|
||||
|
||||
line.Points = points;
|
||||
line.Measure(size);
|
||||
|
||||
if (FontFamily != null)
|
||||
{
|
||||
label.FontFamily = FontFamily;
|
||||
}
|
||||
|
||||
label.FontSize = FontSize;
|
||||
label.FontStyle = FontStyle;
|
||||
label.FontStretch = FontStretch;
|
||||
label.FontWeight = FontWeight;
|
||||
label.Text = length >= 1000d ? string.Format("{0:0} km", length / 1000d) : string.Format("{0:0} m", length);
|
||||
label.Width = size.Width;
|
||||
label.Height = size.Height;
|
||||
label.Measure(size);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
protected override void OnViewportChanged(ViewportChangedEventArgs e)
|
||||
{
|
||||
InvalidateMeasure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -103,6 +103,9 @@
|
|||
<Compile Include="..\Shared\MapProjection.cs">
|
||||
<Link>MapProjection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapScale.cs">
|
||||
<Link>MapScale.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapTileLayer.cs">
|
||||
<Link>MapTileLayer.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace MapControl
|
|||
public partial class MapOverlay
|
||||
{
|
||||
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(
|
||||
nameof(FontSize), typeof(double), typeof(MapOverlay), new PropertyMetadata(10d));
|
||||
nameof(FontSize), typeof(double), typeof(MapOverlay), new PropertyMetadata(12d));
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
|
||||
nameof(FontFamily), typeof(FontFamily), typeof(MapOverlay), new PropertyMetadata(null));
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@
|
|||
<Compile Include="..\Shared\MapProjection.cs">
|
||||
<Link>MapProjection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapScale.cs">
|
||||
<Link>MapScale.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapTileLayer.cs">
|
||||
<Link>MapTileLayer.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -155,7 +158,6 @@
|
|||
<Compile Include="MapPanel.WPF.cs" />
|
||||
<Compile Include="MapPath.WPF.cs" />
|
||||
<Compile Include="MapPolyline.WPF.cs" />
|
||||
<Compile Include="MapScale.WPF.cs" />
|
||||
<Compile Include="MapTileLayer.WPF.cs" />
|
||||
<Compile Include="Pushpin.WPF.cs" />
|
||||
<Compile Include="TileImageLoader.WPF.cs" />
|
||||
|
|
|
|||
|
|
@ -48,8 +48,14 @@ namespace MapControl
|
|||
var lonLabelStart = Math.Ceiling(bounds.West / lineDistance) * lineDistance;
|
||||
var latLabels = new List<Label>((int)((bounds.North - latLabelStart) / lineDistance) + 1);
|
||||
var lonLabels = new List<Label>((int)((bounds.East - lonLabelStart) / lineDistance) + 1);
|
||||
var typeface = CreateTypeface();
|
||||
var pen = CreatePen();
|
||||
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
|
||||
var pen = new Pen
|
||||
{
|
||||
Brush = Stroke,
|
||||
Thickness = StrokeThickness,
|
||||
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset),
|
||||
DashCap = StrokeDashCap
|
||||
};
|
||||
|
||||
for (var lat = latLabelStart; lat <= bounds.North; lat += lineDistance)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
|
|
@ -50,24 +51,23 @@ namespace MapControl
|
|||
public static readonly DependencyProperty StrokeMiterLimitProperty = Shape.StrokeMiterLimitProperty.AddOwner(
|
||||
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
|
||||
|
||||
protected Typeface CreateTypeface()
|
||||
protected override void SetParentMapOverride(MapBase parentMap)
|
||||
{
|
||||
return new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
|
||||
if (GetBindingExpression(StrokeProperty) != null)
|
||||
{
|
||||
ClearValue(StrokeProperty);
|
||||
}
|
||||
|
||||
protected Pen CreatePen()
|
||||
if (parentMap != null && Stroke == null)
|
||||
{
|
||||
return new Pen
|
||||
SetBinding(StrokeProperty, new Binding
|
||||
{
|
||||
Brush = Stroke ?? Foreground,
|
||||
Thickness = StrokeThickness,
|
||||
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset),
|
||||
DashCap = StrokeDashCap,
|
||||
StartLineCap = StrokeStartLineCap,
|
||||
EndLineCap = StrokeEndLineCap,
|
||||
LineJoin = StrokeLineJoin,
|
||||
MiterLimit = StrokeMiterLimit
|
||||
};
|
||||
Source = parentMap,
|
||||
Path = new PropertyPath("Foreground")
|
||||
});
|
||||
}
|
||||
|
||||
base.SetParentMapOverride(parentMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,96 +0,0 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a map scale overlay.
|
||||
/// </summary>
|
||||
public class MapScale : MapOverlay
|
||||
{
|
||||
public static readonly DependencyProperty PaddingProperty = Control.PaddingProperty.AddOwner(typeof(MapScale));
|
||||
|
||||
private double length;
|
||||
private Size size;
|
||||
|
||||
static MapScale()
|
||||
{
|
||||
IsHitTestVisibleProperty.OverrideMetadata(typeof(MapScale), new FrameworkPropertyMetadata(false));
|
||||
MinWidthProperty.OverrideMetadata(typeof(MapScale), new FrameworkPropertyMetadata(100d));
|
||||
HorizontalAlignmentProperty.OverrideMetadata(typeof(MapScale), new FrameworkPropertyMetadata(HorizontalAlignment.Right));
|
||||
VerticalAlignmentProperty.OverrideMetadata(typeof(MapScale), new FrameworkPropertyMetadata(VerticalAlignment.Bottom));
|
||||
StrokeStartLineCapProperty.OverrideMetadata(typeof(MapScale), new FrameworkPropertyMetadata(PenLineCap.Round));
|
||||
StrokeEndLineCapProperty.OverrideMetadata(typeof(MapScale), new FrameworkPropertyMetadata(PenLineCap.Round));
|
||||
}
|
||||
|
||||
public Thickness Padding
|
||||
{
|
||||
get { return (Thickness)GetValue(PaddingProperty); }
|
||||
set { SetValue(PaddingProperty, value); }
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
if (ParentMap != null && ParentMap.ScaleTransform.ScaleX > 0d)
|
||||
{
|
||||
length = MinWidth / ParentMap.ScaleTransform.ScaleX;
|
||||
var magnitude = Math.Pow(10d, Math.Floor(Math.Log10(length)));
|
||||
|
||||
if (length / magnitude < 2d)
|
||||
{
|
||||
length = 2d * magnitude;
|
||||
}
|
||||
else if (length / magnitude < 5d)
|
||||
{
|
||||
length = 5d * magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 10d * magnitude;
|
||||
}
|
||||
|
||||
size.Width = length * ParentMap.ScaleTransform.ScaleX + StrokeThickness + Padding.Left + Padding.Right;
|
||||
size.Height = FontSize * FontFamily.LineSpacing + StrokeThickness + Padding.Top + Padding.Bottom;
|
||||
}
|
||||
else
|
||||
{
|
||||
size.Width = size.Height = 0d;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext)
|
||||
{
|
||||
if (ParentMap != null)
|
||||
{
|
||||
var x1 = Padding.Left + StrokeThickness / 2d;
|
||||
var x2 = size.Width - Padding.Right - StrokeThickness / 2d;
|
||||
var y1 = size.Height / 2d;
|
||||
var y2 = size.Height - Padding.Bottom - StrokeThickness / 2d;
|
||||
var text = new FormattedText(
|
||||
length >= 1000d ? string.Format("{0:0} km", length / 1000d) : string.Format("{0:0} m", length),
|
||||
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, CreateTypeface(), FontSize, Foreground);
|
||||
var pen = CreatePen();
|
||||
|
||||
drawingContext.DrawRectangle(Background ?? ParentMap.Background, null, new Rect(size));
|
||||
drawingContext.DrawLine(pen, new Point(x1, y1), new Point(x1, y2));
|
||||
drawingContext.DrawLine(pen, new Point(x2, y1), new Point(x2, y2));
|
||||
drawingContext.DrawLine(pen, new Point(x1, y2), new Point(x2, y2));
|
||||
drawingContext.DrawText(text, new Point((size.Width - text.Width) / 2d, 0d));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnViewportChanged(ViewportChangedEventArgs e)
|
||||
{
|
||||
InvalidateMeasure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,8 +8,8 @@ using System.Windows;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@
|
|||
</Image>
|
||||
|
||||
<map:MapGraticule x:Name="mapGraticule" Opacity="0.6"/>
|
||||
<map:MapScale/>
|
||||
|
||||
<!-- use ItemTemplate or ItemContainerStyle alternatively -->
|
||||
<map:MapItemsControl ItemsSource="{Binding Polylines}"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@
|
|||
map:MapPanel.BoundingBox="53.54031,8.08594,53.74871,8.43750"/>
|
||||
|
||||
<map:MapGraticule x:Name="mapGraticule" Opacity="0.6"/>
|
||||
<map:MapScale Margin="4" Opacity="0.8" HorizontalAlignment="Left" Background="Transparent"/>
|
||||
<map:MapScale/>
|
||||
|
||||
<!-- use ItemTemplate or ItemContainerStyle alternatively -->
|
||||
<map:MapItemsControl ItemsSource="{Binding Polylines}"
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.0.1")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue