mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-05-07 13:37:47 +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
86
MapControl/UWP/MapPath.UWP.cs
Normal file
86
MapControl/UWP/MapPath.UWP.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2020 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPath : Path
|
||||
{
|
||||
protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
INotifyCollectionChanged collection;
|
||||
|
||||
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
|
||||
{
|
||||
collection.CollectionChanged -= DataCollectionChanged;
|
||||
}
|
||||
|
||||
if ((collection = e.NewValue as INotifyCollectionChanged) != null)
|
||||
{
|
||||
collection.CollectionChanged += DataCollectionChanged;
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
protected void AddPolylineLocations(PathFigureCollection figures, IEnumerable<Location> locations, bool closed)
|
||||
{
|
||||
if (locations != null && locations.Count() >= 2)
|
||||
{
|
||||
var points = locations.Select(loc => LocationToView(loc)).ToList();
|
||||
if (closed)
|
||||
{
|
||||
points.Add(points[0]);
|
||||
}
|
||||
|
||||
var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue