mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 3.4. Fixed MapTileLayer.RenderTransform calculation.
This commit is contained in:
parent
62fcac5a55
commit
f95be42046
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,10 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
ViewportScale = GetViewportScale(zoomLevel);
|
ViewportScale = GetViewportScale(zoomLevel);
|
||||||
|
|
||||||
|
var center = LocationToPoint(mapCenter);
|
||||||
|
|
||||||
ViewportTransform.Matrix = MatrixEx.TranslateScaleRotateTranslate(
|
ViewportTransform.Matrix = MatrixEx.TranslateScaleRotateTranslate(
|
||||||
LocationToPoint(mapCenter), ViewportScale, -ViewportScale, heading, viewportCenter);
|
center.X, center.Y, ViewportScale, -ViewportScale, heading, viewportCenter.X, viewportCenter.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -319,24 +319,19 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point GetTileCenter(double tileScale) // map center in tile index coordinates
|
|
||||||
{
|
|
||||||
return new Point(
|
|
||||||
tileScale * (0.5 + parentMap.Center.Longitude / 360d),
|
|
||||||
tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TileGrid GetTileGrid()
|
private TileGrid GetTileGrid()
|
||||||
{
|
{
|
||||||
var tileZoomLevel = Math.Max(0, (int)Math.Round(parentMap.ZoomLevel + ZoomLevelOffset));
|
var tileZoomLevel = Math.Max(0, (int)Math.Round(parentMap.ZoomLevel + ZoomLevelOffset));
|
||||||
var tileScale = (1 << tileZoomLevel);
|
var tileScale = (1 << tileZoomLevel);
|
||||||
var scale = tileScale / (Math.Pow(2d, parentMap.ZoomLevel) * TileSource.TileSize);
|
var scale = tileScale / (Math.Pow(2d, parentMap.ZoomLevel) * TileSource.TileSize);
|
||||||
var tileCenter = GetTileCenter(tileScale);
|
var tileCenterX = tileScale * (0.5 + parentMap.Center.Longitude / 360d);
|
||||||
var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);
|
var tileCenterY = tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d);
|
||||||
|
var viewCenterX = parentMap.RenderSize.Width / 2d;
|
||||||
|
var viewCenterY = parentMap.RenderSize.Height / 2d;
|
||||||
|
|
||||||
var transform = new MatrixTransform
|
var transform = new MatrixTransform
|
||||||
{
|
{
|
||||||
Matrix = MatrixEx.TranslateScaleRotateTranslate(viewCenter, scale, -parentMap.Heading, tileCenter)
|
Matrix = MatrixEx.TranslateScaleRotateTranslate(viewCenterX, viewCenterY, scale, scale, -parentMap.Heading, tileCenterX, tileCenterY)
|
||||||
};
|
};
|
||||||
|
|
||||||
var bounds = transform.TransformBounds(new Rect(0d, 0d, parentMap.RenderSize.Width, parentMap.RenderSize.Height));
|
var bounds = transform.TransformBounds(new Rect(0d, 0d, parentMap.RenderSize.Width, parentMap.RenderSize.Height));
|
||||||
|
|
@ -350,12 +345,15 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
var tileScale = (1 << TileGrid.ZoomLevel);
|
var tileScale = (1 << TileGrid.ZoomLevel);
|
||||||
var scale = Math.Pow(2d, parentMap.ZoomLevel) / tileScale;
|
var scale = Math.Pow(2d, parentMap.ZoomLevel) / tileScale;
|
||||||
var tileCenter = GetTileCenter(tileScale);
|
var tileCenterX = tileScale * (0.5 + parentMap.Center.Longitude / 360d);
|
||||||
var tileOrigin = new Point(TileSource.TileSize * (tileCenter.X - TileGrid.XMin), TileSource.TileSize * (tileCenter.Y - TileGrid.YMin));
|
var tileCenterY = tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d);
|
||||||
var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);
|
var tileOriginX = TileSource.TileSize * (tileCenterX - TileGrid.XMin);
|
||||||
|
var tileOriginY = TileSource.TileSize * (tileCenterY - TileGrid.YMin);
|
||||||
|
var viewCenterX = parentMap.RenderSize.Width / 2d;
|
||||||
|
var viewCenterY = parentMap.RenderSize.Height / 2d;
|
||||||
|
|
||||||
((MatrixTransform)RenderTransform).Matrix =
|
((MatrixTransform)RenderTransform).Matrix = MatrixEx.TranslateScaleRotateTranslate(
|
||||||
MatrixEx.TranslateScaleRotateTranslate(tileOrigin, scale, parentMap.Heading, viewCenter);
|
tileOriginX, tileOriginY, scale, scale, parentMap.Heading, viewCenterX, viewCenterY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTiles()
|
private void UpdateTiles()
|
||||||
|
|
|
||||||
|
|
@ -16,27 +16,17 @@ namespace MapControl
|
||||||
internal static class MatrixEx
|
internal static class MatrixEx
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used in MapProjection.
|
/// Used in MapProjection and MapTileLayer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Matrix TranslateScaleRotateTranslate(
|
public static Matrix TranslateScaleRotateTranslate(
|
||||||
Point translation1, double scaleX, double scaleY, double rotationAngle, Point translation2)
|
double translation1X, double translation1Y,
|
||||||
|
double scaleX, double scaleY, double rotationAngle,
|
||||||
|
double translation2X, double translation2Y)
|
||||||
{
|
{
|
||||||
return new Matrix(1d, 0d, 0d, 1d, -translation1.X, -translation1.Y)
|
return new Matrix(1d, 0d, 0d, 1d, -translation1X, -translation1Y)
|
||||||
.Scale(scaleX, scaleY)
|
.Scale(scaleX, scaleY)
|
||||||
.Rotate(rotationAngle)
|
.Rotate(rotationAngle)
|
||||||
.Translate(translation2.X, translation2.Y);
|
.Translate(translation2X, translation2Y);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Used in TileLayer.
|
|
||||||
/// </summary>
|
|
||||||
public static Matrix TranslateScaleRotateTranslate(
|
|
||||||
Point translation1, double scale, double rotationAngle, Point translation2)
|
|
||||||
{
|
|
||||||
return new Matrix(1d, 0d, 0d, 1d, -translation1.X, -translation1.Y)
|
|
||||||
.Scale(scale, scale)
|
|
||||||
.Rotate(rotationAngle)
|
|
||||||
.Translate(translation2.X, translation2.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Matrix Translate(this Matrix matrix, double offsetX, double offsetY)
|
private static Matrix Translate(this Matrix matrix, double offsetX, double offsetY)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// © 2017 Clemens Fischer
|
// © 2017 Clemens Fischer
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
|
|
@ -13,25 +12,14 @@ namespace MapControl
|
||||||
/// Used in MapProjection.
|
/// Used in MapProjection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Matrix TranslateScaleRotateTranslate(
|
public static Matrix TranslateScaleRotateTranslate(
|
||||||
Point translation1, double scaleX, double scaleY, double rotationAngle, Point translation2)
|
double translation1X, double translation1Y,
|
||||||
|
double scaleX, double scaleY, double rotationAngle,
|
||||||
|
double translation2X, double translation2Y)
|
||||||
{
|
{
|
||||||
var matrix = new Matrix(1d, 0d, 0d, 1d, -translation1.X, -translation1.Y);
|
var matrix = new Matrix(1d, 0d, 0d, 1d, -translation1X, -translation1Y);
|
||||||
matrix.Scale(scaleX, scaleY);
|
matrix.Scale(scaleX, scaleY);
|
||||||
matrix.Rotate(rotationAngle);
|
matrix.Rotate(rotationAngle);
|
||||||
matrix.Translate(translation2.X, translation2.Y);
|
matrix.Translate(translation2X, translation2Y);
|
||||||
return matrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Used in MapTileLayer.
|
|
||||||
/// </summary>
|
|
||||||
public static Matrix TranslateScaleRotateTranslate(
|
|
||||||
Point translation1, double scale, double rotationAngle, Point translation2)
|
|
||||||
{
|
|
||||||
var matrix = new Matrix(1d, 0d, 0d, 1d, -translation1.X, -translation1.Y);
|
|
||||||
matrix.Scale(scale, scale);
|
|
||||||
matrix.Rotate(rotationAngle);
|
|
||||||
matrix.Translate(translation2.X, translation2.Y);
|
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ using System.Windows;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyCompany("Clemens Fischer")]
|
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyVersion("3.3.0")]
|
[assembly: AssemblyVersion("3.4.0")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0")]
|
[assembly: AssemblyFileVersion("3.4.0")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue