mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Version 2.4.8: Fixed issue when MapPath.Data is frozen.
This commit is contained in:
parent
e9868a993d
commit
ba45aa5901
19 changed files with 117 additions and 83 deletions
|
|
@ -16,15 +16,20 @@ namespace MapControl
|
|||
{
|
||||
public partial class MapPath : Path
|
||||
{
|
||||
private Geometry data;
|
||||
|
||||
public MapPath()
|
||||
{
|
||||
MapPanel.AddParentMapHandlers(this);
|
||||
}
|
||||
|
||||
private Geometry data;
|
||||
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
if (Stretch != Stretch.None)
|
||||
{
|
||||
Stretch = Stretch.None;
|
||||
}
|
||||
|
||||
// Work-around for missing PropertyChangedCallback for the Data property.
|
||||
if (data != Data)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,14 @@ namespace MapControl
|
|||
{
|
||||
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
|
||||
"Data", typeof(Geometry), typeof(MapPath), new FrameworkPropertyMetadata(
|
||||
null, FrameworkPropertyMetadataOptions.AffectsRender, (o, e) => ((MapPath)o).UpdateData()));
|
||||
null, FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, e) => ((MapPath)o).UpdateData(), CoerceDataProperty));
|
||||
|
||||
static MapPath()
|
||||
{
|
||||
StretchProperty.OverrideMetadata(typeof(MapPath),
|
||||
new FrameworkPropertyMetadata { CoerceValueCallback = (o, v) => Stretch.None });
|
||||
}
|
||||
|
||||
public Geometry Data
|
||||
{
|
||||
|
|
@ -30,5 +37,11 @@ namespace MapControl
|
|||
// Shape.MeasureOverride sometimes returns an empty Size.
|
||||
return new Size(1, 1);
|
||||
}
|
||||
|
||||
private static object CoerceDataProperty(DependencyObject obj, object value)
|
||||
{
|
||||
var data = (Geometry)value;
|
||||
return data != null && data.IsFrozen ? data.CloneCurrentValue() : data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ 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.
|
||||
/// The Stretch property is meaningless for MapPath, it will be reset to None.
|
||||
/// </summary>
|
||||
public partial class MapPath : IMapElement
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,54 +17,62 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class MercatorTransform : MapTransform
|
||||
{
|
||||
private static readonly double maxLatitude = Math.Atan(Math.Sinh(Math.PI)) / Math.PI * 180d;
|
||||
public static readonly double MaxLatitudeValue = Math.Atan(Math.Sinh(Math.PI)) / Math.PI * 180d;
|
||||
|
||||
public override double MaxLatitude
|
||||
public static double RelativeScale(double latitude)
|
||||
{
|
||||
get { return maxLatitude; }
|
||||
}
|
||||
|
||||
public override double RelativeScale(Location location)
|
||||
{
|
||||
if (location.Latitude <= -90d)
|
||||
if (latitude <= -90d)
|
||||
{
|
||||
return double.NegativeInfinity;
|
||||
}
|
||||
|
||||
if (location.Latitude >= 90d)
|
||||
if (latitude >= 90d)
|
||||
{
|
||||
return double.PositiveInfinity;
|
||||
}
|
||||
|
||||
return 1d / Math.Cos(location.Latitude * Math.PI / 180d);
|
||||
return 1d / Math.Cos(latitude * Math.PI / 180d);
|
||||
}
|
||||
|
||||
public static double LatitudeToY(double latitude)
|
||||
{
|
||||
if (latitude <= -90d)
|
||||
{
|
||||
return double.NegativeInfinity;
|
||||
}
|
||||
|
||||
if (latitude >= 90d)
|
||||
{
|
||||
return double.PositiveInfinity;
|
||||
}
|
||||
|
||||
latitude *= Math.PI / 180d;
|
||||
return Math.Log(Math.Tan(latitude) + 1d / Math.Cos(latitude)) / Math.PI * 180d;
|
||||
}
|
||||
|
||||
public static double YToLatitude(double y)
|
||||
{
|
||||
return Math.Atan(Math.Sinh(y * Math.PI / 180d)) / Math.PI * 180d;
|
||||
}
|
||||
|
||||
public override double MaxLatitude
|
||||
{
|
||||
get { return MaxLatitudeValue; }
|
||||
}
|
||||
|
||||
public override double RelativeScale(Location location)
|
||||
{
|
||||
return RelativeScale(location.Latitude);
|
||||
}
|
||||
|
||||
public override Point Transform(Location location)
|
||||
{
|
||||
double latitude;
|
||||
|
||||
if (location.Latitude <= -90d)
|
||||
{
|
||||
latitude = double.NegativeInfinity;
|
||||
}
|
||||
else if (location.Latitude >= 90d)
|
||||
{
|
||||
latitude = double.PositiveInfinity;
|
||||
}
|
||||
else
|
||||
{
|
||||
latitude = location.Latitude * Math.PI / 180d;
|
||||
latitude = Math.Log(Math.Tan(latitude) + 1d / Math.Cos(latitude)) / Math.PI * 180d;
|
||||
}
|
||||
|
||||
return new Point(location.Longitude, latitude);
|
||||
return new Point(location.Longitude, LatitudeToY(location.Latitude));
|
||||
}
|
||||
|
||||
public override Location Transform(Point point)
|
||||
{
|
||||
var latitude = Math.Atan(Math.Sinh(point.Y * Math.PI / 180d)) / Math.PI * 180d;
|
||||
|
||||
return new Location(latitude, point.X);
|
||||
return new Location(YToLatitude(point.Y), point.X);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ using System.Windows;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.4.7")]
|
||||
[assembly: AssemblyFileVersion("2.4.7")]
|
||||
[assembly: AssemblyVersion("2.4.8")]
|
||||
[assembly: AssemblyFileVersion("2.4.8")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -4,11 +4,6 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#if WINDOWS_RUNTIME
|
||||
using Windows.Foundation;
|
||||
#else
|
||||
using System.Windows;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
@ -159,35 +154,32 @@ namespace MapControl
|
|||
|
||||
private Uri GetBoundingBoxUri(int x, int y, int zoomLevel)
|
||||
{
|
||||
var n = (double)(1 << zoomLevel);
|
||||
var x1 = MetersPerDegree * ((double)x * 360d / n - 180d);
|
||||
var x2 = MetersPerDegree * ((double)(x + 1) * 360d / n - 180d);
|
||||
var y1 = MetersPerDegree * (180d - (double)(y + 1) * 360d / n);
|
||||
var y2 = MetersPerDegree * (180d - (double)y * 360d / n);
|
||||
var numTiles = (double)(1 << zoomLevel);
|
||||
var west = MetersPerDegree * ((double)x * 360d / numTiles - 180d);
|
||||
var east = MetersPerDegree * ((double)(x + 1) * 360d / numTiles - 180d);
|
||||
var south = MetersPerDegree * (180d - (double)(y + 1) * 360d / numTiles);
|
||||
var north = MetersPerDegree * (180d - (double)y * 360d / numTiles);
|
||||
|
||||
return new Uri(uriFormat.
|
||||
Replace("{W}", x1.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{S}", y1.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{E}", x2.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{N}", y2.ToString(CultureInfo.InvariantCulture)));
|
||||
Replace("{W}", west.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{S}", south.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{E}", east.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{N}", north.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
|
||||
private Uri GetLatLonBoundingBoxUri(int x, int y, int zoomLevel)
|
||||
{
|
||||
var t = new MercatorTransform();
|
||||
var n = (double)(1 << zoomLevel);
|
||||
var x1 = (double)x * 360d / n - 180d;
|
||||
var x2 = (double)(x + 1) * 360d / n - 180d;
|
||||
var y1 = 180d - (double)(y + 1) * 360d / n;
|
||||
var y2 = 180d - (double)y * 360d / n;
|
||||
var p1 = t.Transform(new Point(x1, y1));
|
||||
var p2 = t.Transform(new Point(x2, y2));
|
||||
var numTiles = (double)(1 << zoomLevel);
|
||||
var west = (double)x * 360d / numTiles - 180d;
|
||||
var east = (double)(x + 1) * 360d / numTiles - 180d;
|
||||
var south = MercatorTransform.YToLatitude(180d - (double)(y + 1) * 360d / numTiles);
|
||||
var north = MercatorTransform.YToLatitude(180d - (double)y * 360d / numTiles);
|
||||
|
||||
return new Uri(uriFormat.
|
||||
Replace("{w}", p1.Longitude.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{s}", p1.Latitude.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{e}", p2.Longitude.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{n}", p2.Latitude.ToString(CultureInfo.InvariantCulture)));
|
||||
Replace("{w}", west.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{s}", south.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{e}", east.ToString(CultureInfo.InvariantCulture)).
|
||||
Replace("{n}", north.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2015 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.4.7")]
|
||||
[assembly: AssemblyFileVersion("2.4.7")]
|
||||
[assembly: AssemblyVersion("2.4.8")]
|
||||
[assembly: AssemblyFileVersion("2.4.8")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue