OSMServer/OSMDatastructure/TagManager.cs

52 lines
1.4 KiB
C#
Raw Normal View History

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);
}
}
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));
}
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);
}
}