mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 22:18:56 +00:00
Version 4.4.1: MapPolygon for UWP in progress
This commit is contained in:
parent
66a97b3fa2
commit
54c924f9e7
15 changed files with 497 additions and 125 deletions
|
|
@ -67,12 +67,18 @@
|
|||
<Compile Include="..\Shared\HyperlinkText.cs">
|
||||
<Link>HyperlinkText.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\Intersections.cs">
|
||||
<Link>Intersections.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\Location.cs">
|
||||
<Link>Location.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\LocationCollection.cs">
|
||||
<Link>LocationCollection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\LocationEx.cs">
|
||||
<Link>LocationEx.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapBase.cs">
|
||||
<Link>MapBase.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -144,6 +150,7 @@
|
|||
<Compile Include="MapGraticule.UWP.cs" />
|
||||
<Compile Include="MapOverlay.UWP.cs" />
|
||||
<Compile Include="MapPanel.UWP.cs" />
|
||||
<Compile Include="MapPolygon.UWP.cs" />
|
||||
<Compile Include="MapPolyline.UWP.cs" />
|
||||
<Compile Include="MapShape.UWP.cs" />
|
||||
<Compile Include="MatrixEx.UWP.cs" />
|
||||
|
|
|
|||
55
MapControl/UWP/MapPolygon.UWP.cs
Normal file
55
MapControl/UWP/MapPolygon.UWP.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// A polygon defined by a collection of Locations.
|
||||
/// </summary>
|
||||
public class MapPolygon : MapShape
|
||||
{
|
||||
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
||||
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon),
|
||||
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).LocationsPropertyChanged(e)));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Locations that define the polyline points.
|
||||
/// </summary>
|
||||
public IEnumerable<Location> Locations
|
||||
{
|
||||
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
||||
set { SetValue(LocationsProperty, value); }
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
var figures = ((PathGeometry)Data).Figures;
|
||||
figures.Clear();
|
||||
|
||||
if (ParentMap != null && Locations != null)
|
||||
{
|
||||
var locations = Locations;
|
||||
var offset = GetLongitudeOffset();
|
||||
|
||||
if (offset != 0d)
|
||||
{
|
||||
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
|
||||
}
|
||||
|
||||
var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc)).ToList();
|
||||
|
||||
if (points.Count >= 2)
|
||||
{
|
||||
points.Add(points[0]);
|
||||
CreatePolylineFigures(points);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
@ -30,72 +29,25 @@ namespace MapControl
|
|||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
var geometry = (PathGeometry)Data;
|
||||
geometry.Figures.Clear();
|
||||
((PathGeometry)Data).Figures.Clear();
|
||||
|
||||
if (ParentMap != null && Locations != null && Locations.Any())
|
||||
if (ParentMap != null && Locations != null)
|
||||
{
|
||||
PathFigure figure = null;
|
||||
PolyLineSegment segment = null;
|
||||
var size = ParentMap.RenderSize;
|
||||
var offset = GetLongitudeOffset();
|
||||
var locations = Locations;
|
||||
var offset = GetLongitudeOffset();
|
||||
|
||||
if (offset != 0d)
|
||||
{
|
||||
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
|
||||
}
|
||||
|
||||
var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc));
|
||||
var p1 = points.First();
|
||||
var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc)).ToList();
|
||||
|
||||
foreach (var p2 in points.Skip(1))
|
||||
if (points.Count >= 2)
|
||||
{
|
||||
if ((p1.X <= 0 && p2.X <= 0) || (p1.X >= size.Width && p2.X >= size.Width) ||
|
||||
(p1.Y <= 0 && p2.Y <= 0) || (p1.Y >= size.Height && p2.Y >= size.Height))
|
||||
{
|
||||
// line (p1,p2) is out of visible bounds, end figure
|
||||
figure = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (figure == null)
|
||||
{
|
||||
figure = new PathFigure { StartPoint = p1, IsClosed = false, IsFilled = false };
|
||||
segment = new PolyLineSegment();
|
||||
figure.Segments.Add(segment);
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
segment.Points.Add(p2);
|
||||
}
|
||||
|
||||
p1 = p2;
|
||||
CreatePolylineFigures(points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LocationsPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var oldCollection = e.OldValue as INotifyCollectionChanged;
|
||||
var newCollection = e.NewValue as INotifyCollectionChanged;
|
||||
|
||||
if (oldCollection != null)
|
||||
{
|
||||
oldCollection.CollectionChanged -= LocationCollectionChanged;
|
||||
}
|
||||
|
||||
if (newCollection != null)
|
||||
{
|
||||
newCollection.CollectionChanged += LocationCollectionChanged;
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -17,5 +22,62 @@ namespace MapControl
|
|||
{
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
protected void LocationsPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var oldCollection = e.OldValue as INotifyCollectionChanged;
|
||||
var newCollection = e.NewValue as INotifyCollectionChanged;
|
||||
|
||||
if (oldCollection != null)
|
||||
{
|
||||
oldCollection.CollectionChanged -= LocationCollectionChanged;
|
||||
}
|
||||
|
||||
if (newCollection != null)
|
||||
{
|
||||
newCollection.CollectionChanged += LocationCollectionChanged;
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
protected void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
protected void CreatePolylineFigures(IList<Point> points)
|
||||
{
|
||||
var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height);
|
||||
var figures = ((PathGeometry)Data).Figures;
|
||||
|
||||
PathFigure figure = null;
|
||||
PolyLineSegment segment = null;
|
||||
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
{
|
||||
var p1 = points[i - 1];
|
||||
var p2 = points[i];
|
||||
var inside = Intersections.GetIntersections(ref p1, ref p2, viewport);
|
||||
|
||||
if (inside)
|
||||
{
|
||||
if (figure == null)
|
||||
{
|
||||
figure = new PathFigure { StartPoint = p1, IsClosed = false, IsFilled = false };
|
||||
segment = new PolyLineSegment();
|
||||
figure.Segments.Add(segment);
|
||||
figures.Add(figure);
|
||||
}
|
||||
|
||||
segment.Points.Add(p2);
|
||||
}
|
||||
|
||||
if (!inside || p2 != points[i])
|
||||
{
|
||||
figure = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.4.0")]
|
||||
[assembly: AssemblyFileVersion("4.4.0")]
|
||||
[assembly: AssemblyVersion("4.4.1")]
|
||||
[assembly: AssemblyFileVersion("4.4.1")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue