簡體   English   中英

使用MapControl的UWP App中的迷你總覽圖

[英]Mini overview map in a UWP App using MapControl

我正在嘗試構建一個與完整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導航到在概覽地圖上單擊的點。 XY是相對於總覽圖單擊的點。

var lon = 360 * x / SmallMapWidth - 180;
var lat = 90 - 180 * y / SmallMapHeight;

我的計算有什么問題? 為什么會有相當明顯的錯誤余量?

問題實際上是我用於方向圖的圖像。 一旦我開始使用適當的Bing Maps圖像,此問題就解決了。

似乎有一個官方的API,可以根據Bing Maps的投影來渲染不同大小的圖像https://docs.microsoft.com/zh-cn/bingmaps/rest-services/imagery/get-a-static-map

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM