我想通过用函数传递硬编码的偏移量值来旋转多边形(例如,此箭头),该函数可以传递标准的指向偏移量和我希望箭头旋转的度数。
我尝试使用Rotation matrix,但效果不佳。
可能是因为距离
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)提供了执行此操作的功能。这是执行此操作的两种不同方式:
空间上准确(由于地图投影可能看起来不一样)
计算多边形的中心,并将其用作旋转多边形的锚点。如果需要,可以使用多边形的任何其他部分。
循环遍历MapPolygon中的每个位置并计算
航向和距锚点的距离。 https://rbrundritt.wordpress.com/2008/10/14/calculating-bearing/
https://megocode3.wordpress.com/2008/02/05/haversine-formula-in-c/
对于每个位置,将要旋转的角度添加到航向,然后计算新的目标位置。 https://rbrundritt.wordpress.com/2008/10/14/calculate-destination-coordinate/
将新计算的位置传递到MapPolygon中。
像素精确(与旋转像素相同,但在空间上不准确)
计算多边形的中心,并将其用作旋转多边形的锚点。如果需要,可以使用多边形的任何其他部分。将其转换为缩放级别19的全局像素坐标:https://msdn.microsoft.com/en-us/library/bb259689.aspx(LatLongToPixelXY)
循环遍历MapPolygon中的每个位置并计算
缩放级别为19时的全局像素坐标。
计算旋转的像素坐标:http://homepages.inf.ed.ac.uk/rbf/HIPR2/rotate.htm
将像素坐标转换回缩放级别19(PixelXyToLatLong)的空间位置
将新计算的位置传递到MapPolygon中。
关于c# - 如何在具有长/纬度坐标的 map 上旋转多边形?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40453026/