我正在尝试构建一个与完整 MapControl 视图同步的迷你概览/方向图,如下所示:(全屏截图)
我在尝试根据 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;
我的计算有什么问题?为什么会有相当明显的误差幅度?