XAML-Map-Control/MapControl/WPF/MapPolypoint.WPF.cs

67 lines
2 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System;
2024-05-26 09:49:00 +02:00
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
2026-04-13 17:14:49 +02:00
namespace MapControl;
public partial class MapPolypoint : MapPath
2024-05-26 09:49:00 +02:00
{
2026-04-13 17:14:49 +02:00
protected void UpdateData(IEnumerable<Location> locations, bool closed)
2024-05-26 09:49:00 +02:00
{
2026-04-13 17:14:49 +02:00
using var context = ((StreamGeometry)Data).Open();
2025-09-14 21:02:21 +02:00
2026-04-13 17:14:49 +02:00
if (ParentMap != null && locations != null)
{
var longitudeOffset = GetLongitudeOffset(locations);
2024-05-26 09:49:00 +02:00
2026-04-13 17:14:49 +02:00
AddPolylinePoints(context, locations, longitudeOffset, closed);
2024-05-26 09:49:00 +02:00
}
2026-04-13 17:14:49 +02:00
}
protected void UpdateData(IEnumerable<IEnumerable<Location>> polygons)
{
using var context = ((StreamGeometry)Data).Open();
2024-05-26 09:49:00 +02:00
2026-04-13 17:14:49 +02:00
if (ParentMap != null && polygons != null)
2024-05-26 09:49:00 +02:00
{
2026-04-13 17:14:49 +02:00
var longitudeOffset = GetLongitudeOffset(polygons.FirstOrDefault());
2025-09-14 21:02:21 +02:00
2026-04-13 17:14:49 +02:00
foreach (var locations in polygons)
2024-05-26 09:49:00 +02:00
{
2026-04-13 17:14:49 +02:00
AddPolylinePoints(context, locations, longitudeOffset, true);
2024-05-26 09:49:00 +02:00
}
}
2026-04-13 17:14:49 +02:00
}
private void AddPolylinePoints(StreamGeometryContext context, IEnumerable<Location> locations, double longitudeOffset, bool closed)
{
var points = locations.Select(location => LocationToView(location, longitudeOffset));
2024-05-26 09:49:00 +02:00
2026-04-13 17:14:49 +02:00
if (points.Any())
2024-05-26 09:49:00 +02:00
{
2026-04-13 17:14:49 +02:00
var start = points.First();
var polyline = points.Skip(1).ToList();
var minX = start.X;
var maxX = start.X;
var minY = start.Y;
var maxY = start.Y;
2024-05-26 09:49:00 +02:00
2026-04-13 17:14:49 +02:00
foreach (var point in polyline)
2024-07-15 13:41:52 +02:00
{
2026-04-13 17:14:49 +02:00
minX = Math.Min(minX, point.X);
maxX = Math.Max(maxX, point.X);
minY = Math.Min(minY, point.Y);
maxY = Math.Max(maxY, point.Y);
}
2024-07-16 21:29:25 +02:00
2026-04-13 17:14:49 +02:00
if (maxX >= 0d && minX <= ParentMap.ActualWidth &&
maxY >= 0d && minY <= ParentMap.ActualHeight)
{
context.BeginFigure(start, true, closed);
context.PolyLineTo(polyline, true, true);
2024-07-15 13:41:52 +02:00
}
2024-05-26 09:49:00 +02:00
}
}
}