Simplified polyline implementations

This commit is contained in:
ClemensFischer 2023-01-25 19:55:42 +01:00
parent 641b4354a0
commit b114243e61
4 changed files with 59 additions and 51 deletions

View file

@ -2,12 +2,18 @@
// Copyright © 2023 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
#elif UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
@ -78,25 +84,6 @@ namespace MapControl
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
protected double GetLongitudeOffset(Location location)
{
var longitudeOffset = 0d;
if (location != null && parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical)
{
var point = parentMap.LocationToView(location);
if (point.HasValue &&
(point.Value.X < 0d || point.Value.X > parentMap.RenderSize.Width ||
point.Value.Y < 0d || point.Value.Y > parentMap.RenderSize.Height))
{
longitudeOffset = parentMap.ConstrainedLongitude(location.Longitude) - location.Longitude;
}
}
return longitudeOffset;
}
protected Point? LocationToMap(Location location, double longitudeOffset)
{
if (longitudeOffset != 0d)
@ -133,6 +120,56 @@ namespace MapControl
return parentMap.ViewTransform.MapToView(point.Value);
}
protected double GetLongitudeOffset(Location location)
{
var longitudeOffset = 0d;
if (location != null && parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical)
{
var point = parentMap.LocationToView(location);
if (point.HasValue &&
(point.Value.X < 0d || point.Value.X > parentMap.RenderSize.Width ||
point.Value.Y < 0d || point.Value.Y > parentMap.RenderSize.Height))
{
longitudeOffset = parentMap.ConstrainedLongitude(location.Longitude) - location.Longitude;
}
}
return longitudeOffset;
}
protected PathFigureCollection GetPolylineFigures(IEnumerable<Location> locations, bool closed)
{
var pathFigures = new PathFigureCollection();
if (parentMap != null && locations != null)
{
var longitudeOffset = GetLongitudeOffset(Location ?? locations.FirstOrDefault());
AddPolylineLocations(pathFigures, locations, longitudeOffset, closed);
}
return pathFigures;
}
protected PathFigureCollection GetMultiPolygonFigures(IEnumerable<IEnumerable<Location>> polygons)
{
var pathFigures = new PathFigureCollection();
if (parentMap != null && polygons != null)
{
var longitudeOffset = GetLongitudeOffset(Location);
foreach (var polygon in polygons)
{
AddPolylineLocations(pathFigures, polygon, longitudeOffset, true);
}
}
return pathFigures;
}
#endregion
}
}

View file

@ -3,7 +3,6 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
@ -55,15 +54,7 @@ namespace MapControl
protected override void UpdateData()
{
var pathFigures = ((PathGeometry)Data).Figures;
pathFigures.Clear();
if (ParentMap != null && Locations != null)
{
var longitudeOffset = GetLongitudeOffset(Location ?? Locations.FirstOrDefault());
AddPolylineLocations(pathFigures, Locations, longitudeOffset, true);
}
((PathGeometry)Data).Figures = GetPolylineFigures(Locations, true);
}
}
}

View file

@ -3,7 +3,6 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
@ -55,15 +54,7 @@ namespace MapControl
protected override void UpdateData()
{
var pathFigures = ((PathGeometry)Data).Figures;
pathFigures.Clear();
if (ParentMap != null && Locations != null)
{
var longitudeOffset = GetLongitudeOffset(Location ?? Locations.FirstOrDefault());
AddPolylineLocations(pathFigures, Locations, longitudeOffset, false);
}
((PathGeometry)Data).Figures = GetPolylineFigures(Locations, false);
}
}
}

View file

@ -48,18 +48,7 @@ namespace MapControl
protected override void UpdateData()
{
var pathFigures = ((PathGeometry)Data).Figures;
pathFigures.Clear();
if (ParentMap != null && Polygons != null)
{
var longitudeOffset = GetLongitudeOffset(Location);
foreach (var polygon in Polygons)
{
AddPolylineLocations(pathFigures, polygon, longitudeOffset, true);
}
}
((PathGeometry)Data).Figures = GetMultiPolygonFigures(Polygons);
}
}
}