mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 22:18:56 +00:00
Version 4.4.0: Fixed MapPolyline performance on UWP. Added MapPolygon and MapMultiPolygon for WPF.
This commit is contained in:
parent
cce5d6e0b4
commit
d1552506f6
80 changed files with 673 additions and 550 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows;
|
||||
|
|
|
|||
|
|
@ -110,24 +110,24 @@
|
|||
<Compile Include="..\Shared\MapPanel.cs">
|
||||
<Link>MapPanel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapPath.cs">
|
||||
<Link>MapPath.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapPolyline.cs">
|
||||
<Link>MapPolyline.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapProjection.cs">
|
||||
<Link>MapProjection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapScale.cs">
|
||||
<Link>MapScale.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapShape.cs">
|
||||
<Link>MapShape.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapTileLayer.cs">
|
||||
<Link>MapTileLayer.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\OrthographicProjection.cs">
|
||||
<Link>OrthographicProjection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\PolygonCollection.cs">
|
||||
<Link>PolygonCollection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\Pushpin.cs">
|
||||
<Link>Pushpin.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -162,10 +162,12 @@
|
|||
<Compile Include="Map.WPF.cs" />
|
||||
<Compile Include="MapBase.WPF.cs" />
|
||||
<Compile Include="MapGraticule.WPF.cs" />
|
||||
<Compile Include="MapMultiPolygon.WPF.cs" />
|
||||
<Compile Include="MapOverlay.WPF.cs" />
|
||||
<Compile Include="MapPanel.WPF.cs" />
|
||||
<Compile Include="MapPath.WPF.cs" />
|
||||
<Compile Include="MapPolygon.WPF.cs" />
|
||||
<Compile Include="MapPolyline.WPF.cs" />
|
||||
<Compile Include="MapShape.WPF.cs" />
|
||||
<Compile Include="TileImageLoader.WPF.cs" />
|
||||
<Compile Include="ImageLoader.WPF.cs" />
|
||||
<Compile Include="TypeConverters.WPF.cs" />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
@ -39,7 +39,7 @@ namespace MapControl
|
|||
{
|
||||
var projection = ParentMap?.MapProjection;
|
||||
|
||||
if (projection != null && !double.IsNaN(projection.LongitudeScale))
|
||||
if (projection != null && !projection.IsAzimuthal)
|
||||
{
|
||||
var bounds = projection.ViewportRectToBoundingBox(new Rect(ParentMap.RenderSize));
|
||||
|
||||
|
|
|
|||
51
MapControl/WPF/MapMultiPolygon.WPF.cs
Normal file
51
MapControl/WPF/MapMultiPolygon.WPF.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// 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 System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// A multi-polygon defined by a collection of collections of Locations.
|
||||
/// With a FillRule of EvenOdd, this allows to draw polygons with holes.
|
||||
///
|
||||
/// A PolygonCollection (with ObservableCollection of Location elements) may be used
|
||||
/// for the Polygons property if collection changes of the property itself and its
|
||||
/// elements are both supposed to trigger a UI update.
|
||||
/// </summary>
|
||||
public class MapMultiPolygon : MapShape, IWeakEventListener
|
||||
{
|
||||
public static readonly DependencyProperty PolygonsProperty = DependencyProperty.Register(
|
||||
nameof(Polygons), typeof(IEnumerable<IEnumerable<Location>>), typeof(MapMultiPolygon),
|
||||
new PropertyMetadata(null, (o, e) => ((MapMultiPolygon)o).DataCollectionPropertyChanged(e)));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Locations that define the multi-polygon points.
|
||||
/// </summary>
|
||||
public IEnumerable<IEnumerable<Location>> Polygons
|
||||
{
|
||||
get { return (IEnumerable<IEnumerable<Location>>)GetValue(PolygonsProperty); }
|
||||
set { SetValue(PolygonsProperty, value); }
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
Data.Figures.Clear();
|
||||
|
||||
if (ParentMap != null && Polygons != null)
|
||||
{
|
||||
foreach (var polygon in Polygons.Where(p => p.Any()))
|
||||
{
|
||||
var points = polygon.Select(loc => LocationToPoint(loc));
|
||||
var polyline = new PolyLineSegment(points.Skip(1), true);
|
||||
|
||||
Data.Figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows;
|
||||
|
|
@ -9,8 +9,8 @@ namespace MapControl
|
|||
public partial class MapPanel
|
||||
{
|
||||
private static readonly DependencyPropertyKey ParentMapPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
|
||||
"ParentMap", typeof(MapBase), typeof(MapPanel),
|
||||
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
|
||||
"ParentMap", typeof(MapBase), typeof(MapPanel), new FrameworkPropertyMetadata(
|
||||
null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPath : Shape
|
||||
{
|
||||
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
|
||||
nameof(Data), typeof(Geometry), typeof(MapPath), new FrameworkPropertyMetadata(
|
||||
null, FrameworkPropertyMetadataOptions.AffectsRender, DataPropertyChanged, CoerceDataProperty));
|
||||
|
||||
static MapPath()
|
||||
{
|
||||
StretchProperty.OverrideMetadata(typeof(MapPath),
|
||||
new FrameworkPropertyMetadata { CoerceValueCallback = (o, v) => Stretch.None });
|
||||
}
|
||||
|
||||
public Geometry Data
|
||||
{
|
||||
get { return (Geometry)GetValue(DataProperty); }
|
||||
set { SetValue(DataProperty, value); }
|
||||
}
|
||||
|
||||
protected override Geometry DefiningGeometry
|
||||
{
|
||||
get { return Data; }
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
return new Size();
|
||||
}
|
||||
|
||||
private static void DataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!ReferenceEquals(e.OldValue, e.NewValue))
|
||||
{
|
||||
var mapPath = (MapPath)obj;
|
||||
|
||||
if (e.OldValue != null)
|
||||
{
|
||||
((Geometry)e.OldValue).ClearValue(Geometry.TransformProperty);
|
||||
}
|
||||
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
((Geometry)e.NewValue).Transform = mapPath.viewportTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static object CoerceDataProperty(DependencyObject obj, object value)
|
||||
{
|
||||
var data = (Geometry)value;
|
||||
|
||||
return (data != null && data.IsFrozen) ? data.CloneCurrentValue() : data;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
MapControl/WPF/MapPolygon.WPF.cs
Normal file
45
MapControl/WPF/MapPolygon.WPF.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// 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.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.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).DataCollectionPropertyChanged(e)));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Locations that define the polygon points.
|
||||
/// </summary>
|
||||
[TypeConverter(typeof(LocationCollectionConverter))]
|
||||
public IEnumerable<Location> Locations
|
||||
{
|
||||
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
||||
set { SetValue(LocationsProperty, value); }
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
Data.Figures.Clear();
|
||||
|
||||
if (ParentMap != null && Locations != null && Locations.Any())
|
||||
{
|
||||
var points = Locations.Select(loc => LocationToPoint(loc));
|
||||
var polyline = new PolyLineSegment(points.Skip(1), true);
|
||||
|
||||
Data.Figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -10,20 +10,17 @@ using System.Windows.Media;
|
|||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPolyline
|
||||
/// <summary>
|
||||
/// A polyline defined by a collection of Locations.
|
||||
/// </summary>
|
||||
public class MapPolyline : MapShape
|
||||
{
|
||||
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register(
|
||||
nameof(FillRule), typeof(FillRule), typeof(MapPolyline), new FrameworkPropertyMetadata(
|
||||
FillRule.EvenOdd, FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, e) => ((StreamGeometry)((MapPolyline)o).Data).FillRule = (FillRule)e.NewValue));
|
||||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = new StreamGeometry();
|
||||
}
|
||||
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
||||
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
|
||||
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).DataCollectionPropertyChanged(e)));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the locations that define the polyline points.
|
||||
/// Gets or sets the Locations that define the polyline points.
|
||||
/// </summary>
|
||||
[TypeConverter(typeof(LocationCollectionConverter))]
|
||||
public IEnumerable<Location> Locations
|
||||
|
|
@ -34,21 +31,14 @@ namespace MapControl
|
|||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
var geometry = (StreamGeometry)Data;
|
||||
Data.Figures.Clear();
|
||||
|
||||
if (ParentMap != null && Locations != null && Locations.Any())
|
||||
{
|
||||
using (var context = geometry.Open())
|
||||
{
|
||||
var points = Locations.Select(l => ParentMap.MapProjection.LocationToPoint(l));
|
||||
var points = Locations.Select(loc => LocationToPoint(loc));
|
||||
var polyline = new PolyLineSegment(points.Skip(1), true);
|
||||
|
||||
context.BeginFigure(points.First(), IsClosed, IsClosed);
|
||||
context.PolyLineTo(points.Skip(1).ToList(), true, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry.Clear();
|
||||
Data.Figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
100
MapControl/WPF/MapShape.WPF.cs
Normal file
100
MapControl/WPF/MapShape.WPF.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public abstract partial class MapShape : Shape, IWeakEventListener
|
||||
{
|
||||
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register(
|
||||
nameof(FillRule), typeof(FillRule), typeof(MapShape),
|
||||
new FrameworkPropertyMetadata(FillRule.EvenOdd, FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, e) => ((MapShape)o).Data.FillRule = (FillRule)e.NewValue));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the FillRule of the StreamGeometry that represents the polyline.
|
||||
/// </summary>
|
||||
public FillRule FillRule
|
||||
{
|
||||
get { return (FillRule)GetValue(FillRuleProperty); }
|
||||
set { SetValue(FillRuleProperty, value); }
|
||||
}
|
||||
|
||||
protected PathGeometry Data { get; }
|
||||
|
||||
protected override Geometry DefiningGeometry
|
||||
{
|
||||
get { return Data; }
|
||||
}
|
||||
|
||||
private void ParentMapChanged()
|
||||
{
|
||||
if (parentMap != null)
|
||||
{
|
||||
var transform = new TransformGroup();
|
||||
transform.Children.Add(new TranslateTransform(GetLongitudeOffset() * parentMap.MapProjection.TrueScale, 0d));
|
||||
transform.Children.Add(parentMap.MapProjection.ViewportTransform);
|
||||
|
||||
Data.Transform = transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.Transform = Transform.Identity;
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
||||
{
|
||||
var transform = (TransformGroup)Data.Transform;
|
||||
var offset = (TranslateTransform)transform.Children[0];
|
||||
|
||||
offset.X = GetLongitudeOffset() * parentMap.MapProjection.TrueScale;
|
||||
|
||||
if (e.ProjectionChanged)
|
||||
{
|
||||
transform.Children[1] = parentMap.MapProjection.ViewportTransform;
|
||||
}
|
||||
|
||||
if (e.ProjectionChanged || parentMap.MapProjection.IsAzimuthal)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
else if (Fill != null)
|
||||
{
|
||||
InvalidateVisual(); // Fill brush may be rendered only partially or not at all
|
||||
}
|
||||
}
|
||||
|
||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
INotifyCollectionChanged locations;
|
||||
|
||||
if ((locations = e.OldValue as INotifyCollectionChanged) != null)
|
||||
{
|
||||
CollectionChangedEventManager.RemoveListener(locations, this);
|
||||
}
|
||||
|
||||
if ((locations = e.NewValue as INotifyCollectionChanged) != null)
|
||||
{
|
||||
CollectionChangedEventManager.AddListener(locations, this);
|
||||
}
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
|
||||
{
|
||||
UpdateData();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows.Media;
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ using System.Windows;
|
|||
[assembly: AssemblyDescription("XAML Map Control Library")]
|
||||
[assembly: AssemblyProduct("XAML Map Control")]
|
||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.3.0")]
|
||||
[assembly: AssemblyFileVersion("4.3.0")]
|
||||
[assembly: AssemblyVersion("4.4.0")]
|
||||
[assembly: AssemblyFileVersion("4.4.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue