/// <summary> /// Creates a KML placemark of the given site. /// </summary> /// <param name="site">The site to convert.</param> /// <param name="styleUrl">The URI of the shared style to use. Null for not to add any style URL.</param> /// <returns>The placemark object reflecting the site.</returns> public static Placemark ToKmlPlacemark(this IHamnetDbSite site, Uri styleUrl = null) { if (site == null) { throw new ArgumentNullException(nameof(site), "site is null"); } var pm = new Placemark { Name = site.Callsign?.ToUpperInvariant(), Id = site.Callsign?.ToUpperInvariant(), // we use callsign for unique ID - must see if that works out Description = new Description { Text = $@"<h2>{site.Callsign?.ToUpperInvariant()}:</h2> <table> <tr><td class=""left"">latitude: </td><td>{site.Latitude}°</td></tr> <tr><td class=""left"">longitude: </td><td>{site.Longitude}°</td></tr> <tr><td class=""left"">ground asl: </td><td>{site.GroundAboveSeaLevel} m</td></tr> <tr><td class=""left"">elevation: </td><td>{site.Elevation} m</td></tr> <tr><td class=""left"">abs. altitude: </td><td>{site.Altitude} m</td></tr> </table> <p>Comment:</p> <p>{site.Comment.Replace("\n", "<br/>")}</p> " }, Geometry = site.ToKmlPoint() }; if (styleUrl != null) { pm.StyleUrl = styleUrl; } return(pm); }
private string ExecuteInternal() { IHamnetDbSite fromSite = string.IsNullOrWhiteSpace(this.fromCall) ? new RawSiteFromFromQuery(this.fromLocation) : this.GetSiteForCall(this.fromCall); IHamnetDbSite toSite = string.IsNullOrWhiteSpace(this.toCall) ? new RawSiteFromToQuery(this.toLocation) : this.GetSiteForCall(this.toCall); var kmlGenerator = new SingleLinkViewKmlGenerator(fromSite, toSite); var kmlString = kmlGenerator.GenerateString(); return(kmlString); }
/// <summary> /// Initializes a new instance for a link between the two given locations. /// </summary> /// <param name="from"> /// The from site for the link.<br/> /// This site will also become the initial camera position. /// </param> /// <param name="to"> /// The to site for the link.<br/> /// The heading to this site will be the initial camera view direction. /// </param> public SingleLinkViewKmlGenerator(IHamnetDbSite from, IHamnetDbSite to) { // a lot of work to make sure we get at least half-way consistent data this.To = to ?? throw new ArgumentNullException(nameof(to), "to site is null"); this.From = from ?? throw new ArgumentNullException(nameof(from), "from site is null"); if (double.IsNaN(this.From.Altitude) || !double.IsFinite(this.From.Altitude)) { throw new ArgumentOutOfRangeException(nameof(from), "The Altitude property of the From location is NaN or inifite. Make sure both, ground above sea level _and_ elevation are set properly"); } if (double.IsNaN(this.From.Latitude) || !double.IsFinite(this.From.Latitude)) { throw new ArgumentOutOfRangeException(nameof(from), "The Latitude property of the From location is NaN or inifite"); } if (double.IsNaN(this.From.Longitude) || !double.IsFinite(this.From.Longitude)) { throw new ArgumentOutOfRangeException(nameof(from), "The Longitude property of the From location is NaN or inifite"); } if (double.IsNaN(this.To.Altitude) || !double.IsFinite(this.To.Altitude)) { throw new ArgumentOutOfRangeException(nameof(to), "The Altitude property of the To location is NaN or inifite. Make sure both, ground above sea level _and_ elevation are set properly"); } if (double.IsNaN(this.To.Latitude) || !double.IsFinite(this.To.Latitude)) { throw new ArgumentOutOfRangeException(nameof(to), "The Latitude property of the To location is NaN or inifite"); } if (double.IsNaN(this.To.Longitude) || !double.IsFinite(this.To.Longitude)) { throw new ArgumentOutOfRangeException(nameof(to), "The Longitude property of the To location is NaN or inifite"); } }