mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 1.1.6: Use StreamGeometry instead of PathGeometry in WPF MapPolyline.
This commit is contained in:
parent
970ea4d4a0
commit
66f254e861
|
|
@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
<Compile Include="MapPanel.cs" />
|
||||
<Compile Include="MapPanel.Silverlight.WinRT.cs" />
|
||||
<Compile Include="MapPolyline.cs" />
|
||||
<Compile Include="MapPolyline.Silverlight.cs" />
|
||||
<Compile Include="MapPolyline.Silverlight.WinRT.cs" />
|
||||
<Compile Include="MapTransform.cs" />
|
||||
<Compile Include="MatrixEx.cs" />
|
||||
<Compile Include="MercatorTransform.cs" />
|
||||
|
|
|
|||
74
MapControl/MapPolyline.Silverlight.WinRT.cs
Normal file
74
MapControl/MapPolyline.Silverlight.WinRT.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
||||
// Copyright © 2013 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Linq;
|
||||
#if NETFX_CORE
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPolyline : Path
|
||||
{
|
||||
protected readonly PathGeometry Geometry = new PathGeometry();
|
||||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = Geometry;
|
||||
MapPanel.AddParentMapHandlers(this);
|
||||
}
|
||||
|
||||
#if SILVERLIGHT
|
||||
// In Silverlight Path.MeasureOverride occasionally tries to create
|
||||
// negative width or height from a transformed geometry in Path.Data.
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
return new Size(Geometry.Bounds.Width, Geometry.Bounds.Height);
|
||||
}
|
||||
#endif
|
||||
|
||||
private void UpdateGeometry()
|
||||
{
|
||||
var parentMap = MapPanel.GetParentMap(this);
|
||||
var locations = Locations;
|
||||
Location first;
|
||||
|
||||
Geometry.Figures.Clear();
|
||||
|
||||
if (parentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
|
||||
{
|
||||
var figure = new PathFigure
|
||||
{
|
||||
StartPoint = parentMap.MapTransform.Transform(first),
|
||||
IsClosed = IsClosed,
|
||||
IsFilled = IsClosed
|
||||
};
|
||||
|
||||
var segment = new PolyLineSegment();
|
||||
|
||||
foreach (var location in locations.Skip(1))
|
||||
{
|
||||
segment.Points.Add(parentMap.MapTransform.Transform(location));
|
||||
}
|
||||
|
||||
if (segment.Points.Count > 0)
|
||||
{
|
||||
figure.Segments.Add(segment);
|
||||
}
|
||||
|
||||
Geometry.Figures.Add(figure);
|
||||
Geometry.Transform = parentMap.ViewportTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Geometry.Transform = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
||||
// Copyright © 2013 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPolyline : Path
|
||||
{
|
||||
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
||||
"Locations", typeof(ICollection<Location>), typeof(MapPolyline),
|
||||
new PropertyMetadata(null, LocationsPropertyChanged));
|
||||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = Geometry;
|
||||
MapPanel.AddParentMapHandlers(this);
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
// MeasureOverride in Silverlight occasionally tries to create
|
||||
// negative width or height from a transformed geometry in Data.
|
||||
return new Size(Geometry.Bounds.Width, Geometry.Bounds.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
|
@ -11,13 +12,37 @@ namespace MapControl
|
|||
{
|
||||
public partial class MapPolyline : Shape
|
||||
{
|
||||
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
||||
"Locations", typeof(ICollection<Location>), typeof(MapPolyline),
|
||||
new PropertyMetadata(null, LocationsPropertyChanged));
|
||||
protected readonly StreamGeometry Geometry = new StreamGeometry();
|
||||
|
||||
protected override Geometry DefiningGeometry
|
||||
{
|
||||
get { return Geometry; }
|
||||
}
|
||||
|
||||
private void UpdateGeometry()
|
||||
{
|
||||
var parentMap = MapPanel.GetParentMap(this);
|
||||
var locations = Locations;
|
||||
Location first;
|
||||
|
||||
if (parentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
|
||||
{
|
||||
using (var context = Geometry.Open())
|
||||
{
|
||||
var startPoint = parentMap.MapTransform.Transform(first);
|
||||
var points = locations.Skip(1).Select(l => parentMap.MapTransform.Transform(l)).ToList();
|
||||
|
||||
context.BeginFigure(startPoint, IsClosed, IsClosed);
|
||||
context.PolyLineTo(points, true, false);
|
||||
}
|
||||
|
||||
Geometry.Transform = parentMap.ViewportTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Geometry.Clear();
|
||||
Geometry.Transform = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
||||
// Copyright © 2013 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPolyline : Path
|
||||
{
|
||||
/// <summary>
|
||||
/// Property type declared as object instead of IEnumerable.
|
||||
/// See here: http://stackoverflow.com/q/10544084/1136211
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
||||
"Locations", typeof(object), typeof(MapPolyline),
|
||||
new PropertyMetadata(null, LocationsPropertyChanged));
|
||||
|
||||
public MapPolyline()
|
||||
{
|
||||
Data = Geometry;
|
||||
MapPanel.AddParentMapHandlers(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,27 +3,33 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
#if NETFX_CORE
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapPolyline : IMapElement
|
||||
{
|
||||
#if NETFX_CORE
|
||||
// For WinRT, the Locations dependency property type is declared as object
|
||||
// instead of IEnumerable. See http://stackoverflow.com/q/10544084/1136211
|
||||
private static readonly Type LocationsPropertyType = typeof(object);
|
||||
#else
|
||||
private static readonly Type LocationsPropertyType = typeof(IEnumerable<Location>);
|
||||
#endif
|
||||
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
||||
"Locations", LocationsPropertyType, typeof(MapPolyline),
|
||||
new PropertyMetadata(null, LocationsPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
||||
"IsClosed", typeof(bool), typeof(MapPolyline),
|
||||
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateGeometry()));
|
||||
|
||||
protected readonly PathGeometry Geometry = new PathGeometry();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the locations that define the polyline points.
|
||||
/// </summary>
|
||||
|
|
@ -42,44 +48,6 @@ namespace MapControl
|
|||
set { SetValue(IsClosedProperty, value); }
|
||||
}
|
||||
|
||||
private void UpdateGeometry()
|
||||
{
|
||||
var parentMap = MapPanel.GetParentMap(this);
|
||||
var locations = Locations;
|
||||
Location first;
|
||||
|
||||
Geometry.Figures.Clear();
|
||||
|
||||
if (parentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
|
||||
{
|
||||
var figure = new PathFigure
|
||||
{
|
||||
StartPoint = parentMap.MapTransform.Transform(first),
|
||||
IsClosed = IsClosed,
|
||||
IsFilled = IsClosed
|
||||
};
|
||||
|
||||
var segment = new PolyLineSegment();
|
||||
|
||||
foreach (var location in locations.Skip(1))
|
||||
{
|
||||
segment.Points.Add(parentMap.MapTransform.Transform(location));
|
||||
}
|
||||
|
||||
if (segment.Points.Count > 0)
|
||||
{
|
||||
figure.Segments.Add(segment);
|
||||
}
|
||||
|
||||
Geometry.Figures.Add(figure);
|
||||
Geometry.Transform = parentMap.ViewportTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Geometry.Transform = null;
|
||||
}
|
||||
}
|
||||
|
||||
void IMapElement.ParentMapChanged(MapBase oldParentMap, MapBase newParentMap)
|
||||
{
|
||||
UpdateGeometry();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ using System.Windows;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@
|
|||
<Compile Include="..\MapPolyline.cs">
|
||||
<Link>MapPolyline.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MapPolyline.WinRT.cs">
|
||||
<Link>MapPolyline.WinRT.cs</Link>
|
||||
<Compile Include="..\MapPolyline.Silverlight.WinRT.cs">
|
||||
<Link>MapPolyline.Silverlight.WinRT.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MapTransform.cs">
|
||||
<Link>MapTransform.cs</Link>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using System.Windows;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using System.Windows;
|
|||
[assembly: AssemblyCopyright("Copyright © 2013 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("1.1.5")]
|
||||
[assembly: AssemblyFileVersion("1.1.5")]
|
||||
[assembly: AssemblyVersion("1.1.6")]
|
||||
[assembly: AssemblyFileVersion("1.1.6")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue