簡體   English   中英

如何在具有長/緯度坐標的地圖上旋轉多邊形?

[英]How to rotate a polygon on a map with the long/lat coordinates?

我想通過用函數傳遞硬編碼的偏移量值來旋轉多邊形(例如,此箭頭),該函數可以傳遞標准的指向偏移量和我希望箭頭旋轉的度數。

我嘗試使用旋轉矩陣,但效果不佳。
可能是因為1緯度的距離。 != 1長。

我正在嘗試這樣做:
箭頭必須代表車輛,並沿車輛前進的方向旋轉。

double centerLatitude = pos.Coordinate.Point.Position.Latitude;
double centerLongitude = pos.Coordinate.Point.Position.Longitude;

MapPolygon mapPolygon = new MapPolygon();
mapPolygon.Path = new Geopath(new List<BasicGeoposition>() {
    new BasicGeoposition() {Longitude=centerLongitude, Latitude=centerLatitude},//top of the arrow
    new BasicGeoposition() {Longitude=centerLongitude-0.001, Latitude=centerLatitude-0.0010},
    new BasicGeoposition() {Longitude=centerLongitude-0.001, Latitude=centerLatitude-0.0030},
    new BasicGeoposition() {Longitude=centerLongitude+0.001, Latitude=centerLatitude-0.0030},
    new BasicGeoposition() {Longitude=centerLongitude+0.001, Latitude=centerLatitude-0.0010},              
});
mapPolygon.ZIndex = 1;
mapPolygon.FillColor = Colors.Orange;
mapPolygon.StrokeColor = Colors.Blue;
mapPolygon.StrokeThickness = 2;
mapPolygon.StrokeDashed = false;
MainMap.MapElements.Add(mapPolygon);

在此處輸入圖片說明

MapPolygons綁定到地圖上的坐標。 UWP中的旋轉變換不適用於MapPolygons。 如果要旋轉MapPolygon,則必須計算旋轉的坐標。 Bing Maps V8地圖控件(Web)提供了執行此操作的功能。 這是執行此操作的兩種不同方式:

空間上准確(由於地圖投影可能看起來不一樣)

像素精確(與旋轉像素相同,但在空間上不准確)

  • 計算多邊形的中心,並將其用作旋轉多邊形的錨點。 如果需要,可以使用多邊形的任何其他部分。 將其轉換為縮放級別19的全局像素坐標: https ://msdn.microsoft.com/zh-cn/library/bb259689.aspx(LatLongToPixelXY)
  • 循環遍歷MapPolygon中的每個位置,並以縮放級別19計算其全局像素坐標。
  • 計算旋轉的像素坐標: http : //homepages.inf.ed.ac.uk/rbf/HIPR2/rotate.htm
  • 將像素坐標轉換回縮放級別19(PixelXyToLatLong)的空間位置
  • 將新計算的位置傳遞到MapPolygon中。

嘗試執行的最佳方法是使用XAML元素,並將其作為子元素添加到地圖控件中。 您可以將XAML固定在地圖的某一點(箭頭的頭部或中心)。 嘗試更新多邊形的每一幀都不會很快或很平滑,因此您真的不想使用地圖多邊形。 上面建議的某些鏈接假設地圖始終在墨卡托投影中並且向北,並且不傾斜,這對於UWP地圖並不總是正確的,因此,我不建議您采用這種方法。

暫無
暫無

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

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