【问题标题】:How to rotate a polygon on a map with the long/lat coordinates?如何使用长/纬度坐标在地图上旋转多边形?
【发布时间】:2016-11-06 18:35:08
【问题描述】:

我想通过将硬编码的偏移值替换为一个函数来旋转多边形(例如这个箭头),在该函数中可以传入北指向偏移和我希望箭头旋转的度数。强>

我尝试使用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);

【问题讨论】:

  • 不是确切的答案,但可能会有所帮助:您可以将您的问题视为如何在线端绘制箭头帽的问题的变体。纬度/经度将是 X/Y,您的多边形将是箭头。有一个很好的post about that on math.stackexchange也许你可以根据你的具体情况调整这些想法。
  • 您是否考虑过使用 xaml 控件而不是 mapPolygon?例如。带箭头的图像控件,会容易得多。
  • 我尝试使用地图图标,但它不想随地图旋转。

标签: c# rotation uwp rotatetransform uwp-maps


【解决方案1】:

MapPolygons 绑定到地图上的坐标。 UWP 中的旋转变换不适用于 MapPolygons。如果要旋转 MapPolygon,则必须计算旋转后的坐标。 Bing Maps V8 地图控件 (web) 提供了执行此操作的功能。以下是它执行此操作的两种不同方式:

空间准确(由于地图投影可能看起来不一样)

像素精确(旋转时看起来一样,但空间不精确)

  • 计算多边形的中心并将其用作旋转多边形的锚点。如果您愿意,可以使用多边形的任何其他部分。将其转换为缩放级别 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。

【讨论】:

    【解决方案2】:

    您尝试的最佳方法是使用 XAML 元素并将其作为子元素添加到地图控件。您可以将 XAML 固定到地图的某一点(箭头的头部或中心)。 尝试每帧更新多边形不会很快或很流畅,所以你真的不想使用地图多边形。 上面建议的一些链接假设地图始终处于墨卡托投影且北上且不倾斜,这对于 UWP 地图并不总是如此,因此我不建议采用这种方法。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 2018-08-27
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多