Minor changes

This commit is contained in:
ClemensF 2017-08-16 21:27:12 +02:00
parent 3774bf2ed3
commit 0be26af38c
9 changed files with 32 additions and 29 deletions

View file

@ -28,14 +28,14 @@ namespace MapControl
public override Point LocationToPoint(Location location) public override Point LocationToPoint(Location location)
{ {
if (location.Equals(projectionCenter)) if (location.Equals(ProjectionCenter))
{ {
return new Point(); return new Point();
} }
double azimuth, distance; double azimuth, distance;
GetAzimuthDistance(projectionCenter, location, out azimuth, out distance); GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);
distance *= Wgs84EquatorialRadius; distance *= Wgs84EquatorialRadius;
@ -46,13 +46,13 @@ namespace MapControl
{ {
if (point.X == 0d && point.Y == 0d) if (point.X == 0d && point.Y == 0d)
{ {
return projectionCenter; return ProjectionCenter;
} }
var azimuth = Math.Atan2(point.X, point.Y); var azimuth = Math.Atan2(point.X, point.Y);
var distance = Math.Sqrt(point.X * point.X + point.Y * point.Y) / Wgs84EquatorialRadius; var distance = Math.Sqrt(point.X * point.X + point.Y * point.Y) / Wgs84EquatorialRadius;
return GetLocation(projectionCenter, azimuth, distance); return GetLocation(ProjectionCenter, azimuth, distance);
} }
} }
} }

View file

@ -17,7 +17,7 @@ namespace MapControl
/// </summary> /// </summary>
public abstract class AzimuthalProjection : MapProjection public abstract class AzimuthalProjection : MapProjection
{ {
protected Location projectionCenter = new Location(); public Location ProjectionCenter { get; private set; } = new Location();
public AzimuthalProjection() public AzimuthalProjection()
{ {
@ -70,7 +70,7 @@ namespace MapControl
public override void SetViewportTransform(Location projectionCenter, Location mapCenter, Point viewportCenter, double zoomLevel, double heading) public override void SetViewportTransform(Location projectionCenter, Location mapCenter, Point viewportCenter, double zoomLevel, double heading)
{ {
this.projectionCenter = projectionCenter; ProjectionCenter = projectionCenter;
base.SetViewportTransform(projectionCenter, mapCenter, viewportCenter, zoomLevel, heading); base.SetViewportTransform(projectionCenter, mapCenter, viewportCenter, zoomLevel, heading);
} }
@ -89,7 +89,7 @@ namespace MapControl
return string.Format(CultureInfo.InvariantCulture, return string.Format(CultureInfo.InvariantCulture,
"{0}={1},1,{2},{3}&BBOX={4},{5},{6},{7}&WIDTH={8}&HEIGHT={9}", "{0}={1},1,{2},{3}&BBOX={4},{5},{6},{7}&WIDTH={8}&HEIGHT={9}",
crs, CrsId, projectionCenter.Longitude, projectionCenter.Latitude, crs, CrsId, ProjectionCenter.Longitude, ProjectionCenter.Latitude,
rect.X, rect.Y, (rect.X + rect.Width), (rect.Y + rect.Height), width, height); rect.X, rect.Y, (rect.X + rect.Width), (rect.Y + rect.Height), width, height);
} }

View file

@ -28,14 +28,14 @@ namespace MapControl
public override Point LocationToPoint(Location location) public override Point LocationToPoint(Location location)
{ {
if (location.Equals(projectionCenter)) if (location.Equals(ProjectionCenter))
{ {
return new Point(); return new Point();
} }
double azimuth, distance; double azimuth, distance;
GetAzimuthDistance(projectionCenter, location, out azimuth, out distance); GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);
var mapDistance = distance < Math.PI / 2d var mapDistance = distance < Math.PI / 2d
? Wgs84EquatorialRadius * Math.Tan(distance) ? Wgs84EquatorialRadius * Math.Tan(distance)
@ -48,14 +48,14 @@ namespace MapControl
{ {
if (point.X == 0d && point.Y == 0d) if (point.X == 0d && point.Y == 0d)
{ {
return projectionCenter; return ProjectionCenter;
} }
var azimuth = Math.Atan2(point.X, point.Y); var azimuth = Math.Atan2(point.X, point.Y);
var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y); var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y);
var distance = Math.Atan(mapDistance / Wgs84EquatorialRadius); var distance = Math.Atan(mapDistance / Wgs84EquatorialRadius);
return GetLocation(projectionCenter, azimuth, distance); return GetLocation(ProjectionCenter, azimuth, distance);
} }
} }
} }

View file

@ -295,12 +295,12 @@ namespace MapControl
/// </summary> /// </summary>
protected abstract bool UpdateImage(BoundingBox boundingBox); protected abstract bool UpdateImage(BoundingBox boundingBox);
private void SetTopImage(BitmapSource bitmapSource) private void SetTopImage(ImageSource imageSource)
{ {
topImageIndex = (topImageIndex + 1) % 2; topImageIndex = (topImageIndex + 1) % 2;
var topImage = (Image)Children[topImageIndex]; var topImage = (Image)Children[topImageIndex];
topImage.Source = bitmapSource; topImage.Source = imageSource;
SetBoundingBox(topImage, boundingBox?.Clone()); SetBoundingBox(topImage, boundingBox?.Clone());
} }

View file

@ -37,7 +37,7 @@ namespace MapControl
public string CrsId { get; set; } public string CrsId { get; set; }
/// <summary> /// <summary>
/// Indicates if this is a web mercator projection, i.e. compatible with map tile layers. /// Indicates if this is a web mercator projection, i.e. compatible with MapTileLayer.
/// </summary> /// </summary>
public bool IsWebMercator { get; protected set; } = false; public bool IsWebMercator { get; protected set; } = false;

View file

@ -28,14 +28,14 @@ namespace MapControl
public override Point LocationToPoint(Location location) public override Point LocationToPoint(Location location)
{ {
if (location.Equals(projectionCenter)) if (location.Equals(ProjectionCenter))
{ {
return new Point(); return new Point();
} }
var lat0 = projectionCenter.Latitude * Math.PI / 180d; var lat0 = ProjectionCenter.Latitude * Math.PI / 180d;
var lat = location.Latitude * Math.PI / 180d; var lat = location.Latitude * Math.PI / 180d;
var dLon = (location.Longitude - projectionCenter.Longitude) * Math.PI / 180d; var dLon = (location.Longitude - ProjectionCenter.Longitude) * Math.PI / 180d;
return new Point( return new Point(
Wgs84EquatorialRadius * Math.Cos(lat) * Math.Sin(dLon), Wgs84EquatorialRadius * Math.Cos(lat) * Math.Sin(dLon),
@ -46,7 +46,7 @@ namespace MapControl
{ {
if (point.X == 0d && point.Y == 0d) if (point.X == 0d && point.Y == 0d)
{ {
return projectionCenter; return ProjectionCenter;
} }
var x = point.X / Wgs84EquatorialRadius; var x = point.X / Wgs84EquatorialRadius;
@ -62,13 +62,13 @@ namespace MapControl
var sinC = r; var sinC = r;
var cosC = Math.Sqrt(1 - r2); var cosC = Math.Sqrt(1 - r2);
var lat0 = projectionCenter.Latitude * Math.PI / 180d; var lat0 = ProjectionCenter.Latitude * Math.PI / 180d;
var cosLat0 = Math.Cos(lat0); var cosLat0 = Math.Cos(lat0);
var sinLat0 = Math.Sin(lat0); var sinLat0 = Math.Sin(lat0);
return new Location( return new Location(
180d / Math.PI * Math.Asin(cosC * sinLat0 + y * sinC * cosLat0 / r), 180d / Math.PI * Math.Asin(cosC * sinLat0 + y * sinC * cosLat0 / r),
180d / Math.PI * Math.Atan2(x * sinC, r * cosC * cosLat0 - y * sinC * sinLat0) + projectionCenter.Longitude); 180d / Math.PI * Math.Atan2(x * sinC, r * cosC * cosLat0 - y * sinC * sinLat0) + ProjectionCenter.Longitude);
} }
} }
} }

View file

@ -28,14 +28,14 @@ namespace MapControl
public override Point LocationToPoint(Location location) public override Point LocationToPoint(Location location)
{ {
if (location.Equals(projectionCenter)) if (location.Equals(ProjectionCenter))
{ {
return new Point(); return new Point();
} }
double azimuth, distance; double azimuth, distance;
GetAzimuthDistance(projectionCenter, location, out azimuth, out distance); GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);
var mapDistance = 2d * Wgs84EquatorialRadius * Math.Tan(distance / 2d); var mapDistance = 2d * Wgs84EquatorialRadius * Math.Tan(distance / 2d);
@ -46,14 +46,14 @@ namespace MapControl
{ {
if (point.X == 0d && point.Y == 0d) if (point.X == 0d && point.Y == 0d)
{ {
return projectionCenter; return ProjectionCenter;
} }
var azimuth = Math.Atan2(point.X, point.Y); var azimuth = Math.Atan2(point.X, point.Y);
var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y); var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y);
var distance = 2d * Math.Atan(mapDistance / (2d * Wgs84EquatorialRadius)); var distance = 2d * Math.Atan(mapDistance / (2d * Wgs84EquatorialRadius));
return GetLocation(projectionCenter, azimuth, distance); return GetLocation(ProjectionCenter, azimuth, distance);
} }
} }
} }

View file

@ -5,6 +5,7 @@
using System; using System;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Media.Imaging;
namespace MapControl namespace MapControl
@ -16,11 +17,11 @@ namespace MapControl
UpdateImage(uri != null ? new BitmapImage(uri) : null); UpdateImage(uri != null ? new BitmapImage(uri) : null);
} }
protected void UpdateImage(BitmapSource bitmapSource) protected void UpdateImage(ImageSource imageSource)
{ {
SetTopImage(bitmapSource); SetTopImage(imageSource);
var bitmapImage = bitmapSource as BitmapImage; var bitmapImage = imageSource as BitmapImage;
if (bitmapImage != null) if (bitmapImage != null)
{ {

View file

@ -18,9 +18,11 @@ namespace MapControl
: null); : null);
} }
protected void UpdateImage(BitmapSource bitmapSource) protected void UpdateImage(ImageSource imageSource)
{ {
SetTopImage(bitmapSource); SetTopImage(imageSource);
var bitmapSource = imageSource as BitmapSource;
if (bitmapSource != null && !bitmapSource.IsFrozen && bitmapSource.IsDownloading) if (bitmapSource != null && !bitmapSource.IsFrozen && bitmapSource.IsDownloading)
{ {