【发布时间】:2018-06-28 15:41:02
【问题描述】:
我正在尝试构建一个与完整 MapControl 视图同步的迷你概览/方向图,如下所示:(Full Screenshot)
我在尝试根据 MapControl 的大小、位置和缩放来计算迷你地图内的红色小矩形的宽度、高度和位置时遇到了麻烦。
它应该与 MapControl 的视图同步,点击小地图也应该改变 MapControl 的 CenterPoint。
完整的地图是 UWP 中的 MapControl,而迷你地图只是静态图像上的 Border UIElement。
我正在使用以下公式。它们有效但不准确。误差幅度非常明显,特别是对于大变焦。
用于计算红色矩形的位置和大小:
var positions = MapControl.GetVisibleRegion(MapVisibleRegionKind.Near).Positions.ToArray();
var topLeft = positions[0];
var bottomLeft = positions[1];
var topRigt = positions[2];
//Transfering the Longitude system from [-180, 180] to [0, 360]
var centerX = (MapControl.Center.Position.Longitude + 180) * (SmallMapWidth / 360);
//Transfering the Latitude system from [-90, 90] to [0, 180]
var centerY = (-MapControl.Center.Position.Latitude + 90) * (SmallMapHeight / 180);
var topLeftX = topLeft.Longitude + 180;
var topRightX = topRigt.Longitude + 180;
//MapControl wraparound by default. In that case, the topRightX might be smaller than topLeftX, as it will start from the 'beginning'.
var deltaX = Math.Abs(topLeftX - (topLeftX < topRightX ? topRightX : 360 - topRightX));
//The width of the red rectangle
SmallMapViewPortWidth = Math.Abs(deltaX) * (SmallMapWidth / 360);
//The height of the red rectangle
SmallMapViewPortHeight = Math.Abs(topLeft.Latitude - bottomLeft.Latitude) * (SmallMapHeight / 180);
//The center point of the red rectangle.
RedRectangleCenterPoint = (centerX - SmallMapViewPortWidth / 2, centerY - SmallMapViewPortHeight / 2);
以下内容用于将 MapControl 导航到在概览图上单击的点。 X 和 Y 是相对于概览图被点击的点。
var lon = 360 * x / SmallMapWidth - 180;
var lat = 90 - 180 * y / SmallMapHeight;
我的计算有什么问题?为什么会有相当明显的误差幅度?
【问题讨论】:
-
请发布您的代码,让我们知道您做了什么。
-
@XavierXie-MSFT 我已经用我正在使用的公式更新了我的问题。感谢您的帮助!
-
嗯,这不是 MapControl 使用的公式。见documentation。您使用的是 equirectangular 投影,但 MapControl 使用 Web Mercator(球形)。
-
@RaymondChen 文档引用了“levelOfDetails”值,而 MapControl 仅公开 ZoomLevel。有没有办法获得 levelOfDetails?将 ZoomLevel 用作 levelOfDetauls 时,结果不准确。谢谢你的帮助!!
-
我看错了。您正在使用 MapControl 报告的纬度/经度,这意味着转换已经反转。您需要将纬度/经度转换为小地图的投影。我会通过取 -25.58524° N、134.5041° E 来调试它,看看这是否会导致澳大利亚周围出现红色矩形。如果不是,那么问题出在您从纬度/经度到小地图坐标的转换中。我不知道你的小地图使用什么投影,所以我无法帮助那里的数学。
标签: c# dictionary uwp mercator