| | 1 | | namespace Itinero.Geo.Elevation; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Contains extension methods to add/handle elevation. |
| | 5 | | /// </summary> |
| | 6 | | public static class ElevationHandlerExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Adds elevation to a given coordinate. |
| | 10 | | /// </summary> |
| | 11 | | /// <param name="coordinate">The coordinate.</param> |
| | 12 | | /// <param name="estimate">The estimate value if there is no handler configured.</param> |
| | 13 | | /// <param name="elevationHandler">The elevation handler, if null, the default will be used.</param> |
| | 14 | | /// <returns>The same coordinate but with an elevation component is available.</returns> |
| | 15 | | public static (double lon, double lat, float? e) AddElevation(this (double lon, double lat) coordinate, |
| | 16 | | float? estimate = null, IElevationHandler? elevationHandler = null) |
| 210 | 17 | | { |
| 210 | 18 | | elevationHandler ??= ElevationHandler.Default; |
| | 19 | |
|
| 210 | 20 | | var e = elevationHandler?.Elevation(coordinate.lon, coordinate.lat) |
| 210 | 21 | | ?? estimate; |
| | 22 | |
|
| 210 | 23 | | return (coordinate.lon, coordinate.lat, e); |
| 210 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Adds elevation to a given coordinate. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="coordinate">The coordinate.</param> |
| | 30 | | /// <param name="estimate">The estimate value if there is no handler configured.</param> |
| | 31 | | /// <param name="elevationHandler">The elevation handler, if null, the default will be used.</param> |
| | 32 | | /// <returns>The same coordinate but with an elevation component is available.</returns> |
| | 33 | | public static (double lon, double lat, float? e) AddElevation( |
| | 34 | | this (double lon, double lat, float? e) coordinate, |
| | 35 | | float? estimate = null, IElevationHandler? elevationHandler = null) |
| 2 | 36 | | { |
| 2 | 37 | | if (coordinate.e != null) |
| 0 | 38 | | { |
| 0 | 39 | | return coordinate; |
| | 40 | | } |
| | 41 | |
|
| 2 | 42 | | return (coordinate.lon, coordinate.lat).AddElevation(estimate, elevationHandler); |
| 2 | 43 | | } |
| | 44 | | } |