mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Version 5.0: Reworked MapBase and MapPath
This commit is contained in:
parent
06fd31c17b
commit
49e15ce424
41 changed files with 466 additions and 1068 deletions
|
|
@ -39,6 +39,9 @@ namespace MapControl
|
|||
nameof(TargetHeading), typeof(double), typeof(MapBase),
|
||||
new PropertyMetadata(0d, (o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue)));
|
||||
|
||||
public static readonly DependencyProperty ViewScaleProperty = DependencyProperty.Register(
|
||||
nameof(ViewScale), typeof(double), typeof(MapBase), new PropertyMetadata(0d));
|
||||
|
||||
internal static readonly DependencyProperty CenterPointProperty = DependencyProperty.Register(
|
||||
"CenterPoint", typeof(Windows.Foundation.Point), typeof(MapBase),
|
||||
new PropertyMetadata(new Windows.Foundation.Point(), (o, e) => ((MapBase)o).CenterPointPropertyChanged((Windows.Foundation.Point)e.NewValue)));
|
||||
|
|
@ -62,6 +65,11 @@ namespace MapControl
|
|||
};
|
||||
}
|
||||
|
||||
private void SetViewScale(double scale)
|
||||
{
|
||||
SetValue(ViewScaleProperty, scale);
|
||||
}
|
||||
|
||||
private void CenterPointPropertyChanged(Windows.Foundation.Point center)
|
||||
{
|
||||
CenterPointPropertyChanged(new Location(center.Y, center.X));
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@
|
|||
<Compile Include="..\Shared\MapPanel.cs">
|
||||
<Link>MapPanel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapPath.cs">
|
||||
<Link>MapPath.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapPolygon.cs">
|
||||
<Link>MapPolygon.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -119,9 +122,6 @@
|
|||
<Compile Include="..\Shared\MapScale.cs">
|
||||
<Link>MapScale.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapShape.cs">
|
||||
<Link>MapShape.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapTileLayer.cs">
|
||||
<Link>MapTileLayer.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -188,7 +188,7 @@
|
|||
<Compile Include="MapItemsControl.UWP.cs" />
|
||||
<Compile Include="MapOverlay.UWP.cs" />
|
||||
<Compile Include="MapPanel.UWP.cs" />
|
||||
<Compile Include="MapShape.UWP.cs" />
|
||||
<Compile Include="MapPath.UWP.cs" />
|
||||
<Compile Include="Matrix.UWP.cs" />
|
||||
<Compile Include="Point.UWP.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@
|
|||
|
||||
using System;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
using Windows.UI.Xaml.Data;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
@ -40,7 +38,7 @@ namespace MapControl
|
|||
Children.Add(path);
|
||||
}
|
||||
|
||||
var bounds = map.ViewportRectToBoundingBox(new Rect(0d, 0d, map.RenderSize.Width, map.RenderSize.Height));
|
||||
var bounds = map.ViewRectToBoundingBox(new Rect(0d, 0d, map.RenderSize.Width, map.RenderSize.Height));
|
||||
var lineDistance = GetLineDistance();
|
||||
|
||||
var labelStart = new Location(
|
||||
|
|
@ -66,14 +64,14 @@ namespace MapControl
|
|||
{
|
||||
var figure = new PathFigure
|
||||
{
|
||||
StartPoint = map.LocationToViewportPoint(new Location(lat, lineStart.Longitude)),
|
||||
StartPoint = map.LocationToView(new Location(lat, lineStart.Longitude)),
|
||||
IsClosed = false,
|
||||
IsFilled = false
|
||||
};
|
||||
|
||||
figure.Segments.Add(new LineSegment
|
||||
{
|
||||
Point = map.LocationToViewportPoint(new Location(lat, lineEnd.Longitude))
|
||||
Point = map.LocationToView(new Location(lat, lineEnd.Longitude))
|
||||
});
|
||||
|
||||
geometry.Figures.Add(figure);
|
||||
|
|
@ -83,14 +81,14 @@ namespace MapControl
|
|||
{
|
||||
var figure = new PathFigure
|
||||
{
|
||||
StartPoint = map.LocationToViewportPoint(new Location(lineStart.Latitude, lon)),
|
||||
StartPoint = map.LocationToView(new Location(lineStart.Latitude, lon)),
|
||||
IsClosed = false,
|
||||
IsFilled = false
|
||||
};
|
||||
|
||||
figure.Segments.Add(new LineSegment
|
||||
{
|
||||
Point = map.LocationToViewportPoint(new Location(lineEnd.Latitude, lon))
|
||||
Point = map.LocationToView(new Location(lineEnd.Latitude, lon))
|
||||
});
|
||||
|
||||
geometry.Figures.Add(figure);
|
||||
|
|
@ -111,22 +109,18 @@ namespace MapControl
|
|||
}
|
||||
else
|
||||
{
|
||||
var renderTransform = new TransformGroup();
|
||||
renderTransform.Children.Add(new TranslateTransform());
|
||||
renderTransform.Children.Add(map.RotateTransform);
|
||||
renderTransform.Children.Add(new TranslateTransform());
|
||||
|
||||
label = new TextBlock { RenderTransform = renderTransform };
|
||||
if (FontFamily != null)
|
||||
{
|
||||
label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(FontFamilyProperty, nameof(FontFamily)));
|
||||
}
|
||||
label = new TextBlock { RenderTransform = new MatrixTransform() };
|
||||
label.SetBinding(TextBlock.FontSizeProperty, GetBinding(FontSizeProperty, nameof(FontSize)));
|
||||
label.SetBinding(TextBlock.FontStyleProperty, GetBinding(FontStyleProperty, nameof(FontStyle)));
|
||||
label.SetBinding(TextBlock.FontStretchProperty, GetBinding(FontStretchProperty, nameof(FontStretch)));
|
||||
label.SetBinding(TextBlock.FontWeightProperty, GetBinding(FontWeightProperty, nameof(FontWeight)));
|
||||
label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
|
||||
|
||||
if (FontFamily != null)
|
||||
{
|
||||
label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(FontFamilyProperty, nameof(FontFamily)));
|
||||
}
|
||||
|
||||
Children.Add(label);
|
||||
}
|
||||
|
||||
|
|
@ -135,10 +129,6 @@ namespace MapControl
|
|||
label.Text = GetLabelText(lat, labelFormat, "NS") + "\n" + GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW");
|
||||
label.Tag = new Location(lat, lon);
|
||||
label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
|
||||
var translateTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[0];
|
||||
translateTransform.X = StrokeThickness / 2d + 2d;
|
||||
translateTransform.Y = -label.DesiredSize.Height / 2d;
|
||||
}
|
||||
|
||||
while (Children.Count > childIndex)
|
||||
|
|
@ -153,10 +143,14 @@ namespace MapControl
|
|||
{
|
||||
var label = (TextBlock)Children[i];
|
||||
var location = (Location)label.Tag;
|
||||
var viewportTransform = (TranslateTransform)((TransformGroup)label.RenderTransform).Children[2];
|
||||
var viewportPosition = map.LocationToViewportPoint(location);
|
||||
viewportTransform.X = viewportPosition.X;
|
||||
viewportTransform.Y = viewportPosition.Y;
|
||||
var viewPosition = map.LocationToView(location);
|
||||
var matrix = new Matrix(1, 0, 0, 1, 0, 0);
|
||||
|
||||
matrix.Translate(StrokeThickness / 2d + 2d, -label.DesiredSize.Height / 2d);
|
||||
matrix.Rotate(map.ViewTransform.Rotation);
|
||||
matrix.Translate(viewPosition.X, viewPosition.Y);
|
||||
|
||||
((MatrixTransform)label.RenderTransform).Matrix = matrix;
|
||||
}
|
||||
}
|
||||
else if (path != null)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ 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));
|
||||
private static readonly DependencyProperty ViewPositionProperty = DependencyProperty.RegisterAttached(
|
||||
"ViewPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata(null));
|
||||
|
||||
public static void InitMapElement(FrameworkElement element)
|
||||
{
|
||||
|
|
@ -61,9 +61,9 @@ namespace MapControl
|
|||
?? FindParentMap(parent));
|
||||
}
|
||||
|
||||
private static void SetViewportPosition(FrameworkElement element, Point? viewportPosition)
|
||||
private static void SetViewPosition(FrameworkElement element, Point? viewPosition)
|
||||
{
|
||||
element.SetValue(ViewportPositionProperty, viewportPosition);
|
||||
element.SetValue(ViewPositionProperty, viewPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using Windows.UI.Xaml.Shapes;
|
|||
|
||||
namespace MapControl
|
||||
{
|
||||
public abstract partial class MapShape : Path
|
||||
public partial class MapPath : Path
|
||||
{
|
||||
protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
|
|
@ -40,13 +40,7 @@ namespace MapControl
|
|||
{
|
||||
if (locations != null && locations.Count() >= 2)
|
||||
{
|
||||
var offset = GetLongitudeOffset();
|
||||
if (offset != 0d)
|
||||
{
|
||||
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
|
||||
}
|
||||
|
||||
var points = locations.Select(loc => LocationToViewportPoint(loc)).ToList();
|
||||
var points = locations.Select(loc => LocationToView(loc)).ToList();
|
||||
if (closed)
|
||||
{
|
||||
points.Add(points[0]);
|
||||
|
|
@ -50,6 +50,16 @@ namespace MapControl
|
|||
return new Vector(v1.X - v2.X, v1.Y - v2.Y);
|
||||
}
|
||||
|
||||
public static Vector operator *(double f, Vector v)
|
||||
{
|
||||
return new Vector(f * v.X, f * v.Y);
|
||||
}
|
||||
|
||||
public static Vector operator *(Vector v, double f)
|
||||
{
|
||||
return new Vector(f * v.X, f * v.Y);
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector v1, Vector v2)
|
||||
{
|
||||
return v1.X == v2.X && v1.Y == v2.Y;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue