Version 4.4.0: Fixed MapPolyline performance on UWP. Added MapPolygon and MapMultiPolygon for WPF.

This commit is contained in:
ClemensF 2018-02-09 17:43:47 +01:00
parent cce5d6e0b4
commit d1552506f6
80 changed files with 673 additions and 550 deletions

View file

@ -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;

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("IImageCache implementation based on EzTools FileDb")]
[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)]

View file

@ -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 FileDbNs;

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("ObjectCache implementation based on EzTools FileDb")]
[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)]

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("MBTiles Support Library for XAML Map Control")]
[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)]

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("MBTiles Support Library for XAML Map Control")]
[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)]

View file

@ -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;

View file

@ -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;
@ -21,13 +21,8 @@ namespace MapControl
public AzimuthalProjection()
{
IsContinuous = false;
IsAzimuthal = true;
LongitudeScale = double.NaN;
}
public override double GetViewportScale(double zoomLevel)
{
return DegreesToViewportScale(zoomLevel) / MetersPerDegree;
}
public override Point GetMapScale(Location location)
@ -37,7 +32,7 @@ namespace MapControl
public override Location TranslateLocation(Location location, Point translation)
{
var scaleY = ViewportScale * MetersPerDegree;
var scaleY = ViewportScale * TrueScale;
var scaleX = scaleY * Math.Cos(location.Latitude * Math.PI / 180d);
return new Location(
@ -112,7 +107,7 @@ namespace MapControl
var cosDistance = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosLon12;
azimuth = Math.Atan2(sinLon12, cosLat1 * sinLat2 / cosLat2 - sinLat1 * cosLon12);
distance = Math.Acos(Math.Max(Math.Min(cosDistance, 1d), -1d));
distance = Math.Acos(Math.Min(Math.Max(cosDistance, -1d), 1d));
}
/// <summary>
@ -128,10 +123,10 @@ namespace MapControl
var cosLat1 = Math.Cos(lat1);
var sinLat1 = Math.Sin(lat1);
var sinLat2 = sinLat1 * cosDistance + cosLat1 * sinDistance * cosAzimuth;
var lat2 = Math.Asin(Math.Max(Math.Min(sinLat2, 1d), -1d));
var lat2 = Math.Asin(Math.Min(Math.Max(sinLat2, -1d), 1d));
var dLon = Math.Atan2(sinDistance * sinAzimuth, cosLat1 * cosDistance - sinLat1 * sinDistance * cosAzimuth);
return new Location(180d / Math.PI * lat2, location.Longitude + 180d / Math.PI * dLon);
return new Location(lat2 * 180d / Math.PI, location.Longitude + dLon * 180d / Math.PI);
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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)
namespace MapControl

View file

@ -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;
@ -20,6 +20,7 @@ namespace MapControl
public EquirectangularProjection()
: this("EPSG:4326")
{
TrueScale = 1;
}
public EquirectangularProjection(string crsId)

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -1,18 +1,17 @@
// 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;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace MapControl
{
/// <summary>
/// An ObservableCollection of Location with support for parsing.
/// A collection of Locations with support for parsing.
/// </summary>
public partial class LocationCollection : ObservableCollection<Location>
public partial class LocationCollection : List<Location>
{
public LocationCollection()
{
@ -23,7 +22,7 @@ namespace MapControl
{
}
public LocationCollection(List<Location> locations)
public LocationCollection(params Location[] locations)
: base(locations)
{
}

View file

@ -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;
@ -291,8 +291,8 @@ namespace MapControl
{
if (Heading != 0d)
{
var cos = Math.Cos(Heading / 180d * Math.PI);
var sin = Math.Sin(Heading / 180d * Math.PI);
var cos = Math.Cos(Heading * Math.PI / 180d);
var sin = Math.Sin(Heading * Math.PI / 180d);
translation = new Point(
translation.X * cos + translation.Y * sin,
@ -352,7 +352,7 @@ namespace MapControl
{
SetTransformCenter(center);
if (double.IsNaN(MapProjection.LongitudeScale))
if (MapProjection.IsAzimuthal)
{
ZoomLevel = zoomLevel;
ResetTransformCenter();
@ -374,13 +374,10 @@ namespace MapControl
{
var rect = MapProjection.BoundingBoxToRect(boundingBox);
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var scale0 = 1d / MapProjection.GetViewportScale(0d);
var lonScale = scale0 * RenderSize.Width / rect.Width;
var latScale = scale0 * RenderSize.Height / rect.Height;
var lonZoom = Math.Log(lonScale, 2d);
var latZoom = Math.Log(latScale, 2d);
var scale = Math.Min(RenderSize.Width / rect.Width, RenderSize.Height / rect.Height)
* MapProjection.TrueScale / MapProjection.PixelPerDegree;
TargetZoomLevel = Math.Min(lonZoom, latZoom);
TargetZoomLevel = Math.Log(scale, 2d);
TargetCenter = MapProjection.PointToLocation(center);
TargetHeading = 0d;
}
@ -479,6 +476,10 @@ namespace MapControl
if (!targetCenter.Equals(Center))
{
var targetCenterLongitude = MapProjection.IsContinuous
? Location.NearestLongitude(targetCenter.Longitude, Center.Longitude)
: targetCenter.Longitude;
if (centerAnimation != null)
{
centerAnimation.Completed -= CenterAnimationCompleted;
@ -487,7 +488,7 @@ namespace MapControl
centerAnimation = new PointAnimation
{
From = new Point(Center.Longitude, Center.Latitude),
To = new Point(Location.NearestLongitude(targetCenter.Longitude, Center.Longitude), targetCenter.Latitude),
To = new Point(targetCenterLongitude, targetCenter.Latitude),
Duration = AnimationDuration,
EasingFunction = AnimationEasingFunction
};

View file

@ -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;
@ -30,7 +30,8 @@ namespace MapControl
private double GetLineDistance()
{
var minDistance = MinLineDistance / MapProjection.DegreesToViewportScale(ParentMap.ZoomLevel);
var pixelPerDegree = ParentMap.MapProjection.ViewportScale * ParentMap.MapProjection.TrueScale;
var minDistance = MinLineDistance / pixelPerDegree;
var scale = 1d;
if (minDistance < 1d)

View file

@ -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;
@ -23,7 +23,7 @@ namespace MapControl
{
/// <summary>
/// Map image layer. Fills the entire viewport with a map image, e.g. provided by a Web Map Service (WMS).
/// The image must be provided by the abstract UpdateImage(BoundingBox) method.
/// The image must be provided by the abstract GetImageAsync method.
/// </summary>
public abstract class MapImageLayer : MapPanel, IMapLayer
{
@ -71,7 +71,7 @@ namespace MapControl
Children.Add(new Image { Opacity = 0d, Stretch = Stretch.Fill });
updateTimer = new DispatcherTimer { Interval = UpdateInterval };
updateTimer.Tick += async (s, e) => await UpdateImage();
updateTimer.Tick += async (s, e) => await UpdateImageAsync();
}
/// <summary>
@ -181,7 +181,7 @@ namespace MapControl
/// <summary>
/// Returns an ImageSource for the specified bounding box.
/// </summary>
protected abstract Task<ImageSource> GetImage(BoundingBox boundingBox);
protected abstract Task<ImageSource> GetImageAsync(BoundingBox boundingBox);
protected override void OnViewportChanged(ViewportChangedEventArgs e)
{
@ -191,7 +191,7 @@ namespace MapControl
base.OnViewportChanged(e);
var task = UpdateImage();
var task = UpdateImageAsync();
}
else
{
@ -211,7 +211,7 @@ namespace MapControl
}
}
protected virtual async Task UpdateImage()
protected virtual async Task UpdateImageAsync()
{
updateTimer.Stop();
@ -231,7 +231,7 @@ namespace MapControl
{
try
{
imageSource = await GetImage(boundingBox);
imageSource = await GetImageAsync(boundingBox);
}
catch (Exception ex)
{

View file

@ -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)
#if WINDOWS_UWP

View file

@ -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)
#if WINDOWS_UWP

View file

@ -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;
@ -203,8 +203,9 @@ namespace MapControl
{
viewportPosition = parentMap.MapProjection.LocationToViewportPoint(location);
if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
if (parentMap.MapProjection.IsContinuous &&
(viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height))
{
viewportPosition = parentMap.MapProjection.LocationToViewportPoint(new Location(
location.Latitude,
@ -262,8 +263,9 @@ namespace MapControl
rotation = parentMap.Heading;
viewportPosition = projection.ViewportTransform.Transform(center);
if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
if (parentMap.MapProjection.IsContinuous &&
(viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height))
{
var location = projection.PointToLocation(center);
location.Longitude = Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude);

View file

@ -1,117 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if WINDOWS_UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
{
/// <summary>
/// Base class for map shapes. The shape geometry is given by the Data property,
/// which must contain a Geometry defined in cartesian (projected) map coordinates.
/// Optionally, the Location property can by set to adjust the viewport position to the
/// visible map viewport, as done for elements where the MapPanel.Location property is set.
/// </summary>
public partial class MapPath : IMapElement
{
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(MapPath),
new PropertyMetadata(null, (o, e) => ((MapPath)o).LocationPropertyChanged()));
public MapPath()
{
MapPanel.InitMapElement(this);
}
public Location Location
{
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
private readonly TransformGroup viewportTransform = new TransformGroup();
private MapBase parentMap;
public MapBase ParentMap
{
get { return parentMap; }
set
{
if (parentMap != null)
{
parentMap.ViewportChanged -= OnViewportChanged;
}
viewportTransform.Children.Clear();
parentMap = value;
if (parentMap != null)
{
viewportTransform.Children.Add(new TranslateTransform());
viewportTransform.Children.Add(parentMap.MapProjection.ViewportTransform);
parentMap.ViewportChanged += OnViewportChanged;
}
UpdateData();
}
}
protected virtual void UpdateData()
{
}
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
double longitudeScale = parentMap.MapProjection.LongitudeScale;
if (e.ProjectionChanged)
{
viewportTransform.Children[1] = parentMap.MapProjection.ViewportTransform;
}
if (e.ProjectionChanged || double.IsNaN(longitudeScale))
{
UpdateData();
}
if (!double.IsNaN(longitudeScale)) // a normal cylindrical projection
{
var longitudeOffset = 0d;
if (Location != null)
{
var viewportPosition = parentMap.MapProjection.LocationToViewportPoint(Location);
if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
{
var nearestLongitude = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude);
longitudeOffset = longitudeScale * (nearestLongitude - Location.Longitude);
}
}
((TranslateTransform)viewportTransform.Children[0]).X = longitudeOffset;
}
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
OnViewportChanged(e);
}
private void LocationPropertyChanged()
{
if (parentMap != null)
{
OnViewportChanged(new ViewportChangedEventArgs());
}
}
}
}

View file

@ -1,71 +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.Collections.Generic;
using System.Collections.Specialized;
#if WINDOWS_UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
{
/// <summary>
/// A polyline or polygon created from a collection of Locations.
/// </summary>
public partial class MapPolyline : MapPath
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsPropertyChanged(e)));
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
nameof(IsClosed), typeof(bool), typeof(MapPolyline),
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateData()));
/// <summary>
/// Gets or sets a value that indicates if the polyline is closed, i.e. is a polygon.
/// </summary>
public bool IsClosed
{
get { return (bool)GetValue(IsClosedProperty); }
set { SetValue(IsClosedProperty, value); }
}
/// <summary>
/// Gets or sets the FillRule of the PathGeometry that represents the polyline.
/// </summary>
public FillRule FillRule
{
get { return (FillRule)GetValue(FillRuleProperty); }
set { SetValue(FillRuleProperty, value); }
}
private void LocationsPropertyChanged(DependencyPropertyChangedEventArgs e)
{
var oldCollection = e.OldValue as INotifyCollectionChanged;
var newCollection = e.NewValue as INotifyCollectionChanged;
if (oldCollection != null)
{
oldCollection.CollectionChanged -= LocationCollectionChanged;
}
if (newCollection != null)
{
newCollection.CollectionChanged += LocationCollectionChanged;
}
UpdateData();
}
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateData();
}
}
}

View file

@ -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;
@ -19,21 +19,11 @@ namespace MapControl
/// </summary>
public abstract class MapProjection
{
public const double Wgs84EquatorialRadius = 6378137d;
public const double Wgs84Flattening = 1d / 298.257223563;
public static readonly double Wgs84Eccentricity = Math.Sqrt((2d - Wgs84Flattening) * Wgs84Flattening);
public const double MetersPerDegree = Wgs84EquatorialRadius * Math.PI / 180d;
public const int TileSize = 256;
public const double PixelPerDegree = TileSize / 360d;
/// <summary>
/// Gets the scaling factor from cartesian map coordinates in degrees to viewport coordinates for the specified zoom level.
/// </summary>
public static double DegreesToViewportScale(double zoomLevel)
{
return Math.Pow(2d, zoomLevel) * TileSize / 360d;
}
public const double Wgs84EquatorialRadius = 6378137d;
public const double MetersPerDegree = Wgs84EquatorialRadius * Math.PI / 180d;
/// <summary>
/// Gets or sets the WMS 1.3.0 CRS Identifier.
@ -41,9 +31,9 @@ namespace MapControl
public string CrsId { get; set; }
/// <summary>
/// Indicates if this is a web mercator projection, i.e. compatible with MapTileLayer.
/// Indicates if the map can be moved infinitely in longitudinal direction.
/// </summary>
public bool IsWebMercator { get; protected set; } = false;
public bool IsContinuous { get; protected set; } = true;
/// <summary>
/// Indicates if this is an azimuthal projection.
@ -51,33 +41,30 @@ namespace MapControl
public bool IsAzimuthal { get; protected set; } = false;
/// <summary>
/// Gets the scale factor from longitude to x values of a normal cylindrical projection.
/// Returns NaN if this is not a normal cylindrical projection.
/// Indicates if this is a web mercator projection, i.e. compatible with MapTileLayer.
/// </summary>
public double LongitudeScale { get; protected set; } = 1d;
public bool IsWebMercator { get; protected set; } = false;
/// <summary>
/// Gets the scale factor from geographic to cartesian coordinates, on the line of true scale
/// of a cylindrical projection, or at the projection center of an azimuthal projection.
/// </summary>
public double TrueScale { get; protected set; } = MetersPerDegree;
/// <summary>
/// Gets the absolute value of the minimum and maximum latitude that can be transformed.
/// </summary>
public double MaxLatitude { get; protected set; } = 90d;
/// <summary>
/// Gets the scaling factor from cartesian map coordinates to viewport coordinates.
/// </summary>
public double ViewportScale { get; protected set; }
/// <summary>
/// Gets the transformation from cartesian map coordinates to viewport coordinates (pixels).
/// </summary>
public MatrixTransform ViewportTransform { get; } = new MatrixTransform();
/// <summary>
/// Gets the scaling factor from cartesian map coordinates to viewport coordinates for the specified zoom level.
/// Gets the scaling factor from cartesian map coordinates to viewport coordinates.
/// </summary>
public virtual double GetViewportScale(double zoomLevel)
{
return DegreesToViewportScale(zoomLevel);
}
public double ViewportScale { get; protected set; }
/// <summary>
/// Gets the map scale at the specified Location as viewport coordinate units per meter (px/m).
@ -149,7 +136,7 @@ namespace MapControl
/// </summary>
public virtual void SetViewportTransform(Location projectionCenter, Location mapCenter, Point viewportCenter, double zoomLevel, double heading)
{
ViewportScale = GetViewportScale(zoomLevel);
ViewportScale = Math.Pow(2d, zoomLevel) * PixelPerDegree / TrueScale;
var center = LocationToPoint(mapCenter);

View file

@ -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;

View file

@ -0,0 +1,111 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if WINDOWS_UWP
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
{
/// <summary>
/// Base class for MapPolyline and MapPolygon.
/// </summary>
public abstract partial class MapShape : IMapElement
{
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(MapShape),
new PropertyMetadata(null, (o, e) => ((MapShape)o).LocationPropertyChanged()));
/// <summary>
/// Gets or sets an optional Location to constrain the viewport position to the visible
/// map viewport, as done for elements where the MapPanel.Location property is set.
/// </summary>
public Location Location
{
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
private MapBase parentMap;
public MapBase ParentMap
{
get { return parentMap; }
set
{
if (parentMap != null)
{
parentMap.ViewportChanged -= OnViewportChanged;
}
parentMap = value;
if (parentMap != null)
{
parentMap.ViewportChanged += OnViewportChanged;
}
ParentMapChanged();
}
}
protected MapShape()
{
Data = new PathGeometry();
MapPanel.InitMapElement(this);
}
protected abstract void UpdateData();
protected Point LocationToPoint(Location location)
{
var point = parentMap.MapProjection.LocationToPoint(location);
if (point.Y == double.PositiveInfinity)
{
point.Y = 1e9;
}
else if (point.X == double.NegativeInfinity)
{
point.Y = -1e9;
}
return point;
}
protected double GetLongitudeOffset()
{
var longitudeOffset = 0d;
if (parentMap.MapProjection.IsContinuous && Location != null)
{
var viewportPosition = parentMap.MapProjection.LocationToViewportPoint(Location);
if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)
{
var nearestLongitude = Location.NearestLongitude(Location.Longitude, parentMap.Center.Longitude);
longitudeOffset = nearestLongitude - Location.Longitude;
}
}
return longitudeOffset;
}
private void LocationPropertyChanged()
{
if (parentMap != null)
{
OnViewportChanged(parentMap, new ViewportChangedEventArgs());
}
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -0,0 +1,74 @@
// 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.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Windows;
namespace MapControl
{
/// <summary>
/// An ObservableCollection of IEnumerable of Location. PolygonCollection adds a CollectionChanged
/// listener to each element that implements INotifyCollectionChanged and, when such an element changes,
/// fires its own CollectionChanged event with NotifyCollectionChangedAction.Replace for that element.
/// </summary>
public class PolygonCollection : ObservableCollection<IEnumerable<Location>>, IWeakEventListener
{
protected override void InsertItem(int index, IEnumerable<Location> polygon)
{
var observablePolygon = polygon as INotifyCollectionChanged;
if (observablePolygon != null)
{
CollectionChangedEventManager.AddListener(observablePolygon, this);
}
base.InsertItem(index, polygon);
}
protected override void SetItem(int index, IEnumerable<Location> polygon)
{
var observablePolygon = this[index] as INotifyCollectionChanged;
if (observablePolygon != null)
{
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
}
base.SetItem(index, polygon);
}
protected override void RemoveItem(int index)
{
var observablePolygon = this[index] as INotifyCollectionChanged;
if (observablePolygon != null)
{
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
}
base.RemoveItem(index);
}
protected override void ClearItems()
{
foreach (var observablePolygon in this.OfType<INotifyCollectionChanged>())
{
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
}
base.ClearItems();
}
bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, sender, sender));
return true;
}
}
}

View file

@ -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)
#if WINDOWS_UWP
@ -21,5 +21,11 @@ namespace MapControl
MapPanel.InitMapElement(this);
}
public Location Location
{
get { return MapPanel.GetLocation(this); }
set { MapPanel.SetLocation(this, value); }
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
@ -13,7 +13,7 @@ namespace MapControl
{
/// <summary>
/// Transforms map coordinates according to the Web (or Pseudo) Mercator Projection, EPSG:3857.
/// Longitude values are transformed linearly to X values in meters, by multiplying with MetersPerDegree.
/// Longitude values are transformed linearly to X values in meters, by multiplying with TrueScale.
/// Latitude values in the interval [-MaxLatitude .. MaxLatitude] are transformed to Y values in meters
/// in the interval [-R*pi .. R*pi], R=Wgs84EquatorialRadius.
/// </summary>
@ -28,15 +28,9 @@ namespace MapControl
{
CrsId = crsId;
IsWebMercator = true;
LongitudeScale = MetersPerDegree;
MaxLatitude = YToLatitude(180d);
}
public override double GetViewportScale(double zoomLevel)
{
return DegreesToViewportScale(zoomLevel) / MetersPerDegree;
}
public override Point GetMapScale(Location location)
{
var scale = ViewportScale / Math.Cos(location.Latitude * Math.PI / 180d);
@ -47,20 +41,20 @@ namespace MapControl
public override Point LocationToPoint(Location location)
{
return new Point(
MetersPerDegree * location.Longitude,
MetersPerDegree * LatitudeToY(location.Latitude));
TrueScale * location.Longitude,
TrueScale * LatitudeToY(location.Latitude));
}
public override Location PointToLocation(Point point)
{
return new Location(
YToLatitude(point.Y / MetersPerDegree),
point.X / MetersPerDegree);
YToLatitude(point.Y / TrueScale),
point.X / TrueScale);
}
public override Location TranslateLocation(Location location, Point translation)
{
var scaleX = MetersPerDegree * ViewportScale;
var scaleX = TrueScale * ViewportScale;
var scaleY = scaleX / Math.Cos(location.Latitude * Math.PI / 180d);
return new Location(
@ -70,9 +64,17 @@ namespace MapControl
public static double LatitudeToY(double latitude)
{
return latitude <= -90d ? double.NegativeInfinity
: latitude >= 90d ? double.PositiveInfinity
: Math.Log(Math.Tan((latitude + 90d) * Math.PI / 360d)) / Math.PI * 180d;
if (latitude <= -90d)
{
return double.NegativeInfinity;
}
if (latitude >= 90d)
{
return double.PositiveInfinity;
}
return Math.Log(Math.Tan((latitude + 90d) * Math.PI / 360d)) / Math.PI * 180d;
}
public static double YToLatitude(double y)

View file

@ -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;
@ -23,27 +23,27 @@ namespace MapControl
{
public static readonly DependencyProperty ServerUriProperty = DependencyProperty.Register(
nameof(ServerUri), typeof(Uri), typeof(WmsImageLayer),
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateImage()));
new PropertyMetadata(null, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
public static readonly DependencyProperty VersionProperty = DependencyProperty.Register(
nameof(Version), typeof(string), typeof(WmsImageLayer),
new PropertyMetadata("1.3.0", async (o, e) => await ((WmsImageLayer)o).UpdateImage()));
new PropertyMetadata("1.3.0", async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
public static readonly DependencyProperty LayersProperty = DependencyProperty.Register(
nameof(Layers), typeof(string), typeof(WmsImageLayer),
new PropertyMetadata(string.Empty, async (o, e) => await ((WmsImageLayer)o).UpdateImage()));
new PropertyMetadata(string.Empty, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
public static readonly DependencyProperty StylesProperty = DependencyProperty.Register(
nameof(Styles), typeof(string), typeof(WmsImageLayer),
new PropertyMetadata(string.Empty, async (o, e) => await ((WmsImageLayer)o).UpdateImage()));
new PropertyMetadata(string.Empty, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
public static readonly DependencyProperty FormatProperty = DependencyProperty.Register(
nameof(Format), typeof(string), typeof(WmsImageLayer),
new PropertyMetadata("image/png", async (o, e) => await ((WmsImageLayer)o).UpdateImage()));
new PropertyMetadata("image/png", async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
public static readonly DependencyProperty TransparentProperty = DependencyProperty.Register(
nameof(Transparent), typeof(bool), typeof(WmsImageLayer),
new PropertyMetadata(false, async (o, e) => await ((WmsImageLayer)o).UpdateImage()));
new PropertyMetadata(false, async (o, e) => await ((WmsImageLayer)o).UpdateImageAsync()));
private string layers = string.Empty;
@ -83,7 +83,7 @@ namespace MapControl
set { SetValue(TransparentProperty, value); }
}
protected override async Task<ImageSource> GetImage(BoundingBox boundingBox)
protected override async Task<ImageSource> GetImageAsync(BoundingBox boundingBox)
{
ImageSource imageSource = null;
@ -94,8 +94,11 @@ namespace MapControl
if (!string.IsNullOrEmpty(projectionParameters))
{
var uri = GetRequestUri("GetMap"
+ "&LAYERS=" + Layers + "&STYLES=" + Styles + "&FORMAT=" + Format
+ "&TRANSPARENT=" + (Transparent ? "TRUE" : "FALSE") + "&" + projectionParameters);
+ "&LAYERS=" + Layers
+ "&STYLES=" + Styles
+ "&FORMAT=" + Format
+ "&TRANSPARENT=" + (Transparent ? "TRUE" : "FALSE")
+ "&" + projectionParameters);
try
{

View file

@ -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;
@ -13,12 +13,15 @@ namespace MapControl
{
/// <summary>
/// Transforms map coordinates according to the "World Mercator" Projection, EPSG:3395.
/// Longitude values are transformed linearly to X values in meters, by multiplying with MetersPerDegree.
/// Longitude values are transformed linearly to X values in meters, by multiplying with TrueScale.
/// Latitude values are transformed according to the elliptical versions of the Mercator equations,
/// as shown in "Map Projections - A Working Manual" (https://pubs.usgs.gov/pp/1395/report.pdf), p.44.
/// </summary>
public class WorldMercatorProjection : MapProjection
{
public const double Wgs84Flattening = 1d / 298.257223563;
public static readonly double Wgs84Eccentricity = Math.Sqrt((2d - Wgs84Flattening) * Wgs84Flattening);
public static double MinLatitudeDelta = 1d / Wgs84EquatorialRadius; // corresponds to 1 meter
public static int MaxIterations = 10;
@ -30,15 +33,9 @@ namespace MapControl
public WorldMercatorProjection(string crsId)
{
CrsId = crsId;
LongitudeScale = MetersPerDegree;
MaxLatitude = YToLatitude(180d);
}
public override double GetViewportScale(double zoomLevel)
{
return DegreesToViewportScale(zoomLevel) / MetersPerDegree;
}
public override Point GetMapScale(Location location)
{
var lat = location.Latitude * Math.PI / 180d;
@ -51,20 +48,20 @@ namespace MapControl
public override Point LocationToPoint(Location location)
{
return new Point(
MetersPerDegree * location.Longitude,
MetersPerDegree * LatitudeToY(location.Latitude));
TrueScale * location.Longitude,
TrueScale * LatitudeToY(location.Latitude));
}
public override Location PointToLocation(Point point)
{
return new Location(
YToLatitude(point.Y / MetersPerDegree),
point.X / MetersPerDegree);
YToLatitude(point.Y / TrueScale),
point.X / TrueScale);
}
public override Location TranslateLocation(Location location, Point translation)
{
var scaleX = MetersPerDegree * ViewportScale;
var scaleX = TrueScale * ViewportScale;
var scaleY = scaleX / Math.Cos(location.Latitude * Math.PI / 180d);
return new Location(

View file

@ -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 Windows.Foundation;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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 Windows.Foundation;

View file

@ -91,18 +91,15 @@
<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>
@ -147,8 +144,8 @@
<Compile Include="MapGraticule.UWP.cs" />
<Compile Include="MapOverlay.UWP.cs" />
<Compile Include="MapPanel.UWP.cs" />
<Compile Include="MapPath.UWP.cs" />
<Compile Include="MapPolyline.UWP.cs" />
<Compile Include="MapShape.UWP.cs" />
<Compile Include="MatrixEx.UWP.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tile.UWP.cs" />

View file

@ -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;
@ -28,7 +28,7 @@ namespace MapControl
{
var projection = ParentMap.MapProjection;
if (!double.IsNaN(projection.LongitudeScale))
if (!projection.IsAzimuthal)
{
if (path == null)
{

View file

@ -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 Windows.UI.Text;

View file

@ -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 Windows.UI.Xaml;

View file

@ -1,41 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.Foundation;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace MapControl
{
public partial class MapPath : Path
{
private Geometry data;
protected override Size MeasureOverride(Size availableSize)
{
if (Stretch != Stretch.None)
{
Stretch = Stretch.None;
}
// Workaround for missing PropertyChangedCallback for the Data property.
if (data != Data)
{
if (data != null)
{
data.ClearValue(Geometry.TransformProperty);
}
data = Data;
if (data != null)
{
data.Transform = viewportTransform;
}
}
return new Size();
}
}
}

View file

@ -1,28 +1,26 @@
// 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;
using System.Collections.Specialized;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.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 PropertyMetadata(FillRule.EvenOdd, (o, e) => ((PathGeometry)((MapPolyline)o).Data).FillRule = (FillRule)e.NewValue));
public MapPolyline()
{
Data = new PathGeometry();
}
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsPropertyChanged(e)));
/// <summary>
/// Gets or sets the locations that define the polyline points.
/// Gets or sets the Locations that define the polyline points.
/// </summary>
public IEnumerable<Location> Locations
{
@ -37,25 +35,67 @@ namespace MapControl
if (ParentMap != null && Locations != null && Locations.Any())
{
var points = Locations.Select(l => ParentMap.MapProjection.LocationToPoint(l));
PathFigure figure = null;
PolyLineSegment segment = null;
var size = ParentMap.RenderSize;
var offset = GetLongitudeOffset();
var locations = Locations;
var figure = new PathFigure
if (offset != 0d)
{
StartPoint = points.First(),
IsClosed = IsClosed,
IsFilled = IsClosed
};
var segment = new PolyLineSegment();
foreach (var point in points.Skip(1))
{
segment.Points.Add(point);
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
}
figure.Segments.Add(segment);
geometry.Figures.Add(figure);
var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc));
var p1 = points.First();
foreach (var p2 in points.Skip(1))
{
if ((p1.X <= 0 && p2.X <= 0) || (p1.X >= size.Width && p2.X >= size.Width) ||
(p1.Y <= 0 && p2.Y <= 0) || (p1.Y >= size.Height && p2.Y >= size.Height))
{
// line (p1,p2) is out of visible bounds, end figure
figure = null;
}
else
{
if (figure == null)
{
figure = new PathFigure { StartPoint = p1, IsClosed = false, IsFilled = false };
segment = new PolyLineSegment();
figure.Segments.Add(segment);
geometry.Figures.Add(figure);
}
segment.Points.Add(p2);
}
p1 = p2;
}
}
}
private void LocationsPropertyChanged(DependencyPropertyChangedEventArgs e)
{
var oldCollection = e.OldValue as INotifyCollectionChanged;
var newCollection = e.NewValue as INotifyCollectionChanged;
if (oldCollection != null)
{
oldCollection.CollectionChanged -= LocationCollectionChanged;
}
if (newCollection != null)
{
newCollection.CollectionChanged += LocationCollectionChanged;
}
UpdateData();
}
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateData();
}
}
}

View file

@ -0,0 +1,21 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.UI.Xaml.Shapes;
namespace MapControl
{
public abstract partial class MapShape : Path
{
private void ParentMapChanged()
{
UpdateData();
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
UpdateData();
}
}
}

View file

@ -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;

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[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)]

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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" />

View file

@ -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));

View 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));
}
}
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
}
}

View 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));
}
}
}
}

View file

@ -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));
}
}
}

View 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;
}
}
}

View file

@ -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;

View file

@ -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)]

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -130,15 +130,6 @@
<map:MapItemsControl ItemsSource="{Binding Pushpins}"
ItemContainerStyle="{StaticResource PushpinItemStyle}"/>
<Path Stroke="Blue" StrokeThickness="3">
<map:MapPanel.Location>
<map:Location Latitude="53.5" Longitude="8.2"/>
</map:MapPanel.Location>
<Path.Data>
<EllipseGeometry RadiusX="1852" RadiusY="1852" Transform="{Binding ScaleRotateTransform, ElementName=map}"/>
</Path.Data>
</Path>
<map:Pushpin Background="Yellow" Foreground="Blue" Content="N 53° 30' E 8° 12'">
<map:MapPanel.Location>
<map:Location Latitude="53.5" Longitude="8.2"/>

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("XAML Map Control Universal Windows Sample Application")]
[assembly: AssemblyProduct("XAML Map Control")]
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("4.3.0")]
[assembly: AssemblyFileVersion("4.3.0")]
[assembly: AssemblyVersion("4.4.0")]
[assembly: AssemblyFileVersion("4.4.0")]
[assembly: AssemblyConfiguration("")]
[assembly: ComVisible(false)]

View file

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("XAML Map Control WPF Sample Application")]
[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)]