1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
// License: BSD/LGPL
// Copyright (C) 2011-2018 Thomas d'Otreppe
using System;
using System.Collections;
using System.Text;
namespace WirelessPanda
{
public class Coordinates
{
#region Dictionary stuff
private Hashtable _dictionary = new Hashtable();
private void setDictValue(string elem, double value)
{
if (this._dictionary.ContainsKey(elem))
{
this._dictionary.Remove(elem);
}
this._dictionary.Add(elem, value);
}
private double getDictValue(string elem)
{
if (this._dictionary.ContainsKey(elem))
{
return (double)this._dictionary[elem];
}
throw new MissingFieldException("Value <" + elem + "> is not set or does not exist");
}
#endregion
#region Properties
/// <summary>
/// Latitude
/// </summary>
public double Latitude
{
get
{
return this.getDictValue("Latitude");
}
set
{
this.setDictValue("Latitude", value);
}
}
/// <summary>
/// Longitude
/// </summary>
public double Longitude
{
get
{
return this.getDictValue("Longitude");
}
set
{
this.setDictValue("Longitude", value);
}
}
/// <summary>
/// Altitude (in meters)
/// </summary>
public double Altitude
{
get
{
return this.getDictValue("Altitude");
}
set
{
this.setDictValue("Altitude", value);
}
}
/// <summary>
/// Speed (UOM: probably knot but unsure)
/// </summary>
public double Speed
{
get
{
return this.getDictValue("Speed");
}
set
{
this.setDictValue("Speed", value);
}
}
#endregion
public Coordinates(string latitude = null, string longitude = null, string altitude = null, string speed = null)
{
if (!string.IsNullOrEmpty(latitude))
{
this.Latitude = double.Parse(latitude);
}
if (!string.IsNullOrEmpty(longitude))
{
this.Longitude = double.Parse(longitude);
}
if (!string.IsNullOrEmpty(altitude))
{
this.Altitude = double.Parse(altitude);
}
if (!string.IsNullOrEmpty(speed))
{
this.Speed = double.Parse(speed);
}
}
public Coordinates(double latitude, double longitude)
{
this.Latitude = latitude;
}
public Coordinates(double latitude, double longitude, double altitude) : this(latitude, longitude)
{
this.Altitude = latitude;
}
public Coordinates(double latitude, double longitude, double altitude, double speed) : this(latitude, longitude, altitude)
{
this.Speed = speed;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
try
{
sb.Append(this.Latitude);
sb.Append(", ");
sb.Append(this.Longitude);
if (this._dictionary.ContainsKey("Altitude"))
{
sb.Append(" - Altitude: ");
sb.Append(this.Altitude);
}
if (this._dictionary.ContainsKey("Speed"))
{
sb.Append(" - Speed: ");
sb.Append(this.Speed);
}
}
catch
{
if (sb.Length > 0)
{
sb.Remove(0, sb.Length);
}
}
return sb.ToString();
}
}
}
|