2023-04-06 01:29:30 +02:00
|
|
|
using System.Text.Json.Serialization;
|
2023-03-30 18:24:57 +02:00
|
|
|
|
2023-04-09 17:06:45 +02:00
|
|
|
namespace OSMDatastructure;
|
2023-03-30 18:24:57 +02:00
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class TagManager
|
|
|
|
{
|
2023-04-06 01:29:30 +02:00
|
|
|
[JsonRequired]public Dictionary<ulong, HashSet<Tag>> wayTagSets { get; set; }
|
|
|
|
|
|
|
|
public TagManager()
|
|
|
|
{
|
|
|
|
wayTagSets = new();
|
|
|
|
}
|
2023-03-30 18:24:57 +02:00
|
|
|
|
|
|
|
public bool ContainsKey(ulong wayId, Tag.TagType key)
|
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
return wayTagSets.ContainsKey(wayId) && wayTagSets[wayId].Any(tag => tag.key == key);
|
2023-03-30 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public object? GetTag(ulong wayId, Tag.TagType key)
|
|
|
|
{
|
2023-04-01 14:21:39 +02:00
|
|
|
return ContainsKey(wayId, key) ? wayTagSets[wayId].First(tag => tag.key == key).value : null;
|
2023-03-30 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddTag(ulong wayId, string key, string value)
|
|
|
|
{
|
2023-04-09 22:10:23 +02:00
|
|
|
HashSet<Tag> pTags = Tag.ConvertToTags(key, value);
|
2023-04-09 23:55:24 +02:00
|
|
|
if(pTags.Count > 0)
|
|
|
|
foreach (Tag pTag in pTags)
|
|
|
|
AddTag(wayId, pTag);
|
2023-03-30 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddTag(ulong wayId, Tag tag)
|
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
if(!wayTagSets.ContainsKey(wayId))
|
|
|
|
wayTagSets.Add(wayId, new HashSet<Tag>());
|
|
|
|
HashSet<Tag> wayTags = wayTagSets[wayId];
|
|
|
|
if (!wayTags.Any(wayTag => wayTag.key == tag.key))
|
2023-03-30 18:24:57 +02:00
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
wayTags.Add(tag);
|
2023-03-30 18:24:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-01 01:31:58 +02:00
|
|
|
public void AddTag(ulong wayId, KeyValuePair<Tag.TagType, dynamic> tag)
|
2023-03-31 21:54:01 +02:00
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
AddTag(wayId, new Tag(tag.Key, tag.Value));
|
2023-03-31 21:54:01 +02:00
|
|
|
}
|
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
public HashSet<Tag>? GetTagsForWayId(ulong wayId)
|
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
return wayTagSets.TryGetValue(wayId, out HashSet<Tag>? value) ? value : null;
|
2023-03-30 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool ContainsWay(ulong wayId)
|
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
return wayTagSets.ContainsKey(wayId);
|
2023-03-30 18:24:57 +02:00
|
|
|
}
|
|
|
|
}
|