diff --git a/FileDbCache/UWP/Properties/AssemblyInfo.cs b/FileDbCache/UWP/Properties/AssemblyInfo.cs index e28a23e1..9682ea56 100644 --- a/FileDbCache/UWP/Properties/AssemblyInfo.cs +++ b/FileDbCache/UWP/Properties/AssemblyInfo.cs @@ -7,8 +7,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyCompany("Clemens Fischer")] [assembly: AssemblyCopyright("© 2018 Clemens Fischer")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.7.1")] -[assembly: AssemblyFileVersion("4.7.1")] +[assembly: AssemblyVersion("4.8.0")] +[assembly: AssemblyFileVersion("4.8.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/FileDbCache/WPF/Properties/AssemblyInfo.cs b/FileDbCache/WPF/Properties/AssemblyInfo.cs index 50ae554e..9f9ba6fe 100644 --- a/FileDbCache/WPF/Properties/AssemblyInfo.cs +++ b/FileDbCache/WPF/Properties/AssemblyInfo.cs @@ -7,8 +7,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyCompany("Clemens Fischer")] [assembly: AssemblyCopyright("© 2018 Clemens Fischer")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.7.1")] -[assembly: AssemblyFileVersion("4.7.1")] +[assembly: AssemblyVersion("4.8.0")] +[assembly: AssemblyFileVersion("4.8.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/MBTiles/UWP/Properties/AssemblyInfo.cs b/MBTiles/UWP/Properties/AssemblyInfo.cs index 726c3d27..24a51997 100644 --- a/MBTiles/UWP/Properties/AssemblyInfo.cs +++ b/MBTiles/UWP/Properties/AssemblyInfo.cs @@ -7,8 +7,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyCompany("Clemens Fischer")] [assembly: AssemblyCopyright("© 2018 Clemens Fischer")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.7.1")] -[assembly: AssemblyFileVersion("4.7.1")] +[assembly: AssemblyVersion("4.8.0")] +[assembly: AssemblyFileVersion("4.8.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/MBTiles/WPF/Properties/AssemblyInfo.cs b/MBTiles/WPF/Properties/AssemblyInfo.cs index 2079624f..68cd7eb5 100644 --- a/MBTiles/WPF/Properties/AssemblyInfo.cs +++ b/MBTiles/WPF/Properties/AssemblyInfo.cs @@ -7,8 +7,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyCompany("Clemens Fischer")] [assembly: AssemblyCopyright("© 2018 Clemens Fischer")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.7.1")] -[assembly: AssemblyFileVersion("4.7.1")] +[assembly: AssemblyVersion("4.8.0")] +[assembly: AssemblyFileVersion("4.8.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 17e47c74..2c7ab0f6 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -222,7 +222,12 @@ namespace MapControl } /// - /// Gets the scaling transformation from meters to viewport coordinate units at the Center location. + /// Gets the transformation from cartesian map coordinates to viewport coordinates (pixels). + /// + public MatrixTransform ViewportTransform { get; } = new MatrixTransform(); + + /// + /// Gets the scaling transformation from meters to viewport coordinates at the Center location. /// public ScaleTransform ScaleTransform { get; } = new ScaleTransform(); @@ -708,9 +713,12 @@ namespace MapControl } } + ViewportTransform.Matrix = projection.ViewportTransform; + var scale = projection.GetMapScale(center); ScaleTransform.ScaleX = scale.X; ScaleTransform.ScaleY = scale.Y; + RotateTransform.Angle = Heading; OnViewportChanged(new ViewportChangedEventArgs(projectionChanged, Center.Longitude - centerLongitude)); diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index dc3b36df..a7b1878b 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -261,7 +261,7 @@ namespace MapControl var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d); rotation = parentMap.Heading; - viewportPosition = projection.ViewportTransformMatrix.Transform(center); + viewportPosition = projection.ViewportTransform.Transform(center); if (parentMap.MapProjection.IsContinuous && (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width || diff --git a/MapControl/WPF/MapPolygon.WPF.cs b/MapControl/Shared/MapPolygon.cs similarity index 88% rename from MapControl/WPF/MapPolygon.WPF.cs rename to MapControl/Shared/MapPolygon.cs index 839acf2e..a7998eed 100644 --- a/MapControl/WPF/MapPolygon.WPF.cs +++ b/MapControl/Shared/MapPolygon.cs @@ -3,9 +3,14 @@ // Licensed under the Microsoft Public License (Ms-PL) using System.Collections.Generic; +#if WINDOWS_UWP +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; +#else using System.ComponentModel; using System.Windows; using System.Windows.Media; +#endif namespace MapControl { @@ -21,7 +26,9 @@ namespace MapControl /// /// Gets or sets the Locations that define the polygon points. /// +#if !WINDOWS_UWP [TypeConverter(typeof(LocationCollectionConverter))] +#endif public IEnumerable Locations { get { return (IEnumerable)GetValue(LocationsProperty); } @@ -35,7 +42,7 @@ namespace MapControl if (ParentMap != null) { - AddPolylineFigure(figures, Locations, true); + AddPolylineFigures(figures, Locations, true); } } } diff --git a/MapControl/WPF/MapPolyline.WPF.cs b/MapControl/Shared/MapPolyline.cs similarity index 88% rename from MapControl/WPF/MapPolyline.WPF.cs rename to MapControl/Shared/MapPolyline.cs index 2a86b58f..dc67415b 100644 --- a/MapControl/WPF/MapPolyline.WPF.cs +++ b/MapControl/Shared/MapPolyline.cs @@ -3,9 +3,14 @@ // Licensed under the Microsoft Public License (Ms-PL) using System.Collections.Generic; +#if WINDOWS_UWP +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; +#else using System.ComponentModel; using System.Windows; using System.Windows.Media; +#endif namespace MapControl { @@ -21,7 +26,9 @@ namespace MapControl /// /// Gets or sets the Locations that define the polyline points. /// +#if !WINDOWS_UWP [TypeConverter(typeof(LocationCollectionConverter))] +#endif public IEnumerable Locations { get { return (IEnumerable)GetValue(LocationsProperty); } @@ -35,7 +42,7 @@ namespace MapControl if (ParentMap != null) { - AddPolylineFigure(figures, Locations, false); + AddPolylineFigures(figures, Locations, false); } } } diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index 1d6b6706..56d45123 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -59,14 +59,9 @@ namespace MapControl public double MaxLatitude { get; protected set; } = 90d; /// - /// Gets the transformation matrix from cartesian map coordinates to viewport coordinates (pixels). + /// Gets the transform matrix from cartesian map coordinates to viewport coordinates (pixels). /// - public Matrix ViewportTransformMatrix { get; private set; } - - /// - /// Gets the transformation from cartesian map coordinates to viewport coordinates (pixels). - /// - public MatrixTransform ViewportTransform { get; } = new MatrixTransform(); + public Matrix ViewportTransform { get; private set; } /// /// Gets the scaling factor from cartesian map coordinates to viewport coordinates. @@ -114,7 +109,7 @@ namespace MapControl /// public Point LocationToViewportPoint(Location location) { - return ViewportTransformMatrix.Transform(LocationToPoint(location)); + return ViewportTransform.Transform(LocationToPoint(location)); } /// @@ -145,8 +140,7 @@ namespace MapControl var center = LocationToPoint(mapCenter); var matrix = CreateTransformMatrix(center, ViewportScale, -ViewportScale, heading, viewportCenter); - ViewportTransformMatrix = matrix; - ViewportTransform.Matrix = matrix; + ViewportTransform = matrix; matrix.Invert(); inverseViewportTransformMatrix = matrix; diff --git a/MapControl/Shared/MapShape.cs b/MapControl/Shared/MapShape.cs index 467ac2ac..4bb3c0cc 100644 --- a/MapControl/Shared/MapShape.cs +++ b/MapControl/Shared/MapShape.cs @@ -35,7 +35,7 @@ namespace MapControl { if (parentMap != null) { - OnViewportChanged(parentMap, new ViewportChangedEventArgs()); + UpdateData(); } } @@ -58,11 +58,17 @@ namespace MapControl parentMap.ViewportChanged += OnViewportChanged; } - SetDataTransform(); UpdateData(); } } + private void OnViewportChanged(object sender, ViewportChangedEventArgs e) + { + UpdateData(); + } + + protected abstract void UpdateData(); + protected MapShape() : this(new PathGeometry()) { @@ -75,10 +81,6 @@ namespace MapControl MapPanel.InitMapElement(this); } - partial void SetDataTransform(); // WPF only - - protected abstract void UpdateData(); - protected Point LocationToPoint(Location location) { var point = parentMap.MapProjection.LocationToPoint(location); @@ -97,7 +99,7 @@ namespace MapControl protected Point LocationToViewportPoint(Location location) { - return parentMap.MapProjection.ViewportTransformMatrix.Transform(LocationToPoint(location)); + return parentMap.MapProjection.ViewportTransform.Transform(LocationToPoint(location)); } protected double GetLongitudeOffset() diff --git a/MapControl/UWP/MapControl.UWP.csproj b/MapControl/UWP/MapControl.UWP.csproj index 591ec074..338aff06 100644 --- a/MapControl/UWP/MapControl.UWP.csproj +++ b/MapControl/UWP/MapControl.UWP.csproj @@ -97,6 +97,12 @@ MapPanel.cs + + MapPolygon.cs + + + MapPolyline.cs + MapProjection.cs @@ -150,8 +156,6 @@ - - diff --git a/MapControl/UWP/MapPolygon.UWP.cs b/MapControl/UWP/MapPolygon.UWP.cs deleted file mode 100644 index 8bbd439e..00000000 --- a/MapControl/UWP/MapPolygon.UWP.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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 Windows.UI.Xaml; -using Windows.UI.Xaml.Media; - -namespace MapControl -{ - /// - /// A polygon defined by a collection of Locations. - /// - public class MapPolygon : MapShape - { - public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( - nameof(Locations), typeof(IEnumerable), typeof(MapPolygon), - new PropertyMetadata(null, (o, e) => ((MapPolygon)o).LocationsPropertyChanged(e))); - - /// - /// Gets or sets the Locations that define the polyline points. - /// - public IEnumerable Locations - { - get { return (IEnumerable)GetValue(LocationsProperty); } - set { SetValue(LocationsProperty, value); } - } - - protected override void UpdateData() - { - var figures = ((PathGeometry)Data).Figures; - figures.Clear(); - - if (ParentMap != null) - { - AddPolylineFigures(figures, Locations, true); - } - } - } -} diff --git a/MapControl/UWP/MapPolyline.UWP.cs b/MapControl/UWP/MapPolyline.UWP.cs deleted file mode 100644 index 7ac88ce8..00000000 --- a/MapControl/UWP/MapPolyline.UWP.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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 Windows.UI.Xaml; -using Windows.UI.Xaml.Media; - -namespace MapControl -{ - /// - /// A polyline defined by a collection of Locations. - /// - public class MapPolyline : MapShape - { - public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( - nameof(Locations), typeof(IEnumerable), typeof(MapPolyline), - new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsPropertyChanged(e))); - - /// - /// Gets or sets the Locations that define the polyline points. - /// - public IEnumerable Locations - { - get { return (IEnumerable)GetValue(LocationsProperty); } - set { SetValue(LocationsProperty, value); } - } - - protected override void UpdateData() - { - var figures = ((PathGeometry)Data).Figures; - figures.Clear(); - - if (ParentMap != null) - { - AddPolylineFigures(figures, Locations, false); - } - } - } -} diff --git a/MapControl/UWP/MapShape.UWP.cs b/MapControl/UWP/MapShape.UWP.cs index a052dc70..54ea79fd 100644 --- a/MapControl/UWP/MapShape.UWP.cs +++ b/MapControl/UWP/MapShape.UWP.cs @@ -14,40 +14,33 @@ namespace MapControl { public abstract partial class MapShape : Path { - private void OnViewportChanged(object sender, ViewportChangedEventArgs e) + protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { UpdateData(); } - protected void LocationsPropertyChanged(DependencyPropertyChangedEventArgs e) + protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) { INotifyCollectionChanged collection; if ((collection = e.OldValue as INotifyCollectionChanged) != null) { - collection.CollectionChanged -= LocationCollectionChanged; + collection.CollectionChanged -= DataCollectionChanged; } if ((collection = e.NewValue as INotifyCollectionChanged) != null) { - collection.CollectionChanged += LocationCollectionChanged; + collection.CollectionChanged += DataCollectionChanged; } UpdateData(); } - protected void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - UpdateData(); - } - protected void AddPolylineFigures(PathFigureCollection figures, IEnumerable locations, bool closed) { if (locations != null && locations.Count() >= 2) { - var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height); var offset = GetLongitudeOffset(); - if (offset != 0d) { locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset)); @@ -59,6 +52,7 @@ namespace MapControl points.Add(points[0]); } + var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height); PathFigure figure = null; PolyLineSegment segment = null; diff --git a/MapControl/UWP/Properties/AssemblyInfo.cs b/MapControl/UWP/Properties/AssemblyInfo.cs index 44a37f24..1903f2b0 100644 --- a/MapControl/UWP/Properties/AssemblyInfo.cs +++ b/MapControl/UWP/Properties/AssemblyInfo.cs @@ -7,8 +7,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyCompany("Clemens Fischer")] [assembly: AssemblyCopyright("© 2018 Clemens Fischer")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.7.1")] -[assembly: AssemblyFileVersion("4.7.1")] +[assembly: AssemblyVersion("4.8.0")] +[assembly: AssemblyFileVersion("4.8.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] diff --git a/MapControl/WPF/MapControl.WPF.csproj b/MapControl/WPF/MapControl.WPF.csproj index 1b838a51..8bf4be89 100644 --- a/MapControl/WPF/MapControl.WPF.csproj +++ b/MapControl/WPF/MapControl.WPF.csproj @@ -116,6 +116,12 @@ MapPanel.cs + + MapPolygon.cs + + + MapPolyline.cs + MapProjection.cs @@ -171,8 +177,6 @@ - - diff --git a/MapControl/WPF/MapMultiPolygon.WPF.cs b/MapControl/WPF/MapMultiPolygon.WPF.cs index 85f3136b..7410aacc 100644 --- a/MapControl/WPF/MapMultiPolygon.WPF.cs +++ b/MapControl/WPF/MapMultiPolygon.WPF.cs @@ -40,7 +40,7 @@ namespace MapControl { foreach (var polygon in Polygons) { - AddPolylineFigure(figures, polygon, true); + AddPolylineFigures(figures, polygon, true); } } } diff --git a/MapControl/WPF/MapShape.WPF.cs b/MapControl/WPF/MapShape.WPF.cs index 4b90960e..8b770af7 100644 --- a/MapControl/WPF/MapShape.WPF.cs +++ b/MapControl/WPF/MapShape.WPF.cs @@ -21,50 +21,9 @@ namespace MapControl get { return Data; } } - partial void SetDataTransform() - { - if (parentMap != null) - { - var transform = new TransformGroup(); - var offsetX = GetLongitudeOffset() * parentMap.MapProjection.TrueScale; - - transform.Children.Add(new TranslateTransform(offsetX, 0d)); - transform.Children.Add(parentMap.MapProjection.ViewportTransform); - - Data.Transform = transform; - } - else - { - Data.Transform = Transform.Identity; - } - } - - 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 - } - } - bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e) { UpdateData(); - return true; } @@ -85,11 +44,17 @@ namespace MapControl UpdateData(); } - protected void AddPolylineFigure(PathFigureCollection figures, IEnumerable locations, bool closed) + protected void AddPolylineFigures(PathFigureCollection figures, IEnumerable locations, bool closed) { if (locations != null && locations.Count() >= 2) { - var points = locations.Select(loc => LocationToPoint(loc)); + var offset = GetLongitudeOffset(); + if (offset != 0d) + { + locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset)); + } + + var points = locations.Select(loc => LocationToViewportPoint(loc)); var figure = new PathFigure { StartPoint = points.First(), diff --git a/MapControl/WPF/Properties/AssemblyInfo.cs b/MapControl/WPF/Properties/AssemblyInfo.cs index 0f813a52..d811e385 100644 --- a/MapControl/WPF/Properties/AssemblyInfo.cs +++ b/MapControl/WPF/Properties/AssemblyInfo.cs @@ -8,8 +8,8 @@ using System.Windows; [assembly: AssemblyCompany("Clemens Fischer")] [assembly: AssemblyCopyright("© 2018 Clemens Fischer")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.7.1")] -[assembly: AssemblyFileVersion("4.7.1")] +[assembly: AssemblyVersion("4.8.0")] +[assembly: AssemblyFileVersion("4.8.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)]