public static RouteResult FromJson(JsonObject jsonObject)
{
if (jsonObject == null)
{
return null;
}
RouteResult result = new RouteResult();
#region Bounds
if (jsonObject["bounds"] != null)
{
double mbMinX = (double)jsonObject["bounds"]["leftBottom"]["x"];
double mbMinY = (double)jsonObject["bounds"]["leftBottom"]["y"];
double mbMaxX = (double)jsonObject["bounds"]["rightTop"]["x"];
double mbMaxY = (double)jsonObject["bounds"]["rightTop"]["y"];
result.Bounds = new Rectangle2D(mbMinX, mbMinY, mbMaxX, mbMaxY);
}
#endregion
#region Costs
JsonArray costsInJson = (JsonArray)jsonObject["costs"];
if (costsInJson != null && costsInJson.Count > 0)
{
result.Costs = new List<double>();
for (int i = 0; i < costsInJson.Count; i++)
{
result.Costs.Add((double)costsInJson[i]);
}
}
#endregion
#region EdgeIDs
JsonArray edgeIDsInJson = (JsonArray)jsonObject["edgeIDs"];
if (edgeIDsInJson != null && edgeIDsInJson.Count > 0)
{
result.EdgeIDs = new List<int>();
for (int i = 0; i < edgeIDsInJson.Count; i++)
{
result.EdgeIDs.Add((int)edgeIDsInJson[i]);
}
}
#endregion
#region NodeIDs
JsonArray nodeIDsInJson = (JsonArray)jsonObject["nodeIDs"];
if (nodeIDsInJson != null && nodeIDsInJson.Count > 0)
{
result.NodeIDs = new List<int>();
for (int i = 0; i < nodeIDsInJson.Count; i++)
{
result.NodeIDs.Add((int)nodeIDsInJson[i]);
}
}
#endregion
#region NodePositions
JsonArray nodePositionsInJson = (JsonArray)jsonObject["nodePositions"];
if (nodePositionsInJson != null && nodePositionsInJson.Count > 0)
{
result.NodePositions = new Point2DCollection();
for (int i = 0; i < nodePositionsInJson.Count; i++)
{
result.NodePositions.Add(new Point2D(nodePositionsInJson[i]["x"], nodePositionsInJson[i]["y"]));
}
}
#endregion
#region PathGuides
JsonArray pathGuidesInJson = (JsonArray)jsonObject["pathGuides"];
if (pathGuidesInJson != null && pathGuidesInJson.Count > 0)
{
result.PathGuides = new List<PathGuide>();
for (int i = 0; i < pathGuidesInJson.Count; i++)
{
PathGuide pg = PathGuide.FromJson((JsonObject)pathGuidesInJson[i]);
result.PathGuides.Add(pg);
}
}
#endregion
result.PathTable = DataTable.FromJson((JsonObject)jsonObject["pathTable"]);
result.TotalLength = (double)jsonObject["totalLength"];
//result.TrackingLayerIndex = (int)jsonObject["trackingLayerIndex"];
//result.UserID = (string)jsonObject["userID"];
return result;
}