mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Version 4.4.0: Fixed MapPolyline performance on UWP. Added MapPolygon and MapMultiPolygon for WPF.
This commit is contained in:
parent
cce5d6e0b4
commit
d1552506f6
80 changed files with 673 additions and 550 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
111
MapControl/Shared/MapShape.cs
Normal file
111
MapControl/Shared/MapShape.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
74
MapControl/Shared/PolygonCollection.cs
Normal file
74
MapControl/Shared/PolygonCollection.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue