2023-03-30 18:24:57 +02:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
namespace OSMDatastructure.Graph;
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class TagManager
|
|
|
|
{
|
|
|
|
public readonly Dictionary<ulong, HashSet<Tag>> wayTags = new();
|
|
|
|
|
|
|
|
public bool ContainsKey(ulong wayId, Tag.TagType key)
|
|
|
|
{
|
|
|
|
return wayTags.ContainsKey(wayId) && wayTags[wayId].Any(tag => tag.key == key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public object? GetTag(ulong wayId, Tag.TagType key)
|
|
|
|
{
|
|
|
|
return ContainsKey(wayId, key) ? wayTags[wayId].First(tag => tag.key == key) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddTag(ulong wayId, string key, string value)
|
|
|
|
{
|
|
|
|
Tag tag = Tag.ConvertToTag(key, value);
|
|
|
|
AddTag(wayId, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddTag(ulong wayId, Tag tag)
|
|
|
|
{
|
|
|
|
if (tag.key != Tag.TagType.EMPTY)
|
|
|
|
{
|
|
|
|
if(!wayTags.ContainsKey(wayId))
|
|
|
|
wayTags.Add(wayId, new HashSet<Tag>());
|
|
|
|
wayTags[wayId].Add(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 21:54:01 +02:00
|
|
|
public void AddTag(ulong wayId, KeyValuePair<Tag.TagType, dynamic> keyValuePair)
|
|
|
|
{
|
|
|
|
if(!wayTags.ContainsKey(wayId))
|
|
|
|
wayTags.Add(wayId, new HashSet<Tag>());
|
|
|
|
wayTags[wayId].Add(new Tag(keyValuePair.Key, keyValuePair.Value));
|
|
|
|
}
|
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
public HashSet<Tag>? GetTagsForWayId(ulong wayId)
|
|
|
|
{
|
|
|
|
return wayTags.TryGetValue(wayId, out HashSet<Tag>? value) ? value : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ContainsWay(ulong wayId)
|
|
|
|
{
|
|
|
|
return wayTags.ContainsKey(wayId);
|
|
|
|
}
|
|
|
|
}
|