mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Added MapPolypoint base class
This commit is contained in:
parent
aeb3fd047f
commit
84890090f8
11 changed files with 357 additions and 317 deletions
|
|
@ -2,8 +2,6 @@
|
|||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
|
@ -84,8 +82,6 @@ namespace MapControl
|
|||
MapPanel.SetLocation(this, Location);
|
||||
}
|
||||
|
||||
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
|
||||
|
||||
protected Point? LocationToMap(Location location, double longitudeOffset)
|
||||
{
|
||||
if (longitudeOffset != 0d)
|
||||
|
|
@ -140,34 +136,5 @@ namespace MapControl
|
|||
|
||||
return longitudeOffset;
|
||||
}
|
||||
|
||||
protected PathFigureCollection GetPathFigures(IEnumerable<Location> locations, bool closed)
|
||||
{
|
||||
var pathFigures = new PathFigureCollection();
|
||||
|
||||
if (parentMap != null && locations != null)
|
||||
{
|
||||
var longitudeOffset = GetLongitudeOffset(Location ?? locations.FirstOrDefault());
|
||||
|
||||
AddPolylinePoints(pathFigures, locations, longitudeOffset, closed);
|
||||
}
|
||||
|
||||
return pathFigures;
|
||||
}
|
||||
|
||||
protected void AddMultiPolygonPoints(PathFigureCollection pathFigures, IEnumerable<IEnumerable<Location>> polygons)
|
||||
{
|
||||
if (parentMap != null && polygons != null)
|
||||
{
|
||||
var longitudeOffset = GetLongitudeOffset(Location);
|
||||
|
||||
foreach (var polygon in polygons)
|
||||
{
|
||||
AddPolylinePoints(pathFigures, polygon, longitudeOffset, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,11 @@
|
|||
using System.Collections.Generic;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif AVALONIA
|
||||
using Avalonia.Media;
|
||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
#endif
|
||||
|
||||
|
|
@ -22,16 +18,12 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// A polygon defined by a collection of Locations.
|
||||
/// </summary>
|
||||
public class MapPolygon : MapPath
|
||||
public class MapPolygon : MapPolypoint
|
||||
{
|
||||
public static readonly DependencyProperty LocationsProperty =
|
||||
DependencyPropertyHelper.Register<MapPolygon, IEnumerable<Location>>(nameof(Locations), null,
|
||||
(polygon, oldValue, newValue) => polygon.DataCollectionPropertyChanged(oldValue, newValue));
|
||||
|
||||
public static readonly DependencyProperty FillRuleProperty =
|
||||
DependencyPropertyHelper.Register<MapPolygon, FillRule>(nameof(FillRule), FillRule.EvenOdd,
|
||||
(polygon, oldValue, newValue) => ((PathGeometry)polygon.Data).FillRule = newValue);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Locations that define the polygon points.
|
||||
/// </summary>
|
||||
|
|
@ -44,20 +36,9 @@ namespace MapControl
|
|||
set => SetValue(LocationsProperty, value);
|
||||
}
|
||||
|
||||
public FillRule FillRule
|
||||
{
|
||||
get => (FillRule)GetValue(FillRuleProperty);
|
||||
set => SetValue(FillRuleProperty, value);
|
||||
}
|
||||
|
||||
public MapPolygon()
|
||||
{
|
||||
Data = new PathGeometry();
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
SetPathFigures(GetPathFigures(Locations, true));
|
||||
UpdateData(Locations, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,11 @@
|
|||
using System.Collections.Generic;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif AVALONIA
|
||||
using Avalonia.Media;
|
||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
#endif
|
||||
|
||||
|
|
@ -22,16 +18,12 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// A polyline defined by a collection of Locations.
|
||||
/// </summary>
|
||||
public class MapPolyline : MapPath
|
||||
public class MapPolyline : MapPolypoint
|
||||
{
|
||||
public static readonly DependencyProperty LocationsProperty =
|
||||
DependencyPropertyHelper.Register<MapPolyline, IEnumerable<Location>>(nameof(Locations), null,
|
||||
(polyline, oldValue, newValue) => polyline.DataCollectionPropertyChanged(oldValue, newValue));
|
||||
|
||||
public static readonly DependencyProperty FillRuleProperty =
|
||||
DependencyPropertyHelper.Register<MapPolyline, FillRule>(nameof(FillRule), FillRule.EvenOdd,
|
||||
(polyline, oldValue, newValue) => ((PathGeometry)polyline.Data).FillRule = newValue);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Locations that define the polyline points.
|
||||
/// </summary>
|
||||
|
|
@ -44,20 +36,9 @@ namespace MapControl
|
|||
set => SetValue(LocationsProperty, value);
|
||||
}
|
||||
|
||||
public FillRule FillRule
|
||||
{
|
||||
get => (FillRule)GetValue(FillRuleProperty);
|
||||
set => SetValue(FillRuleProperty, value);
|
||||
}
|
||||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = new PathGeometry();
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
SetPathFigures(GetPathFigures(Locations, true));
|
||||
UpdateData(Locations, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue