如何在 bing 地图 wpf c# 上绘制贝塞尔曲线折线?

问题描述 投票:0回答:3

wpf 的 Bing 地图库似乎不包含任何绘制贝塞尔曲线的帮助器。 它有MapPolyLine,可用于在n个点之间绘制直线。 有什么解决办法吗?

谢谢

c# wpf bing-maps bezier
3个回答
0
投票

Bing 地图不直接支持弯曲几何图形,因此可以通过创建包含多个小线段的折线来近似曲线的形状。

希望这篇文章对您有所帮助 https://alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/


0
投票

除了使用测地线之外,如果您不关心空间精确度,还可以使用此处的代码将坐标转换为缩放级别 19 的像素坐标:https://msdn.microsoft.com/en-us /库/bb259689.aspx

然后通过标准贝塞尔曲线算法传递像素坐标。获取结果值并将其转换回位置。


0
投票

我一直在使用 WPF 和 VS Basic,并且没有可用的 Google API 或 Microsoft Maps API 来允许我绘制代表从 A 到 B 的航班的测地线。 找到了参考资料 [1],其中提供了答案的数学原理。

    Public Function GetGeodesicPath(startLocation As Location, endLocation As Location, segments As Integer) As LocationCollection
    Dim lc As New LocationCollection
    lc.Add(startLocation)

    ' Convert coordinates from degrees to Radians
    Dim lat1 = startLocation.Latitude * Math.PI / 180
    Dim lon1 = startLocation.Longitude * Math.PI / 180
    Dim lat2 = endLocation.Latitude * Math.PI / 180
    Dim lon2 = endLocation.Longitude * Math.PI / 180

    ' Calculate the length of the route
    Dim length = 2 * Math.Asin(Math.Sqrt(Math.Pow((Math.Sin((lat1 - lat2) / 2)), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow((Math.Sin((lon1 - lon2) / 2)), 2)))

    ' Calculate positions at fixed intervals along the route - 32 segments to provide a smooth curve

    For counter = 1 To segments

        Dim segmentlength = (counter / segments)
        Dim A = Math.Sin((1 - segmentlength) * length) / Math.Sin(length)
        Dim B = Math.Sin(segmentlength * length) / Math.Sin(length)

        ' Obtain 3D cartesian co-ordinates of each point

        Dim x = A * Math.Cos(lat1) * Math.Cos(lon1) + B * Math.Cos(lat2) * Math.Cos(lon2)
        Dim y = A * Math.Cos(lat1) * Math.Sin(lon1) + B * Math.Cos(lat2) * Math.Sin(lon2)
        Dim z = A * Math.Sin(lat1) + B * Math.Sin(lat2)

        Dim segmentLat = Math.Atan2(z, Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)))
        Dim segmentLon = Math.Atan2(y, x)

        ' Create a Location by converting lat lon to degrees
        Dim location As New Location
        location.Latitude = segmentLat / (Math.PI / 180)
        location.Longitude = segmentLon / (Math.PI / 180)

        ' Add location to Location Collection
        lc.Add(location)

    Next

    Return lc

End Function

这会返回一个位置集合,可以将其添加到您的地图折线中

© www.soinside.com 2019 - 2024. All rights reserved.