Fixed MapPolyline.

This commit is contained in:
ClemensF 2012-12-15 18:54:40 +01:00
parent f45ca78ddd
commit 3f5e3d752b
12 changed files with 84 additions and 51 deletions

View file

@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -19,7 +19,7 @@ namespace MapControl
public LocationCollection(IEnumerable<Location> locations) public LocationCollection(IEnumerable<Location> locations)
{ {
foreach (Location location in locations) foreach (var location in locations)
{ {
Add(location); Add(location);
} }

View file

@ -575,16 +575,16 @@ namespace MapControl
Location.NormalizeLongitude(location.Longitude)); Location.NormalizeLongitude(location.Longitude));
} }
private bool CoerceCenterProperty(DependencyProperty property, ref Location value) private bool CoerceCenterProperty(DependencyProperty property, ref Location center)
{ {
Location coercedValue = CoerceLocation(value); Location coercedValue = CoerceLocation(center);
if (!coercedValue.Equals(value)) if (!coercedValue.Equals(center))
{ {
SetProperty(property, coercedValue); SetProperty(property, coercedValue);
} }
return coercedValue != value; return coercedValue != center;
} }
private void CenterPropertyChanged(Location center) private void CenterPropertyChanged(Location center)
@ -672,7 +672,7 @@ namespace MapControl
private void MaxZoomLevelPropertyChanged(double maxZoomLevel) private void MaxZoomLevelPropertyChanged(double maxZoomLevel)
{ {
var coercedValue = Math.Min(Math.Max(maxZoomLevel, MinZoomLevel), 20d); var coercedValue = Math.Min(Math.Max(maxZoomLevel, MinZoomLevel), 22d);
if (coercedValue != maxZoomLevel) if (coercedValue != maxZoomLevel)
{ {
@ -684,21 +684,21 @@ namespace MapControl
} }
} }
private double CoerceZoomLevel(double value) private double CoerceZoomLevel(double zoomLevel)
{ {
return Math.Min(Math.Max(value, MinZoomLevel), MaxZoomLevel); return Math.Min(Math.Max(zoomLevel, MinZoomLevel), MaxZoomLevel);
} }
private bool CoerceZoomLevelProperty(DependencyProperty property, ref double value) private bool CoerceZoomLevelProperty(DependencyProperty property, ref double zoomLevel)
{ {
var coercedValue = CoerceZoomLevel(value); var coercedValue = CoerceZoomLevel(zoomLevel);
if (coercedValue != value) if (coercedValue != zoomLevel)
{ {
SetProperty(property, coercedValue); SetProperty(property, coercedValue);
} }
return coercedValue != value; return coercedValue != zoomLevel;
} }
private void ZoomLevelPropertyChanged(double zoomLevel) private void ZoomLevelPropertyChanged(double zoomLevel)
@ -752,21 +752,21 @@ namespace MapControl
} }
} }
private double CoerceHeading(double value) private double CoerceHeading(double heading)
{ {
return (value >= -180d && value <= 360d) ? value : ((value + 360d) % 360d); return (heading >= -180d && heading <= 360d) ? heading : ((heading + 360d) % 360d);
} }
private bool CoerceHeadingProperty(DependencyProperty property, ref double value) private bool CoerceHeadingProperty(DependencyProperty property, ref double heading)
{ {
var coercedValue = CoerceHeading(value); var coercedValue = CoerceHeading(heading);
if (coercedValue != value) if (coercedValue != heading)
{ {
SetProperty(property, coercedValue); SetProperty(property, coercedValue);
} }
return coercedValue != value; return coercedValue != heading;
} }
private void HeadingPropertyChanged(double heading) private void HeadingPropertyChanged(double heading)

View file

@ -3,6 +3,8 @@
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System.Linq; using System.Linq;
using System.Collections.Generic;
using System.Collections.Specialized;
#if NETFX_CORE #if NETFX_CORE
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media;
@ -16,21 +18,21 @@ namespace MapControl
public partial class MapPolyline : IMapElement public partial class MapPolyline : IMapElement
{ {
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
"Locations", typeof(LocationCollection), typeof(MapPolyline), "Locations", typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).UpdateGeometry())); new PropertyMetadata(null, LocationsPropertyChanged));
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register( public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
"IsClosed", typeof(bool), typeof(MapPolyline), "IsClosed", typeof(bool), typeof(MapPolyline),
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateGeometry())); new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateGeometry()));
protected PathGeometry Geometry = new PathGeometry(); protected readonly PathGeometry Geometry = new PathGeometry();
/// <summary> /// <summary>
/// Gets or sets the locations that define the polyline points. /// Gets or sets the locations that define the polyline points.
/// </summary> /// </summary>
public LocationCollection Locations public IEnumerable<Location> Locations
{ {
get { return (LocationCollection)GetValue(LocationsProperty); } get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
set { SetValue(LocationsProperty, value); } set { SetValue(LocationsProperty, value); }
} }
@ -43,40 +45,71 @@ namespace MapControl
set { SetValue(IsClosedProperty, value); } set { SetValue(IsClosedProperty, value); }
} }
protected virtual void UpdateGeometry() private void UpdateGeometry()
{ {
var parentMap = MapPanel.GetParentMap(this); var parentMap = MapPanel.GetParentMap(this);
var locations = Locations; var locations = Locations;
Location first;
if (parentMap != null && locations != null && locations.Count > 0) Geometry.Figures.Clear();
if (parentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
{ {
var figure = new PathFigure var figure = new PathFigure
{ {
StartPoint = parentMap.MapTransform.Transform(locations[0]), StartPoint = parentMap.MapTransform.Transform(first),
IsClosed = IsClosed, IsClosed = IsClosed,
IsFilled = IsClosed IsFilled = IsClosed
}; };
if (locations.Count > 1) var segment = new PolyLineSegment();
foreach (var location in locations.Skip(1))
{ {
var segment = new PolyLineSegment(); segment.Points.Add(parentMap.MapTransform.Transform(location));
}
foreach (Location location in locations.Skip(1))
{
segment.Points.Add(parentMap.MapTransform.Transform(location));
}
if (segment.Points.Count > 0)
{
figure.Segments.Add(segment); figure.Segments.Add(segment);
} }
Geometry.Figures.Add(figure); Geometry.Figures.Add(figure);
Geometry.Transform = parentMap.ViewportTransform; Geometry.Transform = parentMap.ViewportTransform;
} }
else
{
Geometry.Transform = null;
}
} }
void IMapElement.ParentMapChanged(MapBase oldParentMap, MapBase newParentMap) void IMapElement.ParentMapChanged(MapBase oldParentMap, MapBase newParentMap)
{ {
UpdateGeometry(); UpdateGeometry();
} }
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateGeometry();
}
private static void LocationsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var mapPolyline = (MapPolyline)obj;
var oldNotifyCollectionChanged = e.OldValue as INotifyCollectionChanged;
var newNotifyCollectionChanged = e.NewValue as INotifyCollectionChanged;
if (oldNotifyCollectionChanged != null)
{
oldNotifyCollectionChanged.CollectionChanged -= mapPolyline.LocationCollectionChanged;
}
if (newNotifyCollectionChanged != null)
{
newNotifyCollectionChanged.CollectionChanged += mapPolyline.LocationCollectionChanged;
}
mapPolyline.UpdateGeometry();
}
} }
} }

View file

@ -16,6 +16,6 @@ using System.Windows;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -9,6 +9,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

View file

@ -10,7 +10,7 @@ using System.Windows;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

View file

@ -10,7 +10,7 @@ using System.Windows;
[assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")] [assembly: AssemblyCopyright("Copyright © 2012 Clemens Fischer")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.2")] [assembly: AssemblyVersion("1.1.3")]
[assembly: AssemblyFileVersion("1.1.2")] [assembly: AssemblyFileVersion("1.1.3")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]