Reputation: 190
Bing maps library for wpf seems not to include any helper to draw a bezier curve. It has MapPolyLine which can be used to draw straight lines between n points. Any solution?
Thanks
Upvotes: 0
Views: 656
Reputation: 11
I was stuck using WPF and VS Basic and no available Google API or Microsoft Maps API to allow me to draw a geodesic curve representing a flight from A to B. Found reference [1] which provided the maths for the answer.
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
This returns a locationCollection which can be added to your mapPolyline
Upvotes: 0
Reputation: 17954
Alternatively to using geodesic, if you don't care about being spatially accurate you can take your coordinates, convert them to pixel coordinates at zoom level 19 using the code here: https://msdn.microsoft.com/en-us/library/bb259689.aspx
Then pass the pixel coordinates through a standard Bezier curve algorithm. Take the resulting values and convert them back to locations.
Upvotes: 0
Reputation: 56
Bing Maps does not support curved geometries directly, so instead can approximate the shape of a curved line by creating a polyline containing several small segments.
Hope this article will help https://alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/
Upvotes: 0