diff --git a/MapControl/Map.Silverlight.WPF.cs b/MapControl/Map.Silverlight.WPF.cs index 1a0d8b55..5903a450 100644 --- a/MapControl/Map.Silverlight.WPF.cs +++ b/MapControl/Map.Silverlight.WPF.cs @@ -10,8 +10,11 @@ namespace MapControl { public partial class Map { - partial void Initialize() + private Point? mousePosition; + + public Map() { + MouseWheelZoomChange = 1d; MouseWheel += OnMouseWheel; MouseLeftButtonDown += OnMouseLeftButtonDown; MouseLeftButtonUp += OnMouseLeftButtonUp; @@ -26,7 +29,7 @@ namespace MapControl private void OnMouseWheel(object sender, MouseWheelEventArgs e) { - ZoomMap(e.GetPosition(this), TargetZoomLevel + mouseWheelZoom * Math.Sign(e.Delta)); + ZoomMap(e.GetPosition(this), TargetZoomLevel + MouseWheelZoomChange * Math.Sign(e.Delta)); } private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) diff --git a/MapControl/Map.WinRT.cs b/MapControl/Map.WinRT.cs index 9ba36c70..ff913837 100644 --- a/MapControl/Map.WinRT.cs +++ b/MapControl/Map.WinRT.cs @@ -11,8 +11,11 @@ namespace MapControl { public partial class Map { - partial void Initialize() + private Point? mousePosition; + + public Map() { + MouseWheelZoomChange = 1d; ManipulationMode = ManipulationModes.All; ManipulationDelta += OnManipulationDelta; PointerWheelChanged += OnPointerWheelChanged; @@ -34,7 +37,7 @@ namespace MapControl private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) { var point = e.GetCurrentPoint(this); - ZoomMap(point.Position, TargetZoomLevel + mouseWheelZoom * Math.Sign(point.Properties.MouseWheelDelta)); + ZoomMap(point.Position, TargetZoomLevel + MouseWheelZoomChange * Math.Sign(point.Properties.MouseWheelDelta)); } private void OnPointerPressed(object sender, PointerRoutedEventArgs e) diff --git a/MapControl/Map.cs b/MapControl/Map.cs index a73f290b..fa11a35f 100644 --- a/MapControl/Map.cs +++ b/MapControl/Map.cs @@ -2,12 +2,6 @@ // Copyright © 2012 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) -#if WINRT -using Windows.Foundation; -#else -using System.Windows; -#endif - namespace MapControl { /// @@ -15,20 +9,9 @@ namespace MapControl /// public partial class Map : MapBase { - private double mouseWheelZoom = 1d; - private Point? mousePosition; - - public Map() - { - Initialize(); - } - - partial void Initialize(); - - public double MouseWheelZoom - { - get { return mouseWheelZoom; } - set { mouseWheelZoom = value; } - } + /// + /// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event. + /// + public double MouseWheelZoomChange { get; set; } } } diff --git a/MapControl/MapBase.cs b/MapControl/MapBase.cs index 8ed125d3..ee08fb18 100644 --- a/MapControl/MapBase.cs +++ b/MapControl/MapBase.cs @@ -124,30 +124,49 @@ namespace MapControl /// public event EventHandler ViewportChanged; + /// + /// Gets or sets the map foreground Brush. + /// public Brush Foreground { get { return (Brush)GetValue(ForegroundProperty); } set { SetValue(ForegroundProperty, value); } } + /// + /// Gets or sets a Brush that (when not null) is used as value of the + /// Foreground property when TileLayer.HasDarkBackground is false. + /// public Brush LightForeground { get { return (Brush)GetValue(LightForegroundProperty); } set { SetValue(LightForegroundProperty, value); } } + /// + /// Gets or sets a Brush that (when not null) is used as value of the + /// Foreground property when TileLayer.HasDarkBackground is true. + /// public Brush DarkForeground { get { return (Brush)GetValue(DarkForegroundProperty); } set { SetValue(DarkForegroundProperty, value); } } + /// + /// Gets or sets a Brush that (when not null) is used as value of the + /// Background property when TileLayer.HasDarkBackground is false. + /// public Brush LightBackground { get { return (Brush)GetValue(LightBackgroundProperty); } set { SetValue(LightBackgroundProperty, value); } } + /// + /// Gets or sets a Brush that (when not null) is used as value of the + /// Background property when TileLayer.HasDarkBackground is true. + /// public Brush DarkBackground { get { return (Brush)GetValue(DarkBackgroundProperty); } diff --git a/MapControl/MapControl.Silverlight.csproj b/MapControl/MapControl.Silverlight.csproj index ef1131e5..0863860f 100644 --- a/MapControl/MapControl.Silverlight.csproj +++ b/MapControl/MapControl.Silverlight.csproj @@ -83,7 +83,6 @@ - diff --git a/MapControl/MapItem.WPF.cs b/MapControl/MapItem.WPF.cs index 6b97f5d9..441f822e 100644 --- a/MapControl/MapItem.WPF.cs +++ b/MapControl/MapItem.WPF.cs @@ -21,6 +21,9 @@ namespace MapControl typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem))); } + /// + /// Gets a value that indicates if the MapItem is the CurrentItem of the containing items collection. + /// public bool IsCurrent { get { return (bool)GetValue(IsCurrentProperty); } diff --git a/MapControl/MapItemsControl.WPF.cs b/MapControl/MapItemsControl.WPF.cs index ff474eb4..4b8daece 100644 --- a/MapControl/MapItemsControl.WPF.cs +++ b/MapControl/MapItemsControl.WPF.cs @@ -33,6 +33,10 @@ namespace MapControl Items.CurrentChanged += OnCurrentItemChanged; } + /// + /// Gets or sets a Geometry that selects all items that lie inside its fill area, + /// i.e. where Geometry.FillContains returns true for the item's viewport position. + /// public Geometry SelectionGeometry { get { return (Geometry)GetValue(SelectionGeometryProperty); } @@ -99,10 +103,11 @@ namespace MapControl private bool IsItemInGeometry(object item, Geometry geometry) { var container = ContainerFromItem(item); + Point? viewportPosition; return container != null && - container.RenderTransform != null && - geometry.FillContains(new Point(container.RenderTransform.Value.OffsetX, container.RenderTransform.Value.OffsetY)); + (viewportPosition = MapPanel.GetViewportPosition(container)).HasValue && + geometry.FillContains(viewportPosition.Value); } } } \ No newline at end of file diff --git a/MapControl/MapPanel.cs b/MapControl/MapPanel.cs index fa303776..f267c596 100644 --- a/MapControl/MapPanel.cs +++ b/MapControl/MapPanel.cs @@ -31,6 +31,9 @@ namespace MapControl public static readonly DependencyProperty LocationProperty = DependencyProperty.RegisterAttached( "Location", typeof(Location), typeof(MapPanel), new PropertyMetadata(null, LocationPropertyChanged)); + public static readonly DependencyProperty ViewportPositionProperty = DependencyProperty.RegisterAttached( + "ViewportPosition", typeof(Point?), typeof(MapPanel), null); + public static Location GetLocation(UIElement element) { return (Location)element.GetValue(LocationProperty); @@ -41,6 +44,11 @@ namespace MapControl element.SetValue(LocationProperty, value); } + public static Point? GetViewportPosition(UIElement element) + { + return (Point?)element.GetValue(ViewportPositionProperty); + } + protected override Size MeasureOverride(Size availableSize) { foreach (UIElement element in Children) @@ -174,21 +182,28 @@ namespace MapControl private static void SetViewportPosition(UIElement element, MapBase parentMap, Location location) { - Transform transform = null; + Point? viewportPosition = null; if (parentMap != null && location != null) { - Point position = parentMap.LocationToViewportPoint(location); - transform = new TranslateTransform { X = position.X, Y = position.Y }; + viewportPosition = parentMap.LocationToViewportPoint(location); + element.SetValue(ViewportPositionProperty, viewportPosition); + } + else + { + element.ClearValue(ViewportPositionProperty); } var transformGroup = element.RenderTransform as TransformGroup; if (transformGroup != null) { - if (transform == null) + var transform = new TranslateTransform(); + + if (viewportPosition.HasValue) { - transform = new TranslateTransform(); + transform.X = viewportPosition.Value.X; + transform.Y = viewportPosition.Value.Y; } var transformIndex = transformGroup.Children.Count - 1; @@ -203,9 +218,13 @@ namespace MapControl transformGroup.Children.Add(transform); } } - else if (transform != null) + else if (viewportPosition.HasValue) { - element.RenderTransform = transform; + element.RenderTransform = new TranslateTransform + { + X = viewportPosition.Value.X, + Y = viewportPosition.Value.Y + }; } else { diff --git a/MapControl/MapPolygon.cs b/MapControl/MapPolygon.cs deleted file mode 100644 index c21e137b..00000000 --- a/MapControl/MapPolygon.cs +++ /dev/null @@ -1,14 +0,0 @@ -// XAML Map Control - http://xamlmapcontrol.codeplex.com/ -// Copyright © 2012 Clemens Fischer -// Licensed under the Microsoft Public License (Ms-PL) - -namespace MapControl -{ - public class MapPolygon : MapPolyline - { - protected override bool IsClosed - { - get { return true; } - } - } -} diff --git a/MapControl/MapPolyline.cs b/MapControl/MapPolyline.cs index c3be1440..9395d278 100644 --- a/MapControl/MapPolyline.cs +++ b/MapControl/MapPolyline.cs @@ -17,23 +17,37 @@ namespace MapControl { public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( "Locations", typeof(LocationCollection), typeof(MapPolyline), - new PropertyMetadata(null, LocationsPropertyChanged)); + new PropertyMetadata(null, (o, e) => ((MapPolyline)o).UpdateGeometry())); + + public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register( + "IsClosed", typeof(bool), typeof(MapPolyline), + new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateGeometry())); protected PathGeometry Geometry = new PathGeometry(); + /// + /// Gets or sets the locations that define the polyline points. + /// public LocationCollection Locations { get { return (LocationCollection)GetValue(LocationsProperty); } set { SetValue(LocationsProperty, value); } } - protected virtual bool IsClosed + /// + /// Gets or sets a value that indicates if the polyline is closed, i.e. is a polygon. + /// + public bool IsClosed { - get { return false; } + get { return (bool)GetValue(IsClosedProperty); } + set { SetValue(IsClosedProperty, value); } } - protected virtual void UpdateGeometry(MapBase parentMap, LocationCollection locations) + protected virtual void UpdateGeometry() { + var parentMap = MapPanel.GetParentMap(this); + var locations = Locations; + if (parentMap != null && locations != null && locations.Count > 0) { var figure = new PathFigure @@ -62,13 +76,7 @@ namespace MapControl void IMapElement.ParentMapChanged(MapBase oldParentMap, MapBase newParentMap) { - UpdateGeometry(newParentMap, Locations); - } - - private static void LocationsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) - { - var polyline = (MapPolyline)obj; - polyline.UpdateGeometry(MapPanel.GetParentMap(polyline), (LocationCollection)e.NewValue); + UpdateGeometry(); } } } diff --git a/MapControl/MapTransform.cs b/MapControl/MapTransform.cs index 6b28c509..9a9c8ad9 100644 --- a/MapControl/MapTransform.cs +++ b/MapControl/MapTransform.cs @@ -11,9 +11,11 @@ using System.Windows; namespace MapControl { /// - /// Defines a normal cylindrical projection. Latitude and longitude values in degrees - /// are transformed to cartesian coordinates with origin at latitude = 0 and longitude = 0. + /// Defines a normal cylindrical projection. Latitude and longitude values in degrees are + /// transformed to cartesian coordinates with origin at latitude = 0 and longitude = 0. /// Longitude values are transformed identically to x values in the interval [-180 .. 180]. + /// Latitude values in the interval [-MaxLatitude .. MaxLatitude] are transformed to y values in + /// the interval [-180 .. 180] according to the actual projection, e.g. the Mercator projection. /// public abstract class MapTransform { diff --git a/MapControl/MercatorTransform.cs b/MapControl/MercatorTransform.cs index 0376d463..3a58b812 100644 --- a/MapControl/MercatorTransform.cs +++ b/MapControl/MercatorTransform.cs @@ -13,7 +13,7 @@ namespace MapControl { /// /// Transforms latitude and longitude values in degrees to cartesian coordinates - /// according to the Mercator transform. + /// according to the Mercator projection. /// public class MercatorTransform : MapTransform { diff --git a/MapControl/WinRT/MapControl.WinRT.csproj b/MapControl/WinRT/MapControl.WinRT.csproj index dbd75e8f..5525621b 100644 --- a/MapControl/WinRT/MapControl.WinRT.csproj +++ b/MapControl/WinRT/MapControl.WinRT.csproj @@ -153,9 +153,6 @@ MapPanel.Silverlight.WinRT.cs - - MapPolygon.cs - MapPolyline.cs