Here's the class for OnlineMapsOSMArea. It's basically OnlineMapsOSMNode with the lat/long stripped away and the name changed.
/// <summary>
/// Open Street Map area element class
/// </summary>
public class OnlineMapsOSMArea : OnlineMapsOSMBase
{
public OnlineMapsOSMArea(OnlineMapsOSMAPIQuery.OSMXMLNode node)
{
id = node.GetAttribute("id");
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="node">Node</param>
public OnlineMapsOSMArea(OnlineMapsXML node)
{
id = node.A("id");
tags = new List<OnlineMapsOSMTag>(node.count);
foreach (OnlineMapsXML subNode in node) tags.Add(new OnlineMapsOSMTag(subNode));
}
}
And here's the changed versions of the two ParseOSMResponse routines.
/// <summary>
/// Get data from the response Open Street Map Overpass API.
/// </summary>
/// <param name="response">Response from Overpass API</param>
/// <param name="nodes">List of nodes</param>
/// <param name="ways">List of ways</param>
/// <param name="relations">List of relations</param>
public static void ParseOSMResponse(string response, out List<OnlineMapsOSMNode> nodes, out List<OnlineMapsOSMWay> ways, out List<OnlineMapsOSMRelation> relations, out List<OnlineMapsOSMArea> areas)
{
nodes = new List<OnlineMapsOSMNode>();
ways = new List<OnlineMapsOSMWay>();
relations = new List<OnlineMapsOSMRelation>();
areas = new List<OnlineMapsOSMArea>();
try
{
OnlineMapsXML xml = OnlineMapsXML.Load(response);
foreach (OnlineMapsXML node in xml)
{
if (node.name == "node") nodes.Add(new OnlineMapsOSMNode(node));
else if (node.name == "way") ways.Add(new OnlineMapsOSMWay(node));
else if (node.name == "relation") relations.Add(new OnlineMapsOSMRelation(node));
else if (node.name == "area") areas.Add(new OnlineMapsOSMArea(node));
}
}
catch
{
Debug.Log(response);
}
}
/// <summary>
/// Get data from the response Open Street Map Overpass API.
/// </summary>
/// <param name="response">Response from Overpass API</param>
/// <param name="nodes">Dictionary of nodes</param>
/// <param name="ways">List of ways</param>
/// <param name="relations">List of relations</param>
public static void ParseOSMResponse(string response, out Dictionary<string, OnlineMapsOSMNode> nodes, out List<OnlineMapsOSMWay> ways, out List<OnlineMapsOSMRelation> relations, out List<OnlineMapsOSMArea> areas)
{
nodes = new Dictionary<string, OnlineMapsOSMNode>(64);
ways = new List<OnlineMapsOSMWay>(64);
relations = new List<OnlineMapsOSMRelation>(64);
areas = new List<OnlineMapsOSMArea>(64); // why do we specify a length of 64 here but not in the other ParseOSMResponse?
try
{
OnlineMapsXML xml = OnlineMapsXML.Load(response);
foreach (OnlineMapsXML node in xml)
{
if (node.name == "node")
{
OnlineMapsOSMNode osmNode = new OnlineMapsOSMNode(node);
nodes.Add(osmNode.id, osmNode);
}
else if (node.name == "way")
{
ways.Add(new OnlineMapsOSMWay(node));
}
else if (node.name == "relation")
{
relations.Add(new OnlineMapsOSMRelation(node));
}
else if (node.name == "area")
{
areas.Add(new OnlineMapsOSMArea(node));
}
}
}
catch
{
Debug.Log(response);
}
}
I didn't implement the change in ParseOSMResponseFast because that was a bit more involved, but you might want to if you decide to incorporate area elements into the base code. Also, a quick question you might have noticed in a comment in the code- why in the overload that uses a Dictionary for the nodes do you set both Dictionary and Lists to a size of 64 when declaring them? Just curious.
I've tested the code here and it appears to be functional. I would love it if you were to incorporate it, as it might be useful to others, and it would keep me from having to pull it out into its own script inheriting from OnlineMapsOSMAPIQuery so as not to get overwritten whenever I update your code.
Thanks again, and I hope this proves useful, especially considering how much example code you provide to those using your asset.