Files
@ bd55ba5f4fde
Branch filter:
Location: seniordesign-ui/GMap.NET.Core/GMap.NET/MapRoute.cs
bd55ba5f4fde
4.3 KiB
text/x-csharp
data display is 'finished'. charts are working. minor fixes also done
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 |
namespace GMap.NET
{
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using GMap.NET.MapProviders;
/// <summary>
/// represents route of map
/// </summary>
[Serializable]
#if !PocketPC
public class MapRoute : ISerializable, IDeserializationCallback
#else
public class MapRoute
#endif
{
/// <summary>
/// points of route
/// </summary>
public readonly List<PointLatLng> Points = new List<PointLatLng>();
/// <summary>
/// route info
/// </summary>
public string Name;
/// <summary>
/// custom object
/// </summary>
public object Tag;
/// <summary>
/// route start point
/// </summary>
public PointLatLng? From
{
get
{
if(Points.Count > 0)
{
return Points[0];
}
return null;
}
}
/// <summary>
/// route end point
/// </summary>
public PointLatLng? To
{
get
{
if(Points.Count > 1)
{
return Points[Points.Count - 1];
}
return null;
}
}
public MapRoute(string name)
{
Name = name;
}
public MapRoute(IEnumerable<PointLatLng> points, string name)
{
Points.AddRange(points);
Name = name;
}
/// <summary>
/// route distance (in km)
/// </summary>
public double Distance
{
get
{
double distance = 0.0;
if(From.HasValue && To.HasValue)
{
for(int i = 1; i < Points.Count; i++)
{
distance += GMapProviders.EmptyProvider.Projection.GetDistance(Points[i - 1], Points[i]);
}
}
return distance;
}
}
/// <summary>
/// clears points and sets tag and name to null
/// </summary>
public void Clear()
{
Points.Clear();
Tag = null;
Name = null;
}
#if !PocketPC
#region ISerializable Members
// Temp store for de-serialization.
private PointLatLng[] deserializedPoints;
/// <summary>
/// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization.</param>
/// <exception cref="T:System.Security.SecurityException">
/// The caller does not have the required permission.
/// </exception>
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Name", this.Name);
info.AddValue("Tag", this.Tag);
info.AddValue("Points", this.Points.ToArray());
}
/// <summary>
/// Initializes a new instance of the <see cref="MapRoute"/> class.
/// </summary>
/// <param name="info">The info.</param>
/// <param name="context">The context.</param>
protected MapRoute(SerializationInfo info, StreamingContext context)
{
this.Name = info.GetString("Name");
this.Tag = Extensions.GetValue<object>(info, "Tag", null);
this.deserializedPoints = Extensions.GetValue<PointLatLng[]>(info, "Points");
this.Points = new List<PointLatLng>();
}
#endregion
#region IDeserializationCallback Members
/// <summary>
/// Runs when the entire object graph has been de-serialized.
/// </summary>
/// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
public virtual void OnDeserialization(object sender)
{
// Accounts for the de-serialization being breadth first rather than depth first.
Points.AddRange(deserializedPoints);
Points.TrimExcess();
}
#endregion
#endif
}
}
|